warp-lang 1.7.2rc1__py3-none-win_amd64.whl → 1.8.1__py3-none-win_amd64.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.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

Files changed (193) hide show
  1. warp/__init__.py +3 -1
  2. warp/__init__.pyi +3489 -1
  3. warp/autograd.py +45 -122
  4. warp/bin/warp-clang.dll +0 -0
  5. warp/bin/warp.dll +0 -0
  6. warp/build.py +241 -252
  7. warp/build_dll.py +130 -26
  8. warp/builtins.py +1907 -384
  9. warp/codegen.py +272 -104
  10. warp/config.py +12 -1
  11. warp/constants.py +1 -1
  12. warp/context.py +770 -238
  13. warp/dlpack.py +1 -1
  14. warp/examples/benchmarks/benchmark_cloth.py +2 -2
  15. warp/examples/benchmarks/benchmark_tile_sort.py +155 -0
  16. warp/examples/core/example_sample_mesh.py +1 -1
  17. warp/examples/core/example_spin_lock.py +93 -0
  18. warp/examples/core/example_work_queue.py +118 -0
  19. warp/examples/fem/example_adaptive_grid.py +5 -5
  20. warp/examples/fem/example_apic_fluid.py +1 -1
  21. warp/examples/fem/example_burgers.py +1 -1
  22. warp/examples/fem/example_convection_diffusion.py +9 -6
  23. warp/examples/fem/example_darcy_ls_optimization.py +489 -0
  24. warp/examples/fem/example_deformed_geometry.py +1 -1
  25. warp/examples/fem/example_diffusion.py +2 -2
  26. warp/examples/fem/example_diffusion_3d.py +1 -1
  27. warp/examples/fem/example_distortion_energy.py +1 -1
  28. warp/examples/fem/example_elastic_shape_optimization.py +387 -0
  29. warp/examples/fem/example_magnetostatics.py +5 -3
  30. warp/examples/fem/example_mixed_elasticity.py +5 -3
  31. warp/examples/fem/example_navier_stokes.py +11 -9
  32. warp/examples/fem/example_nonconforming_contact.py +5 -3
  33. warp/examples/fem/example_streamlines.py +8 -3
  34. warp/examples/fem/utils.py +9 -8
  35. warp/examples/interop/example_jax_callable.py +34 -4
  36. warp/examples/interop/example_jax_ffi_callback.py +2 -2
  37. warp/examples/interop/example_jax_kernel.py +27 -1
  38. warp/examples/optim/example_drone.py +1 -1
  39. warp/examples/sim/example_cloth.py +1 -1
  40. warp/examples/sim/example_cloth_self_contact.py +48 -54
  41. warp/examples/tile/example_tile_block_cholesky.py +502 -0
  42. warp/examples/tile/example_tile_cholesky.py +2 -1
  43. warp/examples/tile/example_tile_convolution.py +1 -1
  44. warp/examples/tile/example_tile_filtering.py +1 -1
  45. warp/examples/tile/example_tile_matmul.py +1 -1
  46. warp/examples/tile/example_tile_mlp.py +2 -0
  47. warp/fabric.py +7 -7
  48. warp/fem/__init__.py +5 -0
  49. warp/fem/adaptivity.py +1 -1
  50. warp/fem/cache.py +152 -63
  51. warp/fem/dirichlet.py +2 -2
  52. warp/fem/domain.py +136 -6
  53. warp/fem/field/field.py +141 -99
  54. warp/fem/field/nodal_field.py +85 -39
  55. warp/fem/field/virtual.py +99 -52
  56. warp/fem/geometry/adaptive_nanogrid.py +91 -86
  57. warp/fem/geometry/closest_point.py +13 -0
  58. warp/fem/geometry/deformed_geometry.py +102 -40
  59. warp/fem/geometry/element.py +56 -2
  60. warp/fem/geometry/geometry.py +323 -22
  61. warp/fem/geometry/grid_2d.py +157 -62
  62. warp/fem/geometry/grid_3d.py +116 -20
  63. warp/fem/geometry/hexmesh.py +86 -20
  64. warp/fem/geometry/nanogrid.py +166 -86
  65. warp/fem/geometry/partition.py +59 -25
  66. warp/fem/geometry/quadmesh.py +86 -135
  67. warp/fem/geometry/tetmesh.py +47 -119
  68. warp/fem/geometry/trimesh.py +77 -270
  69. warp/fem/integrate.py +181 -95
  70. warp/fem/linalg.py +25 -58
  71. warp/fem/operator.py +124 -27
  72. warp/fem/quadrature/pic_quadrature.py +36 -14
  73. warp/fem/quadrature/quadrature.py +40 -16
  74. warp/fem/space/__init__.py +1 -1
  75. warp/fem/space/basis_function_space.py +66 -46
  76. warp/fem/space/basis_space.py +17 -4
  77. warp/fem/space/dof_mapper.py +1 -1
  78. warp/fem/space/function_space.py +2 -2
  79. warp/fem/space/grid_2d_function_space.py +4 -1
  80. warp/fem/space/hexmesh_function_space.py +4 -2
  81. warp/fem/space/nanogrid_function_space.py +3 -1
  82. warp/fem/space/partition.py +11 -2
  83. warp/fem/space/quadmesh_function_space.py +4 -1
  84. warp/fem/space/restriction.py +5 -2
  85. warp/fem/space/shape/__init__.py +10 -8
  86. warp/fem/space/tetmesh_function_space.py +4 -1
  87. warp/fem/space/topology.py +52 -21
  88. warp/fem/space/trimesh_function_space.py +4 -1
  89. warp/fem/utils.py +53 -8
  90. warp/jax.py +1 -2
  91. warp/jax_experimental/ffi.py +210 -67
  92. warp/jax_experimental/xla_ffi.py +37 -24
  93. warp/math.py +171 -1
  94. warp/native/array.h +103 -4
  95. warp/native/builtin.h +182 -35
  96. warp/native/coloring.cpp +6 -2
  97. warp/native/cuda_util.cpp +1 -1
  98. warp/native/exports.h +118 -63
  99. warp/native/intersect.h +5 -5
  100. warp/native/mat.h +8 -13
  101. warp/native/mathdx.cpp +11 -5
  102. warp/native/matnn.h +1 -123
  103. warp/native/mesh.h +1 -1
  104. warp/native/quat.h +34 -6
  105. warp/native/rand.h +7 -7
  106. warp/native/sparse.cpp +121 -258
  107. warp/native/sparse.cu +181 -274
  108. warp/native/spatial.h +305 -17
  109. warp/native/svd.h +23 -8
  110. warp/native/tile.h +603 -73
  111. warp/native/tile_radix_sort.h +1112 -0
  112. warp/native/tile_reduce.h +239 -13
  113. warp/native/tile_scan.h +240 -0
  114. warp/native/tuple.h +189 -0
  115. warp/native/vec.h +10 -20
  116. warp/native/warp.cpp +36 -4
  117. warp/native/warp.cu +588 -52
  118. warp/native/warp.h +47 -74
  119. warp/optim/linear.py +5 -1
  120. warp/paddle.py +7 -8
  121. warp/py.typed +0 -0
  122. warp/render/render_opengl.py +110 -80
  123. warp/render/render_usd.py +124 -62
  124. warp/sim/__init__.py +9 -0
  125. warp/sim/collide.py +253 -80
  126. warp/sim/graph_coloring.py +8 -1
  127. warp/sim/import_mjcf.py +4 -3
  128. warp/sim/import_usd.py +11 -7
  129. warp/sim/integrator.py +5 -2
  130. warp/sim/integrator_euler.py +1 -1
  131. warp/sim/integrator_featherstone.py +1 -1
  132. warp/sim/integrator_vbd.py +761 -322
  133. warp/sim/integrator_xpbd.py +1 -1
  134. warp/sim/model.py +265 -260
  135. warp/sim/utils.py +10 -7
  136. warp/sparse.py +303 -166
  137. warp/tape.py +54 -51
  138. warp/tests/cuda/test_conditional_captures.py +1046 -0
  139. warp/tests/cuda/test_streams.py +1 -1
  140. warp/tests/geometry/test_volume.py +2 -2
  141. warp/tests/interop/test_dlpack.py +9 -9
  142. warp/tests/interop/test_jax.py +0 -1
  143. warp/tests/run_coverage_serial.py +1 -1
  144. warp/tests/sim/disabled_kinematics.py +2 -2
  145. warp/tests/sim/{test_vbd.py → test_cloth.py} +378 -112
  146. warp/tests/sim/test_collision.py +159 -51
  147. warp/tests/sim/test_coloring.py +91 -2
  148. warp/tests/test_array.py +254 -2
  149. warp/tests/test_array_reduce.py +2 -2
  150. warp/tests/test_assert.py +53 -0
  151. warp/tests/test_atomic_cas.py +312 -0
  152. warp/tests/test_codegen.py +142 -19
  153. warp/tests/test_conditional.py +47 -1
  154. warp/tests/test_ctypes.py +0 -20
  155. warp/tests/test_devices.py +8 -0
  156. warp/tests/test_fabricarray.py +4 -2
  157. warp/tests/test_fem.py +58 -25
  158. warp/tests/test_func.py +42 -1
  159. warp/tests/test_grad.py +1 -1
  160. warp/tests/test_lerp.py +1 -3
  161. warp/tests/test_map.py +481 -0
  162. warp/tests/test_mat.py +23 -24
  163. warp/tests/test_quat.py +28 -15
  164. warp/tests/test_rounding.py +10 -38
  165. warp/tests/test_runlength_encode.py +7 -7
  166. warp/tests/test_smoothstep.py +1 -1
  167. warp/tests/test_sparse.py +83 -2
  168. warp/tests/test_spatial.py +507 -1
  169. warp/tests/test_static.py +48 -0
  170. warp/tests/test_struct.py +2 -2
  171. warp/tests/test_tape.py +38 -0
  172. warp/tests/test_tuple.py +265 -0
  173. warp/tests/test_types.py +2 -2
  174. warp/tests/test_utils.py +24 -18
  175. warp/tests/test_vec.py +38 -408
  176. warp/tests/test_vec_constructors.py +325 -0
  177. warp/tests/tile/test_tile.py +438 -131
  178. warp/tests/tile/test_tile_mathdx.py +518 -14
  179. warp/tests/tile/test_tile_matmul.py +179 -0
  180. warp/tests/tile/test_tile_reduce.py +307 -5
  181. warp/tests/tile/test_tile_shared_memory.py +136 -7
  182. warp/tests/tile/test_tile_sort.py +121 -0
  183. warp/tests/unittest_suites.py +14 -6
  184. warp/types.py +462 -308
  185. warp/utils.py +647 -86
  186. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/METADATA +20 -6
  187. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/RECORD +190 -176
  188. warp/stubs.py +0 -3381
  189. warp/tests/sim/test_xpbd.py +0 -399
  190. warp/tests/test_mlp.py +0 -282
  191. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/WHEEL +0 -0
  192. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/licenses/LICENSE.md +0 -0
  193. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/top_level.txt +0 -0
