I'm trying to make a compiled version of this function
LN = Compile[{{a, _Real, 1}, {CMat, _Real}, {P, _Real,
2}, {OMG, _Real, 2}},
Module[{Mat, CoPart, CovT, root, Eigs},
Mat = Developer`ToPackedArray[CMat];
CoPart = ArrayFlatten[Mat[[a, a]]];
CovT = P[1, Length[a] - 1].CoPart.P[1, Length[a] - 1];
root = Eigenvalues[-OMG[Length[a]].CovT.OMG[Length[a]].CovT];
Eigs = Delete[Sqrt[root], Table[{2*i}, {i, 1, Length[root]/2}]];
Sum[-Log2[Min[1, Eigs[[i]]]], {i, 1, Length[Eigs]}]],
Parallelization -> True]
but I face some errors as follows
Compile::cplist: Compile`$8 should be a tensor of type Integer, Real, or Complex; evaluation will use the uncompiled function.
Compile::cplist: Compile`$8.CoPart should be a tensor of type Integer, Real, or Complex; evaluation will use the uncompiled function.
Compile::cplist: Compile`$8 should be a tensor of type Integer, Real, or Complex; evaluation will use the uncompiled function.
General::stop: Further output of Compile::cplist will be suppressed during this calculation.
CMat is an n×n matrix of 2×2 blocks, and P and OMG are some 2n×2n matrices.
Any help would be appreciated.
Developer`ToPackedArray[CMat]in code to be compiled does not make sense; wheneverCMatis an input array of a compiled functions, it is already packed. Morever,Eigenvaluescannot be compiled (it is already essentially a library function) and indexing intoOMGshould be done withOMG[[Length[a]]]instead ofOMG[Length[a]].Parallelization -> TruewithoutRuntimeAttributes -> {Listable}does not do anything. The rank specification ofCMatis certainly wrong; it should be something like{CMat, _Real, 4}. – Henrik Schumacher Apr 25 '19 at 11:56Mat[[a, a]]is going to be troublesome ifais a list of reals. – Henrik Schumacher Apr 25 '19 at 11:59OMGis a square matrix function and the argument is its dimension,Pmatrix as well. Unfortunately, the input for compile function is a list of integers e.g.LN[{1,2,3}]and maybe parallelization wouldn't make any sense. Unluckily, I don't know what the rank of a block matrix is.CMatis a MxM matrix of 2x2 blocks, by the way. Unfortunately,ais a list of integers. – Ghaem Apr 25 '19 at 13:15