Skip to content

Optional out parameter for numpy.dot #33

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

Closed
wants to merge 15 commits into from
Closed

Optional out parameter for numpy.dot #33

wants to merge 15 commits into from

Conversation

luispedro
Copy link
Contributor

This adds an optional output argument for np.dot, for extra performance (I measured a significant different for very large matrices).

I had submitted this before, but there were a few suggestions for improvement. Iimplemented some, pv helped a lot and wrote some code too; all of the suggestions have now been incorportated.

Luis Pedro Coelho and others added 15 commits January 8, 2011 16:21
This avoids the memory allocation. It is very strict in checking that
the types are correct, but since it is intended as an optimisation, it
should only be used when the user knows what they are doing.
Using the toy example in the test as a benchmark, I clocked 63ms with
an `out` parameter, versus 91ms without. Here is the full
benchmark (requires ipython)::

    import numpy as np
    np.random.seed(22)
    f = np.random.rand(1024*128, 16)
    v = np.random.rand(16,32)
    r = np.empty((1024*128, 32))
    _ip.magic("timeit np.dot(f,v,r)")
    _ip.magic("timeit np.dot(f,v)")
(Pointed out by pv on github)
This allows `np.dot(a, b, out=r)`.

Suggested by pv.
This indicates that the function takes 3 arguments
@luispedro
Copy link
Contributor Author

Can this be merged in?

If more changes are needed, I'm willing to work on them.

@pv
Copy link
Member

pv commented Feb 12, 2011

Thanks, it's applied in af1e833

@npinto
Copy link
Contributor

npinto commented Feb 13, 2011

This is great, thank you!

mattip referenced this pull request in mattip/numpy Mar 20, 2019
bashtage referenced this pull request in bashtage/numpy May 27, 2019
Revert "MAINT: Implement API changes for randomgen-derived code"
fangerer added a commit to hpyproject/numpy-hpy that referenced this pull request Jul 7, 2022
… instead of legacy function

Merge in ~STEPAN.SINDELAR_ORACLE.COM/numpy-hpy from fa/init_numeric_casts to labs-hpy-port

* commit 'ad0a23fe9df1c6b869314d3d593e58ef25dcedf3':
  Fix: Use HPyArray_AddCastingImplementation_FromSpec instead of legacy function
luyahan pushed a commit to plctlab/numpy that referenced this pull request Apr 25, 2024
chore: Add macro guard for inclusion
This pull request was closed.
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.

3 participants