warp-lang 1.7.0__py3-none-win_amd64.whl → 1.7.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.
- warp/autograd.py +12 -2
- warp/bin/warp-clang.dll +0 -0
- warp/bin/warp.dll +0 -0
- warp/build.py +1 -1
- warp/builtins.py +11 -10
- warp/codegen.py +17 -5
- warp/config.py +1 -1
- warp/context.py +6 -0
- warp/examples/benchmarks/benchmark_cloth.py +1 -1
- warp/examples/distributed/example_jacobi_mpi.py +507 -0
- warp/fem/field/field.py +11 -1
- warp/fem/field/nodal_field.py +36 -22
- warp/fem/geometry/adaptive_nanogrid.py +7 -3
- warp/fem/geometry/trimesh.py +4 -12
- warp/jax_experimental/custom_call.py +14 -2
- warp/jax_experimental/ffi.py +5 -1
- warp/native/tile.h +11 -11
- warp/native/warp.cu +1 -1
- warp/render/render_opengl.py +19 -17
- warp/render/render_usd.py +93 -3
- warp/sim/collide.py +11 -9
- warp/sim/inertia.py +189 -156
- warp/sim/integrator_euler.py +3 -0
- warp/sim/integrator_xpbd.py +3 -0
- warp/sim/model.py +29 -12
- warp/sim/render.py +4 -0
- warp/stubs.py +1 -1
- warp/tests/assets/torus.usda +1 -1
- warp/tests/sim/test_collision.py +237 -206
- warp/tests/sim/test_inertia.py +161 -0
- warp/tests/sim/{flaky_test_sim_grad.py → test_sim_grad.py} +4 -0
- warp/tests/sim/test_xpbd.py +399 -0
- warp/tests/test_codegen.py +24 -3
- warp/tests/test_examples.py +16 -6
- warp/tests/test_fem.py +75 -10
- warp/tests/test_mat.py +370 -103
- warp/tests/test_quat.py +321 -137
- warp/tests/test_vec.py +320 -174
- warp/tests/tile/test_tile_load.py +97 -0
- warp/tests/unittest_suites.py +2 -5
- warp/types.py +65 -8
- {warp_lang-1.7.0.dist-info → warp_lang-1.7.1.dist-info}/METADATA +21 -9
- {warp_lang-1.7.0.dist-info → warp_lang-1.7.1.dist-info}/RECORD +46 -43
- {warp_lang-1.7.0.dist-info → warp_lang-1.7.1.dist-info}/WHEEL +1 -1
- {warp_lang-1.7.0.dist-info → warp_lang-1.7.1.dist-info}/licenses/LICENSE.md +0 -26
- {warp_lang-1.7.0.dist-info → warp_lang-1.7.1.dist-info}/top_level.txt +0 -0
warp/tests/test_mat.py
CHANGED
|
@@ -50,6 +50,22 @@ def get_select_kernel(dtype):
|
|
|
50
50
|
return getkernel(output_select_kernel_fn, suffix=dtype.__name__)
|
|
51
51
|
|
|
52
52
|
|
|
53
|
+
def test_shape_mismatch(test, device):
|
|
54
|
+
test.assertNotEqual(wp.mat33f(0.0), wp.mat22f(0.0))
|
|
55
|
+
test.assertNotEqual(wp.mat22f(0.0), wp.mat33f(0.0))
|
|
56
|
+
|
|
57
|
+
@wp.kernel
|
|
58
|
+
def kernel():
|
|
59
|
+
wp.expect_neq(wp.mat33f(0.0), wp.mat22f(0.0))
|
|
60
|
+
wp.expect_neq(wp.mat22f(0.0), wp.mat33f(0.0))
|
|
61
|
+
|
|
62
|
+
with test.assertRaisesRegex(
|
|
63
|
+
RuntimeError,
|
|
64
|
+
r"Can't test equality for objects with different types$",
|
|
65
|
+
):
|
|
66
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
67
|
+
|
|
68
|
+
|
|
53
69
|
def test_anon_constructor_error_shape_arg_missing(test, device):
|
|
54
70
|
@wp.kernel
|
|
55
71
|
def kernel():
|
|
@@ -1607,60 +1623,6 @@ def test_transform_vector(test, device, dtype, register_kernels=False):
|
|
|
1607
1623
|
tape.zero()
|
|
1608
1624
|
|
|
1609
1625
|
|
|
1610
|
-
def test_matrix_assign_inplace(test, device, dtype, register_kernels=False):
|
|
1611
|
-
np_type = np.dtype(dtype)
|
|
1612
|
-
wp_type = wp.types.np_dtype_to_warp_type[np_type]
|
|
1613
|
-
|
|
1614
|
-
vec2 = wp.types.vector(length=2, dtype=wp_type)
|
|
1615
|
-
mat22 = wp.types.matrix(shape=(2, 2), dtype=wp_type)
|
|
1616
|
-
|
|
1617
|
-
def mattest_read_write_store(x: wp.array(dtype=wp_type), a: wp.array(dtype=mat22)):
|
|
1618
|
-
tid = wp.tid()
|
|
1619
|
-
|
|
1620
|
-
t = a[tid]
|
|
1621
|
-
t[0, 0] = x[tid]
|
|
1622
|
-
a[tid] = t
|
|
1623
|
-
|
|
1624
|
-
def mattest_in_register(x: wp.array2d(dtype=mat22), y: wp.array(dtype=vec2)):
|
|
1625
|
-
i, j = wp.tid()
|
|
1626
|
-
|
|
1627
|
-
a = mat22(wp_type(0.0))
|
|
1628
|
-
a[0] = y[i]
|
|
1629
|
-
a[1, 1] = wp_type(3.0)
|
|
1630
|
-
x[i, j] = a
|
|
1631
|
-
|
|
1632
|
-
kernel_read_write_store = getkernel(mattest_read_write_store, suffix=dtype.__name__)
|
|
1633
|
-
kernel_in_register = getkernel(mattest_in_register, suffix=dtype.__name__)
|
|
1634
|
-
|
|
1635
|
-
if register_kernels:
|
|
1636
|
-
return
|
|
1637
|
-
|
|
1638
|
-
a = wp.ones(1, dtype=mat22, device=device, requires_grad=True)
|
|
1639
|
-
x = wp.full(1, value=2.0, dtype=wp_type, device=device, requires_grad=True)
|
|
1640
|
-
|
|
1641
|
-
tape = wp.Tape()
|
|
1642
|
-
with tape:
|
|
1643
|
-
wp.launch(kernel_read_write_store, dim=1, inputs=[x, a], device=device)
|
|
1644
|
-
|
|
1645
|
-
tape.backward(grads={a: wp.ones_like(a, requires_grad=False)})
|
|
1646
|
-
|
|
1647
|
-
assert_np_equal(a.numpy(), np.array([[[2.0, 1.0], [1.0, 1.0]]], dtype=np_type))
|
|
1648
|
-
assert_np_equal(x.grad.numpy(), np.array([1.0], dtype=np_type))
|
|
1649
|
-
|
|
1650
|
-
tape.reset()
|
|
1651
|
-
|
|
1652
|
-
x = wp.zeros((1, 1), dtype=mat22, device=device, requires_grad=True)
|
|
1653
|
-
y = wp.ones(1, dtype=vec2, device=device, requires_grad=True)
|
|
1654
|
-
|
|
1655
|
-
with tape:
|
|
1656
|
-
wp.launch(kernel_in_register, dim=(1, 1), inputs=[x, y], device=device)
|
|
1657
|
-
|
|
1658
|
-
tape.backward(grads={x: wp.ones_like(x, requires_grad=False)})
|
|
1659
|
-
|
|
1660
|
-
assert_np_equal(x.numpy(), np.array([[[[1.0, 1.0], [0.0, 3.0]]]], dtype=np_type))
|
|
1661
|
-
assert_np_equal(y.grad.numpy(), np.array([[1.0, 1.0]], dtype=np_type))
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
1626
|
# Test matrix constructors using explicit type (float16)
|
|
1665
1627
|
# note that these tests are specifically not using generics / closure
|
|
1666
1628
|
# args to create kernels dynamically (like the rest of this file)
|
|
@@ -1694,6 +1656,7 @@ def test_matrix_constructor_value_func():
|
|
|
1694
1656
|
c = mat32d()
|
|
1695
1657
|
d = mat32d(c, shape=(3, 2))
|
|
1696
1658
|
e = mat32d(wp.float64(1.0), wp.float64(2.0), wp.float64(1.0), wp.float64(2.0), wp.float64(1.0), wp.float64(2.0))
|
|
1659
|
+
f = wp.matrix(1.0, 2.0, 3.0, 4.0, shape=(2, 2), dtype=float)
|
|
1697
1660
|
|
|
1698
1661
|
|
|
1699
1662
|
@wp.kernel
|
|
@@ -1864,63 +1827,105 @@ def test_matrix_len(test, device):
|
|
|
1864
1827
|
|
|
1865
1828
|
|
|
1866
1829
|
@wp.kernel
|
|
1867
|
-
def
|
|
1868
|
-
|
|
1869
|
-
b: wp.array(dtype=wp.mat22),
|
|
1870
|
-
x: wp.array(dtype=wp.vec2),
|
|
1871
|
-
c: wp.array(dtype=wp.mat22),
|
|
1872
|
-
d: wp.array(dtype=wp.mat22),
|
|
1873
|
-
y: wp.array(dtype=wp.vec2),
|
|
1874
|
-
):
|
|
1875
|
-
i = wp.tid()
|
|
1830
|
+
def mat_extract_element(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=float)):
|
|
1831
|
+
tid = wp.tid()
|
|
1876
1832
|
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1833
|
+
a = x[tid]
|
|
1834
|
+
b = a[0, 0] + 2.0 * a[0, 1] + 3.0 * a[1, 0] + 4.0 * a[1, 1]
|
|
1835
|
+
y[tid] = b
|
|
1836
|
+
|
|
1837
|
+
|
|
1838
|
+
@wp.kernel
|
|
1839
|
+
def mat_extract_row(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.vec2)):
|
|
1840
|
+
tid = wp.tid()
|
|
1841
|
+
|
|
1842
|
+
a = x[tid]
|
|
1843
|
+
b = a[0] + 2.0 * a[1]
|
|
1844
|
+
y[tid] = b
|
|
1845
|
+
|
|
1846
|
+
|
|
1847
|
+
def test_mat_extract(test, device):
|
|
1848
|
+
# matrix element
|
|
1849
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
1850
|
+
y = wp.zeros(1, dtype=float, requires_grad=True, device=device)
|
|
1851
|
+
|
|
1852
|
+
tape = wp.Tape()
|
|
1853
|
+
with tape:
|
|
1854
|
+
wp.launch(mat_extract_element, 1, inputs=[x], outputs=[y], device=device)
|
|
1855
|
+
|
|
1856
|
+
y.grad = wp.ones_like(y)
|
|
1857
|
+
tape.backward()
|
|
1858
|
+
|
|
1859
|
+
assert_np_equal(y.numpy(), np.array([10.0], dtype=float))
|
|
1860
|
+
assert_np_equal(x.grad.numpy(), np.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=float))
|
|
1861
|
+
|
|
1862
|
+
# matrix row
|
|
1863
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
1864
|
+
y = wp.zeros(1, dtype=wp.vec2, requires_grad=True, device=device)
|
|
1865
|
+
|
|
1866
|
+
tape = wp.Tape()
|
|
1867
|
+
with tape:
|
|
1868
|
+
wp.launch(mat_extract_row, 1, inputs=[x], outputs=[y], device=device)
|
|
1880
1869
|
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
m1[1, 1] += m2[1, 1]
|
|
1870
|
+
y.grad = wp.ones_like(y)
|
|
1871
|
+
tape.backward()
|
|
1884
1872
|
|
|
1885
|
-
|
|
1873
|
+
assert_np_equal(y.numpy(), np.array([[3.0, 3.0]], dtype=float))
|
|
1874
|
+
assert_np_equal(x.grad.numpy(), np.array([[[1.0, 1.0], [2.0, 2.0]]], dtype=float))
|
|
1886
1875
|
|
|
1887
|
-
m3 = wp.mat22()
|
|
1888
|
-
m4 = d[i]
|
|
1889
|
-
v4 = y[i]
|
|
1890
1876
|
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1877
|
+
@wp.kernel
|
|
1878
|
+
def mat_assign_element(x: wp.array(dtype=float), y: wp.array(dtype=wp.mat22)):
|
|
1879
|
+
i = wp.tid()
|
|
1894
1880
|
|
|
1895
|
-
|
|
1881
|
+
a = wp.mat22()
|
|
1882
|
+
a[0, 0] = 1.0 * x[i]
|
|
1883
|
+
a[0, 1] = 2.0 * x[i]
|
|
1884
|
+
a[1, 0] = 3.0 * x[i]
|
|
1885
|
+
a[1, 1] = 4.0 * x[i]
|
|
1896
1886
|
|
|
1887
|
+
y[i] = a
|
|
1897
1888
|
|
|
1898
|
-
def test_matrix_augassign(test, device):
|
|
1899
|
-
N = 1
|
|
1900
1889
|
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1890
|
+
@wp.kernel
|
|
1891
|
+
def mat_assign_row(x: wp.array(dtype=wp.vec2), y: wp.array(dtype=wp.mat22)):
|
|
1892
|
+
i = wp.tid()
|
|
1893
|
+
|
|
1894
|
+
a = wp.mat22()
|
|
1895
|
+
a[0] = 1.0 * x[i]
|
|
1896
|
+
a[1] = 2.0 * x[i]
|
|
1897
|
+
|
|
1898
|
+
y[i] = a
|
|
1904
1899
|
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1900
|
+
|
|
1901
|
+
def test_mat_assign(test, device):
|
|
1902
|
+
# matrix element
|
|
1903
|
+
x = wp.ones(1, dtype=float, requires_grad=True, device=device)
|
|
1904
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
1908
1905
|
|
|
1909
1906
|
tape = wp.Tape()
|
|
1910
1907
|
with tape:
|
|
1911
|
-
wp.launch(
|
|
1908
|
+
wp.launch(mat_assign_element, 1, inputs=[x], outputs=[y], device=device)
|
|
1912
1909
|
|
|
1913
|
-
|
|
1910
|
+
y.grad = wp.ones_like(y)
|
|
1911
|
+
tape.backward()
|
|
1914
1912
|
|
|
1915
|
-
assert_np_equal(
|
|
1916
|
-
assert_np_equal(
|
|
1917
|
-
assert_np_equal(b.grad.numpy(), np.array([[[0, 0], [1, 1]]], dtype=float))
|
|
1918
|
-
assert_np_equal(x.grad.numpy(), np.array([[1, 1]], dtype=float))
|
|
1913
|
+
assert_np_equal(y.numpy(), np.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=float))
|
|
1914
|
+
assert_np_equal(x.grad.numpy(), np.array([10.0], dtype=float))
|
|
1919
1915
|
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1916
|
+
# matrix row
|
|
1917
|
+
x = wp.ones(1, dtype=wp.vec2, requires_grad=True, device=device)
|
|
1918
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
1919
|
+
|
|
1920
|
+
tape = wp.Tape()
|
|
1921
|
+
with tape:
|
|
1922
|
+
wp.launch(mat_assign_row, 1, inputs=[x], outputs=[y], device=device)
|
|
1923
|
+
|
|
1924
|
+
y.grad = wp.ones_like(y)
|
|
1925
|
+
tape.backward()
|
|
1926
|
+
|
|
1927
|
+
assert_np_equal(y.numpy(), np.array([[[1.0, 1.0], [2.0, 2.0]]], dtype=float))
|
|
1928
|
+
assert_np_equal(x.grad.numpy(), np.array([[3.0, 3.0]], dtype=float))
|
|
1924
1929
|
|
|
1925
1930
|
|
|
1926
1931
|
def test_matrix_assign_copy(test, device):
|
|
@@ -1953,6 +1958,260 @@ def test_matrix_assign_copy(test, device):
|
|
|
1953
1958
|
wp.config.enable_vector_component_overwrites = saved_enable_vector_component_overwrites_setting
|
|
1954
1959
|
|
|
1955
1960
|
|
|
1961
|
+
@wp.kernel
|
|
1962
|
+
def mat_array_extract_element(x: wp.array2d(dtype=wp.mat22), y: wp.array2d(dtype=float)):
|
|
1963
|
+
i, j = wp.tid()
|
|
1964
|
+
a = x[i, j][0, 0]
|
|
1965
|
+
b = x[i, j][0, 1]
|
|
1966
|
+
c = x[i, j][1, 0]
|
|
1967
|
+
d = x[i, j][1, 1]
|
|
1968
|
+
y[i, j] = 1.0 * a + 2.0 * b + 3.0 * c + 4.0 * d
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
@wp.kernel
|
|
1972
|
+
def mat_array_extract_row(x: wp.array2d(dtype=wp.mat22), y: wp.array2d(dtype=wp.vec2)):
|
|
1973
|
+
i, j = wp.tid()
|
|
1974
|
+
a = x[i, j][0]
|
|
1975
|
+
b = x[i, j][1]
|
|
1976
|
+
y[i, j] = 1.0 * a + 2.0 * b
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
def test_mat_array_extract(test, device):
|
|
1980
|
+
# matrix element
|
|
1981
|
+
x = wp.ones((1, 1), dtype=wp.mat22, requires_grad=True, device=device)
|
|
1982
|
+
y = wp.zeros((1, 1), dtype=float, requires_grad=True, device=device)
|
|
1983
|
+
|
|
1984
|
+
tape = wp.Tape()
|
|
1985
|
+
with tape:
|
|
1986
|
+
wp.launch(mat_array_extract_element, (1, 1), inputs=[x], outputs=[y], device=device)
|
|
1987
|
+
|
|
1988
|
+
y.grad = wp.ones_like(y)
|
|
1989
|
+
tape.backward()
|
|
1990
|
+
|
|
1991
|
+
assert_np_equal(y.numpy(), np.array([[10.0]], dtype=float))
|
|
1992
|
+
assert_np_equal(x.grad.numpy(), np.array([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=float))
|
|
1993
|
+
|
|
1994
|
+
# matrix row
|
|
1995
|
+
x = wp.ones((1, 1), dtype=wp.mat22, requires_grad=True, device=device)
|
|
1996
|
+
y = wp.zeros((1, 1), dtype=wp.vec2, requires_grad=True, device=device)
|
|
1997
|
+
|
|
1998
|
+
tape = wp.Tape()
|
|
1999
|
+
with tape:
|
|
2000
|
+
wp.launch(mat_array_extract_row, (1, 1), inputs=[x], outputs=[y], device=device)
|
|
2001
|
+
|
|
2002
|
+
y.grad = wp.ones_like(y)
|
|
2003
|
+
tape.backward()
|
|
2004
|
+
|
|
2005
|
+
assert_np_equal(y.numpy(), np.array([[[3.0, 3.0]]], dtype=float))
|
|
2006
|
+
assert_np_equal(x.grad.numpy(), np.array([[[[1.0, 1.0], [2.0, 2.0]]]], dtype=float))
|
|
2007
|
+
|
|
2008
|
+
|
|
2009
|
+
""" TODO: gradient propagation for in-place array assignment
|
|
2010
|
+
@wp.kernel
|
|
2011
|
+
def mat_array_assign_element(x: wp.array2d(dtype=float), y: wp.array2d(dtype=wp.mat22)):
|
|
2012
|
+
i, j = wp.tid()
|
|
2013
|
+
|
|
2014
|
+
y[i, j][0, 0] = 1.0 * x[i, j]
|
|
2015
|
+
y[i, j][0, 1] = 2.0 * x[i, j]
|
|
2016
|
+
y[i, j][1, 0] = 3.0 * x[i, j]
|
|
2017
|
+
y[i, j][1, 1] = 4.0 * x[i, j]
|
|
2018
|
+
|
|
2019
|
+
|
|
2020
|
+
@wp.kernel
|
|
2021
|
+
def mat_array_assign_row(x: wp.array2d(dtype=wp.vec3), y: wp.array2d(dtype=wp.mat(shape=(2, 3), dtype=float))):
|
|
2022
|
+
i, j = wp.tid()
|
|
2023
|
+
|
|
2024
|
+
y[i, j][0] = 1.0 * x[i, j]
|
|
2025
|
+
y[i, j][1] = 2.0 * x[i, j]
|
|
2026
|
+
|
|
2027
|
+
|
|
2028
|
+
def test_mat_array_assign(test, device):
|
|
2029
|
+
# matrix element
|
|
2030
|
+
x = wp.ones((1, 1), dtype=float, requires_grad=True, device=device)
|
|
2031
|
+
y = wp.zeros((1, 1), dtype=wp.mat22, requires_grad=True, device=device)
|
|
2032
|
+
|
|
2033
|
+
tape = wp.Tape()
|
|
2034
|
+
with tape:
|
|
2035
|
+
wp.launch(mat_array_assign_element, (1, 1), inputs=[x], outputs=[y], device=device)
|
|
2036
|
+
|
|
2037
|
+
y.grad = wp.ones_like(y)
|
|
2038
|
+
tape.backward()
|
|
2039
|
+
|
|
2040
|
+
assert_np_equal(y.numpy(), np.array([[[[1.0, 2.0], [3.0, 4.0]]]], dtype=float))
|
|
2041
|
+
assert_np_equal(x.grad.numpy(), np.array([[10.0]], dtype=float))
|
|
2042
|
+
|
|
2043
|
+
# matrix row
|
|
2044
|
+
x = wp.ones((1, 1), dtype=wp.vec3, requires_grad=True, device=device)
|
|
2045
|
+
y = wp.zeros((1, 1), dtype=wp.mat(shape=(2, 3), dtype=float), requires_grad=True, device=device)
|
|
2046
|
+
|
|
2047
|
+
tape = wp.Tape()
|
|
2048
|
+
with tape:
|
|
2049
|
+
wp.launch(mat_array_assign_row, (1, 1), inputs=[x], outputs=[y], device=device)
|
|
2050
|
+
|
|
2051
|
+
y.grad = wp.ones_like(y)
|
|
2052
|
+
tape.backward()
|
|
2053
|
+
|
|
2054
|
+
assert_np_equal(y.numpy(), np.array([[[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]]]], dtype=float))
|
|
2055
|
+
assert_np_equal(x.grad.numpy(), np.array([[[3.0, 3.0, 3.0]]], dtype=float))
|
|
2056
|
+
"""
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
@wp.kernel
|
|
2060
|
+
def mat_add_inplace_element(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.mat22)):
|
|
2061
|
+
i = wp.tid()
|
|
2062
|
+
|
|
2063
|
+
a = wp.mat22()
|
|
2064
|
+
b = x[i]
|
|
2065
|
+
|
|
2066
|
+
a[0, 0] += 1.0 * b[0, 0]
|
|
2067
|
+
a[0, 1] += 2.0 * b[0, 1]
|
|
2068
|
+
a[1, 0] += 3.0 * b[1, 0]
|
|
2069
|
+
a[1, 1] += 4.0 * b[1, 1]
|
|
2070
|
+
|
|
2071
|
+
y[i] = a
|
|
2072
|
+
|
|
2073
|
+
|
|
2074
|
+
@wp.kernel
|
|
2075
|
+
def mat_add_inplace_row(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.mat22)):
|
|
2076
|
+
i = wp.tid()
|
|
2077
|
+
|
|
2078
|
+
a = wp.mat22()
|
|
2079
|
+
b = x[i]
|
|
2080
|
+
|
|
2081
|
+
a[0] += 1.0 * b[0]
|
|
2082
|
+
a[1] += 2.0 * b[1]
|
|
2083
|
+
|
|
2084
|
+
y[i] = a
|
|
2085
|
+
|
|
2086
|
+
|
|
2087
|
+
def test_mat_add_inplace(test, device):
|
|
2088
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2089
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2090
|
+
|
|
2091
|
+
tape = wp.Tape()
|
|
2092
|
+
with tape:
|
|
2093
|
+
wp.launch(mat_add_inplace_element, 1, inputs=[x], outputs=[y], device=device)
|
|
2094
|
+
|
|
2095
|
+
y.grad = wp.ones_like(y)
|
|
2096
|
+
tape.backward()
|
|
2097
|
+
|
|
2098
|
+
assert_np_equal(y.numpy(), np.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=float))
|
|
2099
|
+
assert_np_equal(x.grad.numpy(), np.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=float))
|
|
2100
|
+
|
|
2101
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2102
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2103
|
+
|
|
2104
|
+
tape = wp.Tape()
|
|
2105
|
+
with tape:
|
|
2106
|
+
wp.launch(mat_add_inplace_row, 1, inputs=[x], outputs=[y], device=device)
|
|
2107
|
+
|
|
2108
|
+
y.grad = wp.ones_like(y)
|
|
2109
|
+
tape.backward()
|
|
2110
|
+
|
|
2111
|
+
assert_np_equal(y.numpy(), np.array([[[1.0, 1.0], [2.0, 2.0]]], dtype=float))
|
|
2112
|
+
assert_np_equal(x.grad.numpy(), np.array([[[1.0, 1.0], [2.0, 2.0]]], dtype=float))
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
@wp.kernel
|
|
2116
|
+
def mat_sub_inplace_element(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.mat22)):
|
|
2117
|
+
i = wp.tid()
|
|
2118
|
+
|
|
2119
|
+
a = wp.mat22()
|
|
2120
|
+
b = x[i]
|
|
2121
|
+
|
|
2122
|
+
a[0, 0] -= 1.0 * b[0, 0]
|
|
2123
|
+
a[0, 1] -= 2.0 * b[0, 1]
|
|
2124
|
+
a[1, 0] -= 3.0 * b[1, 0]
|
|
2125
|
+
a[1, 1] -= 4.0 * b[1, 1]
|
|
2126
|
+
|
|
2127
|
+
y[i] = a
|
|
2128
|
+
|
|
2129
|
+
|
|
2130
|
+
@wp.kernel
|
|
2131
|
+
def mat_sub_inplace_row(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.mat22)):
|
|
2132
|
+
i = wp.tid()
|
|
2133
|
+
|
|
2134
|
+
a = wp.mat22()
|
|
2135
|
+
b = x[i]
|
|
2136
|
+
|
|
2137
|
+
a[0] -= 1.0 * b[0]
|
|
2138
|
+
a[1] -= 2.0 * b[1]
|
|
2139
|
+
|
|
2140
|
+
y[i] = a
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
def test_mat_sub_inplace(test, device):
|
|
2144
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2145
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2146
|
+
|
|
2147
|
+
tape = wp.Tape()
|
|
2148
|
+
with tape:
|
|
2149
|
+
wp.launch(mat_sub_inplace_element, 1, inputs=[x], outputs=[y], device=device)
|
|
2150
|
+
|
|
2151
|
+
y.grad = wp.ones_like(y)
|
|
2152
|
+
tape.backward()
|
|
2153
|
+
|
|
2154
|
+
assert_np_equal(y.numpy(), np.array([[[-1.0, -2.0], [-3.0, -4.0]]], dtype=float))
|
|
2155
|
+
assert_np_equal(x.grad.numpy(), np.array([[[-1.0, -2.0], [-3.0, -4.0]]], dtype=float))
|
|
2156
|
+
|
|
2157
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2158
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2159
|
+
|
|
2160
|
+
tape = wp.Tape()
|
|
2161
|
+
with tape:
|
|
2162
|
+
wp.launch(mat_sub_inplace_row, 1, inputs=[x], outputs=[y], device=device)
|
|
2163
|
+
|
|
2164
|
+
y.grad = wp.ones_like(y)
|
|
2165
|
+
tape.backward()
|
|
2166
|
+
|
|
2167
|
+
assert_np_equal(y.numpy(), np.array([[[-1.0, -1.0], [-2.0, -2.0]]], dtype=float))
|
|
2168
|
+
assert_np_equal(x.grad.numpy(), np.array([[[-1.0, -1.0], [-2.0, -2.0]]], dtype=float))
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
@wp.kernel
|
|
2172
|
+
def mat_array_add_inplace(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.mat22)):
|
|
2173
|
+
i = wp.tid()
|
|
2174
|
+
|
|
2175
|
+
y[i] += x[i]
|
|
2176
|
+
|
|
2177
|
+
|
|
2178
|
+
def test_mat_array_add_inplace(test, device):
|
|
2179
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2180
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2181
|
+
|
|
2182
|
+
tape = wp.Tape()
|
|
2183
|
+
with tape:
|
|
2184
|
+
wp.launch(mat_array_add_inplace, 1, inputs=[x], outputs=[y], device=device)
|
|
2185
|
+
|
|
2186
|
+
y.grad = wp.ones_like(y)
|
|
2187
|
+
tape.backward()
|
|
2188
|
+
|
|
2189
|
+
assert_np_equal(y.numpy(), np.array([[[1.0, 1.0], [1.0, 1.0]]], dtype=float))
|
|
2190
|
+
assert_np_equal(x.grad.numpy(), np.array([[[1.0, 1.0], [1.0, 1.0]]], dtype=float))
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
@wp.kernel
|
|
2194
|
+
def mat_array_sub_inplace(x: wp.array(dtype=wp.mat22), y: wp.array(dtype=wp.mat22)):
|
|
2195
|
+
i = wp.tid()
|
|
2196
|
+
|
|
2197
|
+
y[i] -= x[i]
|
|
2198
|
+
|
|
2199
|
+
|
|
2200
|
+
def test_mat_array_sub_inplace(test, device):
|
|
2201
|
+
x = wp.ones(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2202
|
+
y = wp.zeros(1, dtype=wp.mat22, requires_grad=True, device=device)
|
|
2203
|
+
|
|
2204
|
+
tape = wp.Tape()
|
|
2205
|
+
with tape:
|
|
2206
|
+
wp.launch(mat_array_sub_inplace, 1, inputs=[x], outputs=[y], device=device)
|
|
2207
|
+
|
|
2208
|
+
y.grad = wp.ones_like(y)
|
|
2209
|
+
tape.backward()
|
|
2210
|
+
|
|
2211
|
+
assert_np_equal(y.numpy(), np.array([[[-1.0, -1.0], [-1.0, -1.0]]], dtype=float))
|
|
2212
|
+
assert_np_equal(x.grad.numpy(), np.array([[[-1.0, -1.0], [-1.0, -1.0]]], dtype=float))
|
|
2213
|
+
|
|
2214
|
+
|
|
1956
2215
|
devices = get_test_devices()
|
|
1957
2216
|
|
|
1958
2217
|
|
|
@@ -2010,6 +2269,12 @@ for dtype in np_signed_int_types + np_float_types:
|
|
|
2010
2269
|
TestMat, f"test_matmul_{dtype.__name__}", test_matmul, devices=devices, dtype=dtype
|
|
2011
2270
|
)
|
|
2012
2271
|
|
|
2272
|
+
add_function_test(
|
|
2273
|
+
TestMat,
|
|
2274
|
+
"test_shape_mismatch",
|
|
2275
|
+
test_shape_mismatch,
|
|
2276
|
+
devices=devices,
|
|
2277
|
+
)
|
|
2013
2278
|
add_function_test(
|
|
2014
2279
|
TestMat,
|
|
2015
2280
|
"test_anon_constructor_error_shape_arg_missing",
|
|
@@ -2073,16 +2338,18 @@ for dtype in np_float_types:
|
|
|
2073
2338
|
TestMat, f"test_determinant_{dtype.__name__}", test_determinant, devices=devices, dtype=dtype
|
|
2074
2339
|
)
|
|
2075
2340
|
add_function_test_register_kernel(TestMat, f"test_skew_{dtype.__name__}", test_skew, devices=devices, dtype=dtype)
|
|
2076
|
-
|
|
2077
|
-
TestMat,
|
|
2078
|
-
f"test_matrix_assign_inplace_{dtype.__name__}",
|
|
2079
|
-
test_matrix_assign_inplace,
|
|
2080
|
-
devices=devices,
|
|
2081
|
-
dtype=dtype,
|
|
2082
|
-
)
|
|
2341
|
+
|
|
2083
2342
|
add_function_test(TestMat, "test_matrix_len", test_matrix_len, devices=devices)
|
|
2084
|
-
add_function_test(TestMat, "
|
|
2343
|
+
add_function_test(TestMat, "test_mat_extract", test_mat_extract, devices=devices)
|
|
2344
|
+
add_function_test(TestMat, "test_mat_assign", test_mat_assign, devices=devices)
|
|
2085
2345
|
add_function_test(TestMat, "test_matrix_assign_copy", test_matrix_assign_copy, devices=devices)
|
|
2346
|
+
add_function_test(TestMat, "test_mat_array_extract", test_mat_array_extract, devices=devices)
|
|
2347
|
+
# add_function_test(TestMat, "test_mat_array_assign", test_mat_array_assign, devices=devices)
|
|
2348
|
+
add_function_test(TestMat, "test_mat_add_inplace", test_mat_add_inplace, devices=devices)
|
|
2349
|
+
add_function_test(TestMat, "test_mat_sub_inplace", test_mat_sub_inplace, devices=devices)
|
|
2350
|
+
add_function_test(TestMat, "test_mat_array_add_inplace", test_mat_array_add_inplace, devices=devices)
|
|
2351
|
+
add_function_test(TestMat, "test_mat_array_sub_inplace", test_mat_array_sub_inplace, devices=devices)
|
|
2352
|
+
|
|
2086
2353
|
|
|
2087
2354
|
if __name__ == "__main__":
|
|
2088
2355
|
wp.clear_kernel_cache()
|