def test_directaccess(): f = tempfile.NamedTemporaryFile() h5save(f.name, 'test') assert_equal(h5load(f.name), 'test') f.close() f = tempfile.NamedTemporaryFile() h5save(f.name, datasets['uni4medium']) assert_array_equal(h5load(f.name).samples, datasets['uni4medium'].samples)
def test_directaccess(): f = tempfile.NamedTemporaryFile() h5save(f.name, "test") assert_equal(h5load(f.name), "test") f.close() f = tempfile.NamedTemporaryFile() h5save(f.name, datasets["uni4medium"]) assert_array_equal(h5load(f.name).samples, datasets["uni4medium"].samples)
def test_dataset_without_chunks(): # ValueError: All chunk dimensions must be positive (Invalid arguments to routine: Out of range) # MH: This is not about Dataset chunks, but about an empty samples array f = tempfile.NamedTemporaryFile() ds = AttrDataset([8], a=dict(custom=1)) save(ds, f.name, compression='gzip') ds_loaded = h5load(f.name) ok_(ds_loaded.a.custom == ds.a.custom)
def test_recursion(): obj = range(2) obj.append(HDFDemo()) obj.append(obj) f = tempfile.NamedTemporaryFile() h5save(f.name, obj) lobj = h5load(f.name) assert_equal(obj[:2], lobj[:2]) assert_equal(type(obj[2]), type(lobj[2])) ok_(obj[3] is obj) ok_(lobj[3] is lobj)
def test_function_ptrs(): ds = load_example_fmri_dataset() # add a mapper with a function ptr inside ds = ds.get_mapped(mean_sample()) f = tempfile.NamedTemporaryFile() h5save(f.name, ds) ds_loaded = h5load(f.name) fresh = load_example_fmri_dataset().O # check that the reconstruction function pointer in the FxMapper points # to the right one assert_array_equal(ds_loaded.a.mapper.forward(fresh), ds.samples)
def test_function_ptrs(): if not externals.exists('nifti') and not externals.exists('nibabel'): raise SkipTest ds = load_example_fmri_dataset() # add a mapper with a function ptr inside ds = ds.get_mapped(mean_sample()) f = tempfile.NamedTemporaryFile() h5save(f.name, ds) ds_loaded = h5load(f.name) fresh = load_example_fmri_dataset().O # check that the reconstruction function pointer in the FxMapper points # to the right one assert_array_equal(ds_loaded.a.mapper.forward(fresh), ds.samples)
def _test_h5py_clfs(): # YOH: For now just to see which ones work (could be stored/loaded) # Later on to become a proper valid test from mvpa.clfs.warehouse import clfswh, regrswh for lrn in clfswh[:] + regrswh[:]: print lrn f = tempfile.NamedTemporaryFile() try: h5save(f.name, lrn) lrn_ = h5load(f.name) print "ok: %s" % lrn_ except Exception, e: #raise AssertionError, print "Failed to store %s due to %r" % (lrn, e)
# lets simply clone it so we could make its all states on lrn = lrn.clone() # Lets enable all the states lrn.ca.enable('all') f = tempfile.NamedTemporaryFile() # Store/reload untrained learner try: h5save(f.name, lrn) except Exception, e: raise AssertionError, \ "Failed to store due to %r" % (e,) try: lrn_ = h5load(f.name) except Exception, e: raise AssertionError, \ "Failed to load due to %r" % (e,) ok_(isinstance(lrn_, Classifier)) # Verify that we have the same ca enabled # XXX FAILS atm! #ok_(set(lrn.ca.enabled) == set(lrn_.ca.enabled)) # lets choose a dataset dsname, errorfx = \ {False: ('uni2large', MeanMismatchErrorFx()), True: ('sin_modulated', CorrErrorFx())}\ ['regression' in lrn.__tags__] ds_train = datasets['%s_train' % dsname]
# lets simply clone it so we could make its all states on lrn = lrn.clone() # Lets enable all the states lrn.ca.enable('all') f = tempfile.NamedTemporaryFile() # Store/reload untrained learner try: h5save(f.name, lrn) except Exception, e: raise AssertionError, \ "Failed to store due to %r" % (e,) try: lrn_ = h5load(f.name) except Exception, e: raise AssertionError, \ "Failed to load due to %r" % (e,) ok_(isinstance(lrn_, Classifier)) # Verify that we have the same ca enabled # XXX FAILS atm! #ok_(set(lrn.ca.enabled) == set(lrn_.ca.enabled)) # lets choose a dataset dsname, errorfx = \ {False: ('uni2large', mean_mismatch_error), True: ('sin_modulated', corr_error)}\ ['regression' in lrn.__tags__] ds = datasets[dsname]
def test_matfile_v73_compat(): mat = h5load(os.path.join(pymvpa_dataroot, 'v73.mat')) assert_equal(len(mat), 2) assert_equal(sorted(mat.keys()), ['x', 'y']) assert_array_equal(mat['x'], np.arange(6)[None].T) assert_array_equal(mat['y'], np.array([(1, 0, 1)], dtype='uint8').T)
def test_0d_object_ndarray(): f = tempfile.NamedTemporaryFile() a = np.array(0, dtype=object) h5save(f.name, a) a_ = h5load(f.name) ok_(a == a_)
def test_matfile_v73_compat(): mat = h5load(os.path.join(pymvpa_dataroot, 'v73.mat')) assert_equal(len(mat), 2) assert_equal(sorted(mat.keys()), ['x', 'y']) assert_array_equal(mat['x'], np.arange(6)[None].T) assert_array_equal(mat['y'], np.array([(1,0,1)], dtype='uint8').T)
def test_matfile_v73_compat(): mat = h5load(os.path.join(pymvpa_dataroot, "v73.mat")) assert_equal(len(mat), 2) assert_equal(sorted(mat.keys()), ["x", "y"]) assert_array_equal(mat["x"], np.arange(6)[None].T) assert_array_equal(mat["y"], np.array([(1, 0, 1)], dtype="uint8").T)