Hi Brian,

I ran and tested your first two solutions

    trim1 =: >@(tess &(cp;._3))@:(<"1)
   trim1 i. 7 10 3
 33  34  35
 42  43  44
 51  52  53

123 124 125
132 133 134
141 142 143
   100000 timespacex 'trim1 i. 7 10 3'
6.47903e_6 21632

   trim2 =: ,"_2@(tess &(cp;._3))@:(]"1)
   (trim1 -: trim2) i. 7 10 3
1
   100000 timespacex 'trim2 i. 7 10 3'
7.05994e_6 20096

To clean up the dangling (<"1) I made a monadic fork with the same performance:

   trima=:>@(tess cp;._3 <"1) NB. Monadic fork
   (trim1 -: trima) i. 7 10 3
1
   100000 timespacex 'trima i. 7 10 3'
6.32724e_6 21376

...then did a dyadic version which could be useful if you wanted to use 
different values for tess. Same speed but a little less space used.

   trimb=:>@([&cp;._3 <"1) NB. Dyadic
   tess (trim1@:] -: trimb) i. 7 10 3  NB. Dyadic trimb compared to trim1
1
   100000 timespacex 'tess trimb i. 7 10 3'
6.23274e_6 17920

...then went with shorter code with a dyadic hook but more space than trimb.

   trimc=:>@(cp;._3 <"1) NB. Dyadic hook
   tess (trim1@:] -: trimc) i. 7 10 3
1
   100000 timespacex 'tess trimc i. 7 10 3'
6.36805e_6 21504

...and finally this dyadic version based on the (]"1) dangler

   trimd=: ,"_2@(cp;._3)
   tess (trim1@:] -: trimd) i. 7 10 3
1
   100000 timespacex 'tess trimd i. 7 10 3'
7.16478e_6 20224


Not any significant differences in speed but trimb uses the least space.

Hope this helps.

Cheers, bob

> On Jun 1, 2017, at 5:32 AM, Brian Schott <[email protected]> wrote:
> 
> cp =: (<1 1)&{   NB. center pixel of 3x3
> tess =: 2 2$3    NB. tesselate
> trim =: >@(tess &(cp;._3))@:(<"1)
> trim =: ,"_2@(tess &(cp;._3))@:(]"1)
> 
> ​I have found the trim's above both accomplish the desired result. My
> question especially is, how can the rank "1 in the latter ​trim be
> incorporated without the trailing @(). Any other suggestions to achieve
> speed improvements would be appreciated, too.
> 
> I am experimenting with the following phrase, for example, and when
> applying rank directly, without the @:() I get length error.
> 
> trim i. 7 10 3   NB. a fake rgb image argument
> 
> ​Thank you,​
> 
> -- 
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to