Fixes Newton body_inertia#4921
Conversation
…reinterpretation
The previous fix assumed get_attribute("body_inertia") returned float32
with ndim==4, but Newton returns mat33f with ndim==2. The ndim guard
always failed, returning raw mat33f arrays instead of (N, B, 9) float32.
Use view(wp.float32).reshape() which correctly reinterprets mat33f as
(3, 3) float32 then flattens to 9 — zero-copy, no clone needed.
The clone created a detached copy, inconsistent with Articulation and RigidObject which use zero-copy view().reshape(). The view+reshape chain on the sliced mat33f array is already zero-copy.
Greptile SummaryThis PR fixes
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Newton model\nget_attribute('body_inertia')"] --> B["Raw wp.array\nshape: (N, P, B) mat33f\n(P=1 padding dim)"]
B --> C["[:, 0] or [:, :, 0]\nSqueeze padding dim"]
C --> D["(N, B) mat33f\nC-contiguous"]
D --> E["view(wp.float32)\nReinterpret mat33f → 9×float32"]
E --> F["(N, B, 9) float32\nzero-copy"]
F --> G["reshape((N, B, 9))\nno-op / name shape"]
G --> H["_sim_bind_body_inertia\nor _body_inertia\n(N, B, 9) float32"]
H --> I["body_inertia property\nreturned to callers"]
H --> J["write_body_inertia_to_buffer\nkernel output target\n(writes back to Newton model)"]
style A fill:#f0f0f0
style F fill:#d4edda
style H fill:#d4edda
Last reviewed commit: 879c5e6 |
| # Newton stores body_inertia as (N, 1, B) mat33f — the [:, 0] removes the padding dim | ||
| # giving (N, B) mat33f. Reinterpret as (N, B, 3, 3) float32 then flatten to (N, B, 9). |
There was a problem hiding this comment.
Slightly inaccurate intermediate-step comment
The comment says "Reinterpret as (N, B, 3, 3) float32 then flatten to (N, B, 9)", implying a 4-dimensional intermediate array. In practice, calling view(wp.float32) on a (N, B) mat33f array will produce a (N, B, 9) float32 array (since Warp adds one trailing dimension of size 9 for the 9 scalar components of mat33f), and the subsequent reshape((N, B, 9)) is then effectively a no-op rather than a flattening step. The same inaccuracy appears in rigid_object_data.py (line 723).
This is cosmetic and does not affect correctness, but the comment could mislead future readers into expecting a 4D intermediate array.
| # Newton stores body_inertia as (N, 1, B) mat33f — the [:, 0] removes the padding dim | |
| # giving (N, B) mat33f. Reinterpret as (N, B, 3, 3) float32 then flatten to (N, B, 9). | |
| # Newton stores body_inertia as (N, 1, B) mat33f — the [:, 0] removes the padding dim | |
| # giving (N, B) mat33f. view(wp.float32) reinterprets each mat33f as 9 float32 scalars, | |
| # yielding (N, B, 9) float32 directly. Both view() and reshape() are zero-copy. |
Signed-off-by: ooctipus <zhengyuz@nvidia.com>
# Description - Fixed ArticulationData.body_inertia and RigidObjectData.body_inertia returning raw mat33f arrays instead of (N, B, 9) float32 as documented in the interface contract. - Removed unnecessary wp.clone() from RigidObjectCollectionData.body_inertia, making all three asset data classes consistently zero-copy. ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by: ooctipus <zhengyuz@nvidia.com> Co-authored-by: ooctipus <zhengyuz@nvidia.com>
Description
Type of change
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there