If you try to evaluate code in which Flatten uses a List as second argument, like the following:
foo = Compile[{{u, _Real, 2}},
Flatten[u, {1, 2}]
]
Mathematica will complain with the following error message:
Compile::cpint: {1,2} at position 2 of Flatten[u,{1,2}] should be a machine-sized integer; evaluation will use the uncompiled function.
Using an integer as second argument of Flatten indeed gives no error.
Why is this? And is there a way around it?
My particular use case is to use Flatten to convert a TensorProduct structure into a structure similar to that given by KroneckerProduct,
that is, to do something like in the following (but for any number of matrices in the TensorProduct structure):
fooMatrix = TensorProduct[
Array[a, {2, 2}], Array[b, {2, 2}], Array[c, {2, 2}]
];
Flatten[fooMatrix, {{1, 3, 5}, {2, 4, 6}}]
It also seems that ArrayFlatten, which could probably be tweaked to work here instead of Flatten, is not compilable (as also shown by trying to compile it and observe the CompilePrint).
Flatten[u, {1, 2}]documented? I cannot find it. – Marius Ladegård Meyer Mar 14 '17 at 20:30Flatten[u, {{1, 2}}]. Using the latter form gives the same problem withCompilethough (and is indeed the one I'm interested in using, I used the one with a rank-1 list as second argument here just to make a simple reproducible example) – glS Mar 14 '17 at 20:37