Beispiel #1
0
    def __init__(self, logger=None, verbose_level=0, trace_errors=False, patterns=None):
        if logger is None: 
            logger = conf.get_test_logger()
        self.logger = logger
        RUBIK_TEST_CONF.verbose_level = verbose_level
        RUBIK_TEST_CONF.trace_errors = trace_errors
        RUBIK_TEST_CONF.logger = logger

        self.name = self.__class__.__name__

        # global setup
        set_random_seed(100)
    
        # create runner
        self.rubik_test_runner = RubikTestRunner()
Beispiel #2
0
    def __init__(self,
                 logger=None,
                 verbose_level=0,
                 trace_errors=False,
                 patterns=None):
        if logger is None:
            logger = conf.get_test_logger()
        self.logger = logger
        RUBIK_TEST_CONF.verbose_level = verbose_level
        RUBIK_TEST_CONF.trace_errors = trace_errors
        RUBIK_TEST_CONF.logger = logger

        self.name = self.__class__.__name__

        # global setup
        set_random_seed(100)

        # create runner
        self.rubik_test_runner = RubikTestRunner()
    def impl_write_cube_out_of_core(self, kind, shape, dtype, buffer_size=None):
        dtype = utilities.get_dtype(dtype)
        shape = Shape(shape)
        filename_format_a = "a_{kind}_{{shape}}_{{dtype}}.{{format}}".format(kind=kind)
        filename_format_b = "b_{kind}_{{shape}}_{{dtype}}.{{format}}".format(kind=kind)
        filename_format_c = "c_{kind}_{{shape}}_{{dtype}}.{{format}}".format(kind=kind)
        if issubclass(dtype, np.integer):
            l_start = dtype(3)
            l_increment = dtype(2)
            c_value = dtype(7)
        else:
            l_start = dtype(0.5)
            l_increment = dtype(1.5)
            c_value = dtype(7.5)
        p_args = []
        n_args = {}
        if kind == "random":
            ooc_function = cb.write_random_cube
            oc_function = cb.random_cube
        elif kind == "linear":
            ooc_function = cb.write_linear_cube
            oc_function = cb.linear_cube
            n_args["start"] = l_start
            n_args["increment"] = l_increment
        elif kind == "const":
            ooc_function = cb.write_const_cube
            oc_function = cb.const_cube
            n_args["value"] = c_value
        else:
            assert False, kind
        cb.set_random_seed(10)
        ooc_function(filename_format_a, shape=shape, dtype=dtype, *p_args, **n_args)
        filename_a = filename_format_a.format(shape=shape, dtype=dtype.__name__, format="raw")
        self.assertFileExistsAndHasShape(filename_a, shape=shape, dtype=dtype)
        ooc_cube = cb.read_cube_raw(filename_format_a, shape=shape, dtype=dtype)
        self.assertTrue(ooc_cube.dtype == dtype)
        self.assertEqual(ooc_cube.size, shape.count())

        cb.set_random_seed(10)
        oc_cube = oc_function(shape=shape, dtype=dtype, *p_args, **n_args)
        self.assertCubesAreEqual(ooc_cube, oc_cube)

        if kind == "random":
            pass
        elif kind == "linear":
            #     0) start +    0 * increment
            #     1) start +    1 * increment
            #     2) start +    2 * increment
            #     3) start +    3 * increment
            #        ...
            # count) start + count * increment
            # ==    (start * count) + (((count - 1) * count) // 2) * increment
            count = shape.count()
            sum_count = ((count - 1) * count) // 2
            l_sum = (l_start * count) + (l_increment * sum_count)
            self.assertEqual(cb.precise_sum(ooc_cube), l_sum)
        elif kind == "const":
            self.assertEqual(cb.precise_sum(ooc_cube), shape.count() * c_value)
        filename_b = filename_format_b.format(shape=shape, dtype=dtype.__name__, format="raw")
        ooc_cube.tofile(filename_b)
        self.assertFilesAreEqual(filename_a, filename_b)
Beispiel #4
0
    def impl_write_cube_out_of_core(self,
                                    kind,
                                    shape,
                                    dtype,
                                    buffer_size=None):
        dtype = utilities.get_dtype(dtype)
        shape = Shape(shape)
        filename_format_a = "a_{kind}_{{shape}}_{{dtype}}.{{format}}".format(
            kind=kind)
        filename_format_b = "b_{kind}_{{shape}}_{{dtype}}.{{format}}".format(
            kind=kind)
        filename_format_c = "c_{kind}_{{shape}}_{{dtype}}.{{format}}".format(
            kind=kind)
        if issubclass(dtype, np.integer):
            l_start = dtype(3)
            l_increment = dtype(2)
            c_value = dtype(7)
        else:
            l_start = dtype(0.5)
            l_increment = dtype(1.5)
            c_value = dtype(7.5)
        p_args = []
        n_args = {}
        if kind == 'random':
            ooc_function = cb.write_random_cube
            oc_function = cb.random_cube
        elif kind == 'linear':
            ooc_function = cb.write_linear_cube
            oc_function = cb.linear_cube
            n_args['start'] = l_start
            n_args['increment'] = l_increment
        elif kind == 'const':
            ooc_function = cb.write_const_cube
            oc_function = cb.const_cube
            n_args['value'] = c_value
        else:
            assert False, kind
        cb.set_random_seed(10)
        ooc_function(filename_format_a,
                     shape=shape,
                     dtype=dtype,
                     *p_args,
                     **n_args)
        filename_a = filename_format_a.format(
            shape=shape,
            dtype=dtype.__name__,
            format='raw',
        )
        self.assertFileExistsAndHasShape(filename_a, shape=shape, dtype=dtype)
        ooc_cube = cb.read_cube_raw(filename_format_a,
                                    shape=shape,
                                    dtype=dtype)
        self.assertTrue(ooc_cube.dtype == dtype)
        self.assertEqual(ooc_cube.size, shape.count())

        cb.set_random_seed(10)
        oc_cube = oc_function(shape=shape, dtype=dtype, *p_args, **n_args)
        self.assertCubesAreEqual(ooc_cube, oc_cube)

        if kind == 'random':
            pass
        elif kind == 'linear':
            #     0) start +    0 * increment
            #     1) start +    1 * increment
            #     2) start +    2 * increment
            #     3) start +    3 * increment
            #        ...
            # count) start + count * increment
            # ==    (start * count) + (((count - 1) * count) // 2) * increment
            count = shape.count()
            sum_count = ((count - 1) * count) // 2
            l_sum = (l_start * count) + (l_increment * sum_count)
            self.assertEqual(cb.precise_sum(ooc_cube), l_sum)
        elif kind == 'const':
            self.assertEqual(cb.precise_sum(ooc_cube), shape.count() * c_value)
        filename_b = filename_format_b.format(
            shape=shape,
            dtype=dtype.__name__,
            format='raw',
        )
        ooc_cube.tofile(filename_b)
        self.assertFilesAreEqual(filename_a, filename_b)