I was very interested in the answer of How to avoid “CopyTensor” in compile function with external call? and tried it on my own example below. And it does not work. Just curious why?
mvMu = With[{Part = Compile`GetElement},
Compile[{{i, _Integer}, {j, _Integer, 1}},
Module[{sum = 0}, Do[If[j[[k]] > i, sum++], {k, Length[j]}]; sum],
CompilationTarget -> "C", "RuntimeOptions" -> "Speed"]
]
mvMuS = With[{mvMu = mvMu, Part = Compile`GetElement},
Compile[{{i, _Integer, 1}, {j, _Integer, 1}},
Module[{sum = 0}, Do[sum = sum + mvMu[j[[k]], i], {k, Length[j]}];
sum], CompilationTarget -> "C",
CompilationOptions -> {"ExpressionOptimization" -> True,
"InlineCompiledFunctions" -> True,
"InlineExternalDefinitions" -> True},
"RuntimeOptions" -> "Speed"]]
The code still contains CopyTensor:
CompiledFunctionTools`CompilePrint[mvMuS]
[...]
4 goto 21
5 I6 = GetElement[ T(I1)1, I5]
6 T(I1)2 = CopyTensor[ T(I1)0]]
[...]