@@ -64,25 +64,30 @@ def test_fast_sandwich_dense():
6464
6565
6666def test_dense_sandwich_on_non_contiguous ():
67- """Non-regression test for #208"""
67+ """Non-regression test for #208
68+
69+ DenseMatrix now automatically ensures arrays are contiguous,
70+ so non-contiguous inputs are automatically copied and made contiguous.
71+ """
6872 rng = np .random .default_rng (seed = 123 )
6973 X = rng .standard_normal (size = (100 , 20 ))
7074
71- # Xd wraps a not-contiguous array.
72- Xd = DenseMatrix (X [:, :10 ])
73- Xs = SparseMatrix (csc_matrix (X [:, 10 :]))
74- Xm = SplitMatrix ([Xd , Xs ])
75+ # Column slicing creates a non-contiguous array, but DenseMatrix
76+ # automatically makes it contiguous (copying only if necessary).
77+ non_contiguous_array = X [:, :10 ]
78+ assert not non_contiguous_array .flags ["C_CONTIGUOUS" ]
79+ assert not non_contiguous_array .flags ["F_CONTIGUOUS" ]
7580
76- # Making the sandwich product fail.
77- with pytest . raises ( Exception , match = " The matrix X is not contiguous" ):
78- Xm . sandwich ( np . ones ( X . shape [ 0 ]))
81+ Xd = DenseMatrix ( non_contiguous_array )
82+ # The internal array should now be contiguous
83+ assert Xd . A . flags [ "C_CONTIGUOUS" ] or Xd . A . flags [ "F_CONTIGUOUS" ]
7984
80- # Xd wraps a copy, which makes the data contiguous.
81- Xd = DenseMatrix (X [:, :10 ].copy ())
85+ Xs = SparseMatrix (csc_matrix (X [:, 10 :]))
8286 Xm = SplitMatrix ([Xd , Xs ])
8387
84- # The sandwich product works without problem here.
85- Xm .sandwich (np .ones (X .shape [0 ]))
88+ # The sandwich product should work without problem
89+ result = Xm .sandwich (np .ones (X .shape [0 ]))
90+ assert result is not None
8691
8792
8893def check (A , d , cols ):
0 commit comments