changeset 19979:941e782d0429

gallery: performance increase for minij matrix. * special-matrix/gallery.m: make use of broadcasting @min for performance increase. The increase is dependent on the value N, as it avoids the construction of 2 NxN matrices.
author Carnë Draug <carandraug@octave.org>
date Sat, 14 Mar 2015 14:52:58 +0000
parents 88233ac3f3ea
children f7a805f02723
files scripts/special-matrix/gallery.m
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/special-matrix/gallery.m	Sat Mar 14 15:20:51 2015 +0100
+++ b/scripts/special-matrix/gallery.m	Sat Mar 14 14:52:58 2015 +0000
@@ -1784,7 +1784,7 @@
     error ("gallery: N must be an integer for minij matrix.");
   endif
 
-  A = min (ones (n, 1) * (1:n), (1:n)' * ones (1, n));
+  A = bsxfun (@min, 1:n, (1:n)');
 endfunction
 
 function A = moler (n, alpha = -1)
@@ -2867,3 +2867,7 @@
 %!error <matrix binomial not implemented> gallery ("binomial")
 %!error <unknown matrix with NAME foobar> gallery ("foobar")
 
+%!assert (gallery ("minij", 4), [1 1 1 1; 1 2 2 2; 1 2 3 3; 1 2 3 4])
+%!assert (gallery ("minij", 1), 1)
+%!assert (gallery ("minij", 0), [])
+%!assert (gallery ("minij", -1), [])