~jtaylor/ubuntu/precise/python-numpy/multiarch-fix-818867

« back to all changes in this revision

Viewing changes to numpy/core/tests/test_ufunc.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik, Riku Voipio, Tiziano Zito, Carlos Galisteo, Ondrej Certik
  • Date: 2008-07-08 15:08:16 UTC
  • mfrom: (0.1.21 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080708150816-ekf992jcp2k1eua3
Tags: 1:1.1.0-3
[ Riku Voipio ]
* debian/control: atlas is not available on armel, and after a quick look
  neither on alpha. I'd also suggest dropping
  libatlas-sse-dev|libatlas-sse2-dev|libatlas-3dnow-dev alternative combo
  away, these are potentially dangerous on buildd's. Ondrej: dropped.
  (Closes: #489568)

[ Tiziano Zito ]
* patch: build _dotblas.c when ATLAS is not installed, build-conflict with
  atlas, build-depend on blas+lapack only, as it used to be (Closes: #489726)

[ Carlos Galisteo ]
* debian/control
  - Added Homepage field.

[ Ondrej Certik ]
* Checked the package on i386 and amd64, both with and without atlas, all
  tests run and the numpy package is faster if atlas is around. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import numpy as np
 
2
from numpy.testing import *
 
3
 
 
4
class TestUfunc(NumpyTestCase):
 
5
    def test_reduceat_shifting_sum(self) :
 
6
        L = 6
 
7
        x = np.arange(L)
 
8
        idx = np.array(zip(np.arange(L-2), np.arange(L-2)+2)).ravel()
 
9
        assert_array_equal(np.add.reduceat(x,idx)[::2],
 
10
                           [1,3,5,7])
 
11
    def check_generic_loops(self) :
 
12
        """Test generic loops.
 
13
 
 
14
        The loops to be tested are:
 
15
 
 
16
            PyUFunc_ff_f_As_dd_d
 
17
            PyUFunc_ff_f
 
18
            PyUFunc_dd_d
 
19
            PyUFunc_gg_g
 
20
            PyUFunc_FF_F_As_DD_D
 
21
            PyUFunc_DD_D
 
22
            PyUFunc_FF_F
 
23
            PyUFunc_GG_G
 
24
            PyUFunc_OO_O
 
25
            PyUFunc_OO_O_method
 
26
            PyUFunc_f_f_As_d_d
 
27
            PyUFunc_d_d
 
28
            PyUFunc_f_f
 
29
            PyUFunc_g_g
 
30
            PyUFunc_F_F_As_D_D
 
31
            PyUFunc_F_F
 
32
            PyUFunc_D_D
 
33
            PyUFunc_G_G
 
34
            PyUFunc_O_O
 
35
            PyUFunc_O_O_method
 
36
            PyUFunc_On_Om
 
37
 
 
38
        Where:
 
39
 
 
40
            f -- float
 
41
            d -- double
 
42
            g -- long double
 
43
            F -- complex float
 
44
            D -- complex double
 
45
            G -- complex long double
 
46
            O -- python object
 
47
 
 
48
        It is difficult to assure that each of these loops is entered from the
 
49
        Python level as the special cased loops are a moving target and the
 
50
        corresponding types are architecture dependent. We probably need to
 
51
        define C level testing ufuncs to get at them. For the time being, I've
 
52
        just looked at the signatures registered in the build directory to find
 
53
        relevant functions.
 
54
 
 
55
        Fixme, currently untested:
 
56
 
 
57
            PyUFunc_ff_f_As_dd_d
 
58
            PyUFunc_FF_F_As_DD_D
 
59
            PyUFunc_f_f_As_d_d
 
60
            PyUFunc_F_F_As_D_D
 
61
            PyUFunc_On_Om
 
62
 
 
63
        """
 
64
        fone = np.exp
 
65
        ftwo = lambda x,y : x**y
 
66
        fone_val = 1
 
67
        ftwo_val = 1
 
68
        # check unary PyUFunc_f_f.
 
69
        msg = "PyUFunc_f_f"
 
70
        x = np.zeros(10, dtype=np.single)[0::2]
 
71
        assert_almost_equal(fone(x), fone_val, err_msg=msg)
 
72
        # check unary PyUFunc_d_d.
 
73
        msg = "PyUFunc_d_d"
 
74
        x = np.zeros(10, dtype=np.double)[0::2]
 
75
        assert_almost_equal(fone(x), fone_val, err_msg=msg)
 
76
        # check unary PyUFunc_g_g.
 
77
        msg = "PyUFunc_g_g"
 
78
        x = np.zeros(10, dtype=np.longdouble)[0::2]
 
79
        assert_almost_equal(fone(x), fone_val, err_msg=msg)
 
80
        # check unary PyUFunc_F_F.
 
81
        msg = "PyUFunc_F_F"
 
82
        x = np.zeros(10, dtype=np.csingle)[0::2]
 
83
        assert_almost_equal(fone(x), fone_val, err_msg=msg)
 
84
        # check unary PyUFunc_D_D.
 
85
        msg = "PyUFunc_D_D"
 
86
        x = np.zeros(10, dtype=np.cdouble)[0::2]
 
87
        assert_almost_equal(fone(x), fone_val, err_msg=msg)
 
88
        # check unary PyUFunc_G_G.
 
89
        msg = "PyUFunc_G_G"
 
90
        x = np.zeros(10, dtype=np.clongdouble)[0::2]
 
91
        assert_almost_equal(fone(x), fone_val, err_msg=msg)
 
92
 
 
93
        # check binary PyUFunc_ff_f.
 
94
        msg = "PyUFunc_ff_f"
 
95
        x = np.ones(10, dtype=np.single)[0::2]
 
96
        assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
 
97
        # check binary PyUFunc_dd_d.
 
98
        msg = "PyUFunc_dd_d"
 
99
        x = np.ones(10, dtype=np.double)[0::2]
 
100
        assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
 
101
        # check binary PyUFunc_gg_g.
 
102
        msg = "PyUFunc_gg_g"
 
103
        x = np.ones(10, dtype=np.longdouble)[0::2]
 
104
        assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
 
105
        # check binary PyUFunc_FF_F.
 
106
        msg = "PyUFunc_FF_F"
 
107
        x = np.ones(10, dtype=np.csingle)[0::2]
 
108
        assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
 
109
        # check binary PyUFunc_DD_D.
 
110
        msg = "PyUFunc_DD_D"
 
111
        x = np.ones(10, dtype=np.cdouble)[0::2]
 
112
        assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
 
113
        # check binary PyUFunc_GG_G.
 
114
        msg = "PyUFunc_GG_G"
 
115
        x = np.ones(10, dtype=np.clongdouble)[0::2]
 
116
        assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
 
117
 
 
118
        # class to use in testing object method loops
 
119
        class foo :
 
120
            def logical_not(self) :
 
121
                return np.bool_(1)
 
122
            def logical_and(self, obj) :
 
123
                return np.bool_(1)
 
124
 
 
125
        # check unary PyUFunc_O_0
 
126
        msg = "PyUFunc_O_O"
 
127
        x = np.ones(10, dtype=np.object)[0::2]
 
128
        assert np.all(np.abs(x) == 1), msg
 
129
        # check unary PyUFunc_O_0_method
 
130
        msg = "PyUFunc_O_O_method"
 
131
        x = np.zeros(10, dtype=np.object)[0::2]
 
132
        for i in range(len(x)) :
 
133
            x[i] = foo()
 
134
        assert np.all(np.logical_not(x) == True), msg
 
135
 
 
136
        # check binary PyUFunc_OO_0
 
137
        msg = "PyUFunc_OO_O"
 
138
        x = np.ones(10, dtype=np.object)[0::2]
 
139
        assert np.all(np.add(x,x) == 2), msg
 
140
        # check binary PyUFunc_OO_0_method
 
141
        msg = "PyUFunc_OO_O_method"
 
142
        x = np.zeros(10, dtype=np.object)[0::2]
 
143
        for i in range(len(x)) :
 
144
            x[i] = foo()
 
145
        assert np.all(np.logical_and(x,x) == 1), msg
 
146
 
 
147
        # check PyUFunc_On_Om
 
148
        # fixme -- I don't know how to do this yet
 
149
 
 
150
if __name__ == "__main__":
 
151
    NumpyTest().run()