示例#1
0
 def test_operators(self):
     from operator import truediv
     from _numpypy import float64, int_, True_, False_
     assert 5 / int_(2) == int_(2)
     assert truediv(int_(3), int_(2)) == float64(1.5)
     assert truediv(3, int_(2)) == float64(1.5)
     assert int_(8) % int_(3) == int_(2)
     assert 8 % int_(3) == int_(2)
     assert divmod(int_(8), int_(3)) == (int_(2), int_(2))
     assert divmod(8, int_(3)) == (int_(2), int_(2))
     assert 2**int_(3) == int_(8)
     assert int_(3) << int_(2) == int_(12)
     assert 3 << int_(2) == int_(12)
     assert int_(8) >> int_(2) == int_(2)
     assert 8 >> int_(2) == int_(2)
     assert int_(3) & int_(1) == int_(1)
     assert 2 & int_(3) == int_(2)
     assert int_(2) | int_(1) == int_(3)
     assert 2 | int_(1) == int_(3)
     assert int_(3) ^ int_(5) == int_(6)
     assert True_ ^ False_ is True_
     assert 5 ^ int_(3) == int_(6)
     assert +int_(3) == int_(3)
     assert ~int_(3) == int_(-4)
     raises(TypeError, lambda: float64(3) & 1)
示例#2
0
    def test_operators(self):
        from operator import truediv
        from _numpypy import float64, int_, True_, False_

        assert 5 / int_(2) == int_(2)
        assert truediv(int_(3), int_(2)) == float64(1.5)
        assert truediv(3, int_(2)) == float64(1.5)
        assert int_(8) % int_(3) == int_(2)
        assert 8 % int_(3) == int_(2)
        assert divmod(int_(8), int_(3)) == (int_(2), int_(2))
        assert divmod(8, int_(3)) == (int_(2), int_(2))
        assert 2 ** int_(3) == int_(8)
        assert int_(3) << int_(2) == int_(12)
        assert 3 << int_(2) == int_(12)
        assert int_(8) >> int_(2) == int_(2)
        assert 8 >> int_(2) == int_(2)
        assert int_(3) & int_(1) == int_(1)
        assert 2 & int_(3) == int_(2)
        assert int_(2) | int_(1) == int_(3)
        assert 2 | int_(1) == int_(3)
        assert int_(3) ^ int_(5) == int_(6)
        assert True_ ^ False_ is True_
        assert 5 ^ int_(3) == int_(6)

        assert +int_(3) == int_(3)
        assert ~int_(3) == int_(-4)

        raises(TypeError, lambda: float64(3) & 1)
示例#3
0
    def test_float64(self):
        import _numpypy as numpy

        assert numpy.float64.mro() == [numpy.float64, numpy.floating, numpy.inexact, numpy.number, numpy.generic, float, object]

        a = numpy.array([1, 2, 3], numpy.float64)
        assert type(a[1]) is numpy.float64
        assert numpy.dtype(float).type is numpy.float64

        assert "{:3f}".format(numpy.float64(3)) == "3.000000"

        assert numpy.float64(2.0) == 2.0
        assert numpy.float64('23.4') == numpy.float64(23.4)
        raises(ValueError, numpy.float64, '23.2df')
示例#4
0
    def test_float32(self):
        import _numpypy as numpy

        assert numpy.float32.mro() == [numpy.float32, numpy.floating, numpy.inexact, numpy.number, numpy.generic, object]

        assert numpy.float32(12) == numpy.float64(12)
        assert numpy.float32('23.4') == numpy.float32(23.4)
        raises(ValueError, numpy.float32, '23.2df')
示例#5
0
    def test_float64(self):
        import _numpypy as numpy

        assert numpy.float64.mro() == [
            numpy.float64, numpy.floating, numpy.inexact, numpy.number,
            numpy.generic, float, object
        ]

        a = numpy.array([1, 2, 3], numpy.float64)
        assert type(a[1]) is numpy.float64
        assert numpy.dtype(float).type is numpy.float64

        assert "{:3f}".format(numpy.float64(3)) == "3.000000"

        assert numpy.float64(2.0) == 2.0
        assert numpy.float64('23.4') == numpy.float64(23.4)
        raises(ValueError, numpy.float64, '23.2df')
示例#6
0
    def test_float64(self):
        import _numpypy as numpy

        assert numpy.float64.mro() == [
            numpy.float64,
            numpy.floating,
            numpy.inexact,
            numpy.number,
            numpy.generic,
            float,
            object,
        ]

        a = numpy.array([1, 2, 3], numpy.float64)
        assert type(a[1]) is numpy.float64
        assert numpy.dtype(float).type is numpy.float64

        assert numpy.float64(2.0) == 2.0
        assert numpy.float64("23.4") == numpy.float64(23.4)
        raises(ValueError, numpy.float64, "23.2df")
示例#7
0
    def test_float32(self):
        import _numpypy as numpy

        assert numpy.float32.mro() == [
            numpy.float32, numpy.floating, numpy.inexact, numpy.number,
            numpy.generic, object
        ]

        assert numpy.float32(12) == numpy.float64(12)
        assert numpy.float32('23.4') == numpy.float32(23.4)
        raises(ValueError, numpy.float32, '23.2df')
