def test_RectGrid_is_subgrid(): vec1 = np.array([2, 3, 4, 5]) vec1_sup = np.array([2, 3, 4, 5, 6, 7]) vec2 = np.array([-4, -2, 0, 2, 4]) vec2_sup = np.array([-6, -4, -2, 0, 2, 4, 6]) vec2_sub = np.array([-4, -2, 0, 2]) scalar = 0.5 grid = RectGrid(vec1, vec2) assert grid.is_subgrid(grid) sup_grid = RectGrid(vec1_sup, vec2_sup) assert grid.is_subgrid(sup_grid) assert not sup_grid.is_subgrid(grid) not_sup_grid = RectGrid(vec1_sup, vec2_sub) assert not grid.is_subgrid(not_sup_grid) assert not not_sup_grid.is_subgrid(grid) # Fuzzy check fuzzy_vec1_sup = vec1_sup + (0.1, 0.05, 0, -0.1, 0, 0.1) fuzzy_vec2_sup = vec2_sup + (0.1, 0.05, 0, -0.1, 0, 0.1, 0.05) fuzzy_sup_grid = RectGrid(fuzzy_vec1_sup, fuzzy_vec2_sup) assert grid.is_subgrid(fuzzy_sup_grid, atol=0.15) fuzzy_vec2_sup = vec2_sup + (0.1, 0.05, 0, -0.1, 0, 0.11, 0.05) fuzzy_sup_grid = RectGrid(fuzzy_vec1_sup, fuzzy_vec2_sup) assert not grid.is_subgrid(fuzzy_sup_grid, atol=0.1) # Changes in the non-overlapping part don't matter fuzzy_vec2_sup = vec2_sup + (0.1, 0.05, 0, -0.1, 0, 0.05, 0.11) fuzzy_sup_grid = RectGrid(fuzzy_vec1_sup, fuzzy_vec2_sup) assert grid.is_subgrid(fuzzy_sup_grid, atol=0.15) # With degenerate axis grid = RectGrid(vec1, scalar, vec2) sup_grid = RectGrid(vec1_sup, scalar, vec2_sup) assert grid.is_subgrid(sup_grid) fuzzy_sup_grid = RectGrid(vec1, scalar + 0.1, vec2) assert grid.is_subgrid(fuzzy_sup_grid, atol=0.15)
def test_empty_grid(): """Check if empty grids behave as expected and all methods work.""" grid = RectGrid() assert grid.ndim == grid.size == len(grid) == 0 assert grid.shape == () assert grid.coord_vectors == () assert grid.nondegen_byaxis == () assert np.array_equal(grid.min_pt, []) assert np.array_equal(grid.max_pt, []) assert np.array_equal(grid.mid_pt, []) assert np.array_equal(grid.stride, []) assert np.array_equal(grid.extent, []) out = np.array([]) grid.min(out=out) grid.max(out=out) assert grid.is_uniform assert grid.convex_hull() == odl.IntervalProd([], []) same = RectGrid() assert grid == same assert hash(grid) == hash(same) other = RectGrid([0, 2, 3]) assert grid != other assert grid.is_subgrid(other) assert [] in grid assert 1.0 not in grid assert grid.insert(0, other) == other assert other.insert(0, grid) == other assert other.insert(1, grid) == other assert grid.squeeze() == grid assert np.array_equal(grid.points(), np.array([]).reshape((0, 0))) assert grid.corner_grid() == grid assert np.array_equal(grid.corners(), np.array([]).reshape((0, 0))) assert grid.meshgrid == () assert grid[[]] == grid assert np.array_equal(np.asarray(grid), np.array([]).reshape((0, 0))) assert grid == uniform_grid([], [], ()) repr(grid)