Tag Info

New answers tagged

2

This bug was speedily confirmed... Bug reported internally. Thank you! – ilian Aug 7 at 15:22 and fixed...internally at least Fixed in the development version. – ilian Aug 11 at 15:16


3

The reason for the error message is machine integer overflow. The largest machine integer on a 64-bit platform is 2^63 - 1 Developer`$MaxMachineInteger == 2^63 - 1 (* True *) Compare the following examples where the second one overflows but the first one doesn't cf1 = Compile[{}, Developer`$MaxMachineInteger]; cf1[] (* 9223372036854775807 *) cf2 = ...


0

This is not an answer, because unfortunately, recursion is not supported by the compiler. We can see this with a very simple example: the Fibonacci sequence. Recall that one can write a recursive pure function by using slot #0 to refer to the function itself. Hence: With[{fibonacci = Function[Null, If[#1 == 1 || #1 == 2, 1, #0[#1 - 1] + #0[#1 - 2]]]}, ...


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 = ...


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 ...


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 ...


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

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 @@@ ...



Top 50 recent answers are included