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
2 changes: 1 addition & 1 deletion dm_control/mujoco/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def convert_key_item(self, key_item):
key_item = np.array([self._names_to_offsets[util.to_native_string(k)]
for k in key_item.flat])
# Ensure the output shape is the same as that of the input.
key_item.shape = original_shape
key_item = key_item.reshape(original_shape)

return key_item

Expand Down
13 changes: 11 additions & 2 deletions dm_control/mujoco/index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def assertIndexExpressionEqual(self, expected, actual):
self.fail('Indexing expressions are not equal.\n'
'expected: {!r}\nactual: {!r}'.format(expected, actual))

def testRegularNamedAxisPreservesMultidimensionalShape(self):
axis = index.RegularNamedAxis(['first', 'second'])
key = np.array([['second'], ['first']])

converted = axis.convert_key_item(key)

np.testing.assert_array_equal(converted, [[1], [0]])
self.assertEqual(converted.shape, key.shape)

@parameterized.parameters(
# (field name, named index key, expected integer index key)
('actuator_gear', 'slide', 0),
Expand Down Expand Up @@ -347,8 +356,8 @@ def testReadWrite_(self, field):
# Write unique values to the FieldIndexer and read them back again.
# Don't write to non-float fields since these might contain pointers.
if np.issubdtype(old_contents.dtype, np.floating):
new_contents = np.arange(old_contents.size, dtype=old_contents.dtype)
new_contents.shape = old_contents.shape
new_contents = np.arange(
old_contents.size, dtype=old_contents.dtype).reshape(old_contents.shape)
field[:] = new_contents
np.testing.assert_array_equal(new_contents, field[:])

Expand Down