Esempio n. 1
0
def test_shapes_and_strides():

    for shape in [
        (9, ),
        (109, ),
        (9, 4),
        (109, 104),
        (9, 4, 5),
        (109, 104, 105),
        (9, 4, 5, 6),  # not (109, 104, 105, 106) -> too big
    ]:

        # Test shape and strides
        a = np.empty(shape)
        b = tnp.empty(shape)
        assert a.ndim == len(shape)
        assert a.ndim == b.ndim
        assert a.shape == b.shape
        assert a.strides == b.strides
        assert a.size == b.size

        # Also test repr length
        if b.size > 100:
            assert len(repr(b)) < 80
        else:
            assert len(repr(b)) > (b.size * 3)  # "x.0" for each element
Esempio n. 2
0
def test_dtype():
    
    for shape in [(9, ), (9, 4), (9, 4, 5)]:
        for dtype in ['bool', 'int8', 'uint8', 'int16', 'uint16',
                      'int32', 'uint32', 'float32', 'float64']:
            a = np.empty(shape, dtype=dtype)
            b = tnp.empty(shape, dtype=dtype)
            assert a.shape == b.shape
            assert a.dtype == b.dtype
            assert a.itemsize == b.itemsize
    
    raises(TypeError, tnp.zeros, (9, ), 'blaa')
    
    assert tnp.array([1.0, 2.0]).dtype == 'float64'
    assert tnp.array([1, 2]).dtype == 'int64'
Esempio n. 3
0
def test_shapes_and_strides():
    
    for shape in [(9, ), (109, ), 
                  (9, 4), (109, 104), 
                  (9, 4, 5), (109, 104, 105),
                  (9, 4, 5, 6),  # not (109, 104, 105, 106) -> too big
                  ]:
        
        # Test shape and strides
        a = np.empty(shape)
        b = tnp.empty(shape)
        assert a.ndim == len(shape)
        assert a.ndim == b.ndim
        assert a.shape == b.shape
        assert a.strides == b.strides
        assert a.size == b.size
        
        # Also test repr length
        if b.size > 100:
            assert len(repr(b)) < 80
        else:
            assert len(repr(b)) > (b.size * 3)  # "x.0" for each element