def setUp(self): self.h5py = import_or_skip('h5py') self.dac = Context(targets=[0, 1]) self.output_path = temp_filepath('.hdf5') self.expected = np.arange(20).reshape(2, 10) with self.h5py.File(self.output_path, 'w') as fp: fp["test"] = self.expected
def setUpClass(cls): # raise a skipTest if plotting import fails # (because matplotlib isn't installed, probably) cls.plt = import_or_skip("distarray.plotting") super(TestPlotting, cls).setUpClass() cls.da = Distribution(cls.context, (64, 64)) cls.arr = cls.context.ones(cls.da)
def test_writing_two_datasets(self): h5py = import_or_skip('h5py') datalen = 33 dac = Context(self.client) da = dac.empty((datalen,), dist={0: 'b'}) for i in range(datalen): da[i] = i output_path = temp_filepath('.hdf5') try: # make a file, and write to dataset 'foo' with h5py.File(output_path, 'w') as fp: fp['foo'] = np.arange(10) # try saving to a different dataset dac.save_hdf5(output_path, da, key='bar', mode='a') with h5py.File(output_path, 'r') as fp: self.assertTrue("foo" in fp) self.assertTrue("bar" in fp) finally: if os.path.exists(output_path): os.remove(output_path)
def test_write_3d(self): h5py = import_or_skip('h5py') shape = (4, 5, 3) source = np.random.random(shape) dac = Context(self.client) dist = {0: 'b', 1: 'c', 2: 'n'} da = dac.empty(shape, dist=dist) for i in range(shape[0]): for j in range(shape[1]): for k in range(shape[2]): da[i, j, k] = source[i, j, k] output_path = temp_filepath('.hdf5') try: dac.save_hdf5(output_path, da, mode='w') self.assertTrue(os.path.exists(output_path)) with h5py.File(output_path, 'r') as fp: self.assertTrue("buffer" in fp) assert_allclose(source, fp["buffer"]) finally: if os.path.exists(output_path): os.remove(output_path)
def setUp(self): self.rank = self.comm.Get_rank() self.h5py = import_or_skip('h5py') self.key = "data" # set up a common file to work with if self.rank == 0: self.output_path = temp_filepath(extension='.hdf5') else: self.output_path = None self.output_path = self.comm.bcast(self.output_path, root=0)
def setUpClass(cls): cls.h5py = import_or_skip('h5py') super(TestHdf5FileLoad, cls).setUpClass() cls.output_path = cls.context.apply(engine_temp_path, ('.hdf5',), targets=[cls.context.targets[0]])[0] cls.expected = np.arange(20).reshape(2, 10) def make_test_file(output_path, arr): import h5py with h5py.File(output_path, 'w') as fp: fp["test"] = arr cls.context.apply(make_test_file, (cls.output_path, cls.expected), targets=[cls.context.targets[0]])
def setUp(self): self.rank = self.comm.Get_rank() self.h5py = import_or_skip('h5py') self.key = "data" self.expected = numpy.arange(20).reshape(2, 10) # set up a common file to work with if self.rank == 0: self.output_path = temp_filepath(extension='.hdf5') with self.h5py.File(self.output_path, 'w') as fp: fp[self.key] = self.expected else: self.output_path = None self.comm.Barrier() # wait until file exists self.output_path = self.comm.bcast(self.output_path, root=0)
def test_hdf5_file_write(self): h5py = import_or_skip('h5py') key = "data" larr0 = LocalArray((51,), comm=self.comm) output_dir = tempfile.gettempdir() filename = 'localarray_hdf5test.hdf5' output_path = os.path.join(output_dir, filename) try: save_hdf5(output_path, larr0, key=key, mode='w') if self.comm.Get_rank() == 0: with h5py.File(output_path, 'r') as fp: self.assertTrue("data" in fp) finally: if self.comm.Get_rank() == 0: if os.path.exists(output_path): os.remove(output_path)
def test_write_block(self): h5py = import_or_skip('h5py') datalen = 33 dac = Context(self.client) da = dac.empty((datalen,), dist={0: 'b'}) for i in range(datalen): da[i] = i output_path = temp_filepath('.hdf5') try: dac.save_hdf5(output_path, da, mode='w') self.assertTrue(os.path.exists(output_path)) with h5py.File(output_path, 'r') as fp: self.assertTrue("buffer" in fp) expected = np.arange(datalen) assert_equal(expected, fp["buffer"]) finally: if os.path.exists(output_path): os.remove(output_path)
def setUp(self): super(TestHdf5FileSave, self).setUp() self.h5py = import_or_skip('h5py') self.output_path = self.context.apply(engine_temp_path, ('.hdf5',), targets=[self.context.targets[0]])[0]
def setUp(self): self.h5py = import_or_skip('h5py') self.output_path = temp_filepath('.hdf5') self.dac = Context()