Exemple #1
0
    def test_internal_index_invalid_arg_3d(self):
        morton = MortonOrder(shape=(8, 8, 8))
        with pytest.raises(AssertionError) as err:
            morton.internal_index(1)
        assert err.value.args[0] == "Number of args (1) does not match up with internal dimension (3)."

        with pytest.raises(AssertionError) as err:
            morton.internal_index(1, 1)
        assert err.value.args[0] == "Number of args (2) does not match up with internal dimension (3)."
Exemple #2
0
 def test_iter_keys_2d(self):
     morton = MortonOrder(shape=(4, 4))
     assert list(morton.iter_keys()) == [
         (0, 0), (1, 0), (0, 1), (1, 1),
         (2, 0), (3, 0), (2, 1), (3, 1),
         (0, 2), (1, 2), (0, 3), (1, 3),
         (2, 2), (3, 2), (2, 3), (3, 3)
     ]
     morton = MortonOrder(shape=(32, 32))
     assert len(list(morton.iter_keys())) == 32**2
    def test_same_internal_acces_pattern_yields_same_stats(self):
        vals = np.random.rand(16, 16, 16)
        morton = MortonOrder(vals, cache=make_cache())
        block_arr = BlockArray(vals, cache=make_cache())
        row_arr = RowMajorArray(vals, cache=make_cache())

        stats = []
        for data in [morton, block_arr, row_arr]:
            for is_warm_up in [True, False]:
                res = data.empty_of_same_shape()
                for key in data.iter_keys():
                    res[key] = 2 * data[key]
                data.cache.force_write_back()
                if not is_warm_up:
                    stats.append(list(data.cache.stats()))
                data.cache.reset_stats()
        assert stats[0] == stats[1] and stats[1] == stats[2]
Exemple #4
0
 def test_setting_to_2d_pic(self):
     vals = np.random.rand(4, 4)
     morton = MortonOrder(picture=vals)
     assert morton.dim == 2
     assert morton.shape == vals.shape
     np.testing.assert_almost_equal(vals, morton.to_numpy())
Exemple #5
0
 def test_empty_of_same_shape(self):
     vals = np.random.rand(8, 8)
     morton1 = MortonOrder(vals)
     morton2 = morton1.empty_of_same_shape()  # All 0's in same shape
     assert morton1.shape == morton2.shape
     np.testing.assert_almost_equal(np.zeros((8, 8)), morton2.to_numpy())
# Set to true if you want to run the tests again.
# Otherwise just loads results from JSON
GENERATE_NEW_RESULTS = True

# Set to true if you want to save figures to disk. Change path as needed
SAVE_FIGURES_TO_DISK = True
FIG_SAVE_PATH = "../../thesis/figures/props/"

# Global constants for test. Change these if you want to run another test
MAX_PROP_LEVEL = 32
SHAPE = (128, 128, 128)
MID = SHAPE[0] // 2
START_POINTS = [(0, 0, 0), (MID, MID, MID)]
DATA_ARRS = [
    MortonOrder(shape=SHAPE),
    RowMajorArray(shape=SHAPE),
    BlockArray(shape=SHAPE)
]

# Global constants used for type-safety when accessing properties in
# dictionary. Do not change
INF = float("inf")
XS, YS1, YS2 = "xs", "ys1", "ys2"
META, MAX_PROP_LEVEL_STR, SHAPE_STR = "meta", "max_prop_level", "shape"

sns.set(font_scale=1.9)
matplotlib.rcParams['figure.figsize'] = (1.1*18.0, 1.1*4.8)


def indices_for_prop_level_2d(prop_level: int, start_point: tuple) -> set: