warp-lang 1.0.0b5__py3-none-manylinux2014_x86_64.whl → 1.0.0b6__py3-none-manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. docs/conf.py +3 -4
  2. examples/env/env_ant.py +1 -1
  3. examples/env/env_cartpole.py +1 -1
  4. examples/env/env_humanoid.py +1 -1
  5. examples/example_dem.py +28 -26
  6. examples/example_diffray.py +37 -30
  7. examples/example_fluid.py +7 -3
  8. examples/example_jacobian_ik.py +1 -1
  9. examples/example_mesh_intersect.py +10 -7
  10. examples/example_nvdb.py +3 -3
  11. examples/example_render_opengl.py +19 -10
  12. examples/example_sim_cartpole.py +9 -5
  13. examples/example_sim_cloth.py +29 -25
  14. examples/example_sim_fk_grad.py +2 -2
  15. examples/example_sim_fk_grad_torch.py +3 -3
  16. examples/example_sim_grad_bounce.py +11 -8
  17. examples/example_sim_grad_cloth.py +12 -9
  18. examples/example_sim_granular.py +2 -2
  19. examples/example_sim_granular_collision_sdf.py +13 -13
  20. examples/example_sim_neo_hookean.py +3 -3
  21. examples/example_sim_particle_chain.py +2 -2
  22. examples/example_sim_quadruped.py +8 -5
  23. examples/example_sim_rigid_chain.py +8 -5
  24. examples/example_sim_rigid_contact.py +13 -10
  25. examples/example_sim_rigid_fem.py +2 -2
  26. examples/example_sim_rigid_gyroscopic.py +2 -2
  27. examples/example_sim_rigid_kinematics.py +1 -1
  28. examples/example_sim_trajopt.py +3 -2
  29. examples/fem/example_apic_fluid.py +5 -7
  30. examples/fem/example_diffusion_mgpu.py +18 -16
  31. warp/__init__.py +3 -2
  32. warp/bin/warp.so +0 -0
  33. warp/build_dll.py +29 -9
  34. warp/builtins.py +206 -7
  35. warp/codegen.py +58 -38
  36. warp/config.py +3 -1
  37. warp/context.py +234 -128
  38. warp/fem/__init__.py +2 -2
  39. warp/fem/cache.py +2 -1
  40. warp/fem/field/nodal_field.py +18 -17
  41. warp/fem/geometry/hexmesh.py +11 -6
  42. warp/fem/geometry/quadmesh_2d.py +16 -12
  43. warp/fem/geometry/tetmesh.py +19 -8
  44. warp/fem/geometry/trimesh_2d.py +18 -7
  45. warp/fem/integrate.py +341 -196
  46. warp/fem/quadrature/__init__.py +1 -1
  47. warp/fem/quadrature/pic_quadrature.py +138 -53
  48. warp/fem/quadrature/quadrature.py +81 -9
  49. warp/fem/space/__init__.py +1 -1
  50. warp/fem/space/basis_space.py +169 -51
  51. warp/fem/space/grid_2d_function_space.py +2 -2
  52. warp/fem/space/grid_3d_function_space.py +2 -2
  53. warp/fem/space/hexmesh_function_space.py +2 -2
  54. warp/fem/space/partition.py +9 -6
  55. warp/fem/space/quadmesh_2d_function_space.py +2 -2
  56. warp/fem/space/shape/cube_shape_function.py +27 -15
  57. warp/fem/space/shape/square_shape_function.py +29 -18
  58. warp/fem/space/tetmesh_function_space.py +2 -2
  59. warp/fem/space/topology.py +10 -0
  60. warp/fem/space/trimesh_2d_function_space.py +2 -2
  61. warp/fem/utils.py +10 -5
  62. warp/native/array.h +49 -8
  63. warp/native/builtin.h +31 -14
  64. warp/native/cuda_util.cpp +8 -3
  65. warp/native/cuda_util.h +1 -0
  66. warp/native/exports.h +1177 -1108
  67. warp/native/intersect.h +4 -4
  68. warp/native/intersect_adj.h +8 -8
  69. warp/native/mat.h +65 -6
  70. warp/native/mesh.h +126 -5
  71. warp/native/quat.h +28 -4
  72. warp/native/vec.h +76 -14
  73. warp/native/warp.cu +1 -6
  74. warp/render/render_opengl.py +261 -109
  75. warp/sim/import_mjcf.py +13 -7
  76. warp/sim/import_urdf.py +14 -14
  77. warp/sim/inertia.py +17 -18
  78. warp/sim/model.py +67 -67
  79. warp/sim/render.py +1 -1
  80. warp/sparse.py +6 -6
  81. warp/stubs.py +19 -81
  82. warp/tape.py +1 -1
  83. warp/tests/__main__.py +3 -6
  84. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  85. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  86. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  87. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  88. warp/tests/aux_test_unresolved_func.py +14 -0
  89. warp/tests/aux_test_unresolved_symbol.py +14 -0
  90. warp/tests/{test_kinematics.py → disabled_kinematics.py} +10 -12
  91. warp/tests/run_coverage_serial.py +31 -0
  92. warp/tests/test_adam.py +102 -106
  93. warp/tests/test_arithmetic.py +39 -40
  94. warp/tests/test_array.py +46 -48
  95. warp/tests/test_array_reduce.py +25 -19
  96. warp/tests/test_atomic.py +62 -26
  97. warp/tests/test_bool.py +16 -11
  98. warp/tests/test_builtins_resolution.py +1292 -0
  99. warp/tests/test_bvh.py +9 -12
  100. warp/tests/test_closest_point_edge_edge.py +53 -57
  101. warp/tests/test_codegen.py +164 -134
  102. warp/tests/test_compile_consts.py +13 -19
  103. warp/tests/test_conditional.py +30 -32
  104. warp/tests/test_copy.py +9 -12
  105. warp/tests/test_ctypes.py +90 -98
  106. warp/tests/test_dense.py +20 -14
  107. warp/tests/test_devices.py +34 -35
  108. warp/tests/test_dlpack.py +74 -75
  109. warp/tests/test_examples.py +215 -97
  110. warp/tests/test_fabricarray.py +15 -21
  111. warp/tests/test_fast_math.py +14 -11
  112. warp/tests/test_fem.py +280 -97
  113. warp/tests/test_fp16.py +19 -15
  114. warp/tests/test_func.py +177 -194
  115. warp/tests/test_generics.py +71 -77
  116. warp/tests/test_grad.py +83 -32
  117. warp/tests/test_grad_customs.py +7 -9
  118. warp/tests/test_hash_grid.py +6 -10
  119. warp/tests/test_import.py +9 -23
  120. warp/tests/test_indexedarray.py +19 -21
  121. warp/tests/test_intersect.py +15 -9
  122. warp/tests/test_large.py +17 -19
  123. warp/tests/test_launch.py +14 -17
  124. warp/tests/test_lerp.py +63 -63
  125. warp/tests/test_lvalue.py +84 -35
  126. warp/tests/test_marching_cubes.py +9 -13
  127. warp/tests/test_mat.py +388 -3004
  128. warp/tests/test_mat_lite.py +9 -12
  129. warp/tests/test_mat_scalar_ops.py +2889 -0
  130. warp/tests/test_math.py +10 -11
  131. warp/tests/test_matmul.py +104 -100
  132. warp/tests/test_matmul_lite.py +72 -98
  133. warp/tests/test_mesh.py +35 -32
  134. warp/tests/test_mesh_query_aabb.py +18 -25
  135. warp/tests/test_mesh_query_point.py +39 -23
  136. warp/tests/test_mesh_query_ray.py +9 -21
  137. warp/tests/test_mlp.py +8 -9
  138. warp/tests/test_model.py +89 -93
  139. warp/tests/test_modules_lite.py +15 -25
  140. warp/tests/test_multigpu.py +87 -114
  141. warp/tests/test_noise.py +10 -12
  142. warp/tests/test_operators.py +14 -21
  143. warp/tests/test_options.py +10 -11
  144. warp/tests/test_pinned.py +16 -18
  145. warp/tests/test_print.py +16 -20
  146. warp/tests/test_quat.py +121 -88
  147. warp/tests/test_rand.py +12 -13
  148. warp/tests/test_reload.py +27 -32
  149. warp/tests/test_rounding.py +7 -10
  150. warp/tests/test_runlength_encode.py +105 -106
  151. warp/tests/test_smoothstep.py +8 -9
  152. warp/tests/test_snippet.py +13 -22
  153. warp/tests/test_sparse.py +30 -29
  154. warp/tests/test_spatial.py +179 -174
  155. warp/tests/test_streams.py +100 -107
  156. warp/tests/test_struct.py +98 -67
  157. warp/tests/test_tape.py +11 -17
  158. warp/tests/test_torch.py +89 -86
  159. warp/tests/test_transient_module.py +9 -12
  160. warp/tests/test_types.py +328 -50
  161. warp/tests/test_utils.py +217 -218
  162. warp/tests/test_vec.py +133 -2133
  163. warp/tests/test_vec_lite.py +8 -11
  164. warp/tests/test_vec_scalar_ops.py +2099 -0
  165. warp/tests/test_volume.py +391 -382
  166. warp/tests/test_volume_write.py +122 -135
  167. warp/tests/unittest_serial.py +35 -0
  168. warp/tests/unittest_suites.py +291 -0
  169. warp/tests/{test_base.py → unittest_utils.py} +138 -25
  170. warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
  171. warp/tests/{test_debug.py → walkthough_debug.py} +2 -15
  172. warp/thirdparty/unittest_parallel.py +257 -54
  173. warp/types.py +119 -98
  174. warp/utils.py +14 -0
  175. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/METADATA +2 -1
  176. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/RECORD +182 -178
  177. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
  178. warp/tests/test_all.py +0 -239
  179. warp/tests/test_conditional_unequal_types_kernels.py +0 -14
  180. warp/tests/test_coverage.py +0 -38
  181. warp/tests/test_unresolved_func.py +0 -7
  182. warp/tests/test_unresolved_symbol.py +0 -7
  183. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  184. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  185. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  186. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  187. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
