Skip to content

Commit 2809cde

Browse files
committed
Add unit tests to ensure that colour.utilities.tstack and colour.utilities.tsplit definition output is contiguous and independent.
References #1309.
1 parent b7415c3 commit 2809cde

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

colour/utilities/tests/test_array.py

+74
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,33 @@ def test_tstack(self):
14091409
),
14101410
)
14111411

1412+
# Ensuring that contiguity is maintained.
1413+
a = np.array([0, 1, 2], dtype=DTYPE_FLOAT_DEFAULT)
1414+
b = tstack([a, a, a])
1415+
assert b.flags.contiguous
1416+
1417+
# Ensuring that independence is maintained.
1418+
a *= 2
1419+
np.testing.assert_array_equal(
1420+
b,
1421+
np.array(
1422+
[
1423+
[0, 0, 0],
1424+
[1, 1, 1],
1425+
[2, 2, 2],
1426+
],
1427+
),
1428+
)
1429+
1430+
a = np.array([0, 1, 2], dtype=DTYPE_FLOAT_DEFAULT)
1431+
b = tstack([a, a, a])
1432+
1433+
b[1] *= 2
1434+
np.testing.assert_array_equal(
1435+
a,
1436+
np.array([0, 1, 2]),
1437+
)
1438+
14121439

14131440
class TestTsplit(unittest.TestCase):
14141441
"""
@@ -1484,6 +1511,53 @@ def test_tsplit(self):
14841511
),
14851512
)
14861513

1514+
# Ensuring that contiguity is maintained.
1515+
a = np.array(
1516+
[
1517+
[0, 0, 0],
1518+
[1, 1, 1],
1519+
[2, 2, 2],
1520+
],
1521+
dtype=DTYPE_FLOAT_DEFAULT,
1522+
)
1523+
b = tsplit(a)
1524+
assert b.flags.contiguous
1525+
1526+
# Ensuring that independence is maintained.
1527+
a *= 2
1528+
np.testing.assert_array_equal(
1529+
b,
1530+
np.array(
1531+
[
1532+
[0, 1, 2],
1533+
[0, 1, 2],
1534+
[0, 1, 2],
1535+
]
1536+
),
1537+
)
1538+
1539+
a = np.array(
1540+
[
1541+
[0, 0, 0],
1542+
[1, 1, 1],
1543+
[2, 2, 2],
1544+
],
1545+
dtype=DTYPE_FLOAT_DEFAULT,
1546+
)
1547+
b = tsplit(a)
1548+
1549+
b[1] *= 2
1550+
np.testing.assert_array_equal(
1551+
a,
1552+
np.array(
1553+
[
1554+
[0, 0, 0],
1555+
[1, 1, 1],
1556+
[2, 2, 2],
1557+
]
1558+
),
1559+
)
1560+
14871561

14881562
class TestRowAsDiagonal(unittest.TestCase):
14891563
"""

0 commit comments

Comments
 (0)