warp/native/spatial.h CHANGED
@@ -136,6 +136,13 @@ struct transform_t
136
136
  CUDA_CALLABLE inline transform_t(vec_t<3,Type> p=vec_t<3,Type>(), quat_t<Type> q=quat_t<Type>()) : p(p), q(q) {}
137
137
  CUDA_CALLABLE inline transform_t(Type) {} // helps uniform initialization
138
138
 
139
+ template<typename OtherType>
140
+ inline explicit CUDA_CALLABLE transform_t(const transform_t<OtherType>& other)
141
+ {
142
+ p = other.p;
143
+ q = other.q;
144
+ }
145
+
139
146
  CUDA_CALLABLE inline transform_t(const initializer_array<7, Type> &l)
140
147
  {
141
148
  p = vec_t<3,Type>(l[0], l[1], l[2]);
@@ -163,6 +170,35 @@ CUDA_CALLABLE inline transform_t<Type> transform_identity()
163
170
  return transform_t<Type>(vec_t<3,Type>(), quat_identity<Type>());
164
171
  }
165
172
 
173
+ template<typename Type>
174
+ inline CUDA_CALLABLE transform_t<Type> operator - (const transform_t<Type>& x)
175
+ {
176
+ transform_t<Type> ret;
177
+
178
+ ret.p = -x.p;
179
+ ret.q = -x.q;
180
+
181
+ return ret;
182
+ }
183
+
184
+ template<typename Type>
185
+ CUDA_CALLABLE inline transform_t<Type> pos(const transform_t<Type>& x)
186
+ {
187
+ return x;
188
+ }
189
+
190
+ template<typename Type>
191
+ CUDA_CALLABLE inline transform_t<Type> neg(const transform_t<Type>& x)
192
+ {
193
+ return -x;
194
+ }
195
+
196
+ template<typename Type>
197
+ CUDA_CALLABLE inline void adj_neg(const transform_t<Type>& x, transform_t<Type>& adj_x, const transform_t<Type>& adj_ret)
198
+ {
199
+ adj_x -= adj_ret;
200
+ }
201
+
166
202
  template<typename Type>
