test_return_by_ref.py
Go to the documentation of this file.
1 import return_by_ref
2 from return_by_ref import Matrix, RowMatrix, Vector
3 import numpy as np
4 
5 def test_shared(mat):
6 
7  m_ref = mat.ref()
8  m_ref.fill(0)
9  m_copy = mat.copy()
10  assert np.array_equal(m_ref,m_copy)
11 
12  m_const_ref = mat.const_ref()
13  assert np.array_equal(m_const_ref,m_copy)
14  assert np.array_equal(m_const_ref,m_ref)
15 
16  m_ref.fill(1)
17  assert not np.array_equal(m_ref,m_copy)
18  assert np.array_equal(m_const_ref,m_ref)
19 
20  try:
21  m_const_ref.fill(2)
22  assert False
23  except:
24  assert True
25 
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 
47 rows = 10
48 cols = 30
49 
50 mat = Matrix(rows,cols)
51 row_mat = RowMatrix(rows,cols)
52 vec = Vector(rows,1)
53 
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 


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Apr 17 2021 02:37:59