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

Function _get_attributes

dm_control/mjcf/physics.py:63–91  ·  view source on GitHub ↗

Creates a dict of valid attribute from Mujoco array size name.

(size_names, strip_prefixes)

Source from the content-addressed store, hash-verified

61
62
63def _get_attributes(size_names, strip_prefixes):
64 """Creates a dict of valid attribute from Mujoco array size name."""
65 strip_regex = re.compile(r'\A({})_'.format('|'.join(strip_prefixes)))
66 strip = lambda string: strip_regex.sub('', string)
67 out = {}
68 for name, size in sizes.array_sizes['mjdata'].items():
69 if size[0] in size_names:
70 attrib_name = strip(name)
71 named_indexer_getter = (
72 lambda physics, name=name: getattr(physics.named.data, name))
73 triggers_dirty = attrib_name in constants.MJDATA_TRIGGERS_DIRTY
74 out[attrib_name] = _Attribute(
75 name=attrib_name,
76 get_named_indexer=named_indexer_getter,
77 triggers_dirty=triggers_dirty,
78 disable_on_write=())
79 for name, size in sizes.array_sizes['mjmodel'].items():
80 if size[0] in size_names:
81 attrib_name = strip(name)
82 named_indexer_getter = (
83 lambda physics, name=name: getattr(physics.named.model, name))
84 triggers_dirty = attrib_name not in constants.MJMODEL_DOESNT_TRIGGER_DIRTY
85 disable_on_write = constants.MJMODEL_DISABLE_ON_WRITE.get(name, ())
86 out[attrib_name] = _Attribute(
87 name=attrib_name,
88 get_named_indexer=named_indexer_getter,
89 triggers_dirty=triggers_dirty,
90 disable_on_write=disable_on_write)
91 return out
92
93
94_ATTRIBUTES = {

Callers 1

physics.pyFile · 0.85

Calls 3

_AttributeClass · 0.85
itemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…