Skip to content

[WIP] Broadcast and Merge library nodes, reachable from NumPy - #2515

Draft
ThrudPrimrose wants to merge 1 commit into
mainfrom
libnode/broadcast-merge
Draft

[WIP] Broadcast and Merge library nodes, reachable from NumPy#2515
ThrudPrimrose wants to merge 1 commit into
mainfrom
libnode/broadcast-merge

Conversation

@ThrudPrimrose

Copy link
Copy Markdown
Collaborator

Adds two standard library nodes -- Broadcast (Fortran SPREAD with an integer dim, the right-aligned NumPy rule with dim=None) and MergeLibraryNode (the per-element select: Fortran MERGE, np.where, element-wise if-then-else) -- both describing every operand by the same broadcasting rule instead of a special case. numpy.where hands the node the case it expresses exactly (three arrays, no cast, a condition that broadcasts into the result) and keeps the inlined tasklet otherwise, and numpy.broadcast_to is new.

@dace.program
def k(a: dace.float64[N, 1], b: dace.float64[N, 4], c: dace.bool_[N, 4]):
    return np.where(c, a, b)     # (N, 1) operand read at column 0 for every column

Broadcast covers Fortran SPREAD (integer dim, insert one axis) and, with dim=None,
the right-aligned NumPy rule; Merge is the per-element select -- Fortran
MERGE(t, f, mask), np.where(mask, t, f), an element-wise if-then-else -- with every
operand broadcast against the result by that same rule.

numpy.where hands the node the case it expresses exactly (three arrays, no cast, a
condition that broadcasts into the result rather than widening it) and keeps the
inlined tasklet otherwise; numpy.broadcast_to is new, and materializes a transient
because NumPy's zero-stride view would make every write to the result alias.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant