New answers tagged

2

I think you need "InlineCompiledFunctions" -> False: f = With[{bigNastyFunction = Compile[{{y, _Complex}}, Sin[y](*,CompilationTarget\[Rule]C*)]}, Compile[{{x, _Complex}}, bigNastyFunction[x] + bigNastyFunction[x^2]^2 + 3 bigNastyFunction[x^3], CompilationOptions -> {"InlineCompiledFunctions" -> False}]] …… 1 C1 = ...


2

Here is one way: With[{opts = SystemOptions[]}, With[{bigNastyFunction = Function[{y}, Sin[y]]}, Internal`WithLocalSettings[ SetSystemOptions["CompileOptions" -> "CompileReportExternal" -> True], f = Compile[{{x, _Complex}}, bigNastyFunction[x] + bigNastyFunction[x^2]^2 + 3 bigNastyFunction[x^3]], SetSystemOptions[opts] ]]] ...


0

As a general rule, you can only call a function f from inside a Compile'd function c if f is also compiled or is a built-in numerical Mathematica function. The solution I would suggest is to make bigNastyFunction a compiled funciton: bigNastyFunction = Compile[{{x, _Complex}}, Sin[x]]; Then call it from your function: f = Compile[ {{x, _Complex}}, ...


2

If you want integer division, use Quotient: Compile[{}, Module[{n}, n = Length[{1, 2, 3, 4}]; n = Quotient[n, 2]]] If you want n to be real instead of an integer, you can coerce it's type in a number of ways. For example, these will both result in n being real: Compile[{}, Module[{n = 0.0}, n = Length[{1, 2, 3, 4}]; n = n/2]] Compile[{}, Module[{n}, n = ...


7

You can get it through Compile as below. Note that I have not tested for correctness. myFncC = Compile[{{X, _Real, 2}}, Block[ {n, val}, n = Length[X]; If[n == 1, Return[{2., 1.}]]; val = Total[ Table[ Block[ {XmT = Total[X[[1 ;; m]]], XmnT = Total[X[[m + 1 ;; n]]], mFm = myFncC[X[[1 ;; m]]], mFmn = myFncC[X[[m ...


2

OK, let me kill the unanswered question. Your func can be simplified to: func[z_, nei_] := Module[{t = ConstantArray[0, Length@Flatten@z]}, t[[Rest@nei]] = 1; Partition[t, Length@z]]; func[Z, Neighbors[[2]]] If you still want to compile it, you just need a little modification: cfunc = Compile[{{z, _Integer, 2}, {nei, _Integer, ...


6

Your Func is far beyond best. As mentioned before, currently you'd better set effort on learning to code in "Mathematica-style" rather than try to relieve the slowness (which is mostly caused by bad coding in my view) with Compile. Here's an uncompiled function that's about 300 times faster than your Func: func = Function[{l0, l1, l2, ll3}, Module[{l3 = ...


6

Leonid Shifrin has already given an excellent answer for the question but it's so… long and may be frustrating for someone just beginning to learn the usage of Compile so I decided to post this as an answer. Recently (OK… actually it's more than a year ago) I found that Ted Ersek's Mathematica tricks(.nb version can be found here) contains a brief but ...


2

You are using the global symbol t within a compiled function. This is not going to work like you expect it. What you probably want is the following simple function providing that I understood you correctly: f = Compile[{{l, _Integer, 1}}, Module[{ list = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}, t = Most[{{1}}]}, t = Map[list[[#]] &, l]; t ...


0

Compile[{{r, _Integer, 2}, {d, _Integer, 2}}, a = Position[Sign@MapThread[#1 - #2 &, {r, d}], 1] ]



Top 50 recent answers are included