Tag Info

New answers tagged

4

The argument pattern can be read directly from the CompiledFunction expression as DaveStrider commented: cf = Compile[{{x, _Real}, {y, _Integer}}, Round[x/y]]; cf[[2]] {_Real, _Integer} The result information is printed by the CompiledFunctionTools package command CompilePrint: Needs["CompiledFunctionTools`"] CompilePrint[cf] 2 arguments ...


8

1. Optimising the code given So I've completely rewritten my answer to this optimization, after @brama pointed out my versions returned a scalar rather than a matrix - my mistake, apologies. First recall the performance of @brama's code: Do[main[10], {100}]; // AbsoluteTiming (* 1.10 seconds *) But what if we compile @brama's main function to C, like ...


5

You can get a significant boost by compiling ysaf: ysafc = Compile[{x, y}, Evaluate @ N @ ysaf[λ ArcSin[Sqrt[x^2 + y^2]], ArcTan[x, y]]]; func[x_?NumericQ, y_?NumericQ] := ysafc[x, y] gr = ContourPlot[{func[x, y] == 0, Sqrt[x^2 + y^2] == rmx}, {x, -rmx, rmx}, {y, -rmx, rmx}, RegionFunction -> Function[{x, y, z}, Sqrt[x^2 + y^2] <= rmx], Axes ...


4

One can gain a considerable speed gain by omitting RegionFunction and setting PlotPoints to 10. The following only needs 8 seconds (it uses some ideas of @PhilChang): A = { (8 Sqrt[1035741])/15625, 0, 0, 0, 0, Sqrt[6597877/15]/6250, 0, 0, 0, 0, -(Sqrt[(6338501/10)]/3125), 0, 0, 0, 0, (29 Sqrt[27347/30])/3125, 0, 0, 0, 0, ...


4

Some codes are from the answer of PhilChang Remove["Global`*"]; A = {(8 Sqrt[1035741])/15625, 0, 0, 0, 0, Sqrt[6597877/15]/6250, 0, 0, 0, 0, -(Sqrt[(6338501/10)]/3125), 0, 0, 0, 0, (29 Sqrt[27347/30])/3125, 0, 0, 0, 0, -(Sqrt[(4358874/5)]/3125), 0, 0, 0, 0, -(Sqrt[(352454081/3)]/31250), 0, 0, 0} // N; s[m_, l_] := If[Abs[m] > l, 0, ...


4

The orginal program takes 78s on my computer. First, Make vector A a real vector will make the program a little faster. A = {(8 Sqrt[1035741])/15625, 0, 0, 0, 0, Sqrt[6597877/15]/6250, 0, 0, 0, 0, -(Sqrt[(6338501/10)]/3125), 0, 0, 0, 0, (29 Sqrt[27347/30])/3125, 0, 0, 0, 0, -(Sqrt[(4358874/5)]/3125), 0, 0, 0, 0, ...


2

By default, in compiled functions, underflow is not caught and becomes zero automatically. cf = Compile[x, Module[{z = x, y = x}, While[y > 0, z = y; y = y/2]; {y, z}]]; cf[1.] (* {0., 5.*10^-324} *) Such a number as the number 5.*10^-324 achieved just before underflow is a subnormal machine number. The minimum machine number with full machine ...


4

As @episanty says in a comment, try applying Chop to your data before you return the value. It's compilable, according to List of compilable functions, which means it is appropriate for you here. From the documentation, Chop[expr] replaces approximate real numbers in expr that are close to zero by the exact integer 0. The default tolerance is ...



Top 50 recent answers are included