lambda/ function calls in cython fro complex_plot

13 views
Skip to first unread message

Ethan Van Andel

unread,
Jul 16, 2009, 3:54:08 PM7/16/09
to sage-support
Sorry to keep spamming sage-support.

I have a class instance m with a method riemann_map so that
m.riemann_map(z) returns a (numpy) complex value. I want to do a
complex_plot of that function. If I try:
complex_plot(m.riemann_map,(-2,2),(-2,2)) I get this error:
...
File "fast_eval.pyx", line 1272, in
sage.ext.fast_eval.fast_float_constant (sage/ext/fast_eval.c:7989)
File "fast_eval.pyx", line 513, in
sage.ext.fast_eval.FastDoubleFunc.__init__ (sage/ext/fast_eval.c:3451)
TypeError: a float is required

In regular sage I just plot lambda x: m.riemann_map(x). However, I
want to move that call to cython to reduce overhead, and it seems like
lambda doesn't work in cython.

Is there anything I can do to get around this?

Thanks, and sorry again for asking so many questions.

Ethan

kcrisman

unread,
Jul 16, 2009, 4:37:13 PM7/16/09
to sage-support


On Jul 16, 3:54 pm, Ethan Van Andel <evlu...@gmail.com> wrote:
> Sorry to keep spamming sage-support.
>
> I have a class instance m with a method riemann_map so that
> m.riemann_map(z) returns a (numpy) complex value. I want to do a
> complex_plot of that function. If I try:
> complex_plot(m.riemann_map,(-2,2),(-2,2)) I get this error:
> ...
>   File "fast_eval.pyx", line 1272, in
> sage.ext.fast_eval.fast_float_constant (sage/ext/fast_eval.c:7989)
>   File "fast_eval.pyx", line 513, in
> sage.ext.fast_eval.FastDoubleFunc.__init__ (sage/ext/fast_eval.c:3451)
> TypeError: a float is required
>
> In regular sage I just plot lambda x: m.riemann_map(x). However, I
> want to move that call to cython to reduce overhead, and it seems like
> lambda doesn't work in cython.

According to
http://sage.math.washington.edu/home/mhansen/sage-epydoc/sage.misc.cython-module.html#cython_lambda
which is probably semi-official (I couldn't find it in reference
manual but it seems okay), there is a cython_lambda which should work
okay. Someone else will certainly be able to clarify more :)

- kcrisman

Robert Bradshaw

unread,
Jul 17, 2009, 2:47:44 AM7/17/09
to sage-s...@googlegroups.com
On Jul 16, 2009, at 1:37 PM, kcrisman wrote:

> On Jul 16, 3:54 pm, Ethan Van Andel <evlu...@gmail.com> wrote:
>> Sorry to keep spamming sage-support.
>>
>> I have a class instance m with a method riemann_map so that
>> m.riemann_map(z) returns a (numpy) complex value. I want to do a
>> complex_plot of that function. If I try:
>> complex_plot(m.riemann_map,(-2,2),(-2,2)) I get this error:
>> ...
>> File "fast_eval.pyx", line 1272, in
>> sage.ext.fast_eval.fast_float_constant (sage/ext/fast_eval.c:7989)
>> File "fast_eval.pyx", line 513, in
>> sage.ext.fast_eval.FastDoubleFunc.__init__ (sage/ext/fast_eval.c:
>> 3451)
>> TypeError: a float is required
>>
>> In regular sage I just plot lambda x: m.riemann_map(x). However, I
>> want to move that call to cython to reduce overhead, and it seems
>> like
>> lambda doesn't work in cython.

If you're calling complex_plot, you don't need to be worrying about
the overhead...

> According to
> http://sage.math.washington.edu/home/mhansen/sage-epydoc/
> sage.misc.cython-module.html#cython_lambda


> which is probably semi-official (I couldn't find it in reference
> manual but it seems okay), there is a cython_lambda which should work
> okay. Someone else will certainly be able to clarify more :)

This seems a bit hackish for what you need, and I don't think it will
even work in this case. Is there any reason you can't use an ordinary
function instead of a lambda? The two best options I see are either
writing that part in Python (quick and easy), or fixing complex_plot
to take any callable (which it really should do).

- Robert

Reply all
Reply to author
Forward
0 new messages