Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/iris/tests/unit/util/test_broadcast_to_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
class Test_broadcast_to_shape(tests.IrisTest):
def test_same_shape(self):
# broadcast to current shape should result in no change
a = np.random.random([2, 3])
rng = np.random.default_rng()
a = rng.random((2, 3))

b = broadcast_to_shape(a, a.shape, (0, 1))
self.assertArrayEqual(b, a)

def test_added_dimensions(self):
# adding two dimensions, on at the front and one in the middle of
# the existing dimensions
a = np.random.random([2, 3])
rng = np.random.default_rng()
a = rng.random((2, 3))
b = broadcast_to_shape(a, (5, 2, 4, 3), (1, 3))
for i in range(5):
for j in range(4):
Expand All @@ -37,7 +40,8 @@ def test_added_dimensions(self):
def test_added_dimensions_transpose(self):
# adding dimensions and having the dimensions of the input
# transposed
a = np.random.random([2, 3])
rng = np.random.default_rng()
a = rng.random((2, 3))
b = broadcast_to_shape(a, (5, 3, 4, 2), (3, 1))
for i in range(5):
for j in range(4):
Expand All @@ -47,7 +51,8 @@ def test_added_dimensions_transpose(self):
def test_lazy_added_dimensions_transpose(self, mocked_compute):
# adding dimensions and having the dimensions of the input
# transposed
a = da.random.random([2, 3])
rng = da.random.default_rng()
a = rng.random((2, 3))
b = broadcast_to_shape(a, (5, 3, 4, 2), (3, 1))
mocked_compute.assert_not_called()
for i in range(5):
Expand All @@ -56,7 +61,8 @@ def test_lazy_added_dimensions_transpose(self, mocked_compute):

def test_masked(self):
# masked arrays are also accepted
a = np.random.random([2, 3])
rng = np.random.default_rng()
a = rng.random((2, 3))
m = ma.array(a, mask=[[0, 1, 0], [0, 1, 1]])
b = broadcast_to_shape(m, (5, 3, 4, 2), (3, 1))
for i in range(5):
Expand All @@ -66,7 +72,8 @@ def test_masked(self):
@mock.patch.object(dask.base, "compute", wraps=dask.base.compute)
def test_lazy_masked(self, mocked_compute):
# masked arrays are also accepted
a = np.random.random([2, 3])
rng = np.random.default_rng()
a = rng.random((2, 3))
m = da.ma.masked_array(a, mask=[[0, 1, 0], [0, 1, 1]])
b = broadcast_to_shape(m, (5, 3, 4, 2), (3, 1))
mocked_compute.assert_not_called()
Expand All @@ -76,7 +83,8 @@ def test_lazy_masked(self, mocked_compute):

def test_masked_degenerate(self):
# masked arrays can have degenerate masks too
a = np.random.random([2, 3])
rng = np.random.default_rng()
a = rng.random((2, 3))
m = ma.array(a)
b = broadcast_to_shape(m, (5, 3, 4, 2), (3, 1))
for i in range(5):
Expand Down