Mercurial > octave
annotate libinterp/octave-value/ov-re-diag.cc @ 30139:c789e728d57a
Backed out changeset 938794bc82b7
Renaming octave_base_value::count to m_count breaks some packages that
define new octave_value data types. Maybe those packages shouldn't be
touching the count directly, but they do. Since we may also want to
switch to using std::shared_ptr to manage octave_value objects instead
of our own custom reference counting implmentation, it is probably
best to delay this change until we know exactly what path we want to
take.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Sep 2021 11:14:44 -0400 |
parents | 2dca5c25237d |
children | 796f54d4ddbf |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27957
diff
changeset
|
3 // Copyright (C) 2008-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 #endif |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
30 #include "byte-swap.h" |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
31 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 #include "ov-re-diag.h" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 #include "ov-flt-re-diag.h" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 #include "ov-base-diag.cc" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 #include "ov-scalar.h" |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 #include "ov-re-mat.h" |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
37 #include "ls-utils.h" |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 |
22022
278fc29b69ca
maint: Eliminate unnecessary double newline blocks (only whitespace changes).
Rik <rik@octave.org>
parents:
21782
diff
changeset
|
39 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 template class octave_base_diag<DiagMatrix, Matrix>; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 |
30138
2dca5c25237d
undo matrix -> m_matrix changes in type names and error messages
John W. Eaton <jwe@octave.org>
parents:
30135
diff
changeset
|
42 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_diag_matrix, "diagonal matrix", |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 "double"); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 static octave_base_value * |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 default_numeric_conversion_function (const octave_base_value& a) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 { |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
48 const octave_diag_matrix& v = dynamic_cast<const octave_diag_matrix&> (a); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 return new octave_matrix (v.matrix_value ()); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 octave_base_value::type_conv_info |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 octave_diag_matrix::numeric_conversion_function (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 octave_matrix::static_type_id ()); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 static octave_base_value * |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 default_numeric_demotion_function (const octave_base_value& a) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 { |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
63 const octave_diag_matrix& v = dynamic_cast<const octave_diag_matrix&> (a); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 return new octave_float_diag_matrix (v.float_diag_matrix_value ()); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
66 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 octave_base_value::type_conv_info |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
69 octave_diag_matrix::numeric_demotion_function (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
70 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 return octave_base_value::type_conv_info |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 (default_numeric_demotion_function, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 octave_float_diag_matrix::static_type_id ()); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
74 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
75 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
76 octave_base_value * |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 octave_diag_matrix::try_narrowing_conversion (void) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
78 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
79 octave_base_value *retval = nullptr; |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
80 |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
81 if (m_matrix.nelem () == 1) |
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
82 retval = new octave_scalar (m_matrix (0, 0)); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
83 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
84 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
85 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
86 |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
87 octave_value |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
88 octave_diag_matrix::do_index_op (const octave_value_list& idx, |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
89 bool resize_ok) |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
90 { |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
91 octave_value retval; |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
92 |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
93 // This hack is to allow constructing permutation matrices using |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
94 // 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:
11523
diff
changeset
|
95 // vectors. |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
96 if (! resize_ok && idx.length () == 2 && m_matrix.is_multiple_of_identity (1)) |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
97 { |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
98 int k = 0; // index we're accessing when index_vector throws |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
99 try |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
100 { |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
101 octave::idx_vector idx0 = idx(0).index_vector (); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
102 k = 1; |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
103 octave::idx_vector idx1 = idx(1).index_vector (); |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
104 |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
105 bool left = idx0.is_permutation (m_matrix.rows ()); |
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
106 bool right = idx1.is_permutation (m_matrix.cols ()); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
107 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
108 if (left && right) |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
109 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
110 if (idx0.is_colon ()) left = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
111 if (idx1.is_colon ()) right = false; |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
112 if (left && right) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
113 retval = PermMatrix (idx0, false) * PermMatrix (idx1, true); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
114 else if (left) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
115 retval = PermMatrix (idx0, false); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
116 else if (right) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
117 retval = PermMatrix (idx1, true); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
118 else |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
119 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
120 retval = this; |
30139
c789e728d57a
Backed out changeset 938794bc82b7
John W. Eaton <jwe@octave.org>
parents:
30138
diff
changeset
|
121 this->count++; |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
122 } |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
123 } |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
124 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
27957
diff
changeset
|
125 catch (octave::index_exception& ie) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
126 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
127 // Rethrow to allow more info to be reported later. |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
27957
diff
changeset
|
128 ie.set_pos_if_unset (2, k+1); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
129 throw; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19697
diff
changeset
|
130 } |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
131 } |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
132 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
133 if (retval.is_undefined ()) |
8960
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
134 retval = octave_base_diag<DiagMatrix, Matrix>::do_index_op (idx, resize_ok); |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
135 |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
136 return retval; |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
137 } |
93f18f166aba
remove float perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
138 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
139 DiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
140 octave_diag_matrix::diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
141 { |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
142 return m_matrix; |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
143 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
144 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
145 FloatDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
146 octave_diag_matrix::float_diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
147 { |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
148 return FloatDiagMatrix (m_matrix); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
149 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
150 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
151 ComplexDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
152 octave_diag_matrix::complex_diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
153 { |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
154 return ComplexDiagMatrix (m_matrix); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
155 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
156 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
157 FloatComplexDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
158 octave_diag_matrix::float_complex_diag_matrix_value (bool) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
159 { |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
160 return FloatComplexDiagMatrix (m_matrix); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
161 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
162 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
163 octave_value |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
164 octave_diag_matrix::as_double (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
165 { |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
166 return m_matrix; |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
167 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
168 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
169 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
170 octave_diag_matrix::as_single (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
171 { |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
172 return FloatDiagMatrix (m_matrix); |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
173 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
174 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
175 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
176 octave_diag_matrix::as_int8 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
177 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
178 return int8_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
179 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
180 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
181 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
182 octave_diag_matrix::as_int16 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
183 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
184 return int16_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
185 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
186 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
187 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
188 octave_diag_matrix::as_int32 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
189 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
190 return int32_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
191 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
192 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
193 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
194 octave_diag_matrix::as_int64 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
195 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
196 return int64_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
197 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
198 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
199 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
200 octave_diag_matrix::as_uint8 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
201 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
202 return uint8_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
203 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
204 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
205 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
206 octave_diag_matrix::as_uint16 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
207 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
208 return uint16_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
209 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
210 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
211 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
212 octave_diag_matrix::as_uint32 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
213 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
214 return uint32_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
215 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
216 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
217 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
218 octave_diag_matrix::as_uint64 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
219 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
220 return uint64_array_value (); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
221 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
222 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
223 octave_value |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
224 octave_diag_matrix::map (unary_mapper_t umap) const |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
225 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
226 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
227 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
228 case umap_abs: |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
229 return m_matrix.abs (); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
230 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
231 case umap_conj: |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
232 return m_matrix; |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
233 case umap_imag: |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
234 return DiagMatrix (m_matrix.rows (), m_matrix.cols (), 0.0); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
235 case umap_sqrt: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
236 { |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
237 ComplexColumnVector tmp; |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
238 tmp = m_matrix.extract_diag ().map<Complex> (octave::math::rc_sqrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
239 ComplexDiagMatrix retval (tmp); |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
240 retval.resize (m_matrix.rows (), m_matrix.columns ()); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
241 return retval; |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
242 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
243 default: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
244 return to_dense ().map (umap); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
245 } |
8834
8dd69187c4a2
specialize sqrt for diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
246 } |
8dd69187c4a2
specialize sqrt for diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
247 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
248 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
|
249 octave_diag_matrix::save_binary (std::ostream& os, bool save_as_floats) |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
250 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
251 |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
252 int32_t r = m_matrix.rows (); |
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
253 int32_t c = m_matrix.cols (); |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
254 os.write (reinterpret_cast<char *> (&r), 4); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
255 os.write (reinterpret_cast<char *> (&c), 4); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
256 |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
257 Matrix m = Matrix (m_matrix.extract_diag ()); |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
258 save_type st = LS_DOUBLE; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
259 if (save_as_floats) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
260 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
261 if (m.too_large_for_float ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
262 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
263 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
264 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
265 } |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
266 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
9812
diff
changeset
|
267 st = LS_FLOAT; |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
268 } |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
269 else if (m_matrix.length () > 8192) // FIXME: make this configurable. |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
270 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
271 double max_val, min_val; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
272 if (m.all_integers (max_val, min_val)) |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
273 st = octave::get_save_type (max_val, min_val); |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
274 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
275 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
276 const double *mtmp = m.data (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
277 write_doubles (os, mtmp, st, m.numel ()); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
278 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
279 return true; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
280 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
281 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
282 bool |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
283 octave_diag_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
|
284 octave::mach_info::float_format fmt) |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
285 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
286 int32_t r, c; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
287 char tmp; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
288 if (! (is.read (reinterpret_cast<char *> (&r), 4) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
289 && is.read (reinterpret_cast<char *> (&c), 4) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
290 && is.read (reinterpret_cast<char *> (&tmp), 1))) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
291 return false; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
292 if (swap) |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
293 { |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
294 swap_bytes<4> (&r); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
295 swap_bytes<4> (&c); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
296 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
297 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
298 DiagMatrix m (r, c); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
299 double *re = m.fortran_vec (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
300 octave_idx_type len = m.length (); |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
301 read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
302 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
303 if (! is) |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
304 return false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
305 |
30135
606652e9f446
maint: use "m_" prefix for member variables in class octave_base_diag.
Rik <rik@octave.org>
parents:
30133
diff
changeset
|
306 m_matrix = m; |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
307 |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
308 return true; |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
309 } |
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
310 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
311 bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
312 octave_diag_matrix::chk_valid_scalar (const octave_value& val, |
8398
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
313 double& x) const |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
314 { |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
315 bool retval = val.is_real_scalar (); |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
316 if (retval) |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
317 x = val.double_value (); |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
318 return retval; |
d95282fa0579
allow element assignment to diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8381
diff
changeset
|
319 } |