2
from numpy.testing import *
4
class TestUfunc(NumpyTestCase):
5
def test_reduceat_shifting_sum(self) :
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],
11
def check_generic_loops(self) :
12
"""Test generic loops.
14
The loops to be tested are:
45
G -- complex long double
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
55
Fixme, currently untested:
65
ftwo = lambda x,y : x**y
68
# check unary 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.
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.
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.
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.
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.
90
x = np.zeros(10, dtype=np.clongdouble)[0::2]
91
assert_almost_equal(fone(x), fone_val, err_msg=msg)
93
# check binary 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.
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.
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.
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.
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.
115
x = np.ones(10, dtype=np.clongdouble)[0::2]
116
assert_almost_equal(ftwo(x,x), ftwo_val, err_msg=msg)
118
# class to use in testing object method loops
120
def logical_not(self) :
122
def logical_and(self, obj) :
125
# check unary PyUFunc_O_0
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)) :
134
assert np.all(np.logical_not(x) == True), msg
136
# check binary PyUFunc_OO_0
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)) :
145
assert np.all(np.logical_and(x,x) == 1), msg
147
# check PyUFunc_On_Om
148
# fixme -- I don't know how to do this yet
150
if __name__ == "__main__":