Esempio n. 1
0
def test_load_txt_fixed():
    a = np.arange(10, dtype=np.int32).reshape((2, 5))
    fp = StringIO(dedent(u'''\
        01234X
        56789
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(5I1)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    fp = StringIO(dedent(u'''\
        0123X
        4
        5678
        9
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(4I1)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    a = np.array([[-1, 1, -2, 2, -3],
                  [3, -4, 4, -5, 5]], np.int32)
    fp = StringIO(dedent(u'''\
        -1 1-2 2-3
        3 -44 -55
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(5I2)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype
def test_load_txt_fixed():
    a = np.arange(10, dtype=np.int32).reshape((2, 5))
    fp = StringIO(dedent(u'''\
        01234X
        56789
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(5I1)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    fp = StringIO(
        dedent(u'''\
        0123X
        4
        5678
        9
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(4I1)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    a = np.array([[-1, 1, -2, 2, -3], [3, -4, 4, -5, 5]], np.int32)
    fp = StringIO(dedent(u'''\
        -1 1-2 2-3
        3 -44 -55
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(5I2)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype
Esempio n. 3
0
def test_load_txt_free():
    a = np.ones((10,), dtype=np.float32) * 250.0
    fp = StringIO(u'10*250.0')
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(FREE)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    a = np.arange(10, dtype=np.int32).reshape((2, 5))
    fp = StringIO(dedent(u'''\
        0 1,2,3, 4
        5 6, 7,  8 9
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(FREE)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    a = np.ones((2, 5), dtype=np.float32)
    a[1, 0] = 2.2
    fp = StringIO(dedent(u'''\
        5*1.0
        2.2 2*1.0, +1E-00 1.0
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(FREE)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype
def test_load_txt_free():
    a = np.ones((10, ), dtype=np.float32) * 250.0
    fp = StringIO(u'10*250.0')
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(FREE)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    a = np.arange(10, dtype=np.int32).reshape((2, 5))
    fp = StringIO(dedent(u'''\
        0 1,2,3, 4
        5 6, 7,  8 9
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(FREE)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype

    a = np.ones((2, 5), dtype=np.float32)
    a[1, 0] = 2.2
    fp = StringIO(
        dedent(u'''\
        5*1.0
        2.2 2*1.0, +1E-00 1.0
    '''))
    fa = Util2d.load_txt(a.shape, fp, a.dtype, '(FREE)')
    np.testing.assert_equal(fa, a)
    assert fa.dtype == a.dtype