예제 #1
0
def test_compression_true():
    rs = np.random.RandomState(1234)
    with tmp_filename() as fn:
        x = rs.normal(size=(1000, 5))
        for comp in [None, True, "blosc", "zlib", ("zlib", 5)]:
            h5io.save(fn, x, compression=comp)
            x1 = h5io.load(fn)
            assert (x == x1).all()
예제 #2
0
def test_load_multiple_groups():
    with tmp_filename() as fn:
        x = dict(one=np.ones(10), two="string", three=200)
        h5io.save(fn, x)

        one, three = h5io.load(fn, ["/one", "/three"])
        np.testing.assert_array_equal(one, x["one"])
        assert three == x["three"]

        three, two = h5io.load(fn, ["/three", "/two"])
        assert three == x["three"]
        assert two == x["two"]
예제 #3
0
def test_load_group():
    with tmp_filename() as fn:
        x = dict(one=np.ones(10), two="string")
        h5io.save(fn, x)

        one = h5io.load(fn, "/one")
        np.testing.assert_array_equal(one, x["one"])
        two = h5io.load(fn, "/two")
        assert two == x["two"]

        full = h5io.load(fn, "/")
        np.testing.assert_array_equal(x["one"], full["one"])
        assert x["two"] == full["two"]
예제 #4
0
def test_force_pickle1():
    with tmp_filename() as fn:
        x = dict(one=dict(two=np.arange(10)), three="string")
        xf = dict(one=dict(two=x["one"]["two"]), three=x["three"])

        h5io.save(fn, xf)
        xs = h5io.load(fn)

        np.testing.assert_array_equal(x["one"]["two"], xs["one"]["two"])
        assert x["three"] == xs["three"]

        # Try direct loading one
        two = h5io.load(fn, "/one/two")
        np.testing.assert_array_equal(x["one"]["two"], two)
예제 #5
0
def test_load_slice():
    with tmp_filename() as fn:
        x = np.arange(3 * 4 * 5).reshape((3, 4, 5))
        h5io.save(fn, dict(x=x))

        s = slice(None, 2)
        xs = h5io.load(fn, "/x", sel=s)
        np.testing.assert_array_equal(xs, x[s])

        s = (slice(None), slice(1, 3))
        xs = h5io.load(fn, "/x", sel=s)
        np.testing.assert_array_equal(xs, x[s])

        xs = h5io.load(fn, sel=s, unpack=True)
        np.testing.assert_array_equal(xs, x[s])

        h5io.save(fn, x)
        xs = h5io.load(fn, sel=s)
        np.testing.assert_array_equal(xs, x[s])
예제 #6
0
def assert_array(fn, x):
    h5io.save(fn, x)
    x1 = h5io.load(fn)
    np.testing.assert_array_equal(x, x1)
예제 #7
0
def reconstruct(fn, x):
    h5io.save(fn, x)
    return h5io.load(fn)