a. The sizes of the arguments p1 and p2 are not commensurate 
with the times you are reporting.  You either have a very 
slow machine or the arguments are peculiar.

b. There is no significant performance difference between 
i. e. ~: ~. etc.  They all invoke the same underlying routine.

c. The routine uses hashing to the extent that it can.
Certain types of arguments prevent hashing from being
effective:
- boxed numerics
- floating point matrices with mostly the same value
in column 0 
etc.

d. If >p1 and >p2 are legal, try  e.&:> to see if that is 
significantly faster.

e. If you don't care about tolerance e.!.0 could be
significantly faster than e. .



----- Original Message ----- 
From: "Sashikanth Chandrasekaran" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, April 03, 2006 6:20 PM
Subject: [Jprogramming] e. sensitive to the selectivity of the operands?

Dear J programmers,

Consider two nouns p1, p2 such that most of the
elements of p1 are in p2 but a few of the elements of
p2 are in p1. In my example, all elements of p1 and p2
are unique.

Here is a transcript of my J504 session on Windows:

NB. begin session

   (# ; (3!:0)) p1
+----+--+
|1393|32|
+----+--+
   (# ; (3!:0)) p2
+----+--+
|4873|32|
+----+--+
   6!:2 'r1 =. p1 e. p2'
9.56689
   6!:2 'r2 =. p2 e. p1'
2.40757

   NB. show the differences in selectivity
   (+/ r1) % #p1
0.996411
   (+/ r2) % #p2
0.284835

   NB. show that elements of p1, p2 are unique.
   +/ ~: p1
1393
   +/ ~: p2
4873

   NB. obverse of I. (x. is length of boolean mask)
   invI =: 4 : '1 (y.}) x. # 0' 

   NB. Rephrase e. using i.
   6!:2 'r3 =. p1 (#@:[ invI (i. -. #@:[)) p2'
2.40749
   r3 -: r1
1
   6!:2 'r3 =. p1 ([: }: >:@:#@:[ invI i.) p2'
2.40755
   r3 -: r1
1

   NB. Good for the goose, but not for the gander
   6!:2 'r4 =. p2 (#@:[ invI (i. -. #@:[)) p1'
9.57313
   r4 -: r2
1

NB. end session

Assume that I do not know the distributions of p1, p2
in advance. Is there a way I can get consistent avg.
performance (i.e. 6!:2 'p1 V p2' = approx. 6 seconds
and 6!:2 'p2 V p1' = approx. 6 seconds).

Thanks, -sashi.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to