MCPcopy
hub / github.com/google-deepmind/graph_nets / map

Method map

graph_nets/graphs.py:178–195  ·  view source on GitHub ↗

Applies `field_fn` to the fields `fields` of the instance. `field_fn` is applied exactly once per field in `fields`. The result must satisfy the `GraphsTuple` requirement w.r.t. `None` fields, i.e. the `SENDERS` cannot be `None` if the `EDGES` or `RECEIVERS` are not `None`, etc.

(self, field_fn, fields=GRAPH_FEATURE_FIELDS)

Source from the content-addressed store, hash-verified

176 return output
177
178 def map(self, field_fn, fields=GRAPH_FEATURE_FIELDS):
179 """Applies `field_fn` to the fields `fields` of the instance.
180
181 `field_fn` is applied exactly once per field in `fields`. The result must
182 satisfy the `GraphsTuple` requirement w.r.t. `None` fields, i.e. the
183 `SENDERS` cannot be `None` if the `EDGES` or `RECEIVERS` are not `None`,
184 etc.
185
186 Args:
187 field_fn: A callable that take a single argument.
188 fields: (iterable of `str`). An iterable of the fields to apply
189 `field_fn` to.
190
191 Returns:
192 A copy of the instance, with the fields in `fields` replaced by the result
193 of applying `field_fn` to them.
194 """
195 return self.replace(**{k: field_fn(getattr(self, k)) for k in fields})

Calls 1

replaceMethod · 0.95