I have the following code:
compVDiag = Compile[
{{Nn, _Integer}, {M, _Integer}, {n, _Integer}, {basisvecs, _Integer,
2}, {c1m, _Integer, 2}, {c2m, _Integer, 2}},
Block[
{zpow, wpow, zlen, wlen},
zpow = Union[basisvecs[[n, 1 ;; Nn]]];
wpow = Union[basisvecs[[n, Nn + 1 ;; Nn + M]]];
zlen = Length[zpow];
wlen = Length[wpow];
Sum[
2^(-zpow[[i]] - zpow[[j]])*c1m[[n, zpow[[i]] + 1]]*
c1m[[n, zpow[[j]] + 1]]*
Binomial[zpow[[i]] + zpow[[j]], zpow[[i]]], {i, 1,
zlen - 1}, {j, i + 1, zlen}]
+
Sum[
2^(-wpow[[i]] - wpow[[j]])*c2m[[n, wpow[[i]] + 1]]*
c2m[[n, wpow[[j]] + 1]]*
Binomial[wpow[[i]] + wpow[[j]], wpow[[i]]], {i, 1,
wlen - 1}, {j, i + 1, wlen}]
]
which gives me some warnings:
Compile::cpintlt: i+1 at position 2 of zpow[[i+1]] should be either a nonzero integer or a vector of nonzero integers; evaluation will use the uncompiled function. >>
Compile::cpintlt: i+1 at position 2 of zpow[[i+1]] should be either a nonzero integer or a vector of nonzero integers; evaluation will use the uncompiled function. >>
Compile::cpintlt: i+1 at position 2 of wpow[[i+1]] should be either a nonzero integer or a vector of nonzero integers; evaluation will use the uncompiled function. >>
General::stop: Further output of Compile::cpintlt will be suppressed during this calculation. >>
CompilePrint shows the following weird snippet:
11 R2I4T(I1)3I8T(I1)4 = MainEvaluate[ \
\
\
-zpow[[1]] - zpow[[i + 1]]
Function[{Nn, M, n, basisvecs, c1m, c2m, zlenCompile$1, \
wpowCompile$2, wlenCompile$3, zpowCompile$4}, Block[{zlen = \
zlenCompile$1, wpow = wpowCompile$2, wlen = wlenCompile$3, zpow = \
zpowCompile$4}, {Length[{2 c1m[[n,zpow[[1]] \
+ 1]] c1m[[n,zpow[[i + 1]] + 1]] Binomial[zpow[[1]] + zpow[[i + 1]], \
zpow[[1]]]}[[1]]], zlen, wpow, wlen, zpow}]][ I0, I1, I2, T(I2)0, \
T(I2)1, T(I2)2, I4, T(I1)3, I8, T(I1)4]]
Could I get some help in understanding this? Seems like i is not assigned a value yet when a term in the sum is calculated, even though j starts at i+1? How can I remedy this?
Binomialis not on the List of Compilable Functions -- You could tryGammaand perhapsRound. – Michael E2 May 03 '15 at 23:26Gammain the list added for 10.0.2. I'll compare! – Marius Ladegård Meyer May 04 '15 at 04:04