Right... ts 'sum"1 m' 1.26399277 8389888 ts 'sumr m' 0.120972917 8391232
Yet, fixing can also be an alternative in this case... ts 'sum"1 f. m' 0.114741119 8390208 ----- Original Message ---- From: Roger Hui <[EMAIL PROTECTED]> To: Programming forum <[email protected]> Sent: Thursday, September 18, 2008 11:39:01 AM Subject: Re: [Jprogramming] Applying Amend on each row The improvement in time likely did not come from tacit vs. explicit (which typically would be less than a factor of 2), but from primitive verbs operating on much larger chunks of data. The following example illustrates this point: sum=: +/ sumr=: 3 : '+/"1 y' m=: 1e6 10 [EMAIL PROTECTED] 0 ts=: 6!:2 , 7!:[EMAIL PROTECTED] ts 'sum"1 m' 0.646326 8.38989e6 ts 'sumr m' 0.0631888 8.39123e6 Here, the explicit sumr is faster than the tacit sum"1 . With sumr m the primitives see the entire of m; with sum"1 the primitives see m one row at a time. ----- Original Message ----- From: Alex Rufon <[EMAIL PROTECTED]> Date: Thursday, September 18, 2008 4:24 Subject: RE: [Jprogramming] Applying Amend on each row To: Programming forum <[email protected]> > The tacit definition is WAY faster than using a for loop on > large amount > of data. > M=: ((1024*1024),4)[EMAIL PROTECTED] > ts 'amendZeros M' > 0.11664729735203776 71304192 > ts '_ amendEachZero M' > 5.4896494526538984 67112768 > > Hmmm. This really is a big incentive to learning tacit programming. > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Alex Rufon > Sent: Thursday, September 18, 2008 7:07 PM > To: Programming forum > Subject: RE: [Jprogramming] Applying Amend on each row > > Hi, > > It took me a while to understand what you were doing. > > If parse the code manually, this is what I'll get: > M > 6 5 9 2 > 4 9 0 7 > 0 4 6 8 > 3 8 1 2 > M - (0 i. M) { _ 0 > 6 5 9 2 > 4 9 __ 7 > __ 4 6 8 > 3 8 1 2 > > Hahahah. It took me a while to get it. > > Thanks. > > r/alex > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of R.E. Boss > Sent: Thursday, September 18, 2008 5:22 PM > To: 'Programming forum' > Subject: RE: [Jprogramming] Applying Amend on each row > > rpl=:] - (-/ , 0:)@[ {~ [EMAIL PROTECTED] i. ] NB. from rpl2a in > NB. http://www.jsoftware.com/pipermail/programming/2007- > July/007303.html > [temp=. 2 5 ? 10 > 2 4 0 0 0 > 4 0 9 7 5 > > (0,:_) rpl temp > 2 4 _ _ _ > 4 _ 9 7 5 > > > R.E. Boss > > > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Namens Alex Rufon > Verzonden: donderdag 18 september 2008 10:44 > Aan: Programming forum > Onderwerp: [Jprogramming] Applying Amend on each row > > Hi. > > What I want to do is to replace all zero in the matrix with infinity. > > This is my solution and it works as expected: > amendEachZero=: dyad define > NB. Get the passed parameters > newval=. x > source=. Y > > NB. Loop through each row > for_xyz. source do. > NB. Replace each 0 with a new value > source=. (newval (I. 0 = xyz)} xyz) xyz_index } source > end. > > NB. Return the result > source > ) > > As you can see, this works: > [temp=. 2 5 ? 10 > 5 7 0 0 0 > 3 6 0 5 4 > _ amendEachZero temp > 5 7 _ _ _ > 3 6 _ 5 4 > > But what I really wanted to do was make a tacit definition which would > not require the explicit for_xyz. Loop. > > So how do I apply the (I. 0 =) to each row of a 2 dimension > matrix, then > use that as an the index to an amend operation? Am I approaching this > problem wrong? > > This is actually an extension of the verb conjunction discussion I > started earlier which actually means ... I still haven't > understood how > to use them. :P > > Thanks for any help. > > r/alex ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
