Hmm... meanwhile, for that bit density, Igor's solution also seems to
be slightly faster than an approach which does not box at all (though
maybe that's a benchmarking artifact), and I do not see any timing
difference between an L:0 and an &.> implementation of igor's
mechanism... or, maybe I do?
map=: 3 > ?3000 4000$100
m=: 10000+i.3000
n=: 100000+i.4000
timespacex '((m{~{.),.n{~{:)|:($ #: I.@,) map'
0.020877 2.51692e7
acp=: 1 : '; (<"0 x) ,"0 L: 0 m <@#"1 y'
timespacex 'm map acp n'
0.018302 2.20771e7
timespacex '((m{~{.),.n{~{:)|:($ #: I.@,) map'
0.0189 2.51692e7
timespacex 'm map acp n'
0.01667 2.20771e7
ACP=: 1 : '; (<"0 x) ,"0 &.> m <@#"1 y'
timespacex 'm map ACP n'
0.016675 1.71535e7
timespacex 'm map ACP n'
0.013092 1.71535e7
(((m{~{.),.n{~{:)|:($ #: I.@,) map) -: m map acp n
1
(m map ACP n) -: m map acp n
1
(I find this interesting.)
Thanks,
--
Raul
On Thu, Sep 23, 2021 at 10:58 AM Henry Rich <[email protected]> wrote:
>
> u L:0 on arrays with boxing level 1 is equivalent to u&.> (aka u each).
> &.> supports inplacing of the cells, while L: does not.
>
> Here Igor is doing less work than RE, boxing atoms of x only once.
>
> Henry Rich
>
>
> On 9/23/2021 10:18 AM, 'Michael Day' via Programming wrote:
> > I thought this should perform similarly to Igor's proposal, but
> > evidently not:
> >
> > NB. input:
> > $bigmap
> > 3000 4000
> > (+/%#) ,bigmap
> > 0.030052333
> > 10{.bigm
> > abcabcabca
> > 10{.bign
> > ABCDABCDAB
> >
> > NB. fns:
> > ts NB. timestamp
> >
> > 6!:2 , 7!:2@]
> >
> >
> > acp NB. IZ
> >
> > 1 : (':'; '; (<"0 x) ,"0 L: 0 m <@#"1 y')
> >
> >
> > ix NB. MD - index of ones in boolean
> > $ #: I.@,
> > doix MD. using the index
> > 4 : 0
> > 'mm nn' =. y
> > map =. x
> > 'ixl ixr' =. |: ix map
> > l =. ixl { mm
> > r =. ixr { nn
> > l,. r
> > )
> >
> >
> > ts'#bigmap ((#L:0"1{:),.&;~+/"1@[ #L:0 {.@]) bigm;bign' NB. RE Boss
> > 0.0317587 14097792
> > ts'bigm bigmap acp bign' NB. Igor Zhuravlov
> > 0.016309 3645696
> > ts'bigmap doix bigm;bign' NB. Mike Day
> > 0.0395122 16780064
> >
> >
> > It's clear I should learn how L: works; it apparently outclasses I.
> > for this problem,
> >
> > but why is its application by Igor so much quicker and slimmer than
> > REB's?
> >
> >
> > Cheers,
> >
> >
> > Mike
> >
> >
> >
> > On 23/09/2021 14:12, R.E. Boss wrote:
> >> map ((#L:0"1{:),.&;~+/"1@[ #L:0 {.@]) 'abc';'ABCD'
> >> aA
> >> aD
> >> bB
> >> bC
> >>
> >> My 2 cts.
> >>
> >>
> >> R.E. Boss
> >>
> >>
> >> -----Original Message-----
> >> From: Programming <[email protected]> On
> >> Behalf Of bill lam
> >> Sent: dinsdag 21 september 2021 11:38
> >> To: Programming forum <[email protected]>
> >> Subject: [Jprogramming] cross product
> >>
> >> Say I have a boolean matrix
> >> ] map=. 3 4 $ 1 0 0 1 0 1 1 0 0 0 0 0
> >> 1 0 0 1
> >> 0 1 1 0
> >> 0 0 0 0
> >>
> >> and 2 vectors of dimension equal to the 2 sides of the matrix
> >> m=. 'abc' [ n=. 'ABCD'
> >> I want a cross product for those 1 in the matrix, with result like
> >> this
> >> _2 ]\ 'aAaDbBbC'
> >> aA
> >> aD
> >> bB
> >> bC
> >>
> >> Is it possible to do it without explicit loops? The dimension of the
> >> matrix can be very large so that generating all cross products then
> >> eliminating is not an option.
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >
> >
> >
>
>
> --
> This email has been checked for viruses by AVG.
> https://www.avg.com
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm