@@ -139,7 +139,7 @@ def test_matx_not_shared():
139
139
# create object
140
140
o = CvNp_TestHelper ()
141
141
142
- m_linked = o .mx_ns # Make a numy array that is a copy of mx_ns *without* shared memory
142
+ m_linked = o .mx_ns # Make a numpy array that is a copy of mx_ns *without* shared memory
143
143
assert m_linked .shape == (3 , 2 ) # check its shape
144
144
m_linked [1 , 1 ] = 3 # a value change in the numpy array made from python
145
145
assert o .mx_ns [1 , 1 ] != 3 # is not visible from C++!
@@ -467,9 +467,39 @@ def test_rect():
467
467
o .rect_double = (1 , 2 ) # We should give 4 values!
468
468
469
469
470
+ def test_contiguous_check ():
471
+ # Check regression with numpy 2:
472
+ # See https://github.com/pthom/cvnp/issues/17
473
+ # The contiguous check was changed to:
474
+ # bool is_array_contiguous(const pybind11::array& a) { return a.flags() & pybind11::array::c_style; }
475
+
476
+ # 1. Check contiguous matrix
477
+ m = np .zeros ((10 ,10 ),dtype = np .uint8 )
478
+ cvnp_roundtrip (m )
479
+
480
+ # 2. Check that a non-contiguous matrix raises an error
481
+ full_matrix = np .ones ([10 , 10 ], np .float32 )
482
+ sub_matrix = full_matrix [1 :5 , 2 :4 ]
483
+ with pytest .raises (ValueError ):
484
+ cvnp_roundtrip (sub_matrix )
485
+
486
+
487
+ def test_matx_roundtrip ():
488
+ # This test was failing with numpy 2 when matx_to_nparray
489
+ # did not transmit the stride for small matrices (Matx)
490
+ from cvnp import RoundTripMatx21d
491
+ m = np .zeros ((2 , 1 ), np .float64 )
492
+ m [0 , 0 ] = 42.1
493
+ m [1 , 0 ] = 43.1
494
+ m2 = RoundTripMatx21d (m )
495
+ assert are_float_close (m2 [0 , 0 ], 42.1 )
496
+ assert are_float_close (m2 [1 , 0 ], 43.1 )
497
+
470
498
471
499
def main ():
472
500
# Todo: find a way to call pytest for this file
501
+ test_contiguous_check ()
502
+ test_matx_roundtrip ()
473
503
test_refcount ()
474
504
test_mat_shared ()
475
505
test_mat__shared ()
0 commit comments