Skip to content

Commit

Permalink
Merge branch 'lwawrzyniak/fix-struct-member-init-fp16' into 'main'
Browse files Browse the repository at this point in the history
Fix initialization error when setting struct members

See merge request omniverse/warp!754
  • Loading branch information
nvlukasz committed Sep 27, 2024
2 parents e18931f + b9248b2 commit f357794
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- Fix conditions not being evaluated as expected in `while` statements.
- Fix printing Boolean and 8-bit integer values.
- Fix array interface type strings used for Boolean and 8-bit integer values.
- Fix initialization error when setting struct members.

## [1.3.3] - 2024-09-04

Expand Down
3 changes: 3 additions & 0 deletions warp/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ def __init__(self, cls, key, module):
elif issubclass(var.type, ctypes.Array):
fields.append((label, var.type))
else:
# HACK: fp16 requires conversion functions from warp.so
if var.type is warp.float16:
warp.init()
fields.append((label, var.type._type_))

class StructType(ctypes.Structure):
Expand Down
28 changes: 28 additions & 0 deletions warp/tests/test_implicit_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ class TestImplicitInitIsPeerAccessSupported(unittest.TestCase):
)


# Structs
# ------------------------------------------------------------------------------


def test_struct_member_init(test, device):
@wp.struct
class S:
# fp16 requires conversion functions from warp.so
x: wp.float16
v: wp.vec3h

s = S()
s.x = 42.0
s.v = wp.vec3h(1.0, 2.0, 3.0)


class TestImplicitInitStructMemberInit(unittest.TestCase):
pass


add_function_test(
TestImplicitInitStructMemberInit,
"test_struct_member_init",
test_struct_member_init,
check_output=False,
)


if __name__ == "__main__":
# Do not clear the kernel cache or call anything that would initialize Warp
# since these tests are specifically aiming to catch issues where Warp isn't
Expand Down

0 comments on commit f357794

Please sign in to comment.