167
203
  inline CUDA_CALLABLE bool operator==(const transform_t<Type>& a, const transform_t<Type>& b)
168
204
  {
@@ -188,6 +224,96 @@ CUDA_CALLABLE inline quat_t<Type> transform_get_rotation(const transform_t<Type>
188
224
  return t.q;
189
225
  }
190
226
 
227
+ template<typename Type>
228
+ CUDA_CALLABLE inline void adj_transform_get_translation(const transform_t<Type>& t, transform_t<Type>& adj_t, const vec_t<3,Type>& adj_ret)
229
+ {
230
+ adj_t.p += adj_ret;
231
+ }
232
+
233
+ template<typename Type>
234
+ CUDA_CALLABLE inline void adj_transform_get_rotation(const transform_t<Type>& t, transform_t<Type>& adj_t, const quat_t<Type>& adj_ret)
235
+ {
236
+ adj_t.q += adj_ret;
237
+ }
238
+
239
+ template<typename Type>
240
+ CUDA_CALLABLE inline void transform_set_translation(transform_t<Type>& t, const vec_t<3, Type>& p)
241
+ {
242
+ t.p = p;
243
+ }
244
+
245
+ template<typename Type>
246
+ CUDA_CALLABLE inline void transform_set_rotation(transform_t<Type>& t, const quat_t<Type>& q)
247
+ {
248
+ t.q = q;
249
+ }
250
+
251
+ template<typename Type>
252
+ CUDA_CALLABLE inline transform_t<Type> transform_set_translation_copy(transform_t<Type>& t, const vec_t<3, Type>& p)
253
+ {
254
+ transform_t<Type> ret(t);
255
+ ret.p = p;
256
+ return ret;
257
+ }
258
+
259
+ template<typename Type>
260
+ CUDA_CALLABLE inline transform_t<Type> transform_set_rotation_copy(transform_t<Type>& t, const quat_t<Type>& q)
261
+ {
262
+ transform_t<Type> ret(t);
263
+ ret.q = q;
264
+ return ret;
265
+ }
266
+
267
+ template<typename Type>
268
+ CUDA_CALLABLE inline void adj_transform_set_translation(transform_t<Type>& t, const vec_t<3, Type>& p, const transform_t<Type>& adj_t, vec_t<3, Type>& adj_p)
269
+ {
270
+ adj_p += adj_t.p;
271
+ }
272
+
273
+ template<typename Type>
274
+ CUDA_CALLABLE inline void adj_transform_set_rotation(transform_t<Type>& t, const quat_t<Type>& q, const transform_t<Type>& adj_t, quat_t<Type>& adj_q)
275
+ {
276
+ adj_q += adj_t.q;
277
+ }
278
+
279
+ template<typename Type>
280
+ CUDA_CALLABLE inline void adj_transform_set_translation_copy(transform_t<Type>& t, const vec_t<3, Type>& p, transform_t<Type>& adj_t, vec_t<3, Type>& adj_p, const transform_t<Type>& adj_ret)
281
+ {
282
+ adj_p += adj_ret.p;
283
+ adj_t.q += adj_ret.q;
284
+ }
285
+
286
+ template<typename Type>
287
+ CUDA_CALLABLE inline void adj_transform_set_rotation_copy(transform_t<Type>& t, const quat_t<Type>& q, transform_t<Type>& adj_t, quat_t<Type>& adj_q, const transform_t<Type>& adj_ret)
288
+ {
289
+ adj_q += adj_ret.q;
290
+ adj_t.p += adj_ret.p;
291
+ }
292
+
293
+ template<typename Type>
294
+ inline CUDA_CALLABLE void transform_add_inplace(transform_t<Type>& t, const vec_t<3, Type>& p)
295
+ {
296
+ t.p += p;
297
+ }
298
+
299
+ template<typename Type>
300
+ inline CUDA_CALLABLE void transform_sub_inplace(transform_t<Type>& t, const vec_t<3, Type>& p)
301
+ {
302
+ t.p -= p;
303
+ }
304
+
305
+ template<typename Type>
306
+ inline CUDA_CALLABLE void adj_transform_add_inplace(transform_t<Type>& t, const vec_t<3, Type>& p, transform_t<Type>& adj_t, vec_t<3, Type>& adj_p)
307
+ {
308
+ adj_p += adj_t.p;
309
+ }
310
+
311
+ template<typename Type>
312
+ inline CUDA_CALLABLE void adj_transform_sub_inplace(transform_t<Type>& t, const vec_t<3, Type>& p, transform_t<Type>& adj_t, vec_t<3, Type>& adj_p)
313
+ {
314
+ adj_p -= adj_t.p;
315
+ }
316
+
191
317
  template<typename Type>
192
318
  CUDA_CALLABLE inline transform_t<Type> transform_multiply(const transform_t<Type>& a, const transform_t<Type>& b)
193
319
  {
@@ -271,7 +397,6 @@ CUDA_CALLABLE inline transform_t<Type> operator*(Type s, const transform_t<Type>
271
397
  return mul(a, s);
272
398
  }
273
399
 
274
-
275
400
  template<typename Type>
276
401
  inline CUDA_CALLABLE Type tensordot(const transform_t<Type>& a, const transform_t<Type>& b)
277
402
  {
@@ -280,17 +405,192 @@ inline CUDA_CALLABLE Type tensordot(const transform_t<Type>& a, const transform_
280
405
  }
281
406
 
282
407
  template<typename Type>
283
- inline CUDA_CALLABLE Type extract(const transform_t<Type>& t, int i)
408
+ inline CUDA_CALLABLE Type extract(const transform_t<Type>& t, int idx)
284
409
  {
285
- return t[i];
410
+ #ifndef NDEBUG
411
+ if (idx < 0 || idx >= 7)
412
+ {
413
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
414
+ assert(0);
415
+ }
416
+ #endif
417
+
418
+ return t[idx];
286
419
  }
287
420
 
288
421
  template<typename Type>
289
- inline void CUDA_CALLABLE adj_extract(const transform_t<Type>& t, int i, transform_t<Type>& adj_t, int& adj_i, Type adj_ret)
422
+ inline CUDA_CALLABLE Type* index(transform_t<Type>& t, int idx)
290
423
  {
291
- adj_t[i] += adj_ret;
424
+ #ifndef NDEBUG
425
+ if (idx < 0 || idx >= 7)
426
+ {
427
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
428
+ assert(0);
429
+ }
430
+ #endif
431
+
432
+ return &t[idx];
292
433
  }
293
434
 
435
+ template<typename Type>
436
+ inline CUDA_CALLABLE Type* indexref(transform_t<Type>* t, int idx)
437
+ {
438
+ #ifndef NDEBUG
439
+ if (idx < 0 || idx >= 7)
440
+ {
441
+ printf("transformation store %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
442
+ assert(0);
443
+ }
444
+ #endif
445
+
446
+ return &((*t)[idx]);
447
+ }
448
+
449
+ template<typename Type>
450
+ inline void CUDA_CALLABLE adj_extract(const transform_t<Type>& t, int idx, transform_t<Type>& adj_t, int& adj_idx, Type adj_ret)
451
+ {
452
+ adj_t[idx] += adj_ret;
453
+ }
454
+
455
+ template<typename Type>
456
+ inline CUDA_CALLABLE void adj_index(transform_t<Type>& t, int idx,
457
+ transform_t<Type>& adj_t, int adj_idx, const Type& adj_value)
458
+ {
459
+ // nop
460
+ }
461
+
462
+ template<typename Type>
463
+ inline CUDA_CALLABLE void adj_indexref(transform_t<Type>* t, int idx,
464
+ transform_t<Type>& adj_t, int adj_idx, const Type& adj_value)
465
+ {
466
+ // nop
467
+ }
468
+
469
+ template<typename Type>
470
+ inline CUDA_CALLABLE void add_inplace(transform_t<Type>& t, int idx, Type value)
471
+ {
472
+ #ifndef NDEBUG
473
+ if (idx < 0 || idx >= 7)
474
+ {
475
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
476
+ assert(0);
477
+ }
478
+ #endif
479
+
480
+ t[idx] += value;
481
+ }
482
+
483
+
484
+ template<typename Type>
485
+ inline CUDA_CALLABLE void adj_add_inplace(transform_t<Type>& t, int idx, Type value,
486
+ transform_t<Type>& adj_t, int adj_idx, Type& adj_value)
487
+ {
488
+ #ifndef NDEBUG
489
+ if (idx < 0 || idx >= 7)
490
+ {
491
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
492
+ assert(0);
493
+ }
494
+ #endif
495
+
496
+ adj_value += adj_t[idx];
497
+ }
498
+
499
+
500
+ template<typename Type>
501
+ inline CUDA_CALLABLE void sub_inplace(transform_t<Type>& t, int idx, Type value)
502
+ {
503
+ #ifndef NDEBUG
504
+ if (idx < 0 || idx >= 7)
505
+ {
506
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
507
+ assert(0);
508
+ }
509
+ #endif
510
+
511
+ t[idx] -= value;
512
+ }
513
+
514
+
515
+ template<typename Type>
516
+ inline CUDA_CALLABLE void adj_sub_inplace(transform_t<Type>& t, int idx, Type value,
517
+ transform_t<Type>& adj_t, int adj_idx, Type& adj_value)
518
+ {
519
+ #ifndef NDEBUG
520
+ if (idx < 0 || idx >= 7)
521
+ {
522
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
523
+ assert(0);
524
+ }
525
+ #endif
526
+
527
+ adj_value -= adj_t[idx];
528
+ }
529
+
530
+
531
+ template<typename Type>
532
+ inline CUDA_CALLABLE void assign_inplace(transform_t<Type>& t, int idx, Type value)
533
+ {
534
+ #ifndef NDEBUG
535
+ if (idx < 0 || idx >= 7)
536
+ {
537
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
538
+ assert(0);
539
+ }
540
+ #endif
541
+
542
+ t[idx] = value;
543
+ }
544
+
545
+ template<typename Type>
546
+ inline CUDA_CALLABLE void adj_assign_inplace(transform_t<Type>& t, int idx, Type value, transform_t<Type>& adj_t, int& adj_idx, Type& adj_value)
547
+ {
548
+ #ifndef NDEBUG
549
+ if (idx < 0 || idx >= 7)
550
+ {
551
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
552
+ assert(0);
553
+ }
554
+ #endif
555
+
556
+ adj_value += adj_t[idx];
557
+ }
558
+
559
+
560
+ template<typename Type>
561
+ inline CUDA_CALLABLE transform_t<Type> assign_copy(transform_t<Type>& t, int idx, Type value)
562
+ {
563
+ #ifndef NDEBUG
564
+ if (idx < 0 || idx >= 7)
565
+ {
566
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
567
+ assert(0);
568
+ }
569
+ #endif
570
+
571
+ transform_t<Type> ret(t);
572
+ ret[idx] = value;
573
+ return ret;
574
+ }
575
+
576
+ template<typename Type>
577
+ inline CUDA_CALLABLE void adj_assign_copy(transform_t<Type>& t, int idx, Type value, transform_t<Type>& adj_t, int& adj_idx, Type& adj_value, const transform_t<Type>& adj_ret)
578
+ {
579
+ #ifndef NDEBUG
580
+ if (idx < 0 || idx >= 7)
581
+ {
582
+ printf("transformation index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
583
+ assert(0);
584
+ }
585
+ #endif
586
+
587
+ adj_value += adj_ret[idx];
588
+ for(unsigned i=0; i < 7; ++i)
589
+ {
590
+ if (i != idx)
591
+ adj_t[i] += adj_ret[i];
592
+ }
593
+ }
294
594
 
295
595
  // adjoint methods
296
596
  template<typename Type>
@@ -343,18 +643,6 @@ CUDA_CALLABLE inline void adj_transform_t(const vec_t<3,Type>& p, const quat_t<T
343
643
  adj_q += adj_ret.q;
344
644
  }
345
645
 
346
- template<typename Type>
347
- CUDA_CALLABLE inline void adj_transform_get_translation(const transform_t<Type>& t, transform_t<Type>& adj_t, const vec_t<3,Type>& adj_ret)
348
- {
349
- adj_t.p += adj_ret;
350
- }
351
-
352
- template<typename Type>
353
- CUDA_CALLABLE inline void adj_transform_get_rotation(const transform_t<Type>& t, transform_t<Type>& adj_t, const quat_t<Type>& adj_ret)
354
- {
355
- adj_t.q += adj_ret;
356
- }
357
-
358
646
  template<typename Type>
359
647
  CUDA_CALLABLE inline void adj_transform_inverse(const transform_t<Type>& t, transform_t<Type>& adj_t, const transform_t<Type>& adj_ret)
360
648
  {
warp/native/svd.h CHANGED
@@ -50,12 +50,14 @@ namespace wp
50
50
 
51
51
  template<typename Type>
52
52
  struct _svd_config {
53
+ static constexpr float SVD_EPSILON = 1.e-6f;
53
54
  static constexpr float QR_GIVENS_EPSILON = 1.e-6f;
54
55
  static constexpr int JACOBI_ITERATIONS = 4;
55
56
  };
56
57
 
57
58
  template<>
58
59
  struct _svd_config<double> {
60
+ static constexpr double SVD_EPSILON = 1.e-12;
59
61
  static constexpr double QR_GIVENS_EPSILON = 1.e-12;
60
62
  static constexpr int JACOBI_ITERATIONS = 8;
61
63
  };
@@ -528,13 +530,15 @@ inline CUDA_CALLABLE void adj_svd3(const mat_t<3,3,Type>& A,
528
530
  const mat_t<3,3,Type>& adj_U,
529
531
  const vec_t<3,Type>& adj_sigma,
530
532
  const mat_t<3,3,Type>& adj_V) {
533
+ const Type epsilon = _svd_config<Type>::SVD_EPSILON;
534
+
531
535
  Type sx2 = sigma[0] * sigma[0];
532
536
  Type sy2 = sigma[1] * sigma[1];
533
537
  Type sz2 = sigma[2] * sigma[2];
534
538
 
535
- Type F01 = Type(1) / min(sy2 - sx2, Type(-1e-6f));
536
- Type F02 = Type(1) / min(sz2 - sx2, Type(-1e-6f));
537
- Type F12 = Type(1) / min(sz2 - sy2, Type(-1e-6f));
539
+ Type F01 = Type(1) / min(sy2 - sx2, Type(-epsilon));
540
+ Type F02 = Type(1) / min(sz2 - sx2, Type(-epsilon));
541
+ Type F12 = Type(1) / min(sz2 - sy2, Type(-epsilon));
538
542
 
539
543
  mat_t<3,3,Type> F = mat_t<3,3,Type>(0, F01, F02,
540
544
  -F01, 0, F12,
@@ -553,8 +557,13 @@ inline CUDA_CALLABLE void adj_svd3(const mat_t<3,3,Type>& A,
553
557
 
554
558
  mat_t<3,3,Type> sigma_term = mul(U, mul(adj_sigma_mat, VT));
555
559
 
556
- mat_t<3,3,Type> u_term = mul(mul(U, mul(cw_mul(F, (mul(UT, adj_U) - mul(transpose(adj_U), U))), s_mat)), VT);
557
- mat_t<3,3,Type> v_term = mul(U, mul(s_mat, mul(cw_mul(F, (mul(VT, adj_V) - mul(transpose(adj_V), V))), VT)));
560
+ mat_t<3,3,Type> skew_u = cw_mul(F, mul(UT, adj_U) - mul(transpose(adj_U), U));
561
+ mat_t<3,3,Type> block_u = mul(skew_u, s_mat);
562
+ mat_t<3,3,Type> u_term = mul(mul(U, block_u), VT);
563
+
564
+ mat_t<3,3,Type> skew_v = cw_mul(F, mul(VT, adj_V) - mul(transpose(adj_V), V));
565
+ mat_t<3,3,Type> block_v = mul(skew_v, VT);
566
+ mat_t<3,3,Type> v_term = mul(U, mul(s_mat, block_v));
558
567
 
559
568
  adj_A = adj_A + (u_term + v_term + sigma_term);
560
569
  }
@@ -583,11 +592,13 @@ inline CUDA_CALLABLE void adj_svd2(const mat_t<2,2,Type>& A,
583
592
  const mat_t<2,2,Type>& adj_U,
584
593
  const vec_t<2,Type>& adj_sigma,
585
594
  const mat_t<2,2,Type>& adj_V) {
595
+ const Type epsilon = _svd_config<Type>::SVD_EPSILON;
596
+
586
597
  Type s1_squared = sigma[0] * sigma[0];
587
598
  Type s2_squared = sigma[1] * sigma[1];
588
599
 
589
600
  // Compute inverse of (s1^2 - s2^2) if possible, use small epsilon to prevent division by zero
590
- Type F01 = Type(1) / min(s2_squared - s1_squared, Type(-1e-6f));
601
+ Type F01 = Type(1) / min(s2_squared - s1_squared, Type(-epsilon));
591
602
 
592
603
  // Construct the matrix F for the adjoint
593
604
  mat_t<2,2,Type> F = mat_t<2,2,Type>(0.0, F01,
@@ -609,10 +620,14 @@ inline CUDA_CALLABLE void adj_svd2(const mat_t<2,2,Type>& A,
609
620
  mat_t<2,2,Type> sigma_term = mul(U, mul(adj_sigma_mat, VT));
610
621
 
611
622
  // Compute the adjoint contributions for U (left singular vectors)
612
- mat_t<2,2,Type> u_term = mul(mul(U, mul(cw_mul(F, (mul(UT, adj_U) - mul(transpose(adj_U), U))), s_mat)), VT);
623
+ mat_t<2,2,Type> skew_u = cw_mul(F, mul(UT, adj_U) - mul(transpose(adj_U), U));
624
+ mat_t<2,2,Type> block_u = mul(skew_u, s_mat);
625
+ mat_t<2,2,Type> u_term = mul(mul(U, block_u), VT);
613
626
 
614
627
  // Compute the adjoint contributions for V (right singular vectors)
615
- mat_t<2,2,Type> v_term = mul(U, mul(s_mat, mul(cw_mul(F, (mul(VT, adj_V) - mul(transpose(adj_V), V))), VT)));
628
+ mat_t<2,2,Type> skew_v = cw_mul(F, mul(VT, adj_V) - mul(transpose(adj_V), V));
629
+ mat_t<2,2,Type> block_v = mul(skew_v, VT);
630
+ mat_t<2,2,Type> v_term = mul(U, mul(s_mat, block_v));
616
631
 
617
632
  // Combine the terms to compute the adjoint of A
618
633
  adj_A = adj_A + (u_term + v_term + sigma_term);