I need solve the task of classification of the points regarding their position. So I use such a function:
selector[mas_, reg_] := Select[mas,
RegionMember[
Rectangle[{First@reg - st/2, Last@reg - st/2}, {First@reg + st/2, Last@reg + st/2}],
#[[2]]] &];
It checks if second elements of mas
entries are inside the rectangle defined by point reg
. Finally it returns the list of right mas
entries. There are ~4000 rectangles with ~250000 points and it evidently works too long.
I try to make the compiled version of such function:
cs=Compile[{mas,_Real,4},{reg,_Real,2},
Select[mas,
RegionMember[
Rectangle[{First@reg - st/2, Last@reg - st/2}, {First@reg + st/2, Last@reg + st/2}],
#[[2]]] &]
]
This function produce an error like "The first argument should be a 4 rank tensor". My array has a complicated form like mas={{1,{123.4,654.3},{12.1,21.2}},{...},...}
. Of course it is not a good matrix but what is a problem with an arbitrary shape array?
I was trying make the packed array from the initial one but it does not help.
The question is how to compile a function with arbitrary shape array of Real arguments?
reg
andst
? $\endgroup$st
is an arbitrary number - the rectangle size.reg
- is an arbitrary point (pair of numbers) that defines the position of the rectangle. Yes, the sizes are equal. $\endgroup$