2

I am not very experienced with Compile, I tried to use it for a Meijer-G function

mTest = Compile[{{k, _Integer}, {b, _Real}}, MeijerG[{{1/2, 1/2}, {}}, {{0, 1/2, k}, {-k}}, b^2], {{MeijerG[_, _, _], _Real}}]

but it returns the error

CompiledFunction::cflist: Nontensor object generated; proceeding with uncompiled evaluation.

Does it mean that I can't Compile MeijerG or is there a trick to it. Eventually I would like to Compile a long calculation that contains a few Meijer-G functions.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
ThunderBiggi
  • 1,195
  • 5
  • 13

1 Answers1

11

The reason you get a message is because Compile cannot handle non tensor arrays, and the first argument to MeijerG is not a tensor (i.e. {{1/2, 1/2}, {}}).

Now DumpsterDoofus is correct in that MeijerG cannot be compiled, but we can get around this error, which will make MeijerG usable in compiled code. What I mean by usable is Compile will call Mathematica's main kernel to evaluate your MeijerG expression, and then jump right back into the compiled code. This is much better than the current behavior, where the non tensor causes Compile to jump out and not return.

Mei[m_, n_, p_, q_, args___, x_] := MeijerG[{{args}[[1;;n]], {args}[[n+1;;p]]}, {{args}[[p+1;;p+m]], {args}[[p+m+1;;-1]]}, x]

mTest = Compile[{{k, _Integer}, {b, _Real}}, Mei[3, 2, 2, 4, 0.5,0.5,0, 0.5,k , -k, b^2]]

mTest[3, 2.3]
1.27871
Greg Hurst
  • 35,921
  • 1
  • 90
  • 136
  • I was just wondering whether it is possible to 'break' the MeijerG function down to a series of elementary calculations that can be compiled. I have no idea how Mathematica computes it, but I got this idea while reading this post – ThunderBiggi Jan 28 '15 at 13:55