]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/numpy/dtype.py
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / python / test / numpy / dtype.py
1 #!/usr/bin/env python
2
3 # Copyright Jim Bosch & Ankit Daftery 2010-2012.
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # http://www.boost.org/LICENSE_1_0.txt)
7
8 import dtype_ext
9 import unittest
10 import numpy
11 import sys
12 if (sys.version_info.major >= 3):
13 long = int
14
15 class DtypeTestCase(unittest.TestCase):
16
17 def assertEquivalent(self, a, b):
18 return self.assert_(dtype_ext.equivalent(a, b), "%r is not equivalent to %r")
19
20 def testIntegers(self):
21 for bits in (8, 16, 32, 64):
22 s = getattr(numpy, "int%d" % bits)
23 u = getattr(numpy, "uint%d" % bits)
24 fs = getattr(dtype_ext, "accept_int%d" % bits)
25 fu = getattr(dtype_ext, "accept_uint%d" % bits)
26 self.assertEquivalent(fs(s(1)), numpy.dtype(s))
27 self.assertEquivalent(fu(u(1)), numpy.dtype(u))
28 # these should just use the regular Boost.Python converters
29 self.assertEquivalent(fs(True), numpy.dtype(s))
30 self.assertEquivalent(fu(True), numpy.dtype(u))
31 self.assertEquivalent(fs(int(1)), numpy.dtype(s))
32 self.assertEquivalent(fu(int(1)), numpy.dtype(u))
33 self.assertEquivalent(fs(long(1)), numpy.dtype(s))
34 self.assertEquivalent(fu(long(1)), numpy.dtype(u))
35 for name in ("bool_", "byte", "ubyte", "short", "ushort", "intc", "uintc"):
36 t = getattr(numpy, name)
37 ft = getattr(dtype_ext, "accept_%s" % name)
38 self.assertEquivalent(ft(t(1)), numpy.dtype(t))
39 # these should just use the regular Boost.Python converters
40 self.assertEquivalent(ft(True), numpy.dtype(t))
41 if name != "bool_":
42 self.assertEquivalent(ft(int(1)), numpy.dtype(t))
43 self.assertEquivalent(ft(long(1)), numpy.dtype(t))
44
45
46 def testFloats(self):
47 f = numpy.float32
48 c = numpy.complex64
49 self.assertEquivalent(dtype_ext.accept_float32(f(numpy.pi)), numpy.dtype(f))
50 self.assertEquivalent(dtype_ext.accept_complex64(c(1+2j)), numpy.dtype(c))
51 f = numpy.float64
52 c = numpy.complex128
53 self.assertEquivalent(dtype_ext.accept_float64(f(numpy.pi)), numpy.dtype(f))
54 self.assertEquivalent(dtype_ext.accept_complex128(c(1+2j)), numpy.dtype(c))
55 if hasattr(numpy, "longdouble") and hasattr(dtype_ext, "accept_longdouble"):
56 f = numpy.longdouble
57 c = numpy.clongdouble
58 self.assertEquivalent(dtype_ext.accept_longdouble(f(numpy.pi)), numpy.dtype(f))
59 self.assertEquivalent(dtype_ext.accept_clongdouble(c(1+2j)), numpy.dtype(c))
60
61
62 if __name__=="__main__":
63 unittest.main()