Skip to content

Commit 8eb70f8

Browse files
Leonard Hasenclevercopybara-github
authored andcommitted
Add ability to set references with numpy unicode strings. This allows us directly to use distributions.UniformChoice(material_names) to randomize over materials of a geom.
PiperOrigin-RevId: 690640836 Change-Id: I140fa86b22d5a0571fc8777f6c222dceddecaf81
1 parent e3f93b0 commit 8eb70f8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

dm_control/mjcf/attribute.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ def reference_namespace(self):
317317
return self._reference_namespace
318318

319319
def _assign(self, value):
320-
if not isinstance(value, (base.Element, str)):
320+
if not isinstance(value, (base.Element, str)) and not (
321+
isinstance(value, np.ndarray) and value.dtype.kind == 'U'
322+
):
321323
raise ValueError(
322324
'Expect a string or `mjcf.Element` value: got {}'.format(value))
323325
elif not value:
@@ -330,6 +332,8 @@ def _assign(self, value):
330332
raise ValueError(_INVALID_REFERENCE_TYPE.format(
331333
valid_type=self.reference_namespace,
332334
actual_type=value_namespace))
335+
elif isinstance(value, np.ndarray):
336+
value = value.item()
333337
self._value = value
334338

335339
def _before_clear(self):

0 commit comments

Comments
 (0)