Beispiel #1
0
 def join3(self):
     cube0 = cb.const_cube(shape="3x5", value=1.5)
     cube1 = cb.linear_cube(shape="3x5", start=1.5, increment=0.5)
     cube2 = cb.const_cube(shape="3x5", value=-1.5)
     cubes = (cube0, cube1, cube2)
     result = np.array(cubes)
     return self.impl_join(cubes, result)
Beispiel #2
0
 def join3(self):
     cube0 = cb.const_cube(shape="3x5", value=1.5)
     cube1 = cb.linear_cube(shape="3x5", start=1.5, increment=0.5)
     cube2 = cb.const_cube(shape="3x5", value=-1.5)
     cubes = (cube0, cube1, cube2)
     result = np.array(cubes)
     return self.impl_join(cubes, result)
Beispiel #3
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)
Beispiel #4
0
 def impl_const_cube(self, shape, dtype, value):
     dtype = cb.get_dtype(dtype)
     shape = Shape(shape)
     file_format = 'raw'
     filename_format = "const_{{shape}}_{{dtype}}_{value}.{{format}}".format(value=value)
     filename = filename_format.format(shape=shape, dtype=dtype, format=file_format)
     cube = cb.const_cube(shape=shape, dtype=dtype, value=value)
     
     cube_min = cube.min()
     cube_max = cube.max()
     self.assertEqual(cube_min, value)
     self.assertEqual(cube_max, value)
     self.assertEqual(dtype, cube.dtype.type)
Beispiel #5
0
    def impl_const_cube(self, shape, dtype, value):
        dtype = cb.get_dtype(dtype)
        shape = Shape(shape)
        file_format = 'raw'
        filename_format = "const_{{shape}}_{{dtype}}_{value}.{{format}}".format(
            value=value)
        filename = filename_format.format(shape=shape,
                                          dtype=dtype,
                                          format=file_format)
        cube = cb.const_cube(shape=shape, dtype=dtype, value=value)

        cube_min = cube.min()
        cube_max = cube.max()
        self.assertEqual(cube_min, value)
        self.assertEqual(cube_max, value)
        self.assertEqual(dtype, cube.dtype.type)
Beispiel #6
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)