warp/tests/test_types.py CHANGED
@@ -5,81 +5,359 @@
5
5
  # distribution of this software and related documentation without an express
6
6
  # license agreement from NVIDIA CORPORATION is strictly prohibited.
7
7
 
8
- import contextlib
9
- import io
10
- import inspect
11
8
  import unittest
12
9
 
13
- from warp.tests.test_base import *
14
-
10
+ from warp.tests.unittest_utils import *
15
11
 
16
12
  wp.init()
17
13
 
18
14
 
19
- def test_constant(test, device):
20
- const = wp.constant(123)
21
- test.assertEqual(const, 123)
15
+ devices = get_test_devices()
16
+
17
+
18
+ class TestTypes(unittest.TestCase):
19
+ def test_constant(self):
20
+ const = wp.constant(123)
21
+ self.assertEqual(const, 123)
22
+
23
+ const = wp.constant(1.25)
24
+ self.assertEqual(const, 1.25)
25
+
26
+ const = wp.constant(True)
27
+ self.assertEqual(const, True)
28
+
29
+ const = wp.constant(wp.float16(1.25))
30
+ self.assertEqual(const.value, 1.25)
31
+
32
+ const = wp.constant(wp.int16(123))
33
+ self.assertEqual(const.value, 123)
34
+
35
+ const = wp.constant(wp.vec3i(1, 2, 3))
36
+ self.assertEqual(const, wp.vec3i(1, 2, 3))
37
+
38
+ def test_constant_error_invalid_type(self):
39
+ with self.assertRaisesRegex(
40
+ RuntimeError,
41
+ r"Invalid constant type: <class 'tuple'>$",
42
+ ):
43
+ wp.constant((1, 2, 3))
44
+
45
+ def test_vector(self):
46
+ for dtype in tuple(wp.types.scalar_types) + (int, float):
47
+
48
+ def make_scalar(x):
49
+ # Cast to the correct integer type to simulate wrapping.
50
+ if dtype in wp.types.int_types:
51
+ return dtype._type_(x).value
52
+
53
+ return x
54
+
55
+ def make_vec(*args):
56
+ if dtype in wp.types.int_types:
57
+ # Cast to the correct integer type to simulate wrapping.
58
+ return tuple(dtype._type_(x).value for x in args)
59
+
60
+ return args
61
+
62
+ vec3_cls = wp.vec(3, dtype)
63
+ vec4_cls = wp.vec(4, dtype)
64
+
65
+ v = vec4_cls(1, 2, 3, 4)
66
+ self.assertEqual(v[0], make_scalar(1))
67
+ self.assertEqual(v.x, make_scalar(1))
68
+ self.assertEqual(v.y, make_scalar(2))
69
+ self.assertEqual(v.z, make_scalar(3))
70
+ self.assertEqual(v.w, make_scalar(4))
71
+ self.assertSequenceEqual(v[0:2], make_vec(1, 2))
72
+ self.assertSequenceEqual(v, make_vec(1, 2, 3, 4))
73
+
74
+ v[0] = -1
75
+ self.assertEqual(v[0], make_scalar(-1))
76
+ self.assertEqual(v.x, make_scalar(-1))
77
+ self.assertEqual(v.y, make_scalar(2))
78
+ self.assertEqual(v.z, make_scalar(3))
79
+ self.assertEqual(v.w, make_scalar(4))
80
+ self.assertSequenceEqual(v[0:2], make_vec(-1, 2))
81
+ self.assertSequenceEqual(v, make_vec(-1, 2, 3, 4))
82
+
83
+ v[1:3] = (-2, -3)
84
+ self.assertEqual(v[0], make_scalar(-1))
85
+ self.assertEqual(v.x, make_scalar(-1))
86
+ self.assertEqual(v.y, make_scalar(-2))
87
+ self.assertEqual(v.z, make_scalar(-3))
88
+ self.assertEqual(v.w, make_scalar(4))
89
+ self.assertSequenceEqual(v[0:2], make_vec(-1, -2))
90
+ self.assertSequenceEqual(v, make_vec(-1, -2, -3, 4))
91
+
92
+ v.x = 1
93
+ self.assertEqual(v[0], make_scalar(1))
94
+ self.assertEqual(v.x, make_scalar(1))
95
+ self.assertEqual(v.y, make_scalar(-2))
96
+ self.assertEqual(v.z, make_scalar(-3))
97
+ self.assertEqual(v.w, make_scalar(4))
98
+ self.assertSequenceEqual(v[0:2], make_vec(1, -2))
99
+ self.assertSequenceEqual(v, make_vec(1, -2, -3, 4))
100
+
101
+ v = vec3_cls(2, 4, 6)
102
+ self.assertSequenceEqual(+v, make_vec(2, 4, 6))
103
+ self.assertSequenceEqual(-v, make_vec(-2, -4, -6))
104
+ self.assertSequenceEqual(v + vec3_cls(1, 1, 1), make_vec(3, 5, 7))
105
+ self.assertSequenceEqual(v - vec3_cls(1, 1, 1), make_vec(1, 3, 5))
106
+ self.assertSequenceEqual(v * dtype(2), make_vec(4, 8, 12))
107
+ self.assertSequenceEqual(dtype(2) * v, make_vec(4, 8, 12))
108
+ self.assertSequenceEqual(v / dtype(2), make_vec(1, 2, 3))
109
+ self.assertSequenceEqual(dtype(12) / v, make_vec(6, 3, 2))
110
+
111
+ self.assertTrue(v != vec3_cls(1, 2, 3))
112
+ self.assertEqual(str(v), "[{}]".format(", ".join(str(x) for x in v)))
113
+
114
+ # Check added purely for coverage reasons but is this really a desired
115
+ # behaviour? Not allowing to define new attributes using systems like
116
+ # `__slots__` could help improving memory usage.
117
+ v.foo = 123
118
+ self.assertEqual(v.foo, 123)
119
+
120
+ def test_vector_error_invalid_arg_count(self):
121
+ with self.assertRaisesRegex(
122
+ ValueError,
123
+ r"Invalid number of arguments in vector constructor, expected 3 elements, got 2$",
124
+ ):
125
+ wp.vec3(1, 2)
126
+
127
+ def test_vector_error_invalid_ptr(self):
128
+ with self.assertRaisesRegex(
129
+ RuntimeError,
130
+ r"NULL pointer exception",
131
+ ):
132
+ wp.vec3.from_ptr(0)
133
+
134
+ def test_vector_error_invalid_get_item_key(self):
135
+ v = wp.vec3(1, 2, 3)
136
+
137
+ with self.assertRaisesRegex(
138
+ KeyError,
139
+ r"Invalid key None, expected int or slice",
140
+ ):
141
+ v[None]
142
+
143
+ def test_vector_error_invalid_set_item_key(self):
144
+ v = wp.vec3(1, 2, 3)
145
+ with self.assertRaisesRegex(
146
+ KeyError,
147
+ r"Invalid key None, expected int or slice",
148
+ ):
149
+ v[None] = 0
150
+
151
+ def test_matrix(self):
152
+ for dtype in tuple(wp.types.float_types) + (float,):
153
+
154
+ def make_scalar(x):
155
+ # Cast to the correct integer type to simulate wrapping.
156
+ if dtype in wp.types.int_types:
157
+ return dtype._type_(x).value
158
+
159
+ return x
160
+
161
+ def make_vec(*args):
162
+ if dtype in wp.types.int_types:
163
+ # Cast to the correct integer type to simulate wrapping.
164
+ return tuple(dtype._type_(x).value for x in args)
165
+
166
+ return args
167
+
168
+ def make_mat(*args):
169
+ if dtype in wp.types.int_types:
170
+ # Cast to the correct integer type to simulate wrapping.
171
+ return tuple(tuple(dtype._type_(x).value for x in row) for row in args)
172
+
173
+ return args
174
+
175
+ mat22_cls = wp.mat((2, 2), dtype)
176
+ mat33_cls = wp.mat((3, 3), dtype)
177
+ vec2_cls = wp.vec(2, dtype)
178
+
179
+ m = mat33_cls(((1, 2, 3), (4, 5, 6), (7, 8, 9)))
180
+ self.assertEqual(m[0][0], make_scalar(1))
181
+ self.assertEqual(m[0][1], make_scalar(2))
182
+ self.assertEqual(m[0][2], make_scalar(3))
183
+ self.assertEqual(m[1][0], make_scalar(4))
184
+ self.assertEqual(m[1][1], make_scalar(5))
185
+ self.assertEqual(m[1][2], make_scalar(6))
186
+ self.assertEqual(m[2][0], make_scalar(7))
187
+ self.assertEqual(m[2][1], make_scalar(8))
188
+ self.assertEqual(m[2][2], make_scalar(9))
189
+ self.assertEqual(m[0, 0], make_scalar(1))
190
+ self.assertEqual(m[0, 1], make_scalar(2))
191
+ self.assertEqual(m[0, 2], make_scalar(3))
192
+ self.assertEqual(m[1, 0], make_scalar(4))
193
+ self.assertEqual(m[1, 1], make_scalar(5))
194
+ self.assertEqual(m[1, 2], make_scalar(6))
195
+ self.assertEqual(m[2, 0], make_scalar(7))
196
+ self.assertEqual(m[2, 1], make_scalar(8))
197
+ self.assertEqual(m[2, 2], make_scalar(9))
198
+ self.assertSequenceEqual(m[0], make_vec(1, 2, 3))
199
+ self.assertSequenceEqual(m[1], make_vec(4, 5, 6))
200
+ self.assertSequenceEqual(m[2], make_vec(7, 8, 9))
201
+ self.assertSequenceEqual(m[0][1:3], make_vec(2, 3))
202
+ self.assertSequenceEqual(m[1][0:2], make_vec(4, 5))
203
+ self.assertSequenceEqual(m[2][0:3], make_vec(7, 8, 9))
204
+ # self.assertSequenceEqual(m[0, 1:3], make_vec(2, 3))
205
+ # self.assertSequenceEqual(m[1, 0:2], make_vec(4, 5))
206
+ # self.assertSequenceEqual(m[2, 0:3], make_vec(7, 8, 9))
207
+ self.assertSequenceEqual(m, make_mat((1, 2, 3), (4, 5, 6), (7, 8, 9)))
22
208
 
