John
I find a slight improvement in time & space with this
approach, essentially the same as yours, probably
similar to Brian's though I haven't studied it yet...
NB - Thunderbird (or something) tends to wrap my lines:
slicea=:3 : 0
s =. ({.</.{:) y =. |:/:~y NB. initial boxing
m =. (e.~i.@>:@(>./))~.{.y NB. masking array for nulls
m#^:_1 s NB. expand nulls
)
dobig =: 3 : 0 NB. make up an array of i <: j <: y pairs
i =. /:~ ?y#y
j =. i + ? y - i
i,.j
)
bigdata =: dobig 10000
ts'#slice bigdata'
0.00981431 1.75866e6
ts'#slicea bigdata'
0.00385224 1.07226e6
All the best
Mike
On 05/05/2011 16:06, John Randall wrote:
> I have a set of ordered pairs of nonnegative integers (representing
> pixels that are set in a binary image). To speed up access, I want to
> produce an array s of boxes such that (x,y) is an ordered pair if and
> only if y e. x {:: s . Keys would work perfectly for this except for
> skipped x-values, so I work around it, essentially inserting a bogus
> y-value for every x-value, and then removing it.
>
> data=:>0 1;0 2;0 3;1 1;1 3;2 1;4 1
>
> slice=:3 : 0
> 'X Y'=.|:/:~ y
> m=.>:>./X
> n=.>:>./Y
> X=.(i.m),X
> Y=.(m#n),Y
> -.&n&.> X</.Y
> )
> slice data
> +-----+---+-++-+
> |1 2 3|1 3|1||1|
> +-----+---+-++-+
>
> I also have a test verb.
>
> test=:3 : 0
> y=./:~y
> s=.slice y
> y-:;(<"0 i.#s)(,"_ 0)&.> s
> )
>
> test data
> 1
>
> Does anyone have any suggestions as to how to do this better?
>
> Best wishes,
>
> John
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm