annotate src/ov-base-diag.cc @ 8376:c43481a19bfe

implement ASCII saving of diag & perm matrices
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 05 Dec 2008 12:51:48 +0100
parents 445d27d79f4e
children d95282fa0579
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
1 /*
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
3 Copyright (C) 2008 Jaroslav Hajek <highegg@gmail.com>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 option) any later version.
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 for more details.
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 */
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
24 #include <config.h>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 #endif
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 #include <iostream>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 #include "mach-info.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 #include "ov-base.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 #include "ov-base-mat.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33 #include "pr-output.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34 #include "error.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 #include "gripes.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36 #include "oct-stream.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 #include "ops.h"
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
39 #include "ls-oct-ascii.h"
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
40
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
43 octave_base_diag<DMT, MT>::subsref (const std::string& type,
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 const std::list<octave_value_list>& idx)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 octave_value retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48 switch (type[0])
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 case '(':
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 retval = do_index_op (idx.front ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 break;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 case '{':
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 case '.':
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 std::string nm = type_name ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
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 break;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 default:
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 panic_impossible ();
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
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
66 return retval.next_subsref (type, idx);
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
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
69 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
71 octave_base_diag<DMT, MT>::do_index_op (const octave_value_list& idx,
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72 bool resize_ok)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
74 octave_value retval;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
75 typedef typename DMT::element_type el_type;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
76 el_type one = 1;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
77
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
78 octave_idx_type nidx = idx.length ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
79 idx_vector idx0, idx1;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
80 if (nidx == 2)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
81 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
82 idx0 = idx(0).index_vector ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
83 idx1 = idx(1).index_vector ();
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
84 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
85
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
86 // This hack is to allow constructing permutation matrices using
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
87 // eye(n)(p,:), eye(n)(:,q) && eye(n)(p,q) where p & q are permutation
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
88 // vectors.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
89 // Note that, for better consistency, eye(n)(:,:) still converts to a full
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
90 // matrix.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
91 // FIXME: This check is probably unnecessary for complex matrices.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
92 if (! error_state && nidx == 2 && matrix.is_multiple_of_identity (one))
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93 {
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
94
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
95 bool left = idx0.is_permutation (matrix.rows ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
96 bool right = idx1.is_permutation (matrix.cols ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
97
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
98 if (left && right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
99 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
100 if (idx0.is_colon ()) left = false;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
101 if (idx1.is_colon ()) right = false;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
102 if (left && right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
103 retval = octave_value (PermMatrix (idx0, false) * PermMatrix (idx1, true),
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
104 is_single_type ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
105 else if (left)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
106 retval = octave_value (PermMatrix (idx0, false),
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
107 is_single_type ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
108 else if (right)
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
109 retval = octave_value (PermMatrix (idx1, true),
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
110 is_single_type ());
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
111 }
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
113
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
114 // if error_state is set, we've already griped.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
115 if (! error_state && ! retval.is_defined ())
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
116 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
117 if (nidx == 2 && ! resize_ok &&
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
118 idx0.is_scalar () && idx1.is_scalar ())
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
119 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
120 // FIXME: the proxy mechanism of DiagArray2 causes problems here.
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
121 retval = el_type (matrix.checkelem (idx0(0), idx1(0)));
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
122 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
123 else
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
124 retval = to_dense ().do_index_op (idx, resize_ok);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
125 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
126
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132 octave_base_diag<DMT, MT>::resize (const dim_vector& dv, bool fill) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
133 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134 octave_value retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135 if (dv.length () == 2)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
137 DMT rm (matrix);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 rm.resize (dv(0), dv(1));
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139 retval = rm;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142 retval = to_dense ().resize (dv, fill);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
143 return retval;
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
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
147 bool
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
148 octave_base_diag<DMT, MT>::is_true (void) const
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 return to_dense ().is_true ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
151 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
152
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154 bool
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
155 octave_base_diag<DMT, MT>::valid_as_scalar_index (void) const
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 // FIXME
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
158 return false;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
159 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
160
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
161 // FIXME: this should be achieveable using ::real
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
162 template <class T> inline T helper_getreal (T x) { return x; }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
163 template <class T> inline T helper_getreal (std::complex<T> x) { return x.real (); }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
164 // FIXME: we really need some traits so that ad hoc hooks like this are not necessary
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
165 template <class T> inline T helper_iscomplex (T) { return false; }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
166 template <class T> inline T helper_iscomplex (std::complex<T>) { return true; }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
167
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
168 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
169 double
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
170 octave_base_diag<DMT, MT>::double_value (bool force_conversion) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
171 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
172 double retval = lo_ieee_nan_value ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
173 typedef typename DMT::element_type el_type;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
174
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
175 if (helper_iscomplex (el_type ()) && ! force_conversion)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
176 gripe_implicit_conversion ("Octave:imag-to-real",
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
177 "complex matrix", "real scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
178
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
179 if (numel () > 0)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
180 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
181 gripe_implicit_conversion ("Octave:array-as-scalar",
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
182 type_name (), "real scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
183
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
184 retval = helper_getreal (el_type (matrix (0, 0)));
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
185 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
186 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
187 gripe_invalid_conversion (type_name (), "real scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
188
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
192 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
193 float
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194 octave_base_diag<DMT, MT>::float_value (bool force_conversion) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
195 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
196 float retval = lo_ieee_float_nan_value ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
197 typedef typename DMT::element_type el_type;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
198
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
199 if (helper_iscomplex (el_type ()) && ! force_conversion)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
200 gripe_implicit_conversion ("Octave:imag-to-real",
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
201 "complex matrix", "real scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
202
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
203 if (numel () > 0)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
204 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
205 gripe_implicit_conversion ("Octave:array-as-scalar",
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
206 type_name (), "real scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
207
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
208 retval = helper_getreal (el_type (matrix (0, 0)));
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
209 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
210 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211 gripe_invalid_conversion (type_name (), "real scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
212
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
213 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
214 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
215
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
216 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
217 Complex
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
218 octave_base_diag<DMT, MT>::complex_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
219 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
220 double tmp = lo_ieee_nan_value ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
221
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
222 Complex retval (tmp, tmp);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
223
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
224 if (rows () > 0 && columns () > 0)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
225 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
226 gripe_implicit_conversion ("Octave:array-as-scalar",
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
227 type_name (), "complex scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
228
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
229 retval = matrix (0, 0);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
230 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
231 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
232 gripe_invalid_conversion (type_name (), "complex scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
233
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
234 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
235 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
236
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
237 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
238 FloatComplex
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
239 octave_base_diag<DMT, MT>::float_complex_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
240 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
241 float tmp = lo_ieee_float_nan_value ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
242
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243 FloatComplex retval (tmp, tmp);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
244
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
245 if (rows () > 0 && columns () > 0)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
246 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
247 gripe_implicit_conversion ("Octave:array-as-scalar",
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
248 type_name (), "complex scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
249
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250 retval = matrix (0, 0);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
251 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
252 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
253 gripe_invalid_conversion (type_name (), "complex scalar");
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
254
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
255 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
256 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
257
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
258 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
259 Matrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
260 octave_base_diag<DMT, MT>::matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
261 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
262 return Matrix (diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
263 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
264
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
265 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
266 FloatMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
267 octave_base_diag<DMT, MT>::float_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
268 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
269 return FloatMatrix (float_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
270 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
271
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
272 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
273 ComplexMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
274 octave_base_diag<DMT, MT>::complex_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
275 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
276 return ComplexMatrix (complex_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
277 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
278
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
279 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
280 FloatComplexMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
281 octave_base_diag<DMT, MT>::float_complex_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
282 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
283 return FloatComplexMatrix (float_complex_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
284 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
285
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
286 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
287 NDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
288 octave_base_diag<DMT, MT>::array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
289 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
290 return NDArray (matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
291 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
292
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
293 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
294 FloatNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
295 octave_base_diag<DMT, MT>::float_array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
296 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
297 return FloatNDArray (float_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
298 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
299
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
300 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
301 ComplexNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
302 octave_base_diag<DMT, MT>::complex_array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
303 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
304 return ComplexNDArray (complex_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
305 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
306
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
307 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
308 FloatComplexNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
309 octave_base_diag<DMT, MT>::float_complex_array_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
310 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
311 return FloatComplexNDArray (float_complex_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
312 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
313
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
314 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
315 boolNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
316 octave_base_diag<DMT, MT>::bool_array_value (bool warn) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
317 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
318 return to_dense ().bool_array_value (warn);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
319 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
320
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
321 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
322 charNDArray
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
323 octave_base_diag<DMT, MT>::char_array_value (bool warn) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
324 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
325 return to_dense ().char_array_value (warn);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
326 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
327
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
328 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
329 SparseMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
330 octave_base_diag<DMT, MT>::sparse_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
331 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
332 return SparseMatrix (diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
333 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
334
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
335 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
336 SparseComplexMatrix
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
337 octave_base_diag<DMT, MT>::sparse_complex_matrix_value (bool) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
338 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
339 return SparseComplexMatrix (complex_diag_matrix_value ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
340 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
341
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
342 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
343 idx_vector
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
344 octave_base_diag<DMT, MT>::index_vector (void) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
345 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
346 return to_dense ().index_vector ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
347 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
348
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
349 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
350 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
351 octave_base_diag<DMT, MT>::convert_to_str_internal (bool pad, bool force, char type) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
352 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
353 return to_dense ().convert_to_str_internal (pad, force, type);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
354 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
355
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
356 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
357 bool
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
358 octave_base_diag<DMT, MT>::save_ascii (std::ostream& os)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
359 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
360 os << "# rows: " << matrix.rows () << "\n"
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
361 << "# columns: " << matrix.columns () << "\n";
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
362
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
363 os << matrix.diag ();
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
364
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
365 return true;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
366 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
367
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
368 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
369 bool
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
370 octave_base_diag<DMT, MT>::load_ascii (std::istream& is)
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
371 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
372 octave_idx_type r = 0, c = 0;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
373 bool success = true;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
374
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
375 if (extract_keyword (is, "rows", r, true)
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
376 && extract_keyword (is, "columns", c, true))
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
377 {
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
378 octave_idx_type l = r < c ? r : c;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
379 MT tmp (l, 1);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
380 is >> tmp;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
381
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
382 if (!is)
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
383 {
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
384 error ("load: failed to load diagonal matrix constant");
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
385 success = false;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
386 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
387 else
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
388 {
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
389 // This is a little tricky, as we have the Matrix type, but
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
390 // not ColumnVector type. We need to help the compiler get
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
391 // through the inheritance tree.
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
392 typedef typename DMT::element_type el_type;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
393 matrix = DMT (MDiagArray2<el_type> (MArray<el_type> (tmp)));
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
394 matrix.resize (r, c);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
395
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
396 // Invalidate cache. Probably not necessary, but safe.
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
397 dense_cache = octave_value ();
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
398 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
399 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
400 else
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
401 {
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
402 error ("load: failed to extract number of rows and columns");
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
403 success = false;
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
404 }
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
405
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
406 return success;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
407 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
408
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
409 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
410 void
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
411 octave_base_diag<DMT, MT>::print_raw (std::ostream& os,
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
412 bool pr_as_read_syntax) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
413 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
414 return to_dense ().print_raw (os, pr_as_read_syntax);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
415 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
416
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
417 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
418 mxArray *
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
419 octave_base_diag<DMT, MT>::as_mxArray (void) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
420 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
421 return to_dense ().as_mxArray ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
422 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
423
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
424 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
425 bool
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
426 octave_base_diag<DMT, MT>::print_as_scalar (void) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
427 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
428 dim_vector dv = dims ();
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
429
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
430 return (dv.all_ones () || dv.any_zero ());
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
431 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
432
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
433 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
434 void
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
435 octave_base_diag<DMT, MT>::print (std::ostream& os, bool pr_as_read_syntax) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
436 {
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
437 print_raw (os, pr_as_read_syntax);
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
438 newline (os);
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
439 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
440 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
441 int
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
442 octave_base_diag<DMT, MT>::write (octave_stream& os, int block_size,
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
443 oct_data_conv::data_type output_type, int skip,
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
444 oct_mach_info::float_format flt_fmt) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
445 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
446 return to_dense ().write (os, block_size, output_type, skip, flt_fmt);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
447 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
448
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
449 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
450 void
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
451 octave_base_diag<DMT, MT>::print_info (std::ostream& os,
8376
c43481a19bfe implement ASCII saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
452 const std::string& prefix) const
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
453 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
454 matrix.print_info (os, prefix);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
455 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
456
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
457 template <class DMT, class MT>
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
458 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
459 octave_base_diag<DMT, MT>::to_dense (void) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
460 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
461 if (! dense_cache.is_defined ())
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
462 dense_cache = MT (matrix);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
463
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
464 return dense_cache;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
465 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
466
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
467 #define FORWARD_MAPPER(MAP) \
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
468 template <class DMT, class MT> \
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
469 octave_value \
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
470 octave_base_diag<DMT, MT>::MAP (void) const \
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
471 { \
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
472 return to_dense ().MAP (); \
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
473 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
474
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
475 FORWARD_MAPPER (erf)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
476 FORWARD_MAPPER (erfc)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
477 FORWARD_MAPPER (gamma)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
478 FORWARD_MAPPER (lgamma)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
479 FORWARD_MAPPER (acos)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
480 FORWARD_MAPPER (acosh)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
481 FORWARD_MAPPER (angle)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
482 FORWARD_MAPPER (arg)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
483 FORWARD_MAPPER (asin)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
484 FORWARD_MAPPER (asinh)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
485 FORWARD_MAPPER (atan)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
486 FORWARD_MAPPER (atanh)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
487 FORWARD_MAPPER (ceil)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
488 FORWARD_MAPPER (cos)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
489 FORWARD_MAPPER (cosh)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
490 FORWARD_MAPPER (exp)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
491 FORWARD_MAPPER (expm1)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
492 FORWARD_MAPPER (fix)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
493 FORWARD_MAPPER (floor)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
494 FORWARD_MAPPER (log)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
495 FORWARD_MAPPER (log2)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
496 FORWARD_MAPPER (log10)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
497 FORWARD_MAPPER (log1p)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
498 FORWARD_MAPPER (round)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
499 FORWARD_MAPPER (roundb)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
500 FORWARD_MAPPER (signum)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
501 FORWARD_MAPPER (sin)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
502 FORWARD_MAPPER (sinh)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
503 FORWARD_MAPPER (sqrt)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
504 FORWARD_MAPPER (tan)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
505 FORWARD_MAPPER (tanh)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
506 FORWARD_MAPPER (finite)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
507 FORWARD_MAPPER (isinf)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
508 FORWARD_MAPPER (isna)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
509 FORWARD_MAPPER (isnan)
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
510