Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/adam/model/conversions/idyntree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def _to_sequence(x) -> list[float]:
# Unwrap wrapper that stores the underlying array in `.array`
val = x.array if isinstance(x, ArrayLike) else x
if isinstance(val, (cs.DM, cs.SX, cs.MX)):
val = [float(v) for v in cs.DM(val).full()]
# Convert to full() representation and flatten to 1D list
dm_full = cs.DM(val).full()
val = [float(v) for row in dm_full for v in row]
return val

for i, v in enumerate(val):
Expand All @@ -38,7 +40,10 @@ def _to_scalar(x) -> float:
# Unwrap wrapper that stores the underlying array in `.array`
val = x.array if isinstance(x, ArrayLike) else x
# Handle CasADi types if available. It should be already a casadi type, but let's be safe
val = cs.DM(val).full() if isinstance(val, (cs.DM, cs.SX, cs.MX)) else val
if isinstance(val, (cs.DM, cs.SX, cs.MX)):
dm_full = cs.DM(val).full()
# `full()` returns a NumPy array; flatten and extract the single scalar
val = dm_full.flat[0]
return float(val)


Expand Down
Loading