Skip to content

Bug in source/isaaclab/isaaclab/utils/warp/ops.py ray_distance.view(shape[0], shape[1]) causes shape mismatch #2416

Closed

Description

@Finn-Sueberkrueb

I am trying to use raycast_mesh(..., return_distance=True) with the following input:

ray_starts = torch.randn(4, 3)
ray_directions = torch.randn(4, 3)

This results in:

ray_distance = ray_distance.to(device).view(shape[0], shape[1])
RuntimeError: shape '[4, 3]' is invalid for input of size 4

It seems ray_distance is initialized with shape (N,) where N = 4, but the code attempts to reshape it to (4, 3) which is incorrect for scalar distances.

Shouldn’t the correct line be:

ray_distance = ray_distance.to(device).view(shape[0])

instead of:

ray_distance = ray_distance.to(device).view(shape[0], shape[1])

Activity

  1. Finn-Sueberkrueb commented on May 2, 2025

    @Finn-Sueberkrueb
    Author

    Or in the Docu it should say:

    ray_starts – The starting position of the rays. Shape (N, 1, 3).
    ray_directions – The ray directions for each ray. Shape (N, 1, 3).

  2. RandomOakForest commented on May 5, 2025

    @RandomOakForest
    Collaborator

    Thanks for catching this. We will review.

  3. added
    bug
    on Jun 4, 2025
  4. samirbhattarai135 commented on Aug 12, 2026

    @samirbhattarai135

    I looked into this and opened #7034.

    On the "or the docs should say Shape (N, 1, 3)" alternative — I think the code is the thing to
    fix rather than the docstring, because the reshape is not actually a 3-D design decision. It is
    wrong for every rank except 3, and for some of them it fails silently:

    ray_starts shape ray_distance today
    (N, 3) RuntimeError (this issue)
    (B, N, 3) (B, N) — correct
    (3, 1, 2, 3) RuntimeError
    (2, 3, 1, 3) (2, 3) — no error, wrong shape

    That last row is the part that worried me. When the leading dimensions happen to multiply out to
    shape[0] * shape[1], view(shape[0], shape[1]) succeeds and hands back a tensor whose shape does
    not correspond to the rays that produced it.

    The cause is that line 123 flattens any number of leading dimensions with .view(-1, 3), while
    lines 178 and 182 assume exactly two of them. One line in between, ray_normal already uses the
    generic .view(shape). Using .view(shape[:-1]) for the distance and face-id outputs matches it.

    This is also why documenting 3-D would be awkward in practice: isaaclab/terrains/utils.py calls
    raycast_mesh(points.view(-1, 3), dirs.view(-1, 3), wp_mesh) with genuinely 2-D input and then
    restores the shape itself. It only escapes the crash because it leaves return_distance at its
    default.

    Worth noting that shape[:-1] is not a behaviour change for anyone: for 3-D input it is the same
    expression as (shape[0], shape[1]), so existing callers and the current test_ray_caster.py
    assertions are unaffected. It only turns the error and the silent-wrong-shape cases into correct
    output.

    The PR adds a CPU regression test covering (2,), (1, 2), (3, 1, 2) and (2, 3, 1) ray
    dimensions. It needs neither a GPU nor Isaac Sim, since utils/warp/ops.py imports only numpy,
    torch and warp.

  5. added a commit that references this issue on Sep 26, 2026
    b970149
  6. added a commit that references this issue on Sep 26, 2026
    c791679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions