MCPcopy Create free account
hub / github.com/Simple-Robotics/aligator / test_slicing

Function test_slicing

tests/python/test_functions.py:57–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55 not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio."
56)
57def test_slicing():
58 space = manifolds.R4()
59 nr = 7
60 nx = space.nx
61 A = np.random.randn(nr, nx)
62 nu = 2
63 B = np.random.randn(nr, nu)
64 c = np.zeros(nr)
65 fn = aligator.LinearFunction(A, B, c)
66 x0 = space.rand()
67 u0 = np.zeros(fn.nu)
68
69 dfull = fn.createData()
70
71 idxs = [0, 2]
72 fslice = fn[idxs]
73 dslice = fslice.createData()
74 assert idxs == fslice.indices.tolist()
75
76 fn.evaluate(x0, u0, dfull)
77 fslice.evaluate(x0, u0, dslice)
78
79 assert np.allclose(dfull.value[idxs], dslice.value)
80
81 fn.computeJacobians(x0, u0, dfull)
82 fslice.computeJacobians(x0, u0, dslice)
83
84 assert np.allclose(dfull.jac_buffer[idxs, :], dslice.jac_buffer)
85
86 fs2 = fn[1::2]
87 print("slice size:", fs2.nr)
88 idx2 = [1, 3, 5]
89 assert fs2.indices.tolist() == idx2
90
91 fs3 = fn[1]
92 assert fs3.indices.tolist() == [1]
93
94
95if __name__ == "__main__":

Callers

nothing calls this directly

Calls 4

randMethod · 0.80
createDataMethod · 0.45
evaluateMethod · 0.45
computeJacobiansMethod · 0.45

Tested by

no test coverage detected