23
- const = wp.constant(1.25)
24
- test.assertEqual(const, 1.25)
209
+ m[1, 0] = -4
210
+ self.assertEqual(m[0][0], make_scalar(1))
211
+ self.assertEqual(m[0][1], make_scalar(2))
212
+ self.assertEqual(m[0][2], make_scalar(3))
213
+ self.assertEqual(m[1][0], make_scalar(-4))
214
+ self.assertEqual(m[1][1], make_scalar(5))
215
+ self.assertEqual(m[1][2], make_scalar(6))
216
+ self.assertEqual(m[2][0], make_scalar(7))
217
+ self.assertEqual(m[2][1], make_scalar(8))
218
+ self.assertEqual(m[2][2], make_scalar(9))
219
+ self.assertEqual(m[0, 0], make_scalar(1))
220
+ self.assertEqual(m[0, 1], make_scalar(2))
221
+ self.assertEqual(m[0, 2], make_scalar(3))
222
+ self.assertEqual(m[1, 0], make_scalar(-4))
223
+ self.assertEqual(m[1, 1], make_scalar(5))
224
+ self.assertEqual(m[1, 2], make_scalar(6))
225
+ self.assertEqual(m[2, 0], make_scalar(7))
226
+ self.assertEqual(m[2, 1], make_scalar(8))
227
+ self.assertEqual(m[2, 2], make_scalar(9))
228
+ self.assertSequenceEqual(m[0], make_vec(1, 2, 3))
229
+ self.assertSequenceEqual(m[1], make_vec(-4, 5, 6))
230
+ self.assertSequenceEqual(m[2], make_vec(7, 8, 9))
231
+ self.assertSequenceEqual(m[0][1:3], make_vec(2, 3))
232
+ self.assertSequenceEqual(m[1][0:2], make_vec(-4, 5))
233
+ self.assertSequenceEqual(m[2][0:3], make_vec(7, 8, 9))
234
+ # self.assertSequenceEqual(m[0, 1:3], make_vec(2, 3))
235
+ # self.assertSequenceEqual(m[1, 0:2], make_vec(-4, 5))
236
+ # self.assertSequenceEqual(m[2, 0:3], make_vec(7, 8, 9))
237
+ self.assertSequenceEqual(m, make_mat((1, 2, 3), (-4, 5, 6), (7, 8, 9)))
25
238
 
