4
from numpy.testing import *
6
import numpy.lib;reload(numpy.lib);reload(numpy.lib.type_check)
7
from numpy.lib import *
8
from numpy.core import *
14
class test_mintypecode(ScipyTestCase):
16
def check_default_1(self):
17
for itype in '1bcsuwil':
18
assert_equal(mintypecode(itype),'d')
19
assert_equal(mintypecode('f'),'f')
20
assert_equal(mintypecode('d'),'d')
21
assert_equal(mintypecode('F'),'F')
22
assert_equal(mintypecode('D'),'D')
24
def check_default_2(self):
25
for itype in '1bcsuwil':
26
assert_equal(mintypecode(itype+'f'),'f')
27
assert_equal(mintypecode(itype+'d'),'d')
28
assert_equal(mintypecode(itype+'F'),'F')
29
assert_equal(mintypecode(itype+'D'),'D')
30
assert_equal(mintypecode('ff'),'f')
31
assert_equal(mintypecode('fd'),'d')
32
assert_equal(mintypecode('fF'),'F')
33
assert_equal(mintypecode('fD'),'D')
34
assert_equal(mintypecode('df'),'d')
35
assert_equal(mintypecode('dd'),'d')
36
#assert_equal(mintypecode('dF',savespace=1),'F')
37
assert_equal(mintypecode('dF'),'D')
38
assert_equal(mintypecode('dD'),'D')
39
assert_equal(mintypecode('Ff'),'F')
40
#assert_equal(mintypecode('Fd',savespace=1),'F')
41
assert_equal(mintypecode('Fd'),'D')
42
assert_equal(mintypecode('FF'),'F')
43
assert_equal(mintypecode('FD'),'D')
44
assert_equal(mintypecode('Df'),'D')
45
assert_equal(mintypecode('Dd'),'D')
46
assert_equal(mintypecode('DF'),'D')
47
assert_equal(mintypecode('DD'),'D')
49
def check_default_3(self):
50
assert_equal(mintypecode('fdF'),'D')
51
#assert_equal(mintypecode('fdF',savespace=1),'F')
52
assert_equal(mintypecode('fdD'),'D')
53
assert_equal(mintypecode('fFD'),'D')
54
assert_equal(mintypecode('dFD'),'D')
56
assert_equal(mintypecode('ifd'),'d')
57
assert_equal(mintypecode('ifF'),'F')
58
assert_equal(mintypecode('ifD'),'D')
59
assert_equal(mintypecode('idF'),'D')
60
#assert_equal(mintypecode('idF',savespace=1),'F')
61
assert_equal(mintypecode('idD'),'D')
63
class test_isscalar(ScipyTestCase):
64
def check_basic(self):
66
assert(not isscalar([3]))
67
assert(not isscalar((3,)))
72
class test_real(ScipyTestCase):
75
assert_array_equal(y,real(y))
77
def check_cmplx(self):
78
y = rand(10,)+1j*rand(10,)
79
assert_array_equal(y.real,real(y))
81
class test_imag(ScipyTestCase):
84
assert_array_equal(0,imag(y))
86
def check_cmplx(self):
87
y = rand(10,)+1j*rand(10,)
88
assert_array_equal(y.imag,imag(y))
90
class test_iscomplex(ScipyTestCase):
94
assert(not sometrue(res))
98
assert_array_equal(res,[1,0,0])
100
class test_isreal(ScipyTestCase):
101
def check_pass(self):
104
assert_array_equal(res,[1,1,0])
105
def check_fail(self):
108
assert_array_equal(res,[0,1,1])
110
class test_iscomplexobj(ScipyTestCase):
111
def check_basic(self):
113
assert(not iscomplexobj(z))
114
z = array([-1j,0,-1])
115
assert(iscomplexobj(z))
117
class test_isrealobj(ScipyTestCase):
118
def check_basic(self):
121
z = array([-1j,0,-1])
122
assert(not isrealobj(z))
124
class test_isnan(ScipyTestCase):
125
def check_goodvalues(self):
126
z = array((-1.,0.,1.))
128
assert_all(alltrue(res))
129
def check_posinf(self):
130
assert_all(isnan(array((1.,))/0.) == 0)
131
def check_neginf(self):
132
assert_all(isnan(array((-1.,))/0.) == 0)
134
assert_all(isnan(array((0.,))/0.) == 1)
135
#def check_qnan(self): log(-1) return pi*j now
136
# assert_all(isnan(log(-1.)) == 1)
137
def check_integer(self):
138
assert_all(isnan(1) == 0)
139
def check_complex(self):
140
assert_all(isnan(1+1j) == 0)
141
def check_complex1(self):
142
assert_all(isnan(array(0+0j)/0.) == 1)
144
class test_isfinite(ScipyTestCase):
145
def check_goodvalues(self):
146
z = array((-1.,0.,1.))
147
res = isfinite(z) == 1
148
assert_all(alltrue(res))
149
def check_posinf(self):
150
assert_all(isfinite(array((1.,))/0.) == 0)
151
def check_neginf(self):
152
assert_all(isfinite(array((-1.,))/0.) == 0)
154
assert_all(isfinite(array((0.,))/0.) == 0)
155
#def check_qnan(self):
156
# assert_all(isfinite(log(-1.)) == 0)
157
def check_integer(self):
158
assert_all(isfinite(1) == 1)
159
def check_complex(self):
160
assert_all(isfinite(1+1j) == 1)
161
def check_complex1(self):
162
assert_all(isfinite(array(1+1j)/0.) == 0)
164
class test_isinf(ScipyTestCase):
165
def check_goodvalues(self):
166
z = array((-1.,0.,1.))
168
assert_all(alltrue(res))
169
def check_posinf(self):
170
assert_all(isinf(array((1.,))/0.) == 1)
171
def check_posinf_scalar(self):
172
assert_all(isinf(array(1.,)/0.) == 1)
173
def check_neginf(self):
174
assert_all(isinf(array((-1.,))/0.) == 1)
175
def check_neginf_scalar(self):
176
assert_all(isinf(array(-1.)/0.) == 1)
178
assert_all(isinf(array((0.,))/0.) == 0)
179
#def check_qnan(self):
180
# assert_all(isinf(log(-1.)) == 0)
181
# assert_all(isnan(log(-1.)) == 1)
183
class test_isposinf(ScipyTestCase):
184
def check_generic(self):
185
vals = isposinf(array((-1.,0,1))/0.)
190
class test_isneginf(ScipyTestCase):
191
def check_generic(self):
192
vals = isneginf(array((-1.,0,1))/0.)
197
class test_nan_to_num(ScipyTestCase):
198
def check_generic(self):
199
vals = nan_to_num(array((-1.,0,1))/0.)
200
assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))
202
assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))
203
def check_integer(self):
205
assert_all(vals == 1)
206
def check_complex_good(self):
207
vals = nan_to_num(1+1j)
208
assert_all(vals == 1+1j)
209
def check_complex_bad(self):
213
# !! This is actually (unexpectedly) zero
214
assert_all(isfinite(vals))
215
def check_complex_bad2(self):
217
v += array(-1+1.j)/0.
219
assert_all(isfinite(vals))
220
#assert_all(vals.imag > 1e10) and assert_all(isfinite(vals))
221
# !! This is actually (unexpectedly) positive
222
# !! inf. Comment out for now, and see if it
224
#assert_all(vals.real < -1e10) and assert_all(isfinite(vals))
227
class test_real_if_close(ScipyTestCase):
228
def check_basic(self):
230
b = real_if_close(a+1e-15j)
231
assert_all(isrealobj(b))
232
assert_array_equal(a,b)
233
b = real_if_close(a+1e-7j)
234
assert_all(iscomplexobj(b))
235
b = real_if_close(a+1e-7j,tol=1e-6)
236
assert_all(isrealobj(b))
238
if __name__ == "__main__":