1,
I am trying to make Compilable function which takes Matrix of zeroes and ones f.e:
R= {{1, 1, 1, 0, 0, 0, 1, 1, 1, 0}, {1, 1, 0, 0, 0, 0, 1, 1, 1, 0}, {1,
0, 1, 0, 0, 1, 1, 0, 1, 1}, {0, 0, 0, 1, 1, 1, 0, 0, 0, 1}, {0, 0,
0, 1, 1, 1, 0, 0, 0, 1}, {0, 0, 1, 1, 1, 1, 0, 0, 1, 1}, {1, 1, 1,
0, 0, 0, 1, 1, 1, 0}, {1, 1, 0, 0, 0, 0, 1, 1, 1, 0}, {1, 1, 1, 0,
0, 1, 1, 1, 1, 0}, {0, 0, 1, 1, 1, 1, 0, 0, 0, 1}}
and will make a table of its diagonals, but the problem:CompiledFunction::cflist: Nontensor object generated; proceeding with uncompiled evaluation.
occures. My function is:
f3 = Compile[{{R, _Real, 2}},
Table[Flatten[{0, Table[R[[i]][[i + j]], {i, 1, Length[R] - j}],
0}], {j, 1, Length[R] - 1}], CompilationTarget -> "C",
RuntimeAttributes -> Listable, RuntimeOptions -> "Speed"]
Any suggestion how can I debug it please ?
2, Then I want to make again Compilable fction which can determinate from Flatten[f3[R]]
the number of ones without neighbour, I mean, f.e. vector {1,0,1,0,1,1}
has a 2 ones without neighbour.
Or even better Compilable function which can determinate the number of all the sequances of 1 11 111 1111 ... in Flatten[f3[R]]
.
Table[ArrayPad[Diagonal[R, k], 1], {k, Length[R] - 1}]
$\endgroup$