26
- const = wp.constant(True)
27
- test.assertEqual(const, True)
239
+ m[2] = (-7, 8, -9)
240
+ self.assertEqual(m[0][0], make_scalar(1))
241
+ self.assertEqual(m[0][1], make_scalar(2))
242
+ self.assertEqual(m[0][2], make_scalar(3))
243
+ self.assertEqual(m[1][0], make_scalar(-4))
244
+ self.assertEqual(m[1][1], make_scalar(5))
245
+ self.assertEqual(m[1][2], make_scalar(6))
246
+ self.assertEqual(m[2][0], make_scalar(-7))
247
+ self.assertEqual(m[2][1], make_scalar(8))
248
+ self.assertEqual(m[2][2], make_scalar(-9))
249
+ self.assertEqual(m[0, 0], make_scalar(1))
250
+ self.assertEqual(m[0, 1], make_scalar(2))
251
+ self.assertEqual(m[0, 2], make_scalar(3))
252
+ self.assertEqual(m[1, 0], make_scalar(-4))
253
+ self.assertEqual(m[1, 1], make_scalar(5))
254
+ self.assertEqual(m[1, 2], make_scalar(6))
255
+ self.assertEqual(m[2, 0], make_scalar(-7))
256
+ self.assertEqual(m[2, 1], make_scalar(8))
257
+ self.assertEqual(m[2, 2], make_scalar(-9))
258
+ self.assertSequenceEqual(m[0], make_vec(1, 2, 3))
259
+ self.assertSequenceEqual(m[1], make_vec(-4, 5, 6))
260
+ self.assertSequenceEqual(m[2], make_vec(-7, 8, -9))
261
+ self.assertSequenceEqual(m[0][1:3], make_vec(2, 3))
262
+ self.assertSequenceEqual(m[1][0:2], make_vec(-4, 5))
263
+ self.assertSequenceEqual(m[2][0:3], make_vec(-7, 8, -9))
264
+ # self.assertSequenceEqual(m[0, 1:3], make_vec(2, 3))
265
+ # self.assertSequenceEqual(m[1, 0:2], make_vec(-4, 5))
266
+ # self.assertSequenceEqual(m[2, 0:3], make_vec(-7, 8, -9))
267
+ self.assertSequenceEqual(m, make_mat((1, 2, 3), (-4, 5, 6), (-7, 8, -9)))
28
268
 
