Fused ``Blockwise`` expression A ``Fused`` corresponds to the fusion of multiple ``Blockwise`` expressions into a single ``Expr`` object. Before graph-materialization time, the behavior of this object should be identical to that of the first element of ``Fused.exprs`` (i.e. the
| 3741 | |
| 3742 | |
| 3743 | class Fused(Blockwise): |
| 3744 | """Fused ``Blockwise`` expression |
| 3745 | |
| 3746 | A ``Fused`` corresponds to the fusion of multiple |
| 3747 | ``Blockwise`` expressions into a single ``Expr`` object. |
| 3748 | Before graph-materialization time, the behavior of this |
| 3749 | object should be identical to that of the first element |
| 3750 | of ``Fused.exprs`` (i.e. the top-most expression in |
| 3751 | the fused group). |
| 3752 | |
| 3753 | Parameters |
| 3754 | ---------- |
| 3755 | exprs : List[Expr] |
| 3756 | Group of original ``Expr`` objects being fused together. |
| 3757 | *dependencies: |
| 3758 | List of external ``Expr`` dependencies. External-``Expr`` |
| 3759 | dependencies correspond to any ``Expr`` operand that is |
| 3760 | not already included in ``exprs``. Note that these |
| 3761 | dependencies should be defined in the order of the ``Expr`` |
| 3762 | objects that require them (in ``exprs``). These |
| 3763 | dependencies do not include literal operands, because those |
| 3764 | arguments should already be captured in the fused subgraphs. |
| 3765 | """ |
| 3766 | |
| 3767 | _parameters = ["exprs"] |
| 3768 | |
| 3769 | @functools.cached_property |
| 3770 | def _meta(self): |
| 3771 | return self.exprs[0]._meta |
| 3772 | |
| 3773 | def _tree_repr_lines(self, indent=0, recursive=True): |
| 3774 | header = f"Fused({self._name[-5:]}):" |
| 3775 | if not recursive: |
| 3776 | return [header] |
| 3777 | |
| 3778 | seen = set() |
| 3779 | lines = [] |
| 3780 | stack = [(self.exprs[0], 2)] |
| 3781 | fused_group = [_expr._name for _expr in self.exprs] |
| 3782 | dependencies = {dep._name: dep for dep in self.dependencies()} |
| 3783 | while stack: |
| 3784 | expr, _indent = stack.pop() |
| 3785 | |
| 3786 | if expr._name in seen: |
| 3787 | continue |
| 3788 | seen.add(expr._name) |
| 3789 | |
| 3790 | line = expr._tree_repr_lines(_indent, recursive=False)[0] |
| 3791 | lines.append(line.replace(" ", "|", 1)) |
| 3792 | for dep in expr.dependencies(): |
| 3793 | if dep._name in fused_group: |
| 3794 | stack.append((dep, _indent + 2)) |
| 3795 | elif dep._name in dependencies: |
| 3796 | dependencies.pop(dep._name) |
| 3797 | lines.extend(dep._tree_repr_lines(_indent + 2)) |
| 3798 | |
| 3799 | for dep in dependencies.values(): |
| 3800 | lines.extend(dep._tree_repr_lines(2)) |