Also this one isn't obvious: In [21]: print sympy.ccode(sympy.symbols('x')**2, user_functions={"Pow": "std::pow"}) std::pow(x, 2)
Jason moorepants.info +01 530-601-9791 On Thu, Feb 26, 2015 at 9:53 AM, Jason Moore <moorepa...@gmail.com> wrote: > 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 <jwpeter...@gmail.com> > 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 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/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 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/CAP7f1Aj%2BZg5ucwmseOaHfFNC4HFhUJa3cS5jvHokJ8%2BS5-cXhw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.