Returns new _Mapping with args merged with self. Args: x: `Tensor`. Forward. y: `Tensor`. Inverse. ildj_map: `Dictionary`. This is a mapping from event_ndims to a `Tensor` representing the inverse log det jacobian. kwargs: Python dictionary. Extra args supplied t
(self, x=None, y=None, ildj_map=None, kwargs=None, mapping=None)
| 75 | self._deep_tuple(tuple(sorted(self.kwargs.items())))) |
| 76 | |
| 77 | def merge(self, x=None, y=None, ildj_map=None, kwargs=None, mapping=None): |
| 78 | """Returns new _Mapping with args merged with self. |
| 79 | |
| 80 | Args: |
| 81 | x: `Tensor`. Forward. |
| 82 | y: `Tensor`. Inverse. |
| 83 | ildj_map: `Dictionary`. This is a mapping from event_ndims to a `Tensor` |
| 84 | representing the inverse log det jacobian. |
| 85 | kwargs: Python dictionary. Extra args supplied to |
| 86 | forward/inverse/etc functions. |
| 87 | mapping: Instance of _Mapping to merge. Can only be specified if no other |
| 88 | arg is specified. |
| 89 | |
| 90 | Returns: |
| 91 | mapping: New instance of `_Mapping` which has inputs merged with self. |
| 92 | |
| 93 | Raises: |
| 94 | ValueError: if mapping and any other arg is not `None`. |
| 95 | """ |
| 96 | if mapping is None: |
| 97 | mapping = _Mapping(x=x, y=y, ildj_map=ildj_map, kwargs=kwargs) |
| 98 | elif any(arg is not None for arg in [x, y, ildj_map, kwargs]): |
| 99 | raise ValueError("Cannot simultaneously specify mapping and individual " |
| 100 | "arguments.") |
| 101 | |
| 102 | return _Mapping( |
| 103 | x=self._merge(self.x, mapping.x), |
| 104 | y=self._merge(self.y, mapping.y), |
| 105 | ildj_map=self._merge_dicts(self.ildj_map, mapping.ildj_map), |
| 106 | kwargs=self._merge(self.kwargs, mapping.kwargs)) |
| 107 | |
| 108 | def _merge_dicts(self, old=None, new=None): |
| 109 | """Helper to merge two dictionaries.""" |
no test coverage detected