changeset 2762:aad1f069f8a1 octave-forge

Optimisation.
author sis-sou
date Tue, 21 Nov 2006 19:56:23 +0000
parents 2abd3e8ac3fc
children dac5bde4a3ea
files main/general/inst/issorted.m
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/main/general/inst/issorted.m	Mon Nov 20 18:49:51 2006 +0000
+++ b/main/general/inst/issorted.m	Tue Nov 21 19:56:23 2006 +0000
@@ -21,15 +21,17 @@
 ## @seealso{sort, sortrows}
 ## @end deftypefn
 
-function y = issorted(x,str)
+function y = issorted2(x,str)
 	if(nargin == 0)
 		usage(" \n issorted(x) \n issorted(A,'rows')");
 	else
 		if(nargin == 1)
-			y = all(all(x == sort(x)));
+			y = all(all(diff(x)>=0));
 		else
 			if(nargin == 2 && str == 'rows')
-				y = all(all(x == sortrows(x)));
+				t = sign(diff(x)); # t contains -1, 0, or 1
+   			t(t==1) = columns(x); # t contains -1, 0, or n
+   			y = all(all (cumsum(t,2) >= 0));
 			else
 				error("The second argument must be equal to 'rows'\n");
 			endif;