File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ void returnByArgumentPointer(cv::Mat *mat) {
179
179
mat->at <cv::Vec3w>(0 , 0 ) = cv::Vec3w (4 ,5 ,6 );
180
180
}
181
181
182
+ void returnByArgumentValueWithAllocation (cv::Mat mat) {
183
+ mat = cv::Mat::ones (cv::Size (3 , 3 ), CV_8UC1);
184
+ }
185
+
186
+ void returnByArgumentRefWithAllocation (cv::Mat & mat) {
187
+ mat = cv::Mat::ones (cv::Size (3 , 3 ), CV_8UC1);
188
+ }
189
+
182
190
PYBIND11_MODULE (test_module, m) {
183
191
184
192
NDArrayConverter::init_numpy ();
@@ -228,4 +236,8 @@ PYBIND11_MODULE(test_module, m) {
228
236
229
237
m.def (" returnByArgumentPointer" , &returnByArgumentPointer);
230
238
239
+ m.def (" returnByArgumentValueWithAllocation" , &returnByArgumentValueWithAllocation);
240
+
241
+ m.def (" returnByArgumentRefWithAllocation" , &returnByArgumentRefWithAllocation);
242
+
231
243
}
Original file line number Diff line number Diff line change @@ -53,11 +53,24 @@ def test_return_by_argument_by_value():
53
53
def test_return_by_argument_by_ref ():
54
54
mat = generate_matrix ()
55
55
tm .returnByArgumentRef (mat )
56
- assert (np .any (mat != generate_matrix ()))
57
56
assert (not check_matrix_content (mat ))
58
57
59
58
60
59
def test_return_by_argument_by_pointer ():
61
60
mat = generate_matrix ()
62
61
tm .returnByArgumentPointer (mat )
63
62
assert (not check_matrix_content (mat ))
63
+
64
+
65
+ def test_return_by_argument_by_value ():
66
+ mat = generate_matrix ()
67
+ # During allocation we create a new buffer the data are not linked anymore
68
+ tm .returnByArgumentValueWithAllocation (mat )
69
+ assert (check_matrix_content (mat ))
70
+
71
+
72
+ def test_return_by_argument_by_ref ():
73
+ mat = generate_matrix ()
74
+ # During allocation we create a new buffer the data are not linked anymore
75
+ tm .returnByArgumentRefWithAllocation (mat )
76
+ assert (check_matrix_content (mat ))
You can’t perform that action at this time.
0 commit comments