29
- const = wp.constant(wp.float16(1.25))
30
- test.assertEqual(const.value, 1.25)
269
+ m = mat22_cls(2, 4, 6, 8)
270
+ self.assertSequenceEqual(+m, make_mat((2, 4), (6, 8)))
271
+ self.assertSequenceEqual(-m, make_mat((-2, -4), (-6, -8)))
272
+ self.assertSequenceEqual(m + mat22_cls(1, 1, 1, 1), make_mat((3, 5), (7, 9)))
273
+ self.assertSequenceEqual(m - mat22_cls(1, 1, 1, 1), make_mat((1, 3), (5, 7)))
274
+ self.assertSequenceEqual(m * dtype(2), make_mat((4, 8), (12, 16)))
275
+ self.assertSequenceEqual(dtype(2) * m, make_mat((4, 8), (12, 16)))
276
+ self.assertSequenceEqual(m / dtype(2), make_mat((1, 2), (3, 4)))
277
+ self.assertSequenceEqual(dtype(24) / m, make_mat((12, 6), (4, 3)))
31
278
 
32
- const = wp.constant(wp.int16(123))
33
- test.assertEqual(const.value, 123)
279
+ self.assertSequenceEqual(m * vec2_cls(1, 2), make_vec(10, 22))
280
+ self.assertSequenceEqual(m @ vec2_cls(1, 2), make_vec(10, 22))
281
+ self.assertSequenceEqual(vec2_cls(1, 2) * m, make_vec(14, 20))
282
+ self.assertSequenceEqual(vec2_cls(1, 2) @ m, make_vec(14, 20))
34
283
 
