File tree Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Original file line number Diff line number Diff line change 1+ import return_by_ref
12from return_by_ref import Matrix , RowMatrix , Vector
23import numpy as np
34
4- def test (mat ):
5+ def test_shared (mat ):
56
67 m_ref = mat .ref ()
78 m_ref .fill (0 )
@@ -22,13 +23,41 @@ def test(mat):
2223 except :
2324 assert True
2425
26+ def test_not_shared (mat ):
27+
28+ m_ref = mat .ref ()
29+ m_ref .fill (100. )
30+ m_copy = mat .copy ()
31+ assert not np .array_equal (m_ref ,m_copy )
32+
33+ m_const_ref = mat .const_ref ()
34+ assert np .array_equal (m_const_ref ,m_copy )
35+ assert not np .array_equal (m_const_ref ,m_ref )
36+
37+ m_ref .fill (10. )
38+ assert not np .array_equal (m_ref ,m_copy )
39+ assert not np .array_equal (m_const_ref ,m_ref )
40+
41+ try :
42+ m_const_ref .fill (2 )
43+ assert True
44+ except :
45+ assert False
46+
2547rows = 10
2648cols = 30
2749
2850mat = Matrix (rows ,cols )
2951row_mat = RowMatrix (rows ,cols )
3052vec = Vector (rows ,1 )
3153
32- test (mat )
33- test (row_mat )
34- test (vec )
54+ test_shared (mat )
55+ test_shared (row_mat )
56+ test_shared (vec )
57+
58+ return_by_ref .sharedMemory (False )
59+ test_not_shared (mat )
60+ test_not_shared (row_mat )
61+ test_not_shared (vec )
62+
63+
You can’t perform that action at this time.
0 commit comments