Devectorize.jl
Devectorize.jl copied to clipboard
+ Operator unrecognized in long summation
Hi,
I've repeatedly encountered the issue that Devectorize won't recognize the +
operation, if the number of addends is larger than 3, i.e.:
@devec foo[:] = a .* u + b .* x + c .* y + d .* z
In my experience, this will throw:
ERROR: DeError("Unrecognized function + with 4 arguments (in Devectorize)")
Is this intended behavior? Am I using Devectorize incorrectly for very long expressions like the following one (this is part of an analytical gradient I'm working with)?
@devec stor_g[ind, 3 * n_covars + i] = covars[:, i] .* exp(-2 .* d .* (l + u)) .* (
(8 .* f1 .* (f2 + f3) .* (exp(d .* (2 .* u + l)) - exp(d .* (2 .* l + u))) +
(2 .* f2.^2 + 2 .* f2 .* f3 + f3.^2) .* (exp(2 .* d .* u) .* (1 + 2 .* d .*l) -
exp(2 .* d .* l) .* (1 + 2 .* d .* u))) +
(8 .* d .* f1 .* (f2 + f3) .* (exp(d .* (l + 2 .* u)) .* l -
exp(d .* (u + 2 .* l)) .* u) +
8 .* d.^2 .* f1 .* f3 .* (exp(d .* (l + 2 .* u)) .* l.^2 -
exp(d .* (u + 2 .* l)) .* u.^2)) +
(2 .* d.^2 .* f3 .* (4 .* f2 + f3) .* (exp(2 .* d .* u) .* l.^2 -
exp(2 .* d .* l) .* u.^2) +
4 .* d.^3 .* f3.^2 .* (exp(2 .* d .* u).* l.^3 -
exp(2 .* d .* l) .* u.^3))
) ./ (4 .* d)
The problem can easily be fixed by wrapping several of the chained +
operations in parenthesis:
@devec foo[:] = (a .* u + b .* x) + (c .* y + d .* z)
However, this fix seems to be kind of dirty and messes up the code even more than it is already for such long expression.
Any ideas? Thanks!
Hey @felixjung , I just found the same problem. Thanks for offering a fix.