def impl_stats_random_file(self, shape, dtype, buffer_size): dtype = cb.get_dtype(dtype) shape = Shape(shape) file_format = 'raw' filename_format = "stats_random_{shape}_{dtype}.{format}" filename = filename_format.format(shape=shape, dtype=dtype, format=file_format) dmin = 3 for d in shape: assert d >= dmin, "d={} < {}".format(d, dmin) cube = cb.random_cube(shape=shape, dtype=dtype) stats_info_cube = cb.stats_info(cube) cube.tofile(filename) self.assertFileExistsAndHasShape(filename, shape=shape, dtype=dtype) stats_info_oc = cb.stats_file(filename, shape=shape, dtype=dtype, file_format=file_format, out_of_core=False) self.assertAlmostEqualStatsInfo(stats_info_oc, stats_info_cube) stats_info_ooc = cb.stats_file(filename, shape=shape, dtype=dtype, file_format=file_format, out_of_core=True, progress_frequency=-1.0, buffer_size=buffer_size) self.assertAlmostEqualStatsInfo(stats_info_ooc, stats_info_cube) self.assertEqual(stats_info_oc.report(), stats_info_ooc.report())
def impl_histogram(self, shape, dtype, hlength, bins, mode): dtype = cb.get_dtype(dtype) shape = Shape(shape) cube = cb.random_cube(shape=shape, dtype=dtype) output_lines = cb.histogram(cube, hlength=hlength, bins=bins, mode=mode) self.assertEqual(len(output_lines), bins) for line in output_lines: self.assertEqual(len(line), hlength)
def impl_histogram(self, shape, dtype, hlength, bins, mode): dtype = cb.get_dtype(dtype) shape = Shape(shape) cube = cb.random_cube(shape=shape, dtype=dtype) output_lines = cb.histogram(cube, hlength=hlength, bins=bins, mode=mode) self.assertEqual(len(output_lines), bins) for line in output_lines: self.assertEqual(len(line), hlength)
def create_random_cubes(self, shape, dtype): cube_l = cb.random_cube(shape=shape, dtype=dtype) cube_r = cube_l * 1.5 dmin = 2 for d in shape: assert d >= dmin, "d={} < {}".format(d, dmin) index_diff_0 = tuple(0 for i in shape) index_diff_1 = tuple(1 for i in shape) cube_r[index_diff_0] = cube_l[index_diff_0] * 0.1 cube_r[index_diff_1] = cube_l[index_diff_1] * 10.3 return cube_l, cube_r
def impl_random_cube(self, shape, dtype, min, max): dtype = cb.get_dtype(dtype) shape = Shape(shape) file_format = 'raw' filename_format = "random_{{shape}}_{{dtype}}_{min}_{max}.{{format}}".format(min=min, max=max) filename = filename_format.format(shape=shape, dtype=dtype, format=file_format) cube = cb.random_cube(shape=shape, dtype=dtype, min=min, max=max) cube_min = cube.min() cube_max = cube.max() self.assertGreaterEqual(cube_min, min) self.assertLessEqual(cube_max, max) self.assertEqual(dtype, cube.dtype.type)
def impl_random_cube(self, shape, dtype, min, max): dtype = cb.get_dtype(dtype) shape = Shape(shape) file_format = 'raw' filename_format = "random_{{shape}}_{{dtype}}_{min}_{max}.{{format}}".format( min=min, max=max) filename = filename_format.format(shape=shape, dtype=dtype, format=file_format) cube = cb.random_cube(shape=shape, dtype=dtype, min=min, max=max) cube_min = cube.min() cube_max = cube.max() self.assertGreaterEqual(cube_min, min) self.assertLessEqual(cube_max, max) self.assertEqual(dtype, cube.dtype.type)
def impl_stats_random_file(self, shape, dtype, buffer_size): dtype = cb.get_dtype(dtype) shape = Shape(shape) file_format = 'raw' filename_format = "stats_random_{shape}_{dtype}.{format}" filename = filename_format.format(shape=shape, dtype=dtype, format=file_format) dmin = 3 for d in shape: assert d >= dmin, "d={} < {}".format(d, dmin) cube = cb.random_cube(shape=shape, dtype=dtype) stats_info_cube = cb.stats_info(cube) cube.tofile(filename) self.assertFileExistsAndHasShape(filename, shape=shape, dtype=dtype) stats_info_oc = cb.stats_file(filename, shape=shape, dtype=dtype, file_format=file_format, out_of_core=False) self.assertAlmostEqualStatsInfo(stats_info_oc, stats_info_cube) stats_info_ooc = cb.stats_file(filename, shape=shape, dtype=dtype, file_format=file_format, out_of_core=True, progress_frequency=-1.0, buffer_size=buffer_size) self.assertAlmostEqualStatsInfo(stats_info_ooc, stats_info_cube) self.assertEqual(stats_info_oc.report(), stats_info_ooc.report())
def write_read_cube_text(self): cube = cb.random_cube(shape="5x6", dtype="float32") self.impl_write_read_cube(file_format="text", cube=cube, filename_format="wr_{shape}_{dtype}.{format}")
def write_read_cube_file_format_csv(self): cube = cb.random_cube(shape="4x5x6", dtype="float32") self.impl_write_read_cube_file_format( file_format="csv", cube=cube, filename_format="wr_{shape}_{dtype}.{format}" )
def write_read_cube_text(self): cube = cb.random_cube(shape="5x6", dtype='float32') self.impl_write_read_cube( file_format='text', cube=cube, filename_format="wr_{shape}_{dtype}.{format}")
def write_read_cube_file_format_csv(self): cube = cb.random_cube(shape="4x5x6", dtype='float32') self.impl_write_read_cube_file_format( file_format='csv', cube=cube, filename_format="wr_{shape}_{dtype}.{format}")