Пример #1
0
    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())
Пример #2
0
    def impl_stats_const_file(self, shape, dtype, buffer_size):
        dtype = cb.get_dtype(dtype)
        shape = Shape(shape)
        file_format = 'raw'
        filename_format = "stats_const_{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_max_index = tuple(0 for i in shape)
        cube_min_index = tuple(1 for i in shape)
        cube_zero_index = tuple(2 for i in shape)
        cube_value = 1.0
        cube_max = 10.0
        cube_min = -23.0
        cube_zero = 0.0
        cube_sum = cube_max + cube_min + cube_value * (shape.count() - dmin)
        cube_ave = cube_sum / float(shape.count())
        cube = cb.const_cube(shape=shape, dtype=dtype, value=cube_value)
        cube[cube_max_index] = cube_max
        cube[cube_min_index] = cube_min
        cube[cube_zero_index] = cube_zero
        cube_count_zero = 1
        cube_count_nonzero = shape.count() - cube_count_zero
        cube_count_nan = 0
        cube_count_inf = 0

        stats_info_cube = cb.stats_info(cube)

        self.assertEqual(stats_info_cube.cube_sum, cube_sum)
        self.assertEqual(stats_info_cube.cube_ave, cube_ave)
        self.assertEqual(stats_info_cube.cube_max, cube_max)
        self.assertEqual(stats_info_cube.cube_min, cube_min)
        self.assertEqual(stats_info_cube.cube_max_index, cube_max_index)
        self.assertEqual(stats_info_cube.cube_min_index, cube_min_index)
        self.assertEqual(stats_info_cube.cube_count_zero, cube_count_zero)
        self.assertEqual(stats_info_cube.cube_count_nonzero, cube_count_nonzero)
        self.assertEqual(stats_info_cube.cube_count_nan, cube_count_nan)
        self.assertEqual(stats_info_cube.cube_count_inf, cube_count_inf)

        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.assertEqual(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.assertEqual(stats_info_ooc, stats_info_cube)
Пример #3
0
    def diff_cubes(self, kind, shape, dtype, cube_l, cube_r, buffer_size):
        diff_info_cubes = cb.diff_info(cube_l, cube_r)
        stats_info_cube_l = cb.stats_info(cube_l)
        stats_info_cube_r = cb.stats_info(cube_r)
        stats_info_cube_abs = cb.stats_info(cb.abs_diff_cube(cube_l, cube_r))
        stats_info_cube_rel = cb.stats_info(cb.rel_diff_cube(cube_l, cube_r))

        self.assertAlmostEqualStatsInfo(diff_info_cubes.left, stats_info_cube_l)
        self.assertAlmostEqualStatsInfo(diff_info_cubes.right, stats_info_cube_r)
        self.assertAlmostEqualStatsInfo(diff_info_cubes.abs_diff, stats_info_cube_abs)
        self.assertAlmostEqualStatsInfo(diff_info_cubes.rel_diff, stats_info_cube_rel)

        cube_l_filename_format = "cube_l_{kind}_{{shape}}_{{dtype}}.{{format}}".format(kind=kind)
        cube_l_filename = cube_l_filename_format.format(shape=shape, dtype=dtype, format='raw')
        cube_r_filename_format = "cube_r_{kind}_{{shape}}_{{dtype}}.{{format}}".format(kind=kind)
        cube_r_filename = cube_r_filename_format.format(shape=shape, dtype=dtype, format='raw')
        cube_l.tofile(cube_l_filename)
        cube_r.tofile(cube_r_filename)

        diff_info_oc = cb.diff_files(cube_l_filename, cube_r_filename,
            shape=shape,
            dtype=dtype,
            out_of_core=False)

        self.assertEqual(diff_info_oc, diff_info_cubes)
        diff_info_ooc = cb.diff_files(cube_l_filename, cube_r_filename,
            shape=shape,
            dtype=dtype,
            out_of_core=True,
            buffer_size=buffer_size,
            progress_frequency=-1.0)
        self.assertEqual(diff_info_oc, diff_info_cubes)

        diff_info_oc_report = diff_info_oc.report()
        diff_info_ooc_report = diff_info_ooc.report()
        self.assertEqual(diff_info_oc_report, diff_info_ooc_report)
Пример #4
0
    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())
Пример #5
0
    def impl_stats_const_file(self, shape, dtype, buffer_size):
        dtype = cb.get_dtype(dtype)
        shape = Shape(shape)
        file_format = 'raw'
        filename_format = "stats_const_{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_max_index = tuple(0 for i in shape)
        cube_min_index = tuple(1 for i in shape)
        cube_zero_index = tuple(2 for i in shape)
        cube_value = 1.0
        cube_max = 10.0
        cube_min = -23.0
        cube_zero = 0.0
        cube_sum = cube_max + cube_min + cube_value * (shape.count() - dmin)
        cube_ave = cube_sum / float(shape.count())
        cube = cb.const_cube(shape=shape, dtype=dtype, value=cube_value)
        cube[cube_max_index] = cube_max
        cube[cube_min_index] = cube_min
        cube[cube_zero_index] = cube_zero
        cube_count_zero = 1
        cube_count_nonzero = shape.count() - cube_count_zero
        cube_count_nan = 0
        cube_count_inf = 0

        stats_info_cube = cb.stats_info(cube)

        self.assertEqual(stats_info_cube.cube_sum, cube_sum)
        self.assertEqual(stats_info_cube.cube_ave, cube_ave)
        self.assertEqual(stats_info_cube.cube_max, cube_max)
        self.assertEqual(stats_info_cube.cube_min, cube_min)
        self.assertEqual(stats_info_cube.cube_max_index, cube_max_index)
        self.assertEqual(stats_info_cube.cube_min_index, cube_min_index)
        self.assertEqual(stats_info_cube.cube_count_zero, cube_count_zero)
        self.assertEqual(stats_info_cube.cube_count_nonzero,
                         cube_count_nonzero)
        self.assertEqual(stats_info_cube.cube_count_nan, cube_count_nan)
        self.assertEqual(stats_info_cube.cube_count_inf, cube_count_inf)

        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.assertEqual(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.assertEqual(stats_info_ooc, stats_info_cube)