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


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:33