Hi

I can't comment on the first part but for the boolean expression, it's a
design issue. Booleans have not been derived from Expr class in sympy which
is why it fails.
​

Sudhanshu Mishra

On Tue, Aug 25, 2015 at 2:39 AM, Nico <nico.schloe...@gmail.com> wrote:

> With `codegen`, one can generate code from a sympy expression. Typically,
> it is assumed that the return value is a scalar.
>
> In one of my use cases, the return value is Boolean. (The answer to "Is x
> inside a particular domain?")
> The hack I employed so far is to generate the code as usual
> ```
> from sympy import *
> from sympy.utilities.codegen import codegen
>
> x = Symbol('x')
> expr = x**2 - x + sin(x) < x**3 - 2*x - cos(5*x)  # ok
> [(c_name, c_code), (h_name, c_header)] = codegen(("f", expr), "C")
> print(c_code)
> ```
> and then regex the relevant part out of `c_code`. (If you know of a better
> way to handle this, I'll be happy to hear about it.)
> This works alright, but fails in the most simple cases, e.g.,
> ```
> expr = True
> ```
> with
> ```
> TypeError: The first argument must be a sympy expression.
> ```
> Quite understandable.
>
> Is there a better way/hack to support this kind of code generation?
>
> Cheers,
> Nico
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/21baed7f-e7e6-4d1e-979c-6d30dee206e9%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/21baed7f-e7e6-4d1e-979c-6d30dee206e9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAFW_KCRdTTExAHyVCPj0WoxxCcDe6Zw0br8eUWhNoxaVFLPJHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to