I am trying to compile something similar to the following:
test = Compile[{{data, _Real, 1}},
First@FirstPosition[data, _?(# > 0 &)]]
However I get the following error, which I don't understand:
Compile::part: Part specification FirstPosition[data,_?(#1>0&)][[1]] cannot be compiled since the argument is not a tensor of sufficient rank. Evaluation will use the uncompiled function.
Is there a way to make this work?
FirstPosition
simply will not compile to lower level code, so the only way to do this, is to write your own iterative loop from scratch. A simpleDo
loop with aBreak
should suffice. $\endgroup$ – Sjoerd Smit Dec 6 '19 at 22:25While
loop... $\endgroup$ – Henrik Schumacher Dec 7 '19 at 6:08