Example #1
0
    def test_bool(self):
        import _numpypy as numpy

        assert numpy.bool_.mro() == [numpy.bool_, numpy.generic, object]
        assert numpy.bool_(3) is numpy.True_
        assert numpy.bool_("") is numpy.False_
        assert type(numpy.True_) is type(numpy.False_) is numpy.bool_

        class X(numpy.bool_):
            pass

        assert type(X(True)) is numpy.bool_
        assert X(True) is numpy.True_
        assert numpy.bool_("False") is numpy.True_
Example #2
0
    def test_bool(self):
        import _numpypy as numpy

        assert numpy.bool_.mro() == [numpy.bool_, numpy.generic, object]
        assert numpy.bool_(3) is numpy.True_
        assert numpy.bool_("") is numpy.False_
        assert type(numpy.True_) is type(numpy.False_) is numpy.bool_

        class X(numpy.bool_):
            pass

        assert type(X(True)) is numpy.bool_
        assert X(True) is numpy.True_
        assert numpy.bool_("False") is numpy.True_
Example #3
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)
Example #4
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)
Example #5
0
 def test_tolist_scalar(self):
     from _numpypy import int32, bool_
     x = int32(23)
     assert x.tolist() == 23
     assert type(x.tolist()) is int
     y = bool_(True)
     assert y.tolist() is True
Example #6
0
 def test_tolist_scalar(self):
     from _numpypy import int32, bool_
     x = int32(23)
     assert x.tolist() == 23
     assert type(x.tolist()) is int
     y = bool_(True)
     assert y.tolist() is True
Example #7
0
    >>> np.asarray(a, dtype=np.float64) is a
    False

    Contrary to `asanyarray`, ndarray subclasses are not passed through:

    >>> issubclass(np.matrix, np.ndarray)
    True
    >>> a = np.matrix([[1, 2]])
    >>> np.asarray(a) is a
    False
    >>> np.asanyarray(a) is a
    True

    """
    return array(a, dtype, copy=False, order=order)

set_string_function(array_str, 0)
set_string_function(array_repr, 1)

little_endian = (sys.byteorder == 'little')

Inf = inf = infty = Infinity = PINF = float('inf')
NINF = float('-inf')
PZERO = 0.0
NZERO = -0.0
nan = NaN = NAN = float('nan')
False_ = bool_(False)
True_ = bool_(True)
e = math.e
pi = math.pi
Example #8
0
    True
    >>> a = np.matrix([[1, 2]])
    >>> np.asarray(a) is a
    False
    >>> np.asanyarray(a) is a
    True

    """
    return array(a,
                 dtype,
                 copy=False,
                 order=order,
                 maskna=maskna,
                 ownmaskna=ownmaskna)


set_string_function(array_str, 0)
set_string_function(array_repr, 1)

little_endian = (sys.byteorder == 'little')

Inf = inf = infty = Infinity = PINF = float('inf')
NINF = float('-inf')
PZERO = 0.0
NZERO = -0.0
nan = NaN = NAN = float('nan')
False_ = bool_(False)
True_ = bool_(True)
e = math.e
pi = math.pi