test-cpp2pybind11.py
Go to the documentation of this file.
1 import cpp2pybind11, sys, gc
2 import pinocchio
3 
4 a = pinocchio.SE3.Random()
5 b = pinocchio.SE3.Random()
6 assert cpp2pybind11.multiply_se3_1(a, b) == a * b
7 assert cpp2pybind11.multiply_se3(a, b) == a * b
8 assert cpp2pybind11.no_wrapper.multiply_se3(a, b) == a * b
9 assert cpp2pybind11.multiply_se3(a) == a
10 # assert cpp2pybind11.no_wrapper.multiply_se3(a) == a
11 
12 
13 def print_ref_count(v, what=""):
14  # - 2 because one for variable v and one for variable inside getrefcount
15  idv = id(v)
16  gc.collect()
17  # n = len(gc.get_referrers(v))
18  n = sys.getrefcount(v)
19  print("ref count of", what, idv, n)
20 
21 
22 m = cpp2pybind11.make_model()
23 print_ref_count(m, "m")
24 print(cpp2pybind11.get_ptr(m))
25 print_ref_count(m, "m")
26 
27 m.name = ""
28 cpp2pybind11.testModel1(m)
29 print_ref_count(m, "m")
30 assert m.name.startswith("testModel1")
31 
32 addr2 = cpp2pybind11.testModel2(m, 1)
33 print_ref_count(m, "m")
34 assert m.name.startswith("testModel2")
35 
36 addr3 = cpp2pybind11.testModel3(m, 2)
37 print_ref_count(m, "m")
38 assert addr2 == addr3
39 
40 mm = cpp2pybind11.return_same_model_broken(m)
41 assert cpp2pybind11.get_ptr(m) != cpp2pybind11.get_ptr(mm)
42 
43 mm = cpp2pybind11.return_same_model(m)
44 # Not sure why but the ref count of m and mm sticks to one
45 print_ref_count(m, "m")
46 mmm = m
47 print_ref_count(m, "m")
48 print_ref_count(mm, "mm")
49 assert cpp2pybind11.get_ptr(m) == cpp2pybind11.get_ptr(mm)
50 
51 if False:
52  print("deleting m")
53  del m
54  print("deleted m")
55  print("mm is", mm)
56 else:
57  print("deleting mm")
58  del mm
59  print("deleted mm")
60  print("m is", m)
pinocchio::id
JointIndex id(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdVisitor to get the index of the joint in the kinematic chain.
test-cpp2pybind11.print_ref_count
def print_ref_count(v, what="")
Definition: test-cpp2pybind11.py:13


pinocchio
Author(s):
autogenerated on Thu Jun 13 2024 02:40:52