From octave-maintainers-request at bevo dot che dot wisc dot edu Fri Dec 1 10:42:25 2000 Subject: set patch From: "Lippert, Ross A." To: "'octave-maintainers at octave dot org'" Date: Fri, 1 Dec 2000 11:41:35 -0500 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C05BB5.955DB14C Content-Type: text/plain; charset="iso-8859-1" Faster intersection and complement. Aesthetically more pleasing (well to me anyway) create_set. Here is the diff -c -r <> ------_=_NextPart_000_01C05BB5.955DB14C Content-Type: application/octet-stream; name="setpatch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="setpatch" ? octave/scripts/set/Makefile Index: octave/scripts/set/complement.m =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/octave/scripts/set/complement.m,v retrieving revision 1.12 diff -c -r1.12 complement.m *** octave/scripts/set/complement.m 2000/01/13 08:40:21 1.12 --- octave/scripts/set/complement.m 2000/12/01 16:39:12 *************** *** 32,37 **** --- 32,38 ---- ## at seealso{create_set, union, and intersection} =20 ## Author: jwe + ## Modified: Ross Lippert =20 function y =3D complement (a, b) =20 *************** *** 40,59 **** endif =20 if (isempty (a)) ! y =3D create_set(b); elseif (isempty (b)) y =3D []; else a =3D create_set (a); b =3D create_set (b); ! yindex =3D 1; ! y =3D zeros (1, length (b)); ! for index =3D 1:length (b) ! if (all (a !=3D b (index))) ! y(yindex++) =3D b(index); ! endif ! endfor ! y =3D y(1:(yindex-1)); endif =20 endfunction --- 41,64 ---- endif =20 if (isempty (a)) ! y =3D create_set (b); elseif (isempty (b)) y =3D []; else + ## why can't we just assume a and b are already sets? Why can't + ## that be a requirement of intersection? -Ross a =3D create_set (a); b =3D create_set (b); !=20 ! # Is doubling up on a here the right idea or just a shameful hack? -R ! y =3D sort([a a b]); ! c =3D find([nan y]!=3D[y nan]); ! y =3D y( c( find( diff( c)=3D=3D1) ) ); endif =20 endfunction +=20 +=20 +=20 +=20 +=20 Index: octave/scripts/set/create_set.m =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/octave/scripts/set/create_set.m,v retrieving revision 1.16 diff -c -r1.16 create_set.m *** octave/scripts/set/create_set.m 2000/10/31 02:08:49 1.16 --- octave/scripts/set/create_set.m 2000/12/01 16:39:12 *************** *** 20,26 **** ## -*- texinfo -*- ## at deftypefn {Function File} {} create_set (@var{x}) ## Return a row vector containing the unique values in at var{x}, = sorted in ! ## ascending order. For example, ## ## at example ## at group --- 20,27 ---- ## -*- texinfo -*- ## at deftypefn {Function File} {} create_set (@var{x}) ## Return a row vector containing the unique values in at var{x}, = sorted in ! ## ascending order. Returns a row vector containing the frequencies = of ! ## those values in at var{x} in a second argument. For example, ## ## at example ## at group *************** *** 32,37 **** --- 33,39 ---- ## at seealso{union, intersection, and complement} =20 ## Author: jwe + ## Modified: Ross Lippert =20 function y =3D create_set(x) =20 *************** *** 45,56 **** [nrx, ncx] =3D size (x); nelx =3D nrx * ncx; y =3D sort (reshape (x, 1, nelx)); ! els =3D find (y(1:nelx-1) !=3D y(2:nelx)); ! if (isempty (els)); ! y =3D y(1); ! else ! y =3D y([1, els+1]); ! endif endif =20 endfunction --- 47,58 ---- [nrx, ncx] =3D size (x); nelx =3D nrx * ncx; y =3D sort (reshape (x, 1, nelx)); ! c =3D find([nan y]!=3D[y nan]); ! y =3D y(c(1:length(c)-1)); endif =20 endfunction +=20 +=20 +=20 +=20 Index: octave/scripts/set/intersection.m =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/octave/scripts/set/intersection.m,v retrieving revision 1.11 diff -c -r1.11 intersection.m *** octave/scripts/set/intersection.m 2000/01/13 08:40:22 1.11 --- octave/scripts/set/intersection.m 2000/12/01 16:39:12 *************** *** 32,37 **** --- 32,38 ---- ## at seealso{create_set, union, and complement} =20 ## Author: jwe + ## Modified: Ross Lippert =20 function y =3D intersection(a,b) =20 *************** *** 44,70 **** return; endif =20 a =3D create_set(a); b =3D create_set(b); =20 ! if(length(a) < length(b)) ! yindex =3D 1; ! y =3D zeros(1,length(a)); ! for index =3D 1:length(a) ! if(any(b =3D=3D a(index))) ! y(yindex++) =3D a(index); ! endif ! endfor ! else ! yindex =3D 1; ! y =3D zeros(1,length(b)); ! for index =3D 1:length(b) ! if(any(a =3D=3D b(index))) ! y(yindex++) =3D b(index); ! endif ! endfor ! endif !=20 ! y =3D y(1:(yindex-1)); =20 endfunction --- 45,58 ---- return; endif =20 + ## why can't we just assume a and b are already sets? Why can't + ## that be a requirement of intersection? -Ross a =3D create_set(a); b =3D create_set(b); =20 ! y =3D sort([a b]); ! c =3D find([nan y]!=3D[y nan]); ! y =3D y( c( find( diff( c)=3D=3D2) ) ); =20 endfunction +=20 ------_=_NextPart_000_01C05BB5.955DB14C--