35
- const = wp.constant(wp.vec3i(1, 2, 3))
36
- test.assertEqual(const, wp.vec3i(1, 2, 3))
284
+ self.assertTrue(m != mat22_cls(1, 2, 3, 4))
285
+ self.assertEqual(
286
+ str(m),
287
+ "[{}]".format(",\n ".join("[{}]".format(", ".join(str(y) for y in m[x])) for x in range(m._shape_[0]))),
288
+ )
37
289
 
290
+ # Check added purely for coverage reasons but is this really a desired
291
+ # behaviour? Not allowing to define new attributes using systems like
292
+ # `__slots__` could help improving memory usage.
293
+ m.foo = 123
294
+ self.assertEqual(m.foo, 123)
38
295
 
39
- def test_constant_error_invalid_type(test, device):
40
- with test.assertRaisesRegex(
41
- RuntimeError,
42
- r"Invalid constant type: <class 'tuple'>$",
43
- ):
44
- wp.constant((1, 2, 3))
296
+ def test_matrix_error_invalid_arg_count(self):
297
+ with self.assertRaisesRegex(
298
+ ValueError,
299
+ r"Invalid number of arguments in matrix constructor, expected 4 elements, got 3$",
300
+ ):
301
+ wp.mat22(1, 2, 3)
45
302
 
