Skip to content

Commit f55c286

Browse files
committed
RF: Drop ndim/shape attributes, make explicit comment on __array_priority__
1 parent 8ac45d0 commit f55c286

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

nibabel/pointset.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class Pointset:
6666
coordinates: CoordinateArray
6767
affine: np.ndarray
6868
homogeneous: bool = False
69-
ndim = 2
69+
70+
# Force use of __rmatmul__ with numpy arrays
7071
__array_priority__ = 99
7172

7273
def __init__(
@@ -88,11 +89,6 @@ def __init__(
8889
if np.any(self.affine[-1, :-1] != 0) or self.affine[-1, -1] != 1:
8990
raise ValueError(f'Invalid affine matrix:\n{self.affine}')
9091

91-
@property
92-
def shape(self) -> tuple[int, int]:
93-
"""The shape of the coordinate array"""
94-
return self.coordinates.shape
95-
9692
@property
9793
def n_coords(self) -> int:
9894
"""Number of coordinates

nibabel/tests/test_pointset.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,15 @@ def test_init(self, shape, homogeneous):
3030
if homogeneous:
3131
coords = np.column_stack([coords, np.ones(shape[0])])
3232

33-
expected_shape = (shape[0], shape[1] + homogeneous)
34-
3533
points = ps.Pointset(coords, homogeneous=homogeneous)
36-
assert points.shape == expected_shape
3734
assert np.allclose(points.affine, np.eye(shape[1] + 1))
3835
assert points.homogeneous is homogeneous
39-
assert points.ndim == 2
40-
assert points.n_coords == shape[0]
41-
assert points.dim == shape[1]
36+
assert (points.n_coords, points.dim) == shape
4237

4338
points = ps.Pointset(coords, affine=np.diag([2] * shape[1] + [1]), homogeneous=homogeneous)
44-
assert points.shape == expected_shape
4539
assert np.allclose(points.affine, np.diag([2] * shape[1] + [1]))
4640
assert points.homogeneous is homogeneous
47-
assert points.ndim == 2
48-
assert points.n_coords == shape[0]
49-
assert points.dim == shape[1]
41+
assert (points.n_coords, points.dim) == shape
5042

5143
# Badly shaped affine
5244
with pytest.raises(ValueError):
@@ -148,7 +140,8 @@ def test_from_image(self, shape):
148140
grid = ps.Grid.from_image(img)
149141
grid_coords = grid.get_coords()
150142

151-
assert grid.shape == (prod(shape[:3]), 3)
143+
assert grid.n_coords == prod(shape[:3])
144+
assert grid.dim == 3
152145
assert np.allclose(grid.affine, affine)
153146

154147
assert np.allclose(grid_coords[0], [0, 0, 0])
@@ -164,7 +157,8 @@ def test_from_mask(self):
164157
grid = ps.Grid.from_mask(img)
165158
grid_coords = grid.get_coords()
166159

167-
assert grid.shape == (1, 3)
160+
assert grid.n_coords == 1
161+
assert grid.dim == 3
168162
assert np.array_equal(grid_coords, [[2, 3, 4]])
169163

170164
def test_to_mask(self):

0 commit comments

Comments
 (0)