8000 ENH: Use `syrk` to compute certain dot products more quickly and accurately by jakirkham · Pull Request #6932 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Use syrk to compute certain dot products more quickly and accurately #6932

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

Merged
merged 4 commits into from
Jan 6, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Use the helper function syrk to compute dot more quickly and…
… accurately in certain special cases.
  • Loading branch information
jakirkham committed Jan 6, 2016
commit 924e08f8eabe0aafb77d6c3ce435e2a6cf2df2e6
29 changes: 28 additions & 1 deletion numpy/core/src/multiarray/cblasfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,34 @@ cblas_matrixproduct(int typenum, PyArrayObject *ap1, PyArrayObject *ap2,
Trans2 = CblasTrans;
ldb = (PyArray_DIM(ap2, 0) > 1 ? PyArray_DIM(ap2, 0) : 1);
}
gemm(typenum, Order, Trans1, Trans2, L, N, M, ap1, lda, ap2, ldb, ret);

/*
* Use syrk if we have a case of a matrix times its transpose.
* Otherwise, use gemm for all other cases.
*/
if (
(PyArray_BYTES(ap1) == PyArray_BYTES(ap2)) &&
(PyArray_DIM(ap1, 0) == PyArray_DIM(ap2, 1)) &&
(PyArray_DIM(ap1, 1) == PyArray_DIM(ap2, 0)) &&
(PyArray_STRIDE(ap1, 0) == PyArray_STRIDE(ap2, 1)) &&
(PyArray_STRIDE(ap1, 1) == PyArray_STRIDE(ap2, 0)) &&
((Trans1 == CblasTrans) ^ (Trans2 == CblasTrans)) &&
((Trans1 == CblasNoTrans) ^ (Trans2 == CblasNoTrans))
)
{
if (Trans1 == CblasNoTrans)
{
syrk(typenum, Order, Trans1, N, M, ap1, lda, ret);
}
else
{
syrk(typenum, Order, Trans1, N, M, ap2, ldb, ret);
}
}
else
{
gemm(typenum, Order, Trans1, Trans2, L, N, M, ap1, lda, ap2, ldb, ret);
}
NPY_END_ALLOW_THREADS;
}

Expand Down
0