annotate libinterp/octave-value/ov-perm.cc @ 27919:1891570abac8

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2020.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 22:29:51 -0500
parents b442ec6dda5c
children bd51beb6205e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
1 /*
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 Copyright (C) 2008-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26399
diff changeset
4
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26399
diff changeset
5 See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26399
diff changeset
6 or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26399
diff changeset
7
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 This file is part of Octave.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23577
diff changeset
11 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22508
diff changeset
12 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23577
diff changeset
13 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22508
diff changeset
14 (at your option) any later version.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22508
diff changeset
16 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22508
diff changeset
17 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22508
diff changeset
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22508
diff changeset
19 GNU General Public License for more details.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 You should have received a copy of the GNU General Public License
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23577
diff changeset
23 <https://www.gnu.org/licenses/>.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
24
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 */
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
27 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
28 # include "config.h"
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 #endif
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
31 #include "byte-swap.h"
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
32 #include "dim-vector.h"
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
33
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
34 #include "mxarray.h"
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 #include "ov-perm.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36 #include "ov-re-mat.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 #include "ov-scalar.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20979
diff changeset
39 #include "errwarn.h"
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 #include "ops.h"
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
41 #include "pr-output.h"
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
43 #include "ls-oct-text.h"
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
44
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 octave_value
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 octave_perm_matrix::subsref (const std::string& type,
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47 const std::list<octave_value_list>& idx)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
49 octave_value retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 switch (type[0])
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 case '(':
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 retval = do_index_op (idx.front ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 break;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 case '{':
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 case '.':
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
60 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
61 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 break;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65 default:
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
66 panic_impossible ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
67 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
68
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
69 return retval.next_subsref (type, idx);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
71
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72 octave_value
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73 octave_perm_matrix::do_index_op (const octave_value_list& idx,
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
74 bool resize_ok)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
76 octave_value retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
77 octave_idx_type nidx = idx.length ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
78 idx_vector idx0, idx1;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
79 if (nidx == 2)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
80 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
81 int k = 0; // index we're processing when index_vector throws
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
82 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
83 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
84 idx0 = idx(0).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
85 k = 1;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
86 idx1 = idx(1).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
87 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
88 catch (octave::index_exception& e)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
89 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
90 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
91 e.set_pos_if_unset (2, k+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
92 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20447
diff changeset
93 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
94 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
95
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
96 // This hack is to allow constructing permutation matrices using
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
97 // eye(n)(p,:), eye(n)(:,q) && eye(n)(p,q) where p & q are permutation
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
98 // vectors.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
99 // Note that, for better consistency, eye(n)(:,:) still converts to a full
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
100 // matrix.
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
101 if (nidx == 2)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
102 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103 bool left = idx0.is_permutation (matrix.rows ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104 bool right = idx1.is_permutation (matrix.cols ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 if (left && right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 if (idx0.is_colon ()) left = false;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109 if (idx1.is_colon ()) right = false;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110 if (left || right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 PermMatrix p = matrix;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
113 if (left)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114 p = PermMatrix (idx0, false) * p;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 if (right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116 p = p * PermMatrix (idx1, true);
8960
93f18f166aba remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
117 retval = p;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
118 }
8459
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
119 else
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
120 {
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
121 retval = this;
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
122 this->count++;
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
123 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
127 if (! retval.is_defined ())
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 {
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
129 if (nidx == 2 && ! resize_ok && idx0.is_scalar () && idx1.is_scalar ())
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
130 retval = matrix.checkelem (idx0(0), idx1(0));
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132 retval = to_dense ().do_index_op (idx, resize_ok);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
133 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
137
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
138 // Return true if this matrix has all true elements (non-zero, not NaN/NA).
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
139 // A permutation cannot have NaN/NA.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 bool
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141 octave_perm_matrix::is_true (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142 {
21990
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
143 if (dims ().numel () > 1)
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
144 {
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
145 warn_array_as_logical (dims ());
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
146 return false; // > 1x1 permutation always has zeros, and no NaN.
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
147 }
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
148 else
efce657ceb86 Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21885
diff changeset
149 return dims ().numel (); // 1x1 is [1] == true, 0x0 == false.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
150 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
151
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
152 double
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 octave_perm_matrix::double_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23457
diff changeset
155 if (isempty ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
156 err_invalid_conversion (type_name (), "real scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
157
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
158 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
159 type_name (), "real scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
160
22477
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22407
diff changeset
161 return matrix(0, 0);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
162 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
163
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
164 float
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
165 octave_perm_matrix::float_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
166 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23457
diff changeset
167 if (isempty ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
168 err_invalid_conversion (type_name (), "real scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
169
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
170 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
171 type_name (), "real scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
172
22477
6bf1cbb90705 Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents: 22407
diff changeset
173 return matrix(0, 0);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
174 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
175
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
176 Complex
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
177 octave_perm_matrix::complex_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
178 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
179 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
180 err_invalid_conversion (type_name (), "complex scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
181
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
182 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
183 type_name (), "complex scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
184
22508
0b278f54f60a Remove unnecessary initializations in complex_value methods.
Julien Bect <jbect@users.sourceforge.net>
parents: 22477
diff changeset
185 return Complex (matrix(0, 0), 0);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
186 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
187
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
188 FloatComplex
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189 octave_perm_matrix::float_complex_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191 float tmp = lo_ieee_float_nan_value ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
192
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
193 FloatComplex retval (tmp, tmp);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
195 if (rows () == 0 || columns () == 0)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
196 err_invalid_conversion (type_name (), "complex scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
197
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
198 warn_implicit_conversion ("Octave:array-to-scalar",
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
199 type_name (), "complex scalar");
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
200
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
201 retval = matrix(0, 0);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
202
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
203 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
204 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
205
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
206 #define FORWARD_MATRIX_VALUE(TYPE, PREFIX) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
207 TYPE \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
208 octave_perm_matrix::PREFIX ## _value (bool frc_str_conv) const \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
209 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
210 return to_dense ().PREFIX ## _value (frc_str_conv); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
211 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
212
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
213 SparseMatrix
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
214 octave_perm_matrix::sparse_matrix_value (bool) const
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
215 {
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
216 return SparseMatrix (matrix);
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
217 }
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
218
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
219 SparseBoolMatrix
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
220 octave_perm_matrix::sparse_bool_matrix_value (bool) const
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
221 {
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
222 return SparseBoolMatrix (matrix);
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
223 }
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
224
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
225 SparseComplexMatrix
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
226 octave_perm_matrix::sparse_complex_matrix_value (bool) const
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
227 {
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
228 return SparseComplexMatrix (sparse_matrix_value ());
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
229 }
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
230
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
231 FORWARD_MATRIX_VALUE (Matrix, matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
232 FORWARD_MATRIX_VALUE (FloatMatrix, float_matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
233 FORWARD_MATRIX_VALUE (ComplexMatrix, complex_matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
234 FORWARD_MATRIX_VALUE (FloatComplexMatrix, float_complex_matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
235
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
236 FORWARD_MATRIX_VALUE (NDArray, array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
237 FORWARD_MATRIX_VALUE (FloatNDArray, float_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
238 FORWARD_MATRIX_VALUE (ComplexNDArray, complex_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
239 FORWARD_MATRIX_VALUE (FloatComplexNDArray, float_complex_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
240
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
241 FORWARD_MATRIX_VALUE (boolNDArray, bool_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
242 FORWARD_MATRIX_VALUE (charNDArray, char_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
244 idx_vector
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
245 octave_perm_matrix::index_vector (bool require_integers) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
246 {
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
247 return to_dense ().index_vector (require_integers);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
248 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
249
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250 octave_value
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
251 octave_perm_matrix::convert_to_str_internal (bool pad, bool force,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
252 char type) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
253 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
254 return to_dense ().convert_to_str_internal (pad, force, type);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
255 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
256
22296
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
257 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
258 octave_perm_matrix::as_double (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
259 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
260 return matrix;
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
261 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
262
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
263 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
264 octave_perm_matrix::as_single (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
265 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
266 return float_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
267 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
268
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
269 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
270 octave_perm_matrix::as_int8 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
271 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
272 return int8_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
273 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
274
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
275 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
276 octave_perm_matrix::as_int16 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
277 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
278 return int16_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
279 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
280
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
281 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
282 octave_perm_matrix::as_int32 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
283 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
284 return int32_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
285 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
286
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
287 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
288 octave_perm_matrix::as_int64 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
289 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
290 return int64_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
291 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
292
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
293 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
294 octave_perm_matrix::as_uint8 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
295 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
296 return uint8_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
297 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
298
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
299 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
300 octave_perm_matrix::as_uint16 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
301 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
302 return uint16_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
303 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
304
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
305 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
306 octave_perm_matrix::as_uint32 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
307 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
308 return uint32_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
309 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
310
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
311 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
312 octave_perm_matrix::as_uint64 (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
313 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
314 return uint64_array_value ();
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
315 }
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
316
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
317 float_display_format
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
318 octave_perm_matrix::get_edit_display_format (void) const
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
319 {
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
320 return float_display_format (float_format (1, 0, 0));
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
321 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
322
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
323 std::string
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
324 octave_perm_matrix::edit_display (const float_display_format& fmt,
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
325 octave_idx_type i,
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
326 octave_idx_type j) const
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
327 {
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
328 std::ostringstream buf;
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
329 octave_print_internal (buf, fmt, octave_int<octave_idx_type> (matrix(i,j)));
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
330 return buf.str ();
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
331 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24700
diff changeset
332
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
333 bool
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
334 octave_perm_matrix::save_ascii (std::ostream& os)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
335 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
336 os << "# size: " << matrix.rows () << "\n";
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18678
diff changeset
337 os << "# orient: c\n";
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
338
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18678
diff changeset
339 Array<octave_idx_type> pvec = matrix.col_perm_vec ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
340 octave_idx_type n = pvec.numel ();
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
341 ColumnVector tmp (n);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
342 for (octave_idx_type i = 0; i < n; i++) tmp(i) = pvec(i) + 1;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
343 os << tmp;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
344
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
345 return true;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
346 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
347
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
348 bool
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
349 octave_perm_matrix::load_ascii (std::istream& is)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
350 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
351 octave_idx_type n;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
352 char orient;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
353
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
354 if (! extract_keyword (is, "size", n, true)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
355 || ! extract_keyword (is, "orient", orient, true))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
356 error ("load: failed to extract size & orientation");
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
357
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
358 bool colp = orient == 'c';
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
359 ColumnVector tmp (n);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
360 is >> tmp;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
361 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
362 error ("load: failed to load permutation matrix constant");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
363
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
364 Array<octave_idx_type> pvec (dim_vector (n, 1));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
365 for (octave_idx_type i = 0; i < n; i++) pvec(i) = tmp(i) - 1;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
366 matrix = PermMatrix (pvec, colp);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
367
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21739
diff changeset
368 // Invalidate cache. Probably not necessary, but safe.
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
369 dense_cache = octave_value ();
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
370
21124
95f8c8cdbffe maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents: 21118
diff changeset
371 return true;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
372 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
373
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
374 bool
26399
586413770c7f pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
375 octave_perm_matrix::save_binary (std::ostream& os, bool)
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
376 {
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
377
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
378 int32_t sz = matrix.rows ();
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18678
diff changeset
379 bool colp = true;
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
380 os.write (reinterpret_cast<char *> (&sz), 4);
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
381 os.write (reinterpret_cast<char *> (&colp), 1);
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18678
diff changeset
382 const Array<octave_idx_type>& col_perm = matrix.col_perm_vec ();
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18678
diff changeset
383 os.write (reinterpret_cast<const char *> (col_perm.data ()),
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18678
diff changeset
384 col_perm.byte_size ());
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
385
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
386 return true;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
387 }
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
388
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
389 bool
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
390 octave_perm_matrix::load_binary (std::istream& is, bool swap,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
391 octave::mach_info::float_format)
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
392 {
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
393 int32_t sz;
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
394 bool colp;
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
395 if (! (is.read (reinterpret_cast<char *> (&sz), 4)
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
396 && is.read (reinterpret_cast<char *> (&colp), 1)))
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
397 return false;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
398
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
399 MArray<octave_idx_type> m (dim_vector (sz, 1));
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
400
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
401 if (! is.read (reinterpret_cast<char *> (m.fortran_vec ()), m.byte_size ()))
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
402 return false;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
403
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
404 if (swap)
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
405 {
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
406 int nel = m.numel ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
407 for (int i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
408 switch (sizeof (octave_idx_type))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
409 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
410 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
411 swap_bytes<8> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
412 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
413 case 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
414 swap_bytes<4> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
415 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
416 case 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
417 swap_bytes<2> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
418 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
419 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
420 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
421 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
422 }
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
423 }
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
424
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
425 matrix = PermMatrix (m, colp);
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
426 return true;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
427 }
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
428
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
429 void
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
430 octave_perm_matrix::print_raw (std::ostream& os,
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
431 bool pr_as_read_syntax) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
432 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
433 return octave_print_internal (os, matrix, pr_as_read_syntax,
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
434 current_print_indent_level ());
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
435 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
436
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
437 mxArray *
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
438 octave_perm_matrix::as_mxArray (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
439 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
440 return to_dense ().as_mxArray ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
441 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
442
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
443 bool
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
444 octave_perm_matrix::print_as_scalar (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
445 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
446 dim_vector dv = dims ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
447
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
448 return (dv.all_ones () || dv.any_zero ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
449 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
450
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
451 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18130
diff changeset
452 octave_perm_matrix::print (std::ostream& os, bool pr_as_read_syntax)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
453 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
454 print_raw (os, pr_as_read_syntax);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
455 newline (os);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
456 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
457
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
458 int
23059
b98ebcd7f11c move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
459 octave_perm_matrix::write (octave::stream& os, int block_size,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
460 oct_data_conv::data_type output_type, int skip,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
461 octave::mach_info::float_format flt_fmt) const
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
462 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
463 return to_dense ().write (os, block_size, output_type, skip, flt_fmt);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
464 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
465
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
466 void
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
467 octave_perm_matrix::print_info (std::ostream& os,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
468 const std::string& prefix) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
469 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
470 matrix.print_info (os, prefix);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
471 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
472
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
473 octave_value
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
474 octave_perm_matrix::to_dense (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
475 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
476 if (! dense_cache.is_defined ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
477 dense_cache = Matrix (matrix);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
478
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
479 return dense_cache;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
480 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
481
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
482 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_perm_matrix,
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
483 "permutation matrix", "double");
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
484
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
485 static octave_base_value *
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
486 default_numeric_conversion_function (const octave_base_value& a)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
487 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
488 const octave_perm_matrix& v = dynamic_cast<const octave_perm_matrix&> (a);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
489
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
490 return new octave_matrix (v.matrix_value ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
491 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
492
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
493 octave_base_value::type_conv_info
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
494 octave_perm_matrix::numeric_conversion_function (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
495 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
496 return octave_base_value::type_conv_info (default_numeric_conversion_function,
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
497 octave_matrix::static_type_id ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
498 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
499
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
500 // FIXME: This is duplicated from octave_base_matrix<T>. Could
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
501 // octave_perm_matrix be derived from octave_base_matrix<T>?
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
502
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
503 void
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
504 octave_perm_matrix::short_disp (std::ostream& os) const
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
505 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
506 if (matrix.isempty ())
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
507 os << "[]";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
508 else if (matrix.ndims () == 2)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
509 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
510 // FIXME: should this be configurable?
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
511 octave_idx_type max_elts = 10;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
512 octave_idx_type elts = 0;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
513
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
514 octave_idx_type nel = matrix.numel ();
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
515
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
516 octave_idx_type nr = matrix.rows ();
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
517 octave_idx_type nc = matrix.columns ();
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
518
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
519 os << '[';
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
520
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
521 for (octave_idx_type i = 0; i < nr; i++)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
522 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
523 for (octave_idx_type j = 0; j < nc; j++)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
524 {
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
525 std::ostringstream buf;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
526 octave_int<octave_idx_type> tval (matrix(i,j));
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
527 octave_print_internal (buf, tval);
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
528 std::string tmp = buf.str ();
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
529 size_t pos = tmp.find_first_not_of (' ');
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
530 if (pos != std::string::npos)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
531 os << tmp.substr (pos);
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
532 else if (! tmp.empty ())
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
533 os << tmp[0];
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
534
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
535 if (++elts >= max_elts)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
536 goto done;
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
537
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
538 if (j < nc - 1)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
539 os << ", ";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
540 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
541
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
542 if (i < nr - 1 && elts < max_elts)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
543 os << "; ";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
544 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
545
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
546 done:
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
547
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
548 if (nel <= max_elts)
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
549 os << ']';
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
550 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
551 else
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
552 os << "...";
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
553 }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
554
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
555 octave_base_value *
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
556 octave_perm_matrix::try_narrowing_conversion (void)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
557 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23220
diff changeset
558 octave_base_value *retval = nullptr;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
559
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19864
diff changeset
560 if (matrix.numel () == 1)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
561 retval = new octave_scalar (matrix (0, 0));
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
562
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
563 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
564 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
565
18650
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
566 octave_value
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
567 octave_perm_matrix::fast_elem_extract (octave_idx_type n) const
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
568 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
569 if (n < matrix.numel ())
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
570 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
571 octave_idx_type nr = matrix.rows ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
572
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
573 octave_idx_type r = n % nr;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
574 octave_idx_type c = n / nr;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
575
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
576 return octave_value (matrix.elem (r, c));
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
577 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
578 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
579 return octave_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
580 }