]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/numpy/dtype.py
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)
12 if (sys
.version_info
.major
>= 3):
15 class DtypeTestCase(unittest
.TestCase
):
17 def assertEquivalent(self
, a
, b
):
18 return self
.assert_(dtype_ext
.equivalent(a
, b
), "%r is not equivalent to %r")
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
))
42 self
.assertEquivalent(ft(int(1)), numpy
.dtype(t
))
43 self
.assertEquivalent(ft(long(1)), numpy
.dtype(t
))
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
))
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"):
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
))
62 if __name__
=="__main__":