Skip to content

ENH: Break the assumption that all ufuncs and gufuncs want is element-wise loop aliasing #11416

Description

@mattip

The current implementation of both ufuncs and gufuncs (those with core-dimensions and an inner-loop signature) use the NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE flag to prevent allocating buffer memory if it can be determined that:

  • the data pointers of all overlapping operands are equal
  • the strides and dimensions are equivalent
  • the dtypes are equal.
  • solve_may_have_internal_overlap() for single-byte overlap returns `0

Let's call this element-wise aliasing, since it is intended for elementwise ufuncs like np.sin.
For all other cases, output ndarrays will use writeback semantics to allocate temporary memory.

There should be a point in the gufunc call that a gufunc can say "element-wise aliasing is OK", or "leave all aliasing to the inner loop" or "always copy-on-any-overlap". We need a flag to indicate these (and maybe other, like contiguous) strategies. See also PR #11381 (closed) which proposed unilaterally changing the default.

Activity

  1. njsmith commented on Jun 25, 2018

    @njsmith
    Member

    I'm not sure, but my initial impression is that the two relevant cases are: (1) the loop can tolerate some core inputs being identical to some core outputs, (2) the loop can't tolerate overlap at all. For cases where there's partial overlap between core dimensions, or overlap between different loop iterations, then maybe we should unconditionally copy? Are there any other interesting cases?

  2. pv commented on Jun 25, 2018

    @pv
    Member
  3. pv commented on Jun 25, 2018

    @pv
    Member
  4. mattip commented on Dec 1, 2018

    @mattip
    MemberAuthor

    Allowed overriding the ufunc flags in #11580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions