Skip to content

Feature request: signal broadcasting is OK over core dimension #8811

@mhvk

Description

@mhvk

EDITS:

Rationale

Before numpy 1.10, there was automatic broadcasting over core dimensions in gufunc. While this is not necessarily good for many things (e.g., np.inner1d in the example in the documentation), it is for others, such as the all_equal implementation in #8528. It would be nice if the signature allowed one to make this distinction.

Wishlist beyond broadcasting

  • Multiple related signatures, such as for matmul: (i,k),(k,j)->(i,j), (i,j),(i)=(i,j),(i,1)->(i,j), (i),(i,j)=(1,i),(i,j)->(i,j)
  • Possibly having the output signature be calculated from the input dimensions (min(i,j))

Possible implementations

Noting that signature has to be a single char to remain compatible with the API:

  • Adjust the interpretation of dimensions, e.g., (i|1), (i|1)->() or (i?), (i?)->() (Add an axis argument to generalized ufuncs? #5197) might convey what is needed for all_equal (easy to do with setting relevant strides to 0)
  • Allow multiple signatures; e.g., (i),(i)->(); (i),()->(); (),(i)->(); (),()->(). This would likely make the most sense for things like matmul, but would seem to imply different functions for each signature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions