-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add specification for computing the dot product (linalg: vecdot) #137
Conversation
@kgryte could you add batching vs tensor-product for leading axes to this table? or maybe that's what you mean by "Stacks"? |
I think another thing that is missing from the table is the behavior when the inputs have mixed dimensionality, e.g., 1D x 2D. |
@shoyer Correct. In the table, |
Following @leofang's suggestion, I've renamed the API to |
I wonder if
|
I like this. There's also a precedent for the "vec" part, |
I've renamed the proposed API to |
0607525
to
138e963
Compare
This PR has been open for some time without further comment and resolves issues discussed above. Will merge and we can submit follow-up PRs should any further issues/concerns arise. |
This PR
adds the specification for computing the dot product.
currently deviates from current behavior across array libraries. Follows more closely to NumPy's
inner
.comparisons for API signatures can be found here.
attempts to eliminate overloaded behavior found in the NumPy API. Namely, when
x1
andx2
are 1D: NumPy computes the dot product.x1
andx2
are mixed 1D and ND: NumPy operates on the stack, computing the dot product over the last axis.x1
andx2
are 2D: NumPy performs matrix multiplication.x1
andx2
are ND: NumPy performs a tensor contraction using the second-to-last and the last axes, respectively.This proposal seeks to limit computation to strictly the dot product and limit to a single axis for >1D.
adds
axis
keyword to specify dimension over which to compute the dot product. (Note: this is similar to MATLAB's dot).renames the API as
vecdot
to avoid user confusion regarding expected behavior when transitioning from, e.g.,np.dot
to usingvecdot
.Background
Overview of the various NumPy APIs for computing the dot product:
1 can specify arbitrary axes for tensor contraction as a tuple of sequences.
2 can specify an arbitrary axis for computing a sum.
Notes
NumPy et al perform different quantities (dot product vs matrix multiplication) depending on the input argument shapes. This stems, at least in part, from legacy concerns dating prior to the introduction of
matmul
.Pytorch limits computation to 1D vectors. From their docs (latest
master
):For reference, Julia limits computing the dot product over vectors. Extension to multi-dimensional arrays is supported so long as the dot product operation is defined on the elements. BLAS routines for computing the dot product are limited to strided vectors, with complex conjugation for complex dtypes.
Other Considerations
vdot
).axis
keyword argument is supported, then, similar to statistical reduction APIs (mean
,max
,min
), we could consider supporting akeepdims
keyword argument to retain the reduced dimension.