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)
def test_RectGrid_corners(): vec1 = np.array([2, 3, 4, 5]) vec2 = np.array([-4, -2, 0, 2, 4]) vec3 = np.array([-1, 0]) scalar = 0.5 minmax1 = (vec1[0], vec1[-1]) minmax2 = (vec2[0], vec2[-1]) minmax3 = (vec3[0], vec3[-1]) # C ordering corners = [] for x1 in minmax1: for x2 in minmax2: for x3 in minmax3: corners.append(np.array((x1, x2, x3), dtype=float)) grid = RectGrid(vec1, vec2, vec3) assert all_equal(corners, grid.corners()) assert all_equal(corners, grid.corners(order='C')) # minpt and maxpt should appear at the beginning and the end, resp. assert all_equal(grid.min_pt, grid.corners()[0]) assert all_equal(grid.max_pt, grid.corners()[-1]) # F ordering corners = [] for x3 in minmax3: for x2 in minmax2: for x1 in minmax1: corners.append(np.array((x1, x2, x3), dtype=float)) assert all_equal(corners, grid.corners(order='F')) # Degenerate axis 1 corners = [] for x2 in minmax2: for x3 in minmax3: corners.append(np.array((scalar, x2, x3), dtype=float)) grid = RectGrid(scalar, vec2, vec3) assert all_equal(corners, grid.corners()) # Degenerate axis 2 corners = [] for x1 in minmax1: for x3 in minmax3: corners.append(np.array((x1, scalar, x3), dtype=float)) grid = RectGrid(vec1, scalar, vec3) assert all_equal(corners, grid.corners()) # Degenerate axis 3 corners = [] for x1 in minmax1: for x2 in minmax2: corners.append(np.array((x1, x2, scalar), dtype=float)) grid = RectGrid(vec1, vec2, scalar) assert all_equal(corners, grid.corners()) # All degenerate corners = [(scalar, scalar)] grid = RectGrid(scalar, scalar) assert all_equal(corners, grid.corners())