John,

The key's to the user_functions dictionary should be strings that map to
SymPy functions in the expressions:

In [18]: print sympy.ccode(sympy.sin(sympy.symbols('x')),
user_functions={"sin": "std::sin"})
std::sin(x)

In [19]: print sympy.ccode(sympy.Abs(sympy.symbols('x')),
user_functions={"Abs": "std::abs"})
std::abs(x)



Jason
moorepants.info
+01 530-601-9791

On Thu, Feb 26, 2015 at 8:56 AM, John Peterson <[email protected]> wrote:

> Hi,
>
> It's entirely possible I'm using ccode wrong, but I can't seem to get it
> to recognize my custom replacements for sqrt, fabs, or pow.  Here's a
> simple test case:
>
> #!/usr/bin/env python
>> from sympy import *
>>
>
>
> print ccode(sympify('sqrt(x)'), user_functions={"sqrt": "std::sqrt"})
>> print ccode(sympify('Abs(x)'), user_functions={"fabs": "std::abs"})
>> print ccode(sympify('x**2'), user_functions={"pow": "std::pow"})
>
>
> On my system, this prints:
>
> sqrt(x)
>> fabs(x)
>> pow(x, 2)
>
>
> I can of course work around this pretty easily with text replacement, so
> it's not a big deal...
>
>  --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/32b5380b-83e8-403c-a512-2d0417fbdf3e%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/32b5380b-83e8-403c-a512-2d0417fbdf3e%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 [email protected].
To post to this group, send email to [email protected].
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/CAP7f1AjWVJPSP%3DT3JV0T%2B8euOJcB4Oxcb8N5oiWqq88Mt-JW6Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to