Convert Real packed array of pairs to Complex packed array
Using Dot
is pretty fast:
a = RandomReal[1, {8, 7, 6, 5, 4, 3, 2}];
c = N[{1, I}];
r1 = a.c;// RepeatedTiming
{0.000100, Null}
Get rid of the Apply:
#[[1]] + #[[2]]*I &[
Transpose[arr, Append[Range[2, Depth[arr] - 1], 1]]]
toCmplx =
Compile[{{pair, _Real, 1}}, First@pair + I Last@pair,
RuntimeAttributes -> {Listable}]
I believe this works with arbitrary depth, including ragged arrays, so long as the bottom dimension is 2
for all elements. Primitive test with On["Packing"]
returned no messages.