Bug introduced in 9.0.0 and fixed in 10.3
I am trying to speed up a function that involves continued fractions. Since ContinuedFraction
cannot be compiled, and the alternative way with Nestlist
of FractionalPart
does not produce the same results due to ContinuedFraction
's internal algorithm for the choice of the number of terms, I think the best way is to compute the continued fractions and then pass the integer list to the compiled function. Here's what I did:
fc = Compile[{{z, _Real}, {xcf, _Integer, 1}},
Fold[z/(#1 + #2) &, 0, 1/xcf]/z, RuntimeAttributes -> Listable]
z = {-.5, .5}
xcf = Reverse /@ Rest /@ ContinuedFraction[{.123455, .546452}]
fc[z, xcf]
This approach should work, however on my computer (Mathematica 10.0.2, Xubuntu 15.04), evaluating the compiled function over a list of arguments always crashes the kernel and sometimes displays this message:
No more memory available.
Mathematica kernel has shut down.
Try quitting other applications and then retry.
Why doesn't it work and how to fix this?
By the way, I am trying to recreate a higher quality version of the "Road to the Horizon" transformation of continued fractions from Linas Vepstas's math art gallery.
Update: Setting Parallelization -> False
in the compiled function as per @Joel Klein's answer in 17971 works, and it seems this is a confirmed bug. However, in my case it does not seem to be fixed as reported in that thread.