I would be happy with either of the following implementations, one or the
other of which might be preferred for other reasons. The immediate intended
use is to wrap the resulting function in ctypes so that I can feed it to
some existing code.

- An if/then construct, like what you mentioned. I don't quite understand
why that doesn't work, though.
- 0 + (1-0)*(x>=0.5) (essentially a Heaviside implementation. C interprets
a "false" as 0, and "true" as 1, correct?)


On Tue, Oct 8, 2013 at 2:00 PM, Ondřej Čertík <[email protected]>wrote:

> On Tue, Oct 8, 2013 at 1:58 PM, Ondřej Čertík <[email protected]>
> wrote:
> > Nathan,
> >
> > I am working on a fix.
> >
> > Can you provide the exact C expression that you want Piecewise((0, x <
> > 0.5), (1, x >= 0.5)) to generate?
> > I.e. can you fill in the right hand side here:
> >
> >     assert ccode(Piecewise((0, x < 0.5), (1, x >= 0.5))) ==
> "piecewise(...)"
>
> Ok, it actually works... It produces:
>
> if (x < 0.5) {
>    0
> }
> else if (x >= 0.5) {
>    1
> }
>
> But obviously this will not work inside an expression. Can you provide
> us the exact C code that you expect
> for your expression?
>
> Ondrej
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to