Creates fetch mapper that handles the structure of `fetch`. The default graph must be the one from which we want to fetch values when this function is called. Args: fetch: An arbitrary fetch structure: singleton, list, tuple, namedtuple, or dict. Returns: An in
(fetch)
| 251 | |
| 252 | @staticmethod |
| 253 | def for_fetch(fetch): |
| 254 | """Creates fetch mapper that handles the structure of `fetch`. |
| 255 | |
| 256 | The default graph must be the one from which we want to fetch values when |
| 257 | this function is called. |
| 258 | |
| 259 | Args: |
| 260 | fetch: An arbitrary fetch structure: singleton, list, tuple, namedtuple, |
| 261 | or dict. |
| 262 | |
| 263 | Returns: |
| 264 | An instance of a subclass of `_FetchMapper` that handles the shape. |
| 265 | """ |
| 266 | if fetch is None: |
| 267 | raise TypeError('Fetch argument %r has invalid type %r' % |
| 268 | (fetch, type(fetch))) |
| 269 | elif isinstance(fetch, (list, tuple)): |
| 270 | # NOTE(touts): This is also the code path for namedtuples. |
| 271 | return _ListFetchMapper(fetch) |
| 272 | elif isinstance(fetch, collections_abc.Mapping): |
| 273 | return _DictFetchMapper(fetch) |
| 274 | elif _is_attrs_instance(fetch): |
| 275 | return _AttrsFetchMapper(fetch) |
| 276 | else: |
| 277 | # Look for a handler in the registered expansions. |
| 278 | for tensor_type, fetch_fn, _, _ in _REGISTERED_EXPANSIONS: |
| 279 | if isinstance(fetch, tensor_type): |
| 280 | fetches, contraction_fn = fetch_fn(fetch) |
| 281 | return _ElementFetchMapper(fetches, contraction_fn) |
| 282 | # Did not find anything. |
| 283 | raise TypeError('Fetch argument %r has invalid type %r' % |
| 284 | (fetch, type(fetch))) |
| 285 | |
| 286 | |
| 287 | class _ElementFetchMapper(_FetchMapper): |
no test coverage detected