Mercurial > hg > octave-nkf
annotate scripts/general/triu.m @ 9665:1dba57e9d08d
use blas_trans_type for xgemm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 10:41:07 +0200 |
parents | eb63fbe60fab |
children |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2005, 2006, |
8920 | 2 ## 2007, 2008 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
245 | 19 |
3458 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} triu (@var{a}, @var{k}) | |
3369 | 22 ## See tril. |
3458 | 23 ## @end deftypefn |
4 | 24 |
2314 | 25 ## Author: jwe |
26 | |
2311 | 27 function retval = triu (x, k) |
4 | 28 |
29 if (nargin > 0) | |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
30 if (isstruct (x)) |
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
31 error ("tril: structure arrays not supported"); |
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
32 endif |
4 | 33 [nr, nc] = size (x); |
34 endif | |
35 if (nargin == 1) | |
36 k = 0; | |
37 elseif (nargin == 2) | |
1083 | 38 if ((k > 0 && k > nc) || (k < 0 && k < -nr)) |
1518 | 39 error ("triu: requested diagonal out of range"); |
4 | 40 endif |
41 else | |
6046 | 42 print_usage (); |
4 | 43 endif |
44 | |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7411
diff
changeset
|
45 retval = resize (resize (x, 0), nr, nc); |
2015 | 46 for j = max (1, k+1) : nc |
1083 | 47 nr_limit = min (nr, j-k); |
48 retval (1:nr_limit, j) = x (1:nr_limit, j); | |
4 | 49 endfor |
50 | |
51 endfunction | |
7411 | 52 |
53 %!test | |
54 %! a = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; | |
55 %! | |
56 %! u0 = [1, 2, 3; 0, 5, 6; 0, 0, 9; 0, 0, 0]; | |
57 %! u1 = [0, 2, 3; 0, 0, 6; 0, 0, 0; 0, 0, 0]; | |
58 %! u2 = [0, 0, 3; 0, 0, 0; 0, 0, 0; 0, 0, 0]; | |
59 %! u3 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0]; | |
60 %! um1 = [1, 2, 3; 4, 5, 6; 0, 8, 9; 0, 0, 12]; | |
61 %! um2 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 0, 11, 12]; | |
62 %! um3 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; | |
63 %! | |
64 %! assert((triu (a, -3) == um3 && triu (a, -2) == um2 | |
65 %! && triu (a, -1) == um1 && triu (a) == u0 && triu (a, 1) == u1 | |
66 %! && triu (a, 2) == u2 && triu (a, 3) == u3)); | |
67 | |
68 %!error triu (); | |
69 | |
70 %!error triu (1, 2, 3); | |
71 |