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


pinocchio
Author(s):
autogenerated on Wed Dec 25 2024 03:41:19