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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2005, 2006,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7618
diff changeset
2 ## 2007, 2008 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
18 ## <http://www.gnu.org/licenses/>.
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
19
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3456
diff changeset
20 ## -*- texinfo -*-
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3456
diff changeset
21 ## @deftypefn {Function File} {} triu (@var{a}, @var{k})
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
22 ## See tril.
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3456
diff changeset
23 ## @end deftypefn
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
24
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
25 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
26
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
27 function retval = triu (x, k)
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
28
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
33 [nr, nc] = size (x);
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
34 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
35 if (nargin == 1)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
36 k = 0;
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
37 elseif (nargin == 2)
1083
fb8ca633c439 [project @ 1995-01-28 19:24:32 by jwe]
jwe
parents: 1014
diff changeset
38 if ((k > 0 && k > nc) || (k < 0 && k < -nr))
1518
84bd88b8acee [project @ 1995-10-04 03:35:16 by jwe]
jwe
parents: 1315
diff changeset
39 error ("triu: requested diagonal out of range");
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
40 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
41 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5731
diff changeset
42 print_usage ();
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
43 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
9e4e71b27b3a [project @ 1996-03-20 11:10:42 by jwe]
jwe
parents: 1887
diff changeset
46 for j = max (1, k+1) : nc
1083
fb8ca633c439 [project @ 1995-01-28 19:24:32 by jwe]
jwe
parents: 1014
diff changeset
47 nr_limit = min (nr, j-k);
fb8ca633c439 [project @ 1995-01-28 19:24:32 by jwe]
jwe
parents: 1014
diff changeset
48 retval (1:nr_limit, j) = x (1:nr_limit, j);
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
49 endfor
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
50
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
51 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
52
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
53 %!test
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
54 %! a = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
55 %!
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
56 %! u0 = [1, 2, 3; 0, 5, 6; 0, 0, 9; 0, 0, 0];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
57 %! u1 = [0, 2, 3; 0, 0, 6; 0, 0, 0; 0, 0, 0];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
58 %! u2 = [0, 0, 3; 0, 0, 0; 0, 0, 0; 0, 0, 0];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
59 %! u3 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
60 %! um1 = [1, 2, 3; 4, 5, 6; 0, 8, 9; 0, 0, 12];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
61 %! um2 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 0, 11, 12];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
62 %! um3 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12];
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
63 %!
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
64 %! assert((triu (a, -3) == um3 && triu (a, -2) == um2
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
65 %! && triu (a, -1) == um1 && triu (a) == u0 && triu (a, 1) == u1
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
66 %! && triu (a, 2) == u2 && triu (a, 3) == u3));
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
67
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
68 %!error triu ();
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
69
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
70 %!error triu (1, 2, 3);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
71