예제 #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 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())
예제 #4
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)