303
+ def test_matrix_error_invalid_row_count(self):
304
+ with self.assertRaisesRegex(
305
+ TypeError,
306
+ r"Invalid argument in matrix constructor, expected row of length 2, got \(1, 2, 3\)$",
307
+ ):
308
+ wp.mat22((1, 2, 3), (3, 4, 5))
46
309
 
47
- def test_vector(test, device):
48
- for dtype in (int, float, wp.float16):
49
- vec_cls = wp.vec(3, dtype)
310
+ def test_matrix_error_invalid_ptr(self):
311
+ with self.assertRaisesRegex(
312
+ RuntimeError,
313
+ r"NULL pointer exception",
314
+ ):
315
+ wp.mat22.from_ptr(0)
50
316
 
51
- v = vec_cls(1, 2, 3)
52
- test.assertEqual(v[0], 1)
53
- test.assertSequenceEqual(v[0:2], (1, 2))
54
- test.assertSequenceEqual(v, (1, 2, 3))
317
+ def test_matrix_error_invalid_set_row_index(self):
318
+ m = wp.mat22(1, 2, 3, 4)
319
+ with self.assertRaisesRegex(
320
+ IndexError,
321
+ r"Invalid row index$",
322
+ ):
323
+ m.set_row(2, (0, 0))
55
324
 
