Mercurial > octave
annotate libinterp/corefcn/tril.cc @ 28887:09c071328135
test: remove unnecessary BIST tests in C++ files checking for excessive number of inputs.
Remove BIST tests now that interpreter enforces calling function with no more than
the number of arguments defined in the function prototype.
* chol.cc, colamd.cc, colloc.cc, conv2.cc, data.cc, det.cc, dot.cc, eig.cc,
ellipj.cc, event-manager.cc, find.cc, gcd.cc, givens.cc, hash.cc, hess.cc,
hex2num.cc, input.cc, inv.cc, lu.cc, mappers.cc, max.cc, pr-output.cc, psi.cc,
qr.cc, schur.cc, sparse.cc, strfind.cc, strfns.cc, svd.cc, sylvester.cc,
time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, utils.cc, variables.cc,
gzip.cc, ov-class.cc, ov-fcn-handle.cc, ov.cc:
Remove unnecessary BIST tests checking for excessive number of inputs.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 09 Oct 2020 13:49:52 -0700 |
parents | 98192ec1621f |
children | 06c8e0877864 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 2004-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 #endif |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 #include <algorithm> |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 #include "Array.h" |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 #include "Sparse.h" |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 #include "mx-base.h" |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 #include "ov.h" |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 #include "Cell.h" |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
38 #include "defun.h" |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 #include "error.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
40 #include "ovl.h" |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 // The bulk of the work. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
43 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
44 static Array<T> |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 do_tril (const Array<T>& a, octave_idx_type k, bool pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 { |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
47 octave_idx_type nr = a.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
48 octave_idx_type nc = a.columns (); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 const T *avec = a.fortran_vec (); |
10258 | 50 octave_idx_type zero = 0; |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 if (pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
54 octave_idx_type j1 = std::min (std::max (zero, k), nc); |
10258 | 55 octave_idx_type j2 = std::min (std::max (zero, nr + k), nc); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 octave_idx_type n = j1 * nr + ((j2 - j1) * (nr-(j1-k) + nr-(j2-1-k))) / 2; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
57 Array<T> r (dim_vector (n, 1)); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 T *rvec = r.fortran_vec (); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 for (octave_idx_type j = 0; j < nc; j++) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 { |
10258 | 61 octave_idx_type ii = std::min (std::max (zero, j - k), nr); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 rvec = std::copy (avec + ii, avec + nr, rvec); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 avec += nr; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 return r; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 else |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 Array<T> r (a.dims ()); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 T *rvec = r.fortran_vec (); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
72 for (octave_idx_type j = 0; j < nc; j++) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
73 { |
10258 | 74 octave_idx_type ii = std::min (std::max (zero, j - k), nr); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
75 std::fill (rvec, rvec + ii, T ()); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 std::copy (avec + ii, avec + nr, rvec + ii); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 avec += nr; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
78 rvec += nr; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
79 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
80 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
81 return r; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
82 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
83 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
84 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
85 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
86 static Array<T> |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
87 do_triu (const Array<T>& a, octave_idx_type k, bool pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
88 { |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
89 octave_idx_type nr = a.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
90 octave_idx_type nc = a.columns (); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
91 const T *avec = a.fortran_vec (); |
10258 | 92 octave_idx_type zero = 0; |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
93 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
94 if (pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
95 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
96 octave_idx_type j1 = std::min (std::max (zero, k), nc); |
10258 | 97 octave_idx_type j2 = std::min (std::max (zero, nr + k), nc); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 octave_idx_type n |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 = ((j2 - j1) * ((j1+1-k) + (j2-k))) / 2 + (nc - j2) * nr; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
100 Array<T> r (dim_vector (n, 1)); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
101 T *rvec = r.fortran_vec (); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
102 for (octave_idx_type j = 0; j < nc; j++) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
103 { |
10258 | 104 octave_idx_type ii = std::min (std::max (zero, j + 1 - k), nr); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
105 rvec = std::copy (avec, avec + ii, rvec); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
106 avec += nr; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
107 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
108 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
109 return r; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
110 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
111 else |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
112 { |
27388
90dfdf0d09ad
Avoid unnecessary copy on return in triu (bug #56752).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
113 Array<T> r (a.dims ()); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
114 T *rvec = r.fortran_vec (); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
115 for (octave_idx_type j = 0; j < nc; j++) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
116 { |
10258 | 117 octave_idx_type ii = std::min (std::max (zero, j + 1 - k), nr); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
118 std::copy (avec, avec + ii, rvec); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
119 std::fill (rvec + ii, rvec + nr, T ()); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
120 avec += nr; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
121 rvec += nr; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
122 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
123 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
124 return r; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
125 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
126 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
127 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
128 // These two are by David Bateman. |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
129 // FIXME: optimizations possible. "pack" support missing. |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
130 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
131 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
132 static Sparse<T> |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
133 do_tril (const Sparse<T>& a, octave_idx_type k, bool pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
134 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
135 if (pack) // FIXME |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23583
diff
changeset
|
136 error (R"(tril: "pack" not implemented for sparse matrices)"); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
137 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
138 Sparse<T> m = a; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
139 octave_idx_type nc = m.cols (); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
140 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
141 for (octave_idx_type j = 0; j < nc; j++) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
142 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) |
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
143 if (m.ridx (i) < j-k) |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
144 m.data(i) = 0.; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
145 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
146 m.maybe_compress (true); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
147 |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
148 return m; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
149 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
150 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
151 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
152 static Sparse<T> |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
153 do_triu (const Sparse<T>& a, octave_idx_type k, bool pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
154 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
155 if (pack) // FIXME |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23583
diff
changeset
|
156 error (R"(triu: "pack" not implemented for sparse matrices)"); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
157 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
158 Sparse<T> m = a; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
159 octave_idx_type nc = m.cols (); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
160 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
161 for (octave_idx_type j = 0; j < nc; j++) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
162 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) |
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
163 if (m.ridx (i) > j-k) |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
164 m.data(i) = 0.; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
165 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
166 m.maybe_compress (true); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
167 return m; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
168 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
169 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
170 // Convenience dispatchers. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
171 template <typename T> |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
172 static Array<T> |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
173 do_trilu (const Array<T>& a, octave_idx_type k, bool lower, bool pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
174 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
175 return lower ? do_tril (a, k, pack) : do_triu (a, k, pack); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
176 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
177 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
178 template <typename T> |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
179 static Sparse<T> |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
180 do_trilu (const Sparse<T>& a, octave_idx_type k, bool lower, bool pack) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
181 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
182 return lower ? do_tril (a, k, pack) : do_triu (a, k, pack); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
183 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
184 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
185 static octave_value |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
186 do_trilu (const std::string& name, |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
187 const octave_value_list& args) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
188 { |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
189 bool lower = (name == "tril"); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
190 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
191 int nargin = args.length (); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
192 bool pack = false; |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
193 |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
194 if (nargin >= 2 && args(nargin-1).is_string ()) |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
195 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
196 pack = (args(nargin-1).string_value () == "pack"); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
197 nargin--; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
198 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
199 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
200 if (nargin < 1 || nargin > 2) |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
201 print_usage (); |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
202 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
203 octave_idx_type k = 0; |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
204 if (nargin == 2) |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20974
diff
changeset
|
205 k = args(1).idx_type_value (true); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
206 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
207 octave_value arg = args(0); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
208 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
209 dim_vector dims = arg.dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
210 if (dims.ndims () != 2) |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
211 error ("%s: need a 2-D matrix", name.c_str ()); |
28110
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
212 else if (k < -dims(0)) |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
213 k = -dims(0); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
214 else if (k > dims(1)) |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
215 k = dims(1); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
216 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
217 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
218 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
219 switch (arg.builtin_type ()) |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
220 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
221 case btyp_double: |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
222 if (arg.issparse ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
223 retval = do_trilu (arg.sparse_matrix_value (), k, lower, pack); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
224 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
225 retval = do_trilu (arg.array_value (), k, lower, pack); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
226 break; |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
227 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
228 case btyp_complex: |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
229 if (arg.issparse ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
230 retval = do_trilu (arg.sparse_complex_matrix_value (), k, lower, |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
231 pack); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
232 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
233 retval = do_trilu (arg.complex_array_value (), k, lower, pack); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
234 break; |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
235 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
236 case btyp_bool: |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
237 if (arg.issparse ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
238 retval = do_trilu (arg.sparse_bool_matrix_value (), k, lower, |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
239 pack); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
240 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
241 retval = do_trilu (arg.bool_array_value (), k, lower, pack); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
242 break; |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
243 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
244 #define ARRAYCASE(TYP) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
245 case btyp_ ## TYP: \ |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
246 retval = do_trilu (arg.TYP ## _array_value (), k, lower, pack); \ |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
247 break |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
248 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
249 ARRAYCASE (float); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
250 ARRAYCASE (float_complex); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
251 ARRAYCASE (int8); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
252 ARRAYCASE (int16); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
253 ARRAYCASE (int32); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
254 ARRAYCASE (int64); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
255 ARRAYCASE (uint8); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
256 ARRAYCASE (uint16); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
257 ARRAYCASE (uint32); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
258 ARRAYCASE (uint64); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
259 ARRAYCASE (char); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
260 |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
261 #undef ARRAYCASE |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
262 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
263 default: |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
264 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
265 // Generic code that works on octave-values, that is slow |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
266 // but will also work on arbitrary user types |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
267 if (pack) // FIXME |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23583
diff
changeset
|
268 error (R"(%s: "pack" not implemented for class %s)", |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
269 name.c_str (), arg.class_name ().c_str ()); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
270 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
271 octave_value tmp = arg; |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
272 if (arg.isempty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
273 return arg; |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
274 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
275 octave_idx_type nr = dims(0); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
276 octave_idx_type nc = dims(1); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
277 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
278 // The sole purpose of this code is to force the correct matrix size. |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
279 // This would not be necessary if the octave_value resize function |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
280 // allowed a fill_value. It also allows odd attributes in some user |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
281 // types to be handled. With a fill_value, it should be replaced with |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
282 // |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
283 // octave_value_list ov_idx; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
284 // tmp = tmp.resize(dim_vector (0,0)).resize (dims, fill_value); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
285 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
286 octave_value_list ov_idx; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
287 std::list<octave_value_list> idx_tmp; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
288 ov_idx(1) = static_cast<double> (nc+1); |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28631
diff
changeset
|
289 ov_idx(0) = octave::range<double> (1, nr); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
290 idx_tmp.push_back (ov_idx); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
291 ov_idx(1) = static_cast<double> (nc); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
292 tmp = tmp.resize (dim_vector (0,0)); |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28110
diff
changeset
|
293 tmp = tmp.subsasgn ("(", idx_tmp, arg.index_op (ov_idx)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
294 tmp = tmp.resize (dims); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
295 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
296 if (lower) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
297 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
298 octave_idx_type st = (nc < nr + k ? nc : nr + k); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
299 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
300 for (octave_idx_type j = 1; j <= st; j++) |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
301 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
302 octave_idx_type nr_limit = (1 > j - k ? 1 : j - k); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
303 ov_idx(1) = static_cast<double> (j); |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28631
diff
changeset
|
304 ov_idx(0) = octave::range<double> (nr_limit, nr); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
305 std::list<octave_value_list> idx; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
306 idx.push_back (ov_idx); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
307 |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28110
diff
changeset
|
308 tmp = tmp.subsasgn ("(", idx, arg.index_op (ov_idx)); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
309 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
310 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
311 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
312 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
313 octave_idx_type st = (k + 1 > 1 ? k + 1 : 1); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
314 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
315 for (octave_idx_type j = st; j <= nc; j++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
316 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
317 octave_idx_type nr_limit = (nr < j - k ? nr : j - k); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
318 ov_idx(1) = static_cast<double> (j); |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28631
diff
changeset
|
319 ov_idx(0) = octave::range<double> (1, nr_limit); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
320 std::list<octave_value_list> idx; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
321 idx.push_back (ov_idx); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
322 |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28110
diff
changeset
|
323 tmp = tmp.subsasgn ("(", idx, arg.index_op (ov_idx)); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
324 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
325 } |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
326 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
327 retval = tmp; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
328 } |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
329 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
330 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
331 return retval; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
332 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
333 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
334 DEFUN (tril, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
335 doc: /* -*- texinfo -*- |
25018
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
336 @deftypefn {} {@var{A_LO} =} tril (@var{A}) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
337 @deftypefnx {} {@var{A_LO} =} tril (@var{A}, @var{k}) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
338 @deftypefnx {} {@var{A_LO} =} tril (@var{A}, @var{k}, @var{pack}) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
339 Return a new matrix formed by extracting the lower triangular part of the |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
340 matrix @var{A}, and setting all other elements to zero. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
341 |
25018
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
342 The optional second argument specifies how many diagonals above or below the |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
343 main diagonal should also be set to zero. The default value of @var{k} is |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
344 zero which includes the main diagonal as part of the result. If the value of |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
345 @var{k} is a nonzero integer then the selection of elements starts at an offset |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
346 of @var{k} diagonals above the main diagonal for positive @var{k} or below the |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
347 main diagonal for negative @var{k}. The absolute value of @var{k} may not be |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
348 greater than the number of subdiagonals or superdiagonals. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
349 |
25018
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
350 Example 1 : exclude main diagonal |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
351 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
352 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
353 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
354 tril (ones (3), -1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
355 @result{} 0 0 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
356 1 0 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
357 1 1 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
358 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
359 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
360 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
361 @noindent |
25018
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
362 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
363 Example 2 : include first superdiagonal |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
364 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
365 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
366 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
367 tril (ones (3), 1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
368 @result{} 1 1 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
369 1 1 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
370 1 1 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
371 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
372 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
373 |
25018
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
374 If the optional third argument @qcode{"pack"} is given then the extracted |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
375 elements are not inserted into a matrix, but instead stacked column-wise one |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
376 above another, and returned as a column vector. |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
377 @seealso{triu, istril, diag} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
378 @end deftypefn */) |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
379 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
380 return do_trilu ("tril", args); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
381 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
382 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
383 DEFUN (triu, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
384 doc: /* -*- texinfo -*- |
25018
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
385 @deftypefn {} {@var{A_UP} =} triu (@var{A}) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
386 @deftypefnx {} {@var{A_UP} =} triu (@var{A}, @var{k}) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
387 @deftypefnx {} {@var{A_UP} =} triu (@var{A}, @var{k}, @var{pack}) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
388 Return a new matrix formed by extracting the upper triangular part of the |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
389 matrix @var{A}, and setting all other elements to zero. |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
390 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
391 The optional second argument specifies how many diagonals above or below the |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
392 main diagonal should also be set to zero. The default value of @var{k} is |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
393 zero which includes the main diagonal as part of the result. If the value of |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
394 @var{k} is a nonzero integer then the selection of elements starts at an offset |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
395 of @var{k} diagonals above the main diagonal for positive @var{k} or below the |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
396 main diagonal for negative @var{k}. The absolute value of @var{k} may not be |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
397 greater than the number of subdiagonals or superdiagonals. |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
398 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
399 Example 1 : exclude main diagonal |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
400 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
401 @example |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
402 @group |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
403 triu (ones (3), 1) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
404 @result{} 0 1 1 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
405 0 0 1 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
406 0 0 0 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
407 @end group |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
408 @end example |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
409 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
410 @noindent |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
411 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
412 Example 2 : include first subdiagonal |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
413 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
414 @example |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
415 @group |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
416 triu (ones (3), -1) |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
417 @result{} 1 1 1 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
418 1 1 1 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
419 0 1 1 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
420 @end group |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
421 @end example |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
422 |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
423 If the optional third argument @qcode{"pack"} is given then the extracted |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
424 elements are not inserted into a matrix, but instead stacked column-wise one |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
425 above another, and returned as a column vector. |
ed3d7a33551b
doc: Redo documentation for tril and triu.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
426 @seealso{tril, istriu, diag} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
427 @end deftypefn */) |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
428 { |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
429 return do_trilu ("triu", args); |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
430 } |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
431 |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
432 /* |
28110
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
433 %!shared a, l2, l1, l0, lm1, lm2, lm3, lm4 |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
434 %! a = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
435 %! |
28110
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
436 %! l2 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
437 %! l1 = [1, 2, 0; 4, 5, 6; 7, 8, 9; 10, 11, 12]; |
28110
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
438 %! l0 = [1, 0, 0; 4, 5, 0; 7, 8, 9; 10, 11, 12]; |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
439 %! lm1 = [0, 0, 0; 4, 0, 0; 7, 8, 0; 10, 11, 12]; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
440 %! lm2 = [0, 0, 0; 0, 0, 0; 7, 0, 0; 10, 11, 0]; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
441 %! lm3 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 10, 0, 0]; |
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
442 %! lm4 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
443 %! |
28110
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
444 %!assert (tril (a, 3), l2); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
445 %!assert (tril (a, 2), l2); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
446 %!assert (tril (a, 1), l1); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
447 %!assert (tril (a, 0), l0); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
448 %!assert (tril (a), l0); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
449 %!assert (tril (a, -1), lm1); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
450 %!assert (tril (a, -2), lm2); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
451 %!assert (tril (a, -3), lm3); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
452 %!assert (tril (a, -4), lm4); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
453 %!assert (tril (a, -5), lm4); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
454 |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
455 %!shared a, u3, u2, u1, u0, um1, um2, um3 |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
456 %! |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
457 %! a = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
458 %! |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
459 %! u3 = [0, 0, 0; 0, 0, 0; 0, 0, 0; 0, 0, 0]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
460 %! u2 = [0, 0, 3; 0, 0, 0; 0, 0, 0; 0, 0, 0]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
461 %! u1 = [0, 2, 3; 0, 0, 6; 0, 0, 0; 0, 0, 0]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
462 %! u0 = [1, 2, 3; 0, 5, 6; 0, 0, 9; 0, 0, 0]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
463 %! um1 = [1, 2, 3; 4, 5, 6; 0, 8, 9; 0, 0, 12]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
464 %! um2 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 0, 11, 12]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
465 %! um3 = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12]; |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
466 %! |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
467 %!assert (triu (a, 4), u3); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
468 %!assert (triu (a, 3), u3); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
469 %!assert (triu (a, 2), u2); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
470 %!assert (triu (a, 1), u1); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
471 %!assert (triu (a, 0), u0); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
472 %!assert (triu (a), u0); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
473 %!assert (triu (a, -1), um1); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
474 %!assert (triu (a, -2), um2); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
475 %!assert (triu (a, -3), um3); |
91f245908132
allow K to be out of range in tril and triu functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
476 %!assert (triu (a, -4), um3); |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
477 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
478 %!error tril () |
28887
09c071328135
test: remove unnecessary BIST tests in C++ files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28638
diff
changeset
|
479 %!error <Invalid call> triu () |
9756
b134960cea23
implement built-in tril/triu
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
480 */ |