annotate libinterp/octave-value/ov-perm.cc @ 20587:f90c8372b7ba

eliminate many more simple uses of error_state * Cell.cc, __ichol__.cc, __ilu__.cc, balance.cc, bsxfun.cc, colloc.cc, det.cc, dlmread.cc, dynamic-ld.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, hess.cc, input.cc, levenshtein.cc, load-path.cc, lookup.cc, ls-mat-ascii.cc, ls-mat4.cc, lsode.cc, lu.cc, max.cc, md5sum.cc, mex.cc, pager.cc, pinv.cc, pr-output.cc, qz.cc, schur.cc, sparse.cc, sqrtm.cc, str2double.cc, strfns.cc, sub2ind.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc, amd.cc, audiodevinfo.cc, dmperm.cc, fftw.cc, symrcm.cc, ov-base-diag.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-sparse.cc, ov-builtin.cc, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, op-bm-b.cc, op-bm-bm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-str-m.cc, op-str-s.cc, oct-parse.in.yy, pt-cbinop.cc, pt-colon.cc, pt-decl.cc, pt-exp.cc, pt-id.cc, pt-misc.cc, pt-select.cc, pt-unop.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 19:29:36 -0400
parents dd6345fd8a97
children
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19659
diff changeset
3 Copyright (C) 2008-2015 Jaroslav Hajek
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 option) any later version.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 for more details.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 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
18 along with Octave; see the file COPYING. If not, see
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
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 */
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
24 #include <config.h>
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 #endif
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
27 #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
28 #include "dim-vector.h"
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
29
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
30 #include "mxarray.h"
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 #include "ov-perm.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 #include "ov-re-mat.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33 #include "ov-scalar.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34 #include "error.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 #include "gripes.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36 #include "ops.h"
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
37 #include "pr-output.h"
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38
20482
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20267
diff changeset
39 #include "ls-oct-text.h"
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
40
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 octave_value
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 octave_perm_matrix::subsref (const std::string& type,
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
43 const std::list<octave_value_list>& idx)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 octave_value retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47 switch (type[0])
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 case '(':
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 retval = do_index_op (idx.front ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 break;
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 case '.':
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
56 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
57 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
58 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 break;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61 default:
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 panic_impossible ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 }
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 return retval.next_subsref (type, idx);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
66 }
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 octave_value
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
69 octave_perm_matrix::do_index_op (const octave_value_list& idx,
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 bool resize_ok)
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 retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73 octave_idx_type nidx = idx.length ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
74 idx_vector idx0, idx1;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75 if (nidx == 2)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
76 {
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
77 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: 20482
diff changeset
78 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
79 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
80 idx0 = idx(0).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
81 k = 1;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
82 idx1 = idx(1).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
83 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
84 catch (index_exception& e)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
85 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
86 // 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: 20482
diff changeset
87 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: 20482
diff changeset
88 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20482
diff changeset
89 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
90 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
91
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
92 // This hack is to allow constructing permutation matrices using
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93 // 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
94 // vectors.
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
95 // 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
96 // matrix.
20587
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
97 if (nidx == 2)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
98 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
99 bool left = idx0.is_permutation (matrix.rows ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
100 bool right = idx1.is_permutation (matrix.cols ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
101
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
102 if (left && right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104 if (idx0.is_colon ()) left = false;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 if (idx1.is_colon ()) right = false;
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 PermMatrix p = matrix;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109 if (left)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110 p = PermMatrix (idx0, false) * p;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111 if (right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 p = p * PermMatrix (idx1, true);
8960
93f18f166aba remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
113 retval = p;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114 }
8459
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
115 else
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
116 {
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
117 retval = this;
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
118 this->count++;
d17874a6f161 improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
119 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
120 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122
20587
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
123 if (! retval.is_defined ())
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124 {
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
125 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: 19731
diff changeset
126 retval = matrix.checkelem (idx0(0), idx1(0));
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 retval = to_dense ().do_index_op (idx, resize_ok);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132 }
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 bool
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135 octave_perm_matrix::is_true (void) const
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 return to_dense ().is_true ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 double
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141 octave_perm_matrix::double_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
143 double retval = lo_ieee_nan_value ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
144
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
145 if (numel () > 0)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
147 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
148 type_name (), "real scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
149
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
150 retval = matrix (0, 0);
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 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 gripe_invalid_conversion (type_name (), "real scalar");
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
155 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
156 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
157
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
158 float
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
159 octave_perm_matrix::float_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
160 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
161 float retval = lo_ieee_float_nan_value ();
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 if (numel () > 0)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
164 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
165 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
166 type_name (), "real scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
167
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
168 retval = matrix (0, 0);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
169 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
170 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
171 gripe_invalid_conversion (type_name (), "real scalar");
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
172
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
173 return retval;
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 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
179 double tmp = lo_ieee_nan_value ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
180
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
181 Complex retval (tmp, tmp);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
182
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
183 if (rows () > 0 && columns () > 0)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
184 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
185 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
186 type_name (), "complex scalar");
8367
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 retval = matrix (0, 0);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191 gripe_invalid_conversion (type_name (), "complex scalar");
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 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
195
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
196 FloatComplex
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
197 octave_perm_matrix::float_complex_value (bool) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
198 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
199 float tmp = lo_ieee_float_nan_value ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
200
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
201 FloatComplex retval (tmp, tmp);
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 if (rows () > 0 && columns () > 0)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
204 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
205 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
206 type_name (), "complex scalar");
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
207
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
208 retval = matrix (0, 0);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
209 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
210 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211 gripe_invalid_conversion (type_name (), "complex scalar");
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
212
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
213 return retval;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
214 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
215
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
216 #define FORWARD_MATRIX_VALUE(TYPE, PREFIX) \
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
217 TYPE \
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
218 octave_perm_matrix::PREFIX ## _value (bool frc_str_conv) const \
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
219 { \
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
220 return to_dense ().PREFIX ## _value (frc_str_conv); \
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
221 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
222
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
223 SparseMatrix
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
224 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
225 {
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
226 return SparseMatrix (matrix);
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
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
229 SparseBoolMatrix
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
230 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
231 {
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
232 return SparseBoolMatrix (matrix);
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
233 }
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
234
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
235 SparseComplexMatrix
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
236 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
237 {
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
238 return SparseComplexMatrix (sparse_matrix_value ());
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
239 }
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8891
diff changeset
240
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
241 FORWARD_MATRIX_VALUE (Matrix, matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
242 FORWARD_MATRIX_VALUE (FloatMatrix, float_matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243 FORWARD_MATRIX_VALUE (ComplexMatrix, complex_matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
244 FORWARD_MATRIX_VALUE (FloatComplexMatrix, float_complex_matrix)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
245
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
246 FORWARD_MATRIX_VALUE (NDArray, array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
247 FORWARD_MATRIX_VALUE (FloatNDArray, float_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
248 FORWARD_MATRIX_VALUE (ComplexNDArray, complex_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
249 FORWARD_MATRIX_VALUE (FloatComplexNDArray, float_complex_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
251 FORWARD_MATRIX_VALUE (boolNDArray, bool_array)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
252 FORWARD_MATRIX_VALUE (charNDArray, char_array)
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 idx_vector
18129
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
255 octave_perm_matrix::index_vector (bool require_integers) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
256 {
18129
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
257 return to_dense ().index_vector (require_integers);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
258 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
259
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
260 octave_value
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
261 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
262 char type) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
263 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
264 return to_dense ().convert_to_str_internal (pad, force, type);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
265 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
266
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
267 bool
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
268 octave_perm_matrix::save_ascii (std::ostream& os)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
269 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
270 os << "# size: " << matrix.rows () << "\n";
18883
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18712
diff changeset
271 os << "# orient: c\n";
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
272
18883
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18712
diff changeset
273 Array<octave_idx_type> pvec = matrix.col_perm_vec ();
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20263
diff changeset
274 octave_idx_type n = pvec.numel ();
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
275 ColumnVector tmp (n);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
276 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
277 os << tmp;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
278
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
279 return true;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
280 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
281
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
282 bool
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
283 octave_perm_matrix::load_ascii (std::istream& is)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
284 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
285 octave_idx_type n;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
286 bool success = true;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
287 char orient;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
288
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
289 if (extract_keyword (is, "size", n, true)
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
290 && extract_keyword (is, "orient", orient, true))
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
291 {
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
292 bool colp = orient == 'c';
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
293 ColumnVector tmp (n);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
294 is >> tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
295 if (!is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
296 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
297 error ("load: failed to load permutation matrix constant");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
298 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
299 }
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
300 else
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
301 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
302 Array<octave_idx_type> pvec (dim_vector (n, 1));
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
303 for (octave_idx_type i = 0; i < n; i++) pvec(i) = tmp(i) - 1;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
304 matrix = PermMatrix (pvec, colp);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
305
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
306 // Invalidate cache. Probably not necessary, but safe.
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
307 dense_cache = octave_value ();
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
308 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
309 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
310 else
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
311 {
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
312 error ("load: failed to extract size & orientation");
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
313 success = false;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
314 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
315
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
316 return success;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
317 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
318
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
319 bool
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
320 octave_perm_matrix::save_binary (std::ostream& os, bool&)
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
321 {
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
322
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
323 int32_t sz = matrix.rows ();
18883
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18712
diff changeset
324 bool colp = true;
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
325 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
326 os.write (reinterpret_cast<char *> (&colp), 1);
18883
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18712
diff changeset
327 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: 18712
diff changeset
328 os.write (reinterpret_cast<const char *> (col_perm.data ()),
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18712
diff changeset
329 col_perm.byte_size ());
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
330
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
331 return true;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
332 }
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
333
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
334 bool
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
335 octave_perm_matrix::load_binary (std::istream& is, bool swap,
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18684
diff changeset
336 oct_mach_info::float_format)
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
337 {
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
338 int32_t sz;
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
339 bool colp;
9605
dfc68e6d8741 avoid some gcc warnings
John W. Eaton <jwe@octave.org>
parents: 8960
diff changeset
340 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
341 && is.read (reinterpret_cast<char *> (&colp), 1)))
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
342 return false;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
343
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
344 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
345
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
346 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
347 return false;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
348
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
349 if (swap)
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
350 {
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
351 int nel = m.numel ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
352 for (int i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
353 switch (sizeof (octave_idx_type))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
354 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
355 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
356 swap_bytes<8> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
357 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
358 case 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
359 swap_bytes<4> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
360 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
361 case 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
362 swap_bytes<2> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
363 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
364 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
365 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
366 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 9812
diff changeset
367 }
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
368 }
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
369
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
370 matrix = PermMatrix (m, colp);
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
371 return true;
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
372 }
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8376
diff changeset
373
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
374 void
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
375 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
376 bool pr_as_read_syntax) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
377 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
378 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
379 current_print_indent_level ());
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
380 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
381
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
382 mxArray *
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
383 octave_perm_matrix::as_mxArray (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
384 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
385 return to_dense ().as_mxArray ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
386 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
387
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
388 bool
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
389 octave_perm_matrix::print_as_scalar (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
390 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
391 dim_vector dv = dims ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
392
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
393 return (dv.all_ones () || dv.any_zero ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
394 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
395
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
396 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18129
diff changeset
397 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
398 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
399 print_raw (os, pr_as_read_syntax);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8459
diff changeset
400 newline (os);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
401 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
402
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
403 int
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
404 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
405 oct_data_conv::data_type output_type, int skip,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
406 oct_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
407 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
408 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
409 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
410
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
411 void
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
412 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
413 const std::string& prefix) const
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
414 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
415 matrix.print_info (os, prefix);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
416 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
417
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
418
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
419 octave_value
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
420 octave_perm_matrix::to_dense (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
421 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
422 if (! dense_cache.is_defined ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
423 dense_cache = Matrix (matrix);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
424
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
425 return dense_cache;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
426 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
427
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
428
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
429 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_perm_matrix,
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
430 "permutation matrix", "double");
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
431
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
432 static octave_base_value *
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
433 default_numeric_conversion_function (const octave_base_value& a)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
434 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
435 CAST_CONV_ARG (const octave_perm_matrix&);
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 return new octave_matrix (v.matrix_value ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
438 }
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 octave_base_value::type_conv_info
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
441 octave_perm_matrix::numeric_conversion_function (void) const
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 return octave_base_value::type_conv_info (default_numeric_conversion_function,
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
444 octave_matrix::static_type_id ());
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
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
447 octave_base_value *
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
448 octave_perm_matrix::try_narrowing_conversion (void)
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 octave_base_value *retval = 0;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
451
20263
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
452 if (matrix.numel () == 1)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
453 retval = new octave_scalar (matrix (0, 0));
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
454
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
455 return retval;
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
18684
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
458 octave_value
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
459 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
460 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
461 if (n < matrix.numel ())
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
462 {
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
463 octave_idx_type nr = matrix.rows ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
464
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
465 octave_idx_type r = n % nr;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
466 octave_idx_type c = n / nr;
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
467
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
468 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
469 }
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
470 else
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
471 return octave_value ();
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 18522
diff changeset
472 }