Tag Info

Hot answers tagged

22

First off, your function is very simple without any hard number-crunching, so it will always be hard to get a large speedup for the compiled version. Secondly, your Parallelization option for Compile is useless because it doesn't do any parallelization this way. Let me give slightly changed versions of your examples and explain how you can achieve a large ...


5

There are two issues with your code. The first is that you have a variable name clash when using x as the argument in the definition of temp. Changing it to something else, e.g. q, will work in an uncompiled version of your code. fff[σt : {__Real}, sρ : {__?NumericQ}, dt : {__Real}, x_Real, nnt_Integer, dqt_Real, divt_Integer] := Module[{temp, dq = ...


5

Here's my relatively compact implementation of Glynn's formula, which incorporates the Gray code optimization: SetAttributes[GrayCode, Listable]; GrayCode[n_Integer] := BitXor[n, BitShiftRight[n]] permanent[mat_?MatrixQ] /; Equal @@ Dimensions[mat] := Module[{b = 2^(Length[mat] - 1)}, PadRight[{}, b, {1, -1}].(Times @@@ ...


4

I'm not sure how to answer this question without sounding discouraging. I cannot go into every detail but I still want to help you. Basically, you did several things wrong: using global variables inside Compile which makes that the compiled function calls back to the Mathematica Kernel to ask for instance what the definition of R is. Compiled functions ...


4

Edited to simplify the derivation and reduce the length of the final result. If R21 and R32 are pure imaginary, then the equation is solved easily. R21 /. Solve[eqns /. {Im[R21] -> -I R21, Im[R32] -> -I R32}, term][[1]] (* (I p (2 b q^2 x + 2 b q^2 y - 4 b c x y - p^2 x y - 4 b c x z - p^2 x z))/(6 b p^2 q^2 - 4 a b q^2 x - p^2 q^2 x - q^4 x - ...


4

Using as basis the great resource for core numerical algorithms below, I managed to implement a compiled linear solve which doesn't call MainEvaluate (so quite fast). I needed a linear solve for an optimization where the objective function requires inverting matrices, I was hesitating to use C++, but I preferred to stay in Mathematica. Resources ...


2

When you call compiled functions inside another compiled function, you should consider to inline them. You can do this by wrapping a With statement around and using CompilationOptions -> {"InlineCompiledFunctions" -> True} as option to compile. I have cleaned your code, moving a lot of definitions of variable right where you declare it in Module. I ...



Only top voted, non community-wiki answers of a minimum length are eligible