Skip to content
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

+ Operator unrecognized in long summation #35

Open
felixjung opened this issue Feb 12, 2015 · 1 comment
Open

+ Operator unrecognized in long summation #35

felixjung opened this issue Feb 12, 2015 · 1 comment

Comments

@felixjung
Copy link

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!

@mfariacastro
Copy link

Hey @felixjung , I just found the same problem. Thanks for offering a fix.

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

No branches or pull requests

2 participants