MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / __getattr__

Method __getattr__

dm_control/mjcf/physics.py:314–354  ·  view source on GitHub ↗
(self, name)

Source from the content-addressed store, hash-verified

312 return element_id
313
314 def __getattr__(self, name):
315 if name in Binding.__slots__:
316 return super().__getattr__(name)
317 else:
318 try:
319 out = self._getattr_cache[name]
320 out._synchronize_from_backing_array() # pylint: disable=protected-access
321 except KeyError:
322 array, index = self._get_cached_array_and_index(name)
323 triggers_dirty = self._attributes[name].triggers_dirty
324
325 # A list of (array, index) tuples specifying other addresses that need
326 # to be zeroed out when this array attribute is written to.
327 disable_on_write = []
328 for name_to_disable in self._attributes[name].disable_on_write:
329 array_to_disable, index_to_disable = self._get_cached_array_and_index(
330 name_to_disable)
331 # Ensure that the result of indexing is a `SynchronizingArrayWrapper`
332 # rather than a scalar, otherwise we won't be able to write into it.
333 if array_to_disable.ndim == 1:
334 if isinstance(index_to_disable, np.ndarray):
335 index_to_disable = index_to_disable.copy().reshape(-1, 1)
336 else:
337 index_to_disable = [index_to_disable]
338 disable_on_write.append((array_to_disable, index_to_disable))
339
340 if self._physics.is_dirty and not triggers_dirty:
341 self._physics.forward()
342 if np.issubdtype(type(index), np.integer) and array.ndim == 1:
343 # Case where indexing results in a scalar.
344 out = array[index]
345 else:
346 # Case where indexing results in an array.
347 out = SynchronizingArrayWrapper(
348 backing_array=array,
349 backing_index=index,
350 physics=self._physics,
351 triggers_dirty=triggers_dirty,
352 disable_on_write=disable_on_write)
353 self._getattr_cache[name] = out
354 return out
355
356 def __setattr__(self, name, value):
357 if name in Binding.__slots__:

Callers

nothing calls this directly

Calls 5

copyMethod · 0.45
forwardMethod · 0.45

Tested by

no test coverage detected