Skip to content

treex.Merge

Mixin that adds a .merge() method to the class.

Source code in treeo/mixins.py
class Merge:
    """
    Mixin that adds a `.merge()` method to the class.
    """

    def merge(
        self: A,
        other: A,
        *rest: A,
        inplace: bool = False,
        flatten_mode: tp.Union[api.FlattenMode, str, None] = None,
        ignore_static: bool = False,
    ) -> A:
        """
        `merge` is a wrapper over `treeo.merge` that passes `self` as the first argument.

        Arguments:
            other: The pytree first to get the values to merge with.
            *rest: Additional pytree to perform the merge in order from left to right.
            inplace: If `True`, the input `obj` is mutated and returned.
            flatten_mode: Sets a new `FlattenMode` context for the operation, if `None` the current context is used. If the current flatten context is `None` and `flatten_mode` is not passed then `FlattenMode.all_fields` is used.
            ignore_static: If `True`, bypasses static fields during the process and the statics fields for output are taken from the first input (`obj`).

        Returns:
            A new pytree with the merged values. If `inplace` is `True`, `obj` is returned.
        """
        return api.merge(
            self,
            other,
            *rest,
            inplace=inplace,
            flatten_mode=flatten_mode,
            ignore_static=ignore_static,
        )

merge(self, other, *rest, *, inplace=False, flatten_mode=None, ignore_static=False)

merge is a wrapper over treeo.merge that passes self as the first argument.

Parameters:

Name Type Description Default
other ~A

The pytree first to get the values to merge with.

required
*rest ~A

Additional pytree to perform the merge in order from left to right.

()
inplace bool

If True, the input obj is mutated and returned.

False
flatten_mode Union[treeo.tree.FlattenMode, str]

Sets a new FlattenMode context for the operation, if None the current context is used. If the current flatten context is None and flatten_mode is not passed then FlattenMode.all_fields is used.

None
ignore_static bool

If True, bypasses static fields during the process and the statics fields for output are taken from the first input (obj).

False

Returns:

Type Description
~A

A new pytree with the merged values. If inplace is True, obj is returned.

Source code in treeo/mixins.py
def merge(
    self: A,
    other: A,
    *rest: A,
    inplace: bool = False,
    flatten_mode: tp.Union[api.FlattenMode, str, None] = None,
    ignore_static: bool = False,
) -> A:
    """
    `merge` is a wrapper over `treeo.merge` that passes `self` as the first argument.

    Arguments:
        other: The pytree first to get the values to merge with.
        *rest: Additional pytree to perform the merge in order from left to right.
        inplace: If `True`, the input `obj` is mutated and returned.
        flatten_mode: Sets a new `FlattenMode` context for the operation, if `None` the current context is used. If the current flatten context is `None` and `flatten_mode` is not passed then `FlattenMode.all_fields` is used.
        ignore_static: If `True`, bypasses static fields during the process and the statics fields for output are taken from the first input (`obj`).

    Returns:
        A new pytree with the merged values. If `inplace` is `True`, `obj` is returned.
    """
    return api.merge(
        self,
        other,
        *rest,
        inplace=inplace,
        flatten_mode=flatten_mode,
        ignore_static=ignore_static,
    )