56
- v[0] = -1
57
- test.assertEqual(v[0], -1)
58
- test.assertSequenceEqual(v[0:2], (-1, 2))
59
- test.assertSequenceEqual(v, (-1, 2, 3))
325
+ def test_matrix_error_invalid_get_item_key(self):
326
+ m = wp.mat22(1, 2, 3, 4)
60
327
 
61
- v[1:3] = (-2, -3)
62
- test.assertEqual(v[0], -1)
63
- test.assertSequenceEqual(v[0:2], (-1, -2))
64
- test.assertSequenceEqual(v, (-1, -2, -3))
328
+ with self.assertRaisesRegex(
329
+ KeyError,
330
+ r"Invalid key None, expected int or pair of ints",
331
+ ):
332
+ m[None]
65
333
 
66
- v += vec_cls(1, 1, 1)
67
- test.assertSequenceEqual(v, (0, -1, -2))
334
+ def test_matrix_error_invalid_get_item_key_length(self):
335
+ m = wp.mat22(1, 2, 3, 4)
68
336
 
337
+ with self.assertRaisesRegex(
338
+ KeyError,
339
+ r"Invalid key, expected one or two indices, got 3",
340
+ ):
341
+ m[0, 1, 2]
69
342
 
70
- def register(parent):
71
- devices = get_test_devices()
343
+ def test_matrix_error_invalid_set_item_key(self):
344
+ m = wp.mat22(1, 2, 3, 4)
345
+ with self.assertRaisesRegex(
346
+ KeyError,
347
+ r"Invalid key None, expected int or pair of ints",
348
+ ):
349
+ m[None] = 0
72
350
 
73
- class TestUtils(parent):
74
- pass
351
+ def test_matrix_error_invalid_set_item_key_length(self):
352
+ m = wp.mat22(1, 2, 3, 4)
75
353
 
76
- add_function_test(TestUtils, "test_constant", test_constant)
77
- add_function_test(TestUtils, "test_constant_error_invalid_type", test_constant_error_invalid_type)
78
- add_function_test(TestUtils, "test_vector", test_vector)
79
- return TestUtils
354
+ with self.assertRaisesRegex(
355
+ KeyError,
356
+ r"Invalid key, expected one or two indices, got 3",
357
+ ):
358
+ m[0, 1, 2] = (0, 0)
80
359
 
81
360
 
82
361
  if __name__ == "__main__":
83
362
  wp.build.clear_kernel_cache()
84
- _ = register(unittest.TestCase)
85
363
  unittest.main(verbosity=2)