annotate DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/ma/timer_comparison.py @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2a2c65a20a8b
children
rev   line source
Chris@87 1 from __future__ import division, absolute_import, print_function
Chris@87 2
Chris@87 3 import timeit
Chris@87 4 from functools import reduce
Chris@87 5
Chris@87 6 import numpy as np
Chris@87 7 from numpy import float_
Chris@87 8 import np.core.fromnumeric as fromnumeric
Chris@87 9
Chris@87 10 from np.testing.utils import build_err_msg
Chris@87 11
Chris@87 12 # Fixme: this does not look right.
Chris@87 13 np.seterr(all='ignore')
Chris@87 14
Chris@87 15 pi = np.pi
Chris@87 16
Chris@87 17
Chris@87 18 class moduletester(object):
Chris@87 19 def __init__(self, module):
Chris@87 20 self.module = module
Chris@87 21 self.allequal = module.allequal
Chris@87 22 self.arange = module.arange
Chris@87 23 self.array = module.array
Chris@87 24 # self.average = module.average
Chris@87 25 self.concatenate = module.concatenate
Chris@87 26 self.count = module.count
Chris@87 27 self.equal = module.equal
Chris@87 28 self.filled = module.filled
Chris@87 29 self.getmask = module.getmask
Chris@87 30 self.getmaskarray = module.getmaskarray
Chris@87 31 self.id = id
Chris@87 32 self.inner = module.inner
Chris@87 33 self.make_mask = module.make_mask
Chris@87 34 self.masked = module.masked
Chris@87 35 self.masked_array = module.masked_array
Chris@87 36 self.masked_values = module.masked_values
Chris@87 37 self.mask_or = module.mask_or
Chris@87 38 self.nomask = module.nomask
Chris@87 39 self.ones = module.ones
Chris@87 40 self.outer = module.outer
Chris@87 41 self.repeat = module.repeat
Chris@87 42 self.resize = module.resize
Chris@87 43 self.sort = module.sort
Chris@87 44 self.take = module.take
Chris@87 45 self.transpose = module.transpose
Chris@87 46 self.zeros = module.zeros
Chris@87 47 self.MaskType = module.MaskType
Chris@87 48 try:
Chris@87 49 self.umath = module.umath
Chris@87 50 except AttributeError:
Chris@87 51 self.umath = module.core.umath
Chris@87 52 self.testnames = []
Chris@87 53
Chris@87 54 def assert_array_compare(self, comparison, x, y, err_msg='', header='',
Chris@87 55 fill_value=True):
Chris@87 56 """Asserts that a comparison relation between two masked arrays is satisfied
Chris@87 57 elementwise."""
Chris@87 58 xf = self.filled(x)
Chris@87 59 yf = self.filled(y)
Chris@87 60 m = self.mask_or(self.getmask(x), self.getmask(y))
Chris@87 61
Chris@87 62 x = self.filled(self.masked_array(xf, mask=m), fill_value)
Chris@87 63 y = self.filled(self.masked_array(yf, mask=m), fill_value)
Chris@87 64 if (x.dtype.char != "O"):
Chris@87 65 x = x.astype(float_)
Chris@87 66 if isinstance(x, np.ndarray) and x.size > 1:
Chris@87 67 x[np.isnan(x)] = 0
Chris@87 68 elif np.isnan(x):
Chris@87 69 x = 0
Chris@87 70 if (y.dtype.char != "O"):
Chris@87 71 y = y.astype(float_)
Chris@87 72 if isinstance(y, np.ndarray) and y.size > 1:
Chris@87 73 y[np.isnan(y)] = 0
Chris@87 74 elif np.isnan(y):
Chris@87 75 y = 0
Chris@87 76 try:
Chris@87 77 cond = (x.shape==() or y.shape==()) or x.shape == y.shape
Chris@87 78 if not cond:
Chris@87 79 msg = build_err_msg([x, y],
Chris@87 80 err_msg
Chris@87 81 + '\n(shapes %s, %s mismatch)' % (x.shape,
Chris@87 82 y.shape),
Chris@87 83 header=header,
Chris@87 84 names=('x', 'y'))
Chris@87 85 assert cond, msg
Chris@87 86 val = comparison(x, y)
Chris@87 87 if m is not self.nomask and fill_value:
Chris@87 88 val = self.masked_array(val, mask=m)
Chris@87 89 if isinstance(val, bool):
Chris@87 90 cond = val
Chris@87 91 reduced = [0]
Chris@87 92 else:
Chris@87 93 reduced = val.ravel()
Chris@87 94 cond = reduced.all()
Chris@87 95 reduced = reduced.tolist()
Chris@87 96 if not cond:
Chris@87 97 match = 100-100.0*reduced.count(1)/len(reduced)
Chris@87 98 msg = build_err_msg([x, y],
Chris@87 99 err_msg
Chris@87 100 + '\n(mismatch %s%%)' % (match,),
Chris@87 101 header=header,
Chris@87 102 names=('x', 'y'))
Chris@87 103 assert cond, msg
Chris@87 104 except ValueError:
Chris@87 105 msg = build_err_msg([x, y], err_msg, header=header, names=('x', 'y'))
Chris@87 106 raise ValueError(msg)
Chris@87 107
Chris@87 108 def assert_array_equal(self, x, y, err_msg=''):
Chris@87 109 """Checks the elementwise equality of two masked arrays."""
Chris@87 110 self.assert_array_compare(self.equal, x, y, err_msg=err_msg,
Chris@87 111 header='Arrays are not equal')
Chris@87 112
Chris@87 113 def test_0(self):
Chris@87 114 "Tests creation"
Chris@87 115 x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
Chris@87 116 m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
Chris@87 117 xm = self.masked_array(x, mask=m)
Chris@87 118 xm[0]
Chris@87 119
Chris@87 120 def test_1(self):
Chris@87 121 "Tests creation"
Chris@87 122 x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
Chris@87 123 y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
Chris@87 124 a10 = 10.
Chris@87 125 m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
Chris@87 126 m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
Chris@87 127 xm = self.masked_array(x, mask=m1)
Chris@87 128 ym = self.masked_array(y, mask=m2)
Chris@87 129 z = np.array([-.5, 0., .5, .8])
Chris@87 130 zm = self.masked_array(z, mask=[0, 1, 0, 0])
Chris@87 131 xf = np.where(m1, 1.e+20, x)
Chris@87 132 xm.set_fill_value(1.e+20)
Chris@87 133
Chris@87 134 assert((xm-ym).filled(0).any())
Chris@87 135 #fail_if_equal(xm.mask.astype(int_), ym.mask.astype(int_))
Chris@87 136 s = x.shape
Chris@87 137 assert(xm.size == reduce(lambda x, y:x*y, s))
Chris@87 138 assert(self.count(xm) == len(m1) - reduce(lambda x, y:x+y, m1))
Chris@87 139
Chris@87 140 for s in [(4, 3), (6, 2)]:
Chris@87 141 x.shape = s
Chris@87 142 y.shape = s
Chris@87 143 xm.shape = s
Chris@87 144 ym.shape = s
Chris@87 145 xf.shape = s
Chris@87 146
Chris@87 147 assert(self.count(xm) == len(m1) - reduce(lambda x, y:x+y, m1))
Chris@87 148
Chris@87 149 def test_2(self):
Chris@87 150 "Tests conversions and indexing"
Chris@87 151 x1 = np.array([1, 2, 4, 3])
Chris@87 152 x2 = self.array(x1, mask=[1, 0, 0, 0])
Chris@87 153 x3 = self.array(x1, mask=[0, 1, 0, 1])
Chris@87 154 x4 = self.array(x1)
Chris@87 155 # test conversion to strings
Chris@87 156 junk, garbage = str(x2), repr(x2)
Chris@87 157 # assert_equal(np.sort(x1), self.sort(x2, fill_value=0))
Chris@87 158 # tests of indexing
Chris@87 159 assert type(x2[1]) is type(x1[1])
Chris@87 160 assert x1[1] == x2[1]
Chris@87 161 # assert self.allequal(x1[2],x2[2])
Chris@87 162 # assert self.allequal(x1[2:5],x2[2:5])
Chris@87 163 # assert self.allequal(x1[:],x2[:])
Chris@87 164 # assert self.allequal(x1[1:], x3[1:])
Chris@87 165 x1[2] = 9
Chris@87 166 x2[2] = 9
Chris@87 167 self.assert_array_equal(x1, x2)
Chris@87 168 x1[1:3] = 99
Chris@87 169 x2[1:3] = 99
Chris@87 170 # assert self.allequal(x1,x2)
Chris@87 171 x2[1] = self.masked
Chris@87 172 # assert self.allequal(x1,x2)
Chris@87 173 x2[1:3] = self.masked
Chris@87 174 # assert self.allequal(x1,x2)
Chris@87 175 x2[:] = x1
Chris@87 176 x2[1] = self.masked
Chris@87 177 # assert self.allequal(self.getmask(x2),self.array([0,1,0,0]))
Chris@87 178 x3[:] = self.masked_array([1, 2, 3, 4], [0, 1, 1, 0])
Chris@87 179 # assert self.allequal(self.getmask(x3), self.array([0,1,1,0]))
Chris@87 180 x4[:] = self.masked_array([1, 2, 3, 4], [0, 1, 1, 0])
Chris@87 181 # assert self.allequal(self.getmask(x4), self.array([0,1,1,0]))
Chris@87 182 # assert self.allequal(x4, self.array([1,2,3,4]))
Chris@87 183 x1 = np.arange(5)*1.0
Chris@87 184 x2 = self.masked_values(x1, 3.0)
Chris@87 185 # assert self.allequal(x1,x2)
Chris@87 186 # assert self.allequal(self.array([0,0,0,1,0], self.MaskType), x2.mask)
Chris@87 187 x1 = self.array([1, 'hello', 2, 3], object)
Chris@87 188 x2 = np.array([1, 'hello', 2, 3], object)
Chris@87 189 s1 = x1[1]
Chris@87 190 s2 = x2[1]
Chris@87 191 assert x1[1:1].shape == (0,)
Chris@87 192 # Tests copy-size
Chris@87 193 n = [0, 0, 1, 0, 0]
Chris@87 194 m = self.make_mask(n)
Chris@87 195 m2 = self.make_mask(m)
Chris@87 196 assert(m is m2)
Chris@87 197 m3 = self.make_mask(m, copy=1)
Chris@87 198 assert(m is not m3)
Chris@87 199
Chris@87 200
Chris@87 201 def test_3(self):
Chris@87 202 "Tests resize/repeat"
Chris@87 203 x4 = self.arange(4)
Chris@87 204 x4[2] = self.masked
Chris@87 205 y4 = self.resize(x4, (8,))
Chris@87 206 assert self.allequal(self.concatenate([x4, x4]), y4)
Chris@87 207 assert self.allequal(self.getmask(y4), [0, 0, 1, 0, 0, 0, 1, 0])
Chris@87 208 y5 = self.repeat(x4, (2, 2, 2, 2), axis=0)
Chris@87 209 self.assert_array_equal(y5, [0, 0, 1, 1, 2, 2, 3, 3])
Chris@87 210 y6 = self.repeat(x4, 2, axis=0)
Chris@87 211 assert self.allequal(y5, y6)
Chris@87 212 y7 = x4.repeat((2, 2, 2, 2), axis=0)
Chris@87 213 assert self.allequal(y5, y7)
Chris@87 214 y8 = x4.repeat(2, 0)
Chris@87 215 assert self.allequal(y5, y8)
Chris@87 216
Chris@87 217 #----------------------------------
Chris@87 218 def test_4(self):
Chris@87 219 "Test of take, transpose, inner, outer products"
Chris@87 220 x = self.arange(24)
Chris@87 221 y = np.arange(24)
Chris@87 222 x[5:6] = self.masked
Chris@87 223 x = x.reshape(2, 3, 4)
Chris@87 224 y = y.reshape(2, 3, 4)
Chris@87 225 assert self.allequal(np.transpose(y, (2, 0, 1)), self.transpose(x, (2, 0, 1)))
Chris@87 226 assert self.allequal(np.take(y, (2, 0, 1), 1), self.take(x, (2, 0, 1), 1))
Chris@87 227 assert self.allequal(np.inner(self.filled(x, 0), self.filled(y, 0)),
Chris@87 228 self.inner(x, y))
Chris@87 229 assert self.allequal(np.outer(self.filled(x, 0), self.filled(y, 0)),
Chris@87 230 self.outer(x, y))
Chris@87 231 y = self.array(['abc', 1, 'def', 2, 3], object)
Chris@87 232 y[2] = self.masked
Chris@87 233 t = self.take(y, [0, 3, 4])
Chris@87 234 assert t[0] == 'abc'
Chris@87 235 assert t[1] == 2
Chris@87 236 assert t[2] == 3
Chris@87 237 #----------------------------------
Chris@87 238 def test_5(self):
Chris@87 239 "Tests inplace w/ scalar"
Chris@87 240
Chris@87 241 x = self.arange(10)
Chris@87 242 y = self.arange(10)
Chris@87 243 xm = self.arange(10)
Chris@87 244 xm[2] = self.masked
Chris@87 245 x += 1
Chris@87 246 assert self.allequal(x, y+1)
Chris@87 247 xm += 1
Chris@87 248 assert self.allequal(xm, y+1)
Chris@87 249
Chris@87 250 x = self.arange(10)
Chris@87 251 xm = self.arange(10)
Chris@87 252 xm[2] = self.masked
Chris@87 253 x -= 1
Chris@87 254 assert self.allequal(x, y-1)
Chris@87 255 xm -= 1
Chris@87 256 assert self.allequal(xm, y-1)
Chris@87 257
Chris@87 258 x = self.arange(10)*1.0
Chris@87 259 xm = self.arange(10)*1.0
Chris@87 260 xm[2] = self.masked
Chris@87 261 x *= 2.0
Chris@87 262 assert self.allequal(x, y*2)
Chris@87 263 xm *= 2.0
Chris@87 264 assert self.allequal(xm, y*2)
Chris@87 265
Chris@87 266 x = self.arange(10)*2
Chris@87 267 xm = self.arange(10)*2
Chris@87 268 xm[2] = self.masked
Chris@87 269 x /= 2
Chris@87 270 assert self.allequal(x, y)
Chris@87 271 xm /= 2
Chris@87 272 assert self.allequal(xm, y)
Chris@87 273
Chris@87 274 x = self.arange(10)*1.0
Chris@87 275 xm = self.arange(10)*1.0
Chris@87 276 xm[2] = self.masked
Chris@87 277 x /= 2.0
Chris@87 278 assert self.allequal(x, y/2.0)
Chris@87 279 xm /= self.arange(10)
Chris@87 280 self.assert_array_equal(xm, self.ones((10,)))
Chris@87 281
Chris@87 282 x = self.arange(10).astype(float_)
Chris@87 283 xm = self.arange(10)
Chris@87 284 xm[2] = self.masked
Chris@87 285 id1 = self.id(x.raw_data())
Chris@87 286 x += 1.
Chris@87 287 #assert id1 == self.id(x.raw_data())
Chris@87 288 assert self.allequal(x, y+1.)
Chris@87 289
Chris@87 290
Chris@87 291 def test_6(self):
Chris@87 292 "Tests inplace w/ array"
Chris@87 293
Chris@87 294 x = self.arange(10, dtype=float_)
Chris@87 295 y = self.arange(10)
Chris@87 296 xm = self.arange(10, dtype=float_)
Chris@87 297 xm[2] = self.masked
Chris@87 298 m = xm.mask
Chris@87 299 a = self.arange(10, dtype=float_)
Chris@87 300 a[-1] = self.masked
Chris@87 301 x += a
Chris@87 302 xm += a
Chris@87 303 assert self.allequal(x, y+a)
Chris@87 304 assert self.allequal(xm, y+a)
Chris@87 305 assert self.allequal(xm.mask, self.mask_or(m, a.mask))
Chris@87 306
Chris@87 307 x = self.arange(10, dtype=float_)
Chris@87 308 xm = self.arange(10, dtype=float_)
Chris@87 309 xm[2] = self.masked
Chris@87 310 m = xm.mask
Chris@87 311 a = self.arange(10, dtype=float_)
Chris@87 312 a[-1] = self.masked
Chris@87 313 x -= a
Chris@87 314 xm -= a
Chris@87 315 assert self.allequal(x, y-a)
Chris@87 316 assert self.allequal(xm, y-a)
Chris@87 317 assert self.allequal(xm.mask, self.mask_or(m, a.mask))
Chris@87 318
Chris@87 319 x = self.arange(10, dtype=float_)
Chris@87 320 xm = self.arange(10, dtype=float_)
Chris@87 321 xm[2] = self.masked
Chris@87 322 m = xm.mask
Chris@87 323 a = self.arange(10, dtype=float_)
Chris@87 324 a[-1] = self.masked
Chris@87 325 x *= a
Chris@87 326 xm *= a
Chris@87 327 assert self.allequal(x, y*a)
Chris@87 328 assert self.allequal(xm, y*a)
Chris@87 329 assert self.allequal(xm.mask, self.mask_or(m, a.mask))
Chris@87 330
Chris@87 331 x = self.arange(10, dtype=float_)
Chris@87 332 xm = self.arange(10, dtype=float_)
Chris@87 333 xm[2] = self.masked
Chris@87 334 m = xm.mask
Chris@87 335 a = self.arange(10, dtype=float_)
Chris@87 336 a[-1] = self.masked
Chris@87 337 x /= a
Chris@87 338 xm /= a
Chris@87 339
Chris@87 340 #----------------------------------
Chris@87 341 def test_7(self):
Chris@87 342 "Tests ufunc"
Chris@87 343 d = (self.array([1.0, 0, -1, pi/2]*2, mask=[0, 1]+[0]*6),
Chris@87 344 self.array([1.0, 0, -1, pi/2]*2, mask=[1, 0]+[0]*6),)
Chris@87 345 for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
Chris@87 346 # 'sin', 'cos', 'tan',
Chris@87 347 # 'arcsin', 'arccos', 'arctan',
Chris@87 348 # 'sinh', 'cosh', 'tanh',
Chris@87 349 # 'arcsinh',
Chris@87 350 # 'arccosh',
Chris@87 351 # 'arctanh',
Chris@87 352 # 'absolute', 'fabs', 'negative',
Chris@87 353 # # 'nonzero', 'around',
Chris@87 354 # 'floor', 'ceil',
Chris@87 355 # # 'sometrue', 'alltrue',
Chris@87 356 # 'logical_not',
Chris@87 357 # 'add', 'subtract', 'multiply',
Chris@87 358 # 'divide', 'true_divide', 'floor_divide',
Chris@87 359 # 'remainder', 'fmod', 'hypot', 'arctan2',
Chris@87 360 # 'equal', 'not_equal', 'less_equal', 'greater_equal',
Chris@87 361 # 'less', 'greater',
Chris@87 362 # 'logical_and', 'logical_or', 'logical_xor',
Chris@87 363 ]:
Chris@87 364 #print f
Chris@87 365 try:
Chris@87 366 uf = getattr(self.umath, f)
Chris@87 367 except AttributeError:
Chris@87 368 uf = getattr(fromnumeric, f)
Chris@87 369 mf = getattr(self.module, f)
Chris@87 370 args = d[:uf.nin]
Chris@87 371 ur = uf(*args)
Chris@87 372 mr = mf(*args)
Chris@87 373 self.assert_array_equal(ur.filled(0), mr.filled(0), f)
Chris@87 374 self.assert_array_equal(ur._mask, mr._mask)
Chris@87 375
Chris@87 376 #----------------------------------
Chris@87 377 def test_99(self):
Chris@87 378 # test average
Chris@87 379 ott = self.array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
Chris@87 380 self.assert_array_equal(2.0, self.average(ott, axis=0))
Chris@87 381 self.assert_array_equal(2.0, self.average(ott, weights=[1., 1., 2., 1.]))
Chris@87 382 result, wts = self.average(ott, weights=[1., 1., 2., 1.], returned=1)
Chris@87 383 self.assert_array_equal(2.0, result)
Chris@87 384 assert(wts == 4.0)
Chris@87 385 ott[:] = self.masked
Chris@87 386 assert(self.average(ott, axis=0) is self.masked)
Chris@87 387 ott = self.array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
Chris@87 388 ott = ott.reshape(2, 2)
Chris@87 389 ott[:, 1] = self.masked
Chris@87 390 self.assert_array_equal(self.average(ott, axis=0), [2.0, 0.0])
Chris@87 391 assert(self.average(ott, axis=1)[0] is self.masked)
Chris@87 392 self.assert_array_equal([2., 0.], self.average(ott, axis=0))
Chris@87 393 result, wts = self.average(ott, axis=0, returned=1)
Chris@87 394 self.assert_array_equal(wts, [1., 0.])
Chris@87 395 w1 = [0, 1, 1, 1, 1, 0]
Chris@87 396 w2 = [[0, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 1]]
Chris@87 397 x = self.arange(6)
Chris@87 398 self.assert_array_equal(self.average(x, axis=0), 2.5)
Chris@87 399 self.assert_array_equal(self.average(x, axis=0, weights=w1), 2.5)
Chris@87 400 y = self.array([self.arange(6), 2.0*self.arange(6)])
Chris@87 401 self.assert_array_equal(self.average(y, None), np.add.reduce(np.arange(6))*3./12.)
Chris@87 402 self.assert_array_equal(self.average(y, axis=0), np.arange(6) * 3./2.)
Chris@87 403 self.assert_array_equal(self.average(y, axis=1), [self.average(x, axis=0), self.average(x, axis=0) * 2.0])
Chris@87 404 self.assert_array_equal(self.average(y, None, weights=w2), 20./6.)
Chris@87 405 self.assert_array_equal(self.average(y, axis=0, weights=w2), [0., 1., 2., 3., 4., 10.])
Chris@87 406 self.assert_array_equal(self.average(y, axis=1), [self.average(x, axis=0), self.average(x, axis=0) * 2.0])
Chris@87 407 m1 = self.zeros(6)
Chris@87 408 m2 = [0, 0, 1, 1, 0, 0]
Chris@87 409 m3 = [[0, 0, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0]]
Chris@87 410 m4 = self.ones(6)
Chris@87 411 m5 = [0, 1, 1, 1, 1, 1]
Chris@87 412 self.assert_array_equal(self.average(self.masked_array(x, m1), axis=0), 2.5)
Chris@87 413 self.assert_array_equal(self.average(self.masked_array(x, m2), axis=0), 2.5)
Chris@87 414 # assert(self.average(masked_array(x, m4),axis=0) is masked)
Chris@87 415 self.assert_array_equal(self.average(self.masked_array(x, m5), axis=0), 0.0)
Chris@87 416 self.assert_array_equal(self.count(self.average(self.masked_array(x, m4), axis=0)), 0)
Chris@87 417 z = self.masked_array(y, m3)
Chris@87 418 self.assert_array_equal(self.average(z, None), 20./6.)
Chris@87 419 self.assert_array_equal(self.average(z, axis=0), [0., 1., 99., 99., 4.0, 7.5])
Chris@87 420 self.assert_array_equal(self.average(z, axis=1), [2.5, 5.0])
Chris@87 421 self.assert_array_equal(self.average(z, axis=0, weights=w2), [0., 1., 99., 99., 4.0, 10.0])
Chris@87 422 #------------------------
Chris@87 423 def test_A(self):
Chris@87 424 x = self.arange(24)
Chris@87 425 y = np.arange(24)
Chris@87 426 x[5:6] = self.masked
Chris@87 427 x = x.reshape(2, 3, 4)
Chris@87 428
Chris@87 429
Chris@87 430 ################################################################################
Chris@87 431 if __name__ == '__main__':
Chris@87 432
Chris@87 433 setup_base = "from __main__ import moduletester \n"\
Chris@87 434 "import numpy\n" \
Chris@87 435 "tester = moduletester(module)\n"
Chris@87 436 # setup_new = "import np.ma.core_ini as module\n"+setup_base
Chris@87 437 setup_cur = "import np.ma.core as module\n"+setup_base
Chris@87 438 # setup_alt = "import np.ma.core_alt as module\n"+setup_base
Chris@87 439 # setup_tmp = "import np.ma.core_tmp as module\n"+setup_base
Chris@87 440
Chris@87 441 (nrepeat, nloop) = (10, 10)
Chris@87 442
Chris@87 443 if 1:
Chris@87 444 for i in range(1, 8):
Chris@87 445 func = 'tester.test_%i()' % i
Chris@87 446 # new = timeit.Timer(func, setup_new).repeat(nrepeat, nloop*10)
Chris@87 447 cur = timeit.Timer(func, setup_cur).repeat(nrepeat, nloop*10)
Chris@87 448 # alt = timeit.Timer(func, setup_alt).repeat(nrepeat, nloop*10)
Chris@87 449 # tmp = timeit.Timer(func, setup_tmp).repeat(nrepeat, nloop*10)
Chris@87 450 # new = np.sort(new)
Chris@87 451 cur = np.sort(cur)
Chris@87 452 # alt = np.sort(alt)
Chris@87 453 # tmp = np.sort(tmp)
Chris@87 454 print("#%i" % i +50*'.')
Chris@87 455 print(eval("moduletester.test_%i.__doc__" % i))
Chris@87 456 # print "core_ini : %.3f - %.3f" % (new[0], new[1])
Chris@87 457 print("core_current : %.3f - %.3f" % (cur[0], cur[1]))
Chris@87 458 # print "core_alt : %.3f - %.3f" % (alt[0], alt[1])
Chris@87 459 # print "core_tmp : %.3f - %.3f" % (tmp[0], tmp[1])