Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions warp/_src/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11156,6 +11156,12 @@ def copy(
if not warp._src.types.is_array(src) or not warp._src.types.is_array(dest):
raise RuntimeError("Copy source and destination must be arrays")

if src_offset < 0:
raise RuntimeError(f"Source offset must be non-negative, got {src_offset}")

if dest_offset < 0:
raise RuntimeError(f"Destination offset must be non-negative, got {dest_offset}")

# backwards compatibility, if count is zero then copy entire src array
if count <= 0:
count = src.size
Expand Down
12 changes: 12 additions & 0 deletions warp/tests/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ def test_copy_adjoint(test, device):
assert_np_equal(state_in.grad.numpy(), np.array([1.0, 1.0, 1.0]).astype(np.float32))


def test_copy_negative_offsets(test, device):
src = wp.array([1, 2, 3, 4], dtype=wp.int32, device=device)
dest = wp.zeros_like(src)

with test.assertRaisesRegex(RuntimeError, "Source offset must be non-negative"):
wp.copy(dest, src, src_offset=-1)

with test.assertRaisesRegex(RuntimeError, "Destination offset must be non-negative"):
wp.copy(dest, src, dest_offset=-1)


devices = get_test_devices()


Expand Down Expand Up @@ -301,6 +312,7 @@ class TestCopy(unittest.TestCase):
)

add_function_test(TestCopy, "test_copy_adjoint", test_copy_adjoint, devices=devices)
add_function_test(TestCopy, "test_copy_negative_offsets", test_copy_negative_offsets, devices=devices)

if __name__ == "__main__":
unittest.main(verbosity=2)