Fix setting slices of multidimensional arrays for multiple targets
PiperOrigin-RevId: 758623598 Change-Id: Ie05b36c25be74ddf7451a95377caf1ed1d692141
This commit is contained in:
committed by
Copybara-Service
parent
1165018f71
commit
4ba04586ae
@@ -499,12 +499,13 @@ class BindData(object):
|
|||||||
adr = [adr]
|
adr = [adr]
|
||||||
num = [num]
|
num = [num]
|
||||||
elif isinstance(self.id, list):
|
elif isinstance(self.id, list):
|
||||||
adr = self.id * dim
|
adr = (np.array(self.id) * dim).tolist()
|
||||||
num = [dim for _ in range(len(self.id))]
|
num = [dim for _ in range(len(self.id))]
|
||||||
else:
|
else:
|
||||||
adr = [self.id * dim]
|
adr = [self.id * dim]
|
||||||
num = [dim]
|
num = [dim]
|
||||||
i = 0
|
i = 0
|
||||||
|
value = jax.numpy.array(value).flatten()
|
||||||
for a, n in zip(adr, num):
|
for a, n in zip(adr, num):
|
||||||
shape = array.shape
|
shape = array.shape
|
||||||
array = array.flatten().at[a : a + n].set(value[i : i + n]).reshape(shape)
|
array = array.flatten().at[a : a + n].set(value[i : i + n]).reshape(shape)
|
||||||
|
|||||||
@@ -308,6 +308,16 @@ class SupportTest(parameterized.TestCase):
|
|||||||
np.testing.assert_array_equal(
|
np.testing.assert_array_equal(
|
||||||
dx7.bind(mx, body).xfrc_applied, [0, 0, 0, 0, 0, 0]
|
dx7.bind(mx, body).xfrc_applied, [0, 0, 0, 0, 0, 0]
|
||||||
)
|
)
|
||||||
|
dx10 = dx.bind(mx, s.bodies[0:2]).set(
|
||||||
|
'xfrc_applied',
|
||||||
|
np.array([np.array([1, 1, 1, 1, 1, 1]), np.array([2, 2, 2, 2, 2, 2])]),
|
||||||
|
)
|
||||||
|
np.testing.assert_array_equal(
|
||||||
|
dx10.bind(mx, s.bodies[0]).xfrc_applied, [1, 1, 1, 1, 1, 1]
|
||||||
|
)
|
||||||
|
np.testing.assert_array_equal(
|
||||||
|
dx10.bind(mx, s.bodies[1]).xfrc_applied, [2, 2, 2, 2, 2, 2]
|
||||||
|
)
|
||||||
|
|
||||||
# test attribute and type mismatches
|
# test attribute and type mismatches
|
||||||
with self.assertRaisesRegex(
|
with self.assertRaisesRegex(
|
||||||
|
|||||||
Reference in New Issue
Block a user