Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/lib/tests/test_ufunclike.py @ 87:2a2c65a20a8b
Add Python libs and headers
author | Chris Cannam |
---|---|
date | Wed, 25 Feb 2015 14:05:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
86:413a9d26189e | 87:2a2c65a20a8b |
---|---|
1 from __future__ import division, absolute_import, print_function | |
2 | |
3 import numpy.core as nx | |
4 import numpy.lib.ufunclike as ufl | |
5 from numpy.testing import ( | |
6 run_module_suite, TestCase, assert_, assert_equal, assert_array_equal | |
7 ) | |
8 | |
9 | |
10 class TestUfunclike(TestCase): | |
11 | |
12 def test_isposinf(self): | |
13 a = nx.array([nx.inf, -nx.inf, nx.nan, 0.0, 3.0, -3.0]) | |
14 out = nx.zeros(a.shape, bool) | |
15 tgt = nx.array([True, False, False, False, False, False]) | |
16 | |
17 res = ufl.isposinf(a) | |
18 assert_equal(res, tgt) | |
19 res = ufl.isposinf(a, out) | |
20 assert_equal(res, tgt) | |
21 assert_equal(out, tgt) | |
22 | |
23 def test_isneginf(self): | |
24 a = nx.array([nx.inf, -nx.inf, nx.nan, 0.0, 3.0, -3.0]) | |
25 out = nx.zeros(a.shape, bool) | |
26 tgt = nx.array([False, True, False, False, False, False]) | |
27 | |
28 res = ufl.isneginf(a) | |
29 assert_equal(res, tgt) | |
30 res = ufl.isneginf(a, out) | |
31 assert_equal(res, tgt) | |
32 assert_equal(out, tgt) | |
33 | |
34 def test_fix(self): | |
35 a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) | |
36 out = nx.zeros(a.shape, float) | |
37 tgt = nx.array([[1., 1., 1., 1.], [-1., -1., -1., -1.]]) | |
38 | |
39 res = ufl.fix(a) | |
40 assert_equal(res, tgt) | |
41 res = ufl.fix(a, out) | |
42 assert_equal(res, tgt) | |
43 assert_equal(out, tgt) | |
44 assert_equal(ufl.fix(3.14), 3) | |
45 | |
46 def test_fix_with_subclass(self): | |
47 class MyArray(nx.ndarray): | |
48 def __new__(cls, data, metadata=None): | |
49 res = nx.array(data, copy=True).view(cls) | |
50 res.metadata = metadata | |
51 return res | |
52 | |
53 def __array_wrap__(self, obj, context=None): | |
54 obj.metadata = self.metadata | |
55 return obj | |
56 | |
57 a = nx.array([1.1, -1.1]) | |
58 m = MyArray(a, metadata='foo') | |
59 f = ufl.fix(m) | |
60 assert_array_equal(f, nx.array([1, -1])) | |
61 assert_(isinstance(f, MyArray)) | |
62 assert_equal(f.metadata, 'foo') | |
63 | |
64 if __name__ == "__main__": | |
65 run_module_suite() |