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
Extend numpy.dot() to accept more than 2 arrays. (Trac #741) #1339
Comments
@rkern wrote on 2008-04-17 This has been discussed before, and some implementations were experimented with. The main problem is that the associativity of the multiplications does matter if one is concerned about memory usage. Some intermediates are (much) bigger than others. However, the syntax of At least that's how I remember the conversation. I can't find the thread off-hand, though. |
Milestone changed to |
trac user joris wrote on 2008-04-17 The conversation Robert mentioned can be found in the numpy archives on gmane, with the keywords:[[BR]]
The associativity argument of Tim boils down to:
Bill provides an interesting suggestion: no optimization provided, but giving the user a way to specify the order of multiplication:
etc. with
However, in its current form |
@stefanv wrote on 2008-04-17 Is the optimisation prohibitively expensive for, say, anything up to 5 elements? |
@rkern wrote on 2008-04-17 I would say that the ambiguity would be the deal-breaker. There's no point in making it fast if it's wrong. |
@stefanv wrote on 2008-04-17 Right, because dot does broadcasting as well as matrix multiplication. |
Milestone changed to |
Milestone changed to |
@mwiebe wrote on 2011-03-23 The "dot as a method" introduced in 1.5 improves the syntax available for many dots in a row, so closing the bug as wontfix. The optimization ideas discussed might be served well with the deferred expression evaluation idea. If dot returns an unevaluated expression tree instead of an evaluated result, a complicated end-result expression can be analyzed for reordering that reduce intermediate value sizes, etc. |
Original ticket http://projects.scipy.org/numpy/ticket/741 on 2008-04-17 by trac user joris, assigned to unknown.
if a,b,c,d are numpy arrays, than their matrix multiplication can be computed with:
dot(a, dot(b, dot(c, d)))
or by
array(mat(a) * mat(b) * mat(c) * mat(d))
More convenient would be dot(a,b,c,d). An easy way to implement this would be
def dot(*args):
return reduce(olddot, args)
where 'olddot' is the current implementation of dot that only takes 2 arguments. The suggestion above would not break any code, as dot(a,b) == olddot(a,b).
The text was updated successfully, but these errors were encountered: