Skip to content
Snippets Groups Projects
Verified Commit bfb26e47 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test: test new sharedMemory feature

parent 0334425f
No related branches found
No related tags found
No related merge requests found
import return_by_ref
from return_by_ref import Matrix, RowMatrix, Vector from return_by_ref import Matrix, RowMatrix, Vector
import numpy as np import numpy as np
def test(mat): def test_shared(mat):
m_ref = mat.ref() m_ref = mat.ref()
m_ref.fill(0) m_ref.fill(0)
...@@ -22,6 +23,27 @@ def test(mat): ...@@ -22,6 +23,27 @@ def test(mat):
except: except:
assert True assert True
def test_not_shared(mat):
m_ref = mat.ref()
m_ref.fill(100.)
m_copy = mat.copy()
assert not np.array_equal(m_ref,m_copy)
m_const_ref = mat.const_ref()
assert np.array_equal(m_const_ref,m_copy)
assert not np.array_equal(m_const_ref,m_ref)
m_ref.fill(10.)
assert not np.array_equal(m_ref,m_copy)
assert not np.array_equal(m_const_ref,m_ref)
try:
m_const_ref.fill(2)
assert True
except:
assert False
rows = 10 rows = 10
cols = 30 cols = 30
...@@ -29,6 +51,13 @@ mat = Matrix(rows,cols) ...@@ -29,6 +51,13 @@ mat = Matrix(rows,cols)
row_mat = RowMatrix(rows,cols) row_mat = RowMatrix(rows,cols)
vec = Vector(rows,1) vec = Vector(rows,1)
test(mat) test_shared(mat)
test(row_mat) test_shared(row_mat)
test(vec) test_shared(vec)
return_by_ref.sharedMemory(False)
test_not_shared(mat)
test_not_shared(row_mat)
test_not_shared(vec)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment