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

Logical operators in octave_code #9533

Closed
rgbrown opened this Issue Jun 16, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@rgbrown
Copy link

rgbrown commented Jun 16, 2015

When expressions include logical operators, like &, octave_code uses the wrong logical operator in the produced code. For example the following code:

from sympy import Piecewise
from sympy.abc import x
from sympy.printing import octave_code
print octave_code(Piecewise((1, (x > 0) & (x < 1)), (0, True)))

produces output

((x > 0 && x < 1).*(1) + (~(x > 0 && x < 1)).*(0))

The logical ands (&&) should be single ampersands (&) so that the expression works with vector arguments x in Octave/MATLAB

@cbm755 cbm755 self-assigned this Jun 16, 2015

cbm755 added a commit to cbm755/sympy that referenced this issue Jun 17, 2015

codegen: use vectorized and/or for octave code
Previously it generated code using && and ||.  These are fine
for scalar operations (and in some cases preferable as they
shortcircuit).  But for numerical code, & and | are better as
they are vectoried.  Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy#9533.

cbm755 added a commit to cbm755/sympy that referenced this issue Jun 17, 2015

codegen: use vectorized and/or for octave code
Previously it generated code using && and ||.  These are fine
for scalar operations (and in some cases preferable as they
shortcircuit).  But for numerical code, & and | are better as
they are vectorized.  Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy#9533.

cbm755 added a commit to cbm755/sympy that referenced this issue Jun 17, 2015

codegen: use vectorized and/or for octave code
Previously it generated code using && and ||. These are fine
for scalar operations (and in some cases preferable as they
shortcircuit). But for numerical code, & and | are better as
they are vectorized. Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy#9533.

@jcrist jcrist closed this in #9537 Jun 23, 2015

skirpichev added a commit to diofant/diofant that referenced this issue Sep 28, 2015

codegen: use vectorized and/or for octave code
Previously it generated code using && and ||. These are fine
for scalar operations (and in some cases preferable as they
shortcircuit). But for numerical code, & and | are better as
they are vectorized. Since we are probably generated code do use
in numerical work, this is preferred.

Fixes sympy/sympy#9533.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment