The tolerance thing is a problem... you might be able to solve it with a weird construct like I.!.(tol)^:_1!.(universe) y. I think this would be the same as
(universe) (3 :0)"1 y ($:~ i.@>:@(>./)) y : (universe) <:@(#/.!.(tol))@, y ) Where universe and tol are optional. As for the domain problem with I.^:_1, I. has the same problem in that it only works on numerics, so it is properly reflective of the inverse, and I.^:_1 I. is always the identity minus trailing zeros (which can be added back with ($ $!.0 I.^:_...@i.). I agree that #/.~ is fast, but for arrays that were Boolean before I. (ie. now return 1 for (-:~.)) the amend method is about 10 times faster. Also, #/.`(~...@])`(0 $~ >:@(>./)@])}~ Is a candidate that works the same as the original but is faster for more sparse arrays. However, it only works if we assume a numeric universe. That can probably be fixed--I'll get back to it later. Marshall -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Henry Rich Sent: Monday, September 06, 2010 11:35 AM To: Programming forum Subject: Re: [Jprogramming] Mask from list of indices with multiplicity Allowing !. to change the universe is an interesting idea, but wouldn't !. be needed in its usual role of tolerance, since there are implied comparisons in the operation? Also, your Ii works only on numeric operands, while universe <:@(#/.~)@, y works on all types (and shapes). Since the key part, #/.~ , is already fast, I think that nothing more is really needed. This is a matter of taste. Henry Rich Henry Rich On 9/6/2010 10:06 AM, Marshall Lochbaum wrote: > The only way I. I.^:_1 changes x is that it sorts it, and I.^:_1 I. only cuts > out the trailing 0s: > Ii=. ([:<:@(#/.~) i.@>:@(>./) , ]) > (; (;Ii)@I.) 1...@$2 > ┌───────────────────┬───────────┬─────────────────┐ > │1 1 1 0 0 1 1 0 1 0│0 1 2 5 6 8│1 1 1 0 0 1 1 0 1│ > └───────────────────┴───────────┴─────────────────┘ > (; (;I.)@Ii) 6...@$10 > ┌───────────┬─────────────────┬───────────┐ > │0 0 8 6 6 3│2 0 0 1 0 0 2 0 1│0 0 3 6 6 8│ > └───────────┴─────────────────┴───────────┘ > > I think each of these cases is acceptable, especially if you allow !. to > change the universe (this removes the I.^:_1 I. problem). > > Marshall > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Roger Hui > Sent: Monday, September 06, 2010 2:26 AM > To: Programming forum > Subject: Re: [Jprogramming] Mask from list of indices with > multiplicity > > I.^:_1 seems too far from what<:#/.~universe,x does. > Another way to say that is that I. I.^:_1 x can bear scant resemblance to x . > > > > ----- Original Message ----- > From: Zsbán Ambrus<[email protected]> > Date: Sunday, September 5, 2010 14:21 > Subject: Re: [Jprogramming] Mask from list of indices with > multiplicity > To: Programming forum<[email protected]> > >> On Sun, Sep 5, 2010 at 10:57 PM, Roger Hui<[email protected]> wrote: >>> <: #/.~ (i.7) ,x >> >> Nice solution. >> >>> ----- Original Message ----- >>> From: Zsbán Ambrus<[email protected]> >>>> Would it make >>>> sense if I.^:_1 did this? >> >> ^^^ What's your opinion on this? > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
