Skip to content

Commit bfb26e4

Browse files
committed
test: test new sharedMemory feature
1 parent 0334425 commit bfb26e4

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

unittest/python/test_return_by_ref.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import return_by_ref
12
from return_by_ref import Matrix, RowMatrix, Vector
23
import 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+
2547
rows = 10
2648
cols = 30
2749

2850
mat = Matrix(rows,cols)
2951
row_mat = RowMatrix(rows,cols)
3052
vec = 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+

0 commit comments

Comments
 (0)