Rob,
In my case your solution is even more efficient because my right argument
is always the same shape, (well really there are 2 cases, and each case is
internally shape invariant). So I can create a noun, say ndx, of that value
and apply it as ndx&{ against the right argument. I had thought about such
a solution, but could not come up with your right hand tine of the hook.
Very cool.
(I got a little lost in your answer though, because trimh was not defined
and I couldn't tell where it fit. But I don't think that is relevant to
your trimalt, which I was commenting on above.)
To be honest I haven't completely grokked your right tine of trimalt, but
it seems to work fine.
Thanks,
On Thu, Jun 1, 2017 at 2:30 PM, robert therriault <[email protected]>
wrote:
> Brian,
>
> I thought that as well, but I just finished a slightly different approach
> where I went directly to the selection of the triples from the matrix. It
> looks more complicated but is at least twice as fast and a third of the
> space.
>
> trim1 =: >@(tess &(cp;._3))@:(<"1)
> 100000 timespacex 'trim1 i. 7 10 3'
> 5.78836e_6 21632
>
> trimalt=: {~ <@:(>:@:(3 * i.)@:<.@:(%&3)&.>)@:}:@:$ NB. Hook with
> {~ the left tine
> 100000 timespacex 'trimalt i. 7 10 3'
> 2.41935e_6 7040
>
> 6.17228e_6 21632
>
> (trim1-:trimh) i."1 _3[\ , >,&3 each {3&+@:i. each 15 ;15 NB.
> combinations from 3 3 3 to 15 15 3
> 1
>
> For indices of less than 3 there is a difference in the shape produced, so
> watch out for that boundary.
>
> $ trimalt i. 2 2 3
> 0 0 3
> $ trim1 i. 2 2 3
> 0 0
>
> Cheers, bob
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm