The difference seems negligible and it's hard to imagine a case where this would be a bottleneck but the equivalence version is more straightforward and simpler to read.
m1=. m2=. 1000 1000?@$2e9 NB. Integers (100) 6!:2 'm1-:m2' 1.39989e_6 (100) 6!:2 '(<m1) = <m2' 2.08957e_6 m1=. (1+m1{~ix) (ix=. <?$m1)}m1 NB. One element difference (100) 6!:2 'm1-:m2' 0.000489653 (100) 6!:2 '(<m1) = <m2' 0.000421613 m2=. (1+m2{~ix) (ix)}m2 NB. Change m2 to match (100) 6!:2 'm1-:m2' 0.00116565 (100) 6!:2 '(<m1) = <m2' 0.00109277 m1=. m2=. 1000 1000?@$0 NB. Floating-point (100) 6!:2 '(<m1) = <m2' 2.13473e_6 (100) 6!:2 'm1-:m2' 1.29315e_6 m1=. (1.00001*m1{~ix) (ix=. <?$m1)}m1 (100) 6!:2 '(<m1) = <m2' 0.000613599 (100) 6!:2 'm1-:m2' 0.00059765 m2=. m1=. <:+:1000 1000?@$0 m1-:m2 [ m1=. %.m1 [ m2=. %.m2 1 (100) 6!:2 '(<m1) = <m2' 0.00546757 (100) 6!:2 'm1-:m2' 0.00566366 m1-:m2 [ m2=. +:m2 [ m1=. 2*m1 1 (100) 6!:2 '(<m1) = <m2' 0.00527504 (100) 6!:2 'm1-:m2' 0.00525394 m1-:m2 [ m1=. %:m1 [ m2=. %:m2 NB. Complex 1 (100) 6!:2 'm1-:m2' 0.0163895 (100) 6!:2 '(<m1) = <m2' 0.0153239 m1=. (1+m1{~ix) (ix=. <?$m1)}m1 (100) 6!:2 'm1-:m2' 0.0153072 (100) 6!:2 '(<m1) = <m2' 0.0156345 On Mon, Nov 24, 2014 at 8:39 AM, Jon Hough <jgho...@outlook.com> wrote: > This seems to work. Thanks. > I'm assuming this must be faster than boxing... > > > Date: Mon, 24 Nov 2014 08:33:42 -0500 > > From: devon...@gmail.com > > To: programm...@jsoftware.com > > Subject: Re: [Jprogramming] Best way to check matrix equality > > > > m1 -: m2 > > > > might be better. > > > > On Mon, Nov 24, 2014 at 8:30 AM, Jon Hough <jgho...@outlook.com> wrote: > > > > > What is the best (by which I mean fastest) way to test if two > > > matrices/tables of the same shapeare element-wise equal? > > > At the moment I always use < to box each matrix and then the equality > test > > > is simply to use =.But I am not sure if < is slow, or if there is a > better > > > way to do this. > > > e.g. if m1 is some matrix and I have another matrix m2, which has the > same > > > shape, I do: > > > (< m1) = (< m2) > > > Is this the preferred way? > > > Thanks,Jon > > > ---------------------------------------------------------------------- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > > > > > > > -- > > Devon McCormick, CFA > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Devon McCormick, CFA ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm