Oops, I thought I had included that. But it looks like one of my formatting
edits lost it.

   inds=: I. @ (+./ .*.)

Thanks,

-- 
Raul


On Wed, Oct 12, 2016 at 10:00 PM, Michal Dobrogost <
michal.dobrog...@gmail.com> wrote:

> Hi Raul,
>
> What is the definition of *inds*?
>
> I would describe the higher level operation as: select the rows of Y where
> X is 1. Then take the column-wise OR of them.
>
> However the real thing I'm interested in is generating the lookup tables
> which serve as an intermediate step in the higher level operation.
>
> On Wed, Oct 12, 2016 at 9:35 AM, Raul Miller <rauldmil...@gmail.com>
> wrote:
>
> > I'm not quite sure I understand what you are doing here.
> >
> > Here's what I understand from your description:
> >
> > You're looking for rows where a bit set in X has a bit set in Y, and
> > you want to split up X and Y into smaller pieces for your intermediate
> > result, and you want to use indices rather than bit operations for
> > your final operation.
> >
> > That gives me something like this.
> >
> >    X =: ? 5 $ 2
> >    Y =: 30 > ? 5 6 $ 100
> >    X
> > 0 1 1 1 1
> >    Y
> > 0 0 0 0 0 0
> > 1 0 0 0 0 0
> > 1 1 1 0 0 1
> > 1 0 0 1 0 0
> > 0 0 0 0 0 1
> >    (_2 {. X) inds _2 {. Y
> > 0 3 5
> >    (3 {. X) inds 3 {. Y
> > 0 1 2 5
> >    0 3 5 ([ -. -.) 0 1 2 5
> > 0 5
> >
> > So maybe you would be looking at making an adverb along the lines of:
> >
> > L=: adverb define
> > :
> >    (m {. x) inds m {. y
> > )
> >
> > Or, more concisely:
> >
> > L=: adverb define
> >    inds&(m&{.)
> > )
> >
> > But when I look at your calculations, I don't see anything like this.
> >
> > If I am off base here, could you describe how what you are looking for
> > differs from what I am understanding?
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> > On Wed, Oct 12, 2016 at 12:14 PM, Michal Dobrogost
> > <michal.dobrog...@gmail.com> wrote:
> > > Hi All,
> > >
> > > I've been mucking around generating look up tables in C++. Getting
> > > frustrated, I wrote up this J single liner. Can you think of ways to
> > > simplify the LUT computation (the expression we assign to L2 and L3
> > below)?
> > >
> > > *Original Operator (no LUT)*
> > >
> > >    ] x =. ? 5 $ 2
> > > 1 0 1 1 0
> > >    ] y =. 30 > ? 5 6 $ 100
> > > 1 0 0 0 0 0
> > > 0 1 0 1 1 0
> > > 0 1 0 0 0 1
> > > 0 0 0 0 1 1
> > > 0 1 1 1 0 1
> > >    x (+./@:*.) y
> > > 1 1 0 0 1 1
> > >
> > > *LUT Explanation*
> > >
> > > The idea is to break up x into smaller chunks (2-bits, 3-bits, etc) and
> > > precompute the operation for the corresponding chunks of y. Then we
> just
> > > convert the chunks into indices and look them up in the LUT.
> > >
> > >    _2<\x
> > > ┌───┬───┬─┐
> > > │1 0│1 1│0│
> > > └───┴───┴─┘
> > >    _2#.\x
> > > 2 3 0
> > >
> > > *2-bit LUT*
> > >
> > >    ]L2=. _2((#:@:i.@:(2&^)@:#) (+./"2 @: (*."0 1"1 _)) ])\y
> > > 0 0 0 0 0 0
> > > 0 1 0 1 1 0
> > > 1 0 0 0 0 0
> > > 1 1 0 1 1 0
> > >
> > > 0 0 0 0 0 0
> > > 0 0 0 0 1 1
> > > 0 1 0 0 0 1
> > > 0 1 0 0 1 1
> > >
> > > 0 0 0 0 0 0
> > > 0 1 1 1 0 1
> > > 0 0 0 0 0 0
> > > 0 0 0 0 0 0
> > >
> > >    +./ (_2#.\x) {"0 2 L2    NB. Compute by 2-bit lookups
> > > 1 1 0 0 1 1
> > >
> > > *3-Bit LUT*
> > >
> > >    ]L3=. _3((#:@:i.@:(2&^)@:#) (+./"2 @: (*."0 1"1 _)) ])\y
> > > 0 0 0 0 0 0
> > > 0 1 0 0 0 1
> > > 0 1 0 1 1 0
> > > 0 1 0 1 1 1
> > > 1 0 0 0 0 0
> > > 1 1 0 0 0 1
> > > 1 1 0 1 1 0
> > > 1 1 0 1 1 1
> > >
> > > 0 0 0 0 0 0
> > > 0 1 1 1 0 1
> > > 0 0 0 0 1 1
> > > 0 1 1 1 1 1
> > > 0 0 0 0 0 0
> > > 0 0 0 0 0 0
> > > 0 0 0 0 0 0
> > > 0 0 0 0 0 0
> > >
> > >    +./ (_3#.\x) {"0 2 L3    NB. Compute by 3-bit lookups
> > > 1 1 0 0 1 1
> > > ----------------------------------------------------------------------
> > > 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

Reply via email to