Skip to content

Commit 19d91ea

Browse files
committed
Transformed simulate_planar_pcs into a function
callable from other files for comparison purposes with the users choice parameters : - option of saving or not the results, figures, videos - option of plotting/printing or not the results, figures - option on the type of derivation to use : symbolic, numeric - option on the type of integration and parameter of integration to use : gauss, trapezoid - option on the type of jacobian to use : explicit or autodifferentiation Added the ability to save simulation results in pickle files (.pkl) for later comparison Set up an explicit Jacobian in SE3 to compute B and G - SE(3) Lie algebra operators - convert SE(2) to SE(3) to use operators for the planar case
1 parent 231c9e3 commit 19d91ea

File tree

8 files changed

+2430
-320
lines changed

8 files changed

+2430
-320
lines changed

examples/figures/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/simulate_planar_pcs.py

Lines changed: 643 additions & 241 deletions
Large diffs are not rendered by default.

examples/videos/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/jsrm/math_utils.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from jax import numpy as jnp
22
from jax import Array, lax, jit
33

4-
54
@jit
6-
def blk_diag(a: Array) -> Array:
5+
def blk_diag(
6+
a: Array
7+
) -> Array:
78
"""
89
Create a block diagonal matrix from a tensor of blocks
910
Args:
@@ -31,7 +32,7 @@ def assign_block_diagonal(i, _b):
3132

3233
# Implement for loop to assign each block in `a` to the block-diagonal of `b`
3334
# Hint: use `jax.lax.fori_loop` and pass `assign_block_diagonal` as an argument
34-
b = jnp.zeros((a.shape[0] * a.shape[1], a.shape[0] * a.shape[2]))
35+
b = jnp.zeros((a.shape[0] * a.shape[1], a.shape[0] * a.shape[2]), dtype=a.dtype)
3536
b = lax.fori_loop(
3637
lower=0,
3738
upper=a.shape[0],
@@ -40,3 +41,33 @@ def assign_block_diagonal(i, _b):
4041
)
4142

4243
return b
44+
45+
@jit
46+
def blk_concat(
47+
a: Array
48+
) -> Array:
49+
"""
50+
Concatenate the matrices along the first axis
51+
52+
Args:
53+
a (Array): matrices to be concatenated of shape (N, a, b)
54+
55+
Returns:
56+
Array: concatenated matrix of shape (a, b * N)
57+
"""
58+
b = a.transpose(1, 0, 2).reshape(a.shape[1], -1)
59+
return b
60+
61+
if __name__ == "__main__":
62+
# Example usage
63+
a = jnp.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
64+
print("Original array:")
65+
print(a)
66+
67+
b = blk_diag(a)
68+
print("Block diagonal matrix:")
69+
print(b)
70+
71+
c = blk_concat(a)
72+
print("Concatenated matrix:")
73+
print(c)

0 commit comments

Comments
 (0)