(size_names, strip_prefixes)
return out
Creates a dict of valid attribute from Mujoco array size name.
Creates a dict of valid attribute from Mujoco array size name.
Creates a dict of valid attribute from Mujoco array size name .
def _get_attributes(size_names, strip_prefixes):
  """Creates a dict of valid attribute from Mujoco array size name."""
  strip_regex = re.compile(r'\A({})_'.format('|'.join(strip_prefixes)))
  strip = lambda string: strip_regex.sub('', string)
  out = {}
  for name, size in sizes.array_sizes['mjdata'].items():
    if size[0] in size_names:
      attrib_name = strip(name)
      named_indexer_getter = (
          lambda physics, name=name: getattr(physics.named.data, name))
      triggers_dirty = attrib_name in constants.MJDATA_TRIGGERS_DIRTY
      out[attrib_name] = _Attribute(
          name=attrib_name,
          get_named_indexer=named_indexer_getter,
          triggers_dirty=triggers_dirty,
          disable_on_write=())
  for name, size in sizes.array_sizes['mjmodel'].items():
    if size[0] in size_names:
      attrib_name = strip(name)
      named_indexer_getter = (
          lambda physics, name=name: getattr(physics.named.model, name))
      triggers_dirty = attrib_name not in constants.MJMODEL_DOESNT_TRIGGER_DIRTY
      disable_on_write = constants.MJMODEL_DISABLE_ON_WRITE.get(name, ())
      out[attrib_name] = _Attribute(
          name=attrib_name,
          get_named_indexer=named_indexer_getter,
          triggers_dirty=triggers_dirty,
          disable_on_write=disable_on_write)
  return out
def _get_attributes ( size_names , strip_prefixes ) : strip_regex = re . compile ( r'\A({})_' . format ( '|' . join ( strip_prefixes ) ) ) strip = lambda string : strip_regex . sub ( '' , string ) out = { } for name , size in sizes . array_sizes [ 'mjdata' ] . items ( ) : if size [ 0 ] in size_names : attrib_name = strip ( name ) named_indexer_getter = ( lambda physics , name = name : getattr ( physics . named . data , name ) ) triggers_dirty = attrib_name in constants . MJDATA_TRIGGERS_DIRTY out [ attrib_name ] = _Attribute ( name = attrib_name , get_named_indexer = named_indexer_getter , triggers_dirty = triggers_dirty , disable_on_write = ( ) ) for name , size in sizes . array_sizes [ 'mjmodel' ] . items ( ) : if size [ 0 ] in size_names : attrib_name = strip ( name ) named_indexer_getter = ( lambda physics , name = name : getattr ( physics . named . model , name ) ) triggers_dirty = attrib_name not in constants . MJMODEL_DOESNT_TRIGGER_DIRTY disable_on_write = constants . MJMODEL_DISABLE_ON_WRITE . get ( name , ( ) ) out [ attrib_name ] = _Attribute ( name = attrib_name , get_named_indexer = named_indexer_getter , triggers_dirty = triggers_dirty , disable_on_write = disable_on_write ) return out