示例#8
0
 def test_isnan_isinf(self):
     from _numpypy import isnan, isinf, float64, array
     assert isnan(float('nan'))
     assert isnan(float64(float('nan')))
     assert not isnan(3)
     assert isinf(float('inf'))
     assert not isnan(3.5)
     assert not isinf(3.5)
     assert not isnan(float('inf'))
     assert not isinf(float('nan'))
     assert (isnan(array([0.2, float('inf'), float('nan')])) == [False, False, True]).all()
     assert (isinf(array([0.2, float('inf'), float('nan')])) == [False, True, False]).all()
     assert isinf(array([0.2])).dtype.kind == 'b'
示例#9
0
 def test_isnan_isinf(self):
     from _numpypy import isnan, isinf, float64, array
     assert isnan(float('nan'))
     assert isnan(float64(float('nan')))
     assert not isnan(3)
     assert isinf(float('inf'))
     assert not isnan(3.5)
     assert not isinf(3.5)
     assert not isnan(float('inf'))
     assert not isinf(float('nan'))
     assert (isnan(array([0.2, float('inf'),
                          float('nan')])) == [False, False, True]).all()
     assert (isinf(array([0.2, float('inf'),
                          float('nan')])) == [False, True, False]).all()
     assert isinf(array([0.2])).dtype.kind == 'b'
示例#10
0
    def test_dtype_guessing(self):
        from _numpypy import array, dtype, float64, int8, bool_

        assert array([True]).dtype is dtype(bool)
        assert array([True, False]).dtype is dtype(bool)
        assert array([True, 1]).dtype is dtype(int)
        assert array([1, 2, 3]).dtype is dtype(int)
        assert array([1L, 2, 3]).dtype is dtype(long)
        assert array([1.2, True]).dtype is dtype(float)
        assert array([1.2, 5]).dtype is dtype(float)
        assert array([]).dtype is dtype(float)
        assert array([float64(2)]).dtype is dtype(float)
        assert array([int8(3)]).dtype is dtype("int8")
        assert array([bool_(True)]).dtype is dtype(bool)
        assert array([bool_(True), 3.0]).dtype is dtype(float)
示例#11
0
    def test_dtype_guessing(self):
        from _numpypy import array, dtype, float64, int8, bool_

        assert array([True]).dtype is dtype(bool)
        assert array([True, False]).dtype is dtype(bool)
        assert array([True, 1]).dtype is dtype(int)
        assert array([1, 2, 3]).dtype is dtype(int)
        assert array([1L, 2, 3]).dtype is dtype(long)
        assert array([1.2, True]).dtype is dtype(float)
        assert array([1.2, 5]).dtype is dtype(float)
        assert array([]).dtype is dtype(float)
        assert array([float64(2)]).dtype is dtype(float)
        assert array([int8(3)]).dtype is dtype("int8")
        assert array([bool_(True)]).dtype is dtype(bool)
        assert array([bool_(True), 3.0]).dtype is dtype(float)
示例#12
0
    def test_fromstring_types(self):
        from _numpypy import (fromstring, int8, int16, int32, int64, uint8,
            uint16, uint32, float32, float64)

        a = fromstring('\xFF', dtype=int8)
        assert a[0] == -1
        b = fromstring('\xFF', dtype=uint8)
        assert b[0] == 255
        c = fromstring('\xFF\xFF', dtype=int16)
        assert c[0] == -1
        d = fromstring('\xFF\xFF', dtype=uint16)
        assert d[0] == 65535
        e = fromstring('\xFF\xFF\xFF\xFF', dtype=int32)
        assert e[0] == -1
        f = fromstring('\xFF\xFF\xFF\xFF', dtype=uint32)
        assert repr(f[0]) == '4294967295'
        g = fromstring('\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF', dtype=int64)
        assert g[0] == -1
        h = fromstring(self.float32val, dtype=float32)
        assert h[0] == float32(5.2)
        i = fromstring(self.float64val, dtype=float64)
        assert i[0] == float64(300.4)
        j = fromstring(self.ulongval, dtype='L')
        assert j[0] == 12
示例#13
0
    def test_fromstring_types(self):
        from _numpypy import (fromstring, int8, int16, int32, int64, uint8,
                              uint16, uint32, float32, float64)

        a = fromstring('\xFF', dtype=int8)
        assert a[0] == -1
        b = fromstring('\xFF', dtype=uint8)
        assert b[0] == 255
        c = fromstring('\xFF\xFF', dtype=int16)
        assert c[0] == -1
        d = fromstring('\xFF\xFF', dtype=uint16)
        assert d[0] == 65535
        e = fromstring('\xFF\xFF\xFF\xFF', dtype=int32)
        assert e[0] == -1
        f = fromstring('\xFF\xFF\xFF\xFF', dtype=uint32)
        assert repr(f[0]) == '4294967295'
        g = fromstring('\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF', dtype=int64)
        assert g[0] == -1
        h = fromstring(self.float32val, dtype=float32)
        assert h[0] == float32(5.2)
        i = fromstring(self.float64val, dtype=float64)
        assert i[0] == float64(300.4)
        j = fromstring(self.ulongval, dtype='L')
        assert j[0] == 12
示例#14
0
 def test_long_as_index(self):
     from _numpypy import int_, float64
     assert (1, 2, 3)[int_(1)] == 2
     raises(TypeError, lambda: (1, 2, 3)[float64(1)])
示例#15
0
 def test_long_as_index(self):
     from _numpypy import int_, float64
     assert (1, 2, 3)[int_(1)] == 2
     raises(TypeError, lambda: (1, 2, 3)[float64(1)])