Skip to content

Support indexedarray fields in struct #1327

@FabienPean-Virtonomy

Description

@FabienPean-Virtonomy

wp.indexedarray cannot currently be used as a field in wp.struct (assignment/device transfer/NumPy structured values) while it can be passed as an argument to a wp.kernel. There is no apparent reason not to support this possibility as all the blocks are already in place.

Minimal example for currently erroneous behavior:

import warp as wp

@wp.struct
class Foo:
    arr: wp.indexedarray(dtype=wp.float32)

Result:

Traceback (most recent call last):
  File "examples/tmp.py", line 4, in <module>
    @wp.struct
     ^^^^^^^^^
  File ".pixi/envs/default/lib/python3.12/site-packages/warp/_src/context.py", line 1451, in struct
    return wrapper(c)
           ^^^^^^^^^^
  File ".pixi/envs/default/lib/python3.12/site-packages/warp/_src/context.py", line 1443, in wrapper
    s = warp._src.codegen.Struct(key=warp._src.codegen.make_full_qualified_name(c), cls=c, module=m)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".pixi/envs/default/lib/python3.12/site-packages/warp/_src/codegen.py", line 522, in __init__
    elif issubclass(var.type, ctypes.Array):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class

Expected:
Allow wp.indexedarray fields in structs with the same behavior as wp.array:

  • assign indexedarray (or None) to struct fields
  • StructInstance.to(device) moves indexedarray members
  • works in kernels, nested structs, and struct arrays
  • Struct.numpy_dtype() / StructInstance.numpy_value() work

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions