Mercurial > jwe > octave
annotate libinterp/octave-value/ov-re-mat.cc @ 15195:2fc554ffbc28
split libinterp from src
* libinterp: New directory. Move all files from src directory here
except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc,
mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh.
* libinterp/Makefile.am: New file, extracted from src/Makefile.am.
* src/Makefile.am: Delete everything except targets and definitions
needed to build and link main and utility programs.
* Makefile.am (SUBDIRS): Include libinterp in the list.
* autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not
src/dldfcn directory.
* configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not
src/octave.cc.
(DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src.
(AC_CONFIG_FILES): Include libinterp/Makefile in the list.
* find-docstring-files.sh: Look in libinterp, not src.
* gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in
libinterp, not src.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 18 Aug 2012 16:23:39 -0400 |
parents | src/octave-value/ov-re-mat.cc@62a35ae7d6a2 |
children | 9020dddc925a |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12818
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
2376 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
4100 | 28 #include <climits> |
29 | |
3503 | 30 #include <iostream> |
4726 | 31 #include <vector> |
2901 | 32 |
4944 | 33 #include "data-conv.h" |
2376 | 34 #include "lo-ieee.h" |
35 #include "lo-utils.h" | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
36 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
37 #include "lo-mappers.h" |
4944 | 38 #include "mach-info.h" |
2376 | 39 #include "mx-base.h" |
4153 | 40 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
41 #include "oct-locbuf.h" |
2376 | 42 |
4901 | 43 #include "defun.h" |
2376 | 44 #include "gripes.h" |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
45 #include "mxarray.h" |
2376 | 46 #include "oct-obj.h" |
2979 | 47 #include "oct-lvalue.h" |
4944 | 48 #include "oct-stream.h" |
2410 | 49 #include "ops.h" |
3219 | 50 #include "ov-base.h" |
51 #include "ov-base-mat.h" | |
52 #include "ov-base-mat.cc" | |
2410 | 53 #include "ov-scalar.h" |
2376 | 54 #include "ov-re-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
55 #include "ov-flt-re-mat.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
56 #include "ov-complex.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
57 #include "ov-cx-mat.h" |
7004 | 58 #include "ov-re-sparse.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
59 #include "ov-re-diag.h" |
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
60 #include "ov-cx-diag.h" |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
61 #include "ov-lazy-idx.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
62 #include "ov-perm.h" |
4901 | 63 #include "ov-type-conv.h" |
2376 | 64 #include "pr-output.h" |
2948 | 65 #include "variables.h" |
2376 | 66 |
4687 | 67 #include "byte-swap.h" |
68 #include "ls-oct-ascii.h" | |
69 #include "ls-utils.h" | |
4805 | 70 #include "ls-hdf5.h" |
4687 | 71 |
4100 | 72 #if ! defined (UCHAR_MAX) |
73 #define UCHAR_MAX 255 | |
74 #endif | |
75 | |
4513 | 76 template class octave_base_matrix<NDArray>; |
2376 | 77 |
3219 | 78 DEFINE_OCTAVE_ALLOCATOR (octave_matrix); |
2477 | 79 |
4612 | 80 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_matrix, "matrix", "double"); |
2376 | 81 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
82 static octave_base_value * |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
83 default_numeric_demotion_function (const octave_base_value& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
84 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
85 CAST_CONV_ARG (const octave_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
86 |
8754
900a5bf52309
Fix invalid conversion error on implicit demotion of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
87 return new octave_float_matrix (v.float_array_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
88 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
89 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
90 octave_base_value::type_conv_info |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
91 octave_matrix::numeric_demotion_function (void) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
92 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
93 return octave_base_value::type_conv_info (default_numeric_demotion_function, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
94 octave_float_matrix::static_type_id ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
95 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
96 |
5759 | 97 octave_base_value * |
2410 | 98 octave_matrix::try_narrowing_conversion (void) |
99 { | |
5759 | 100 octave_base_value *retval = 0; |
2410 | 101 |
4513 | 102 if (matrix.nelem () == 1) |
103 retval = new octave_scalar (matrix (0)); | |
2410 | 104 |
105 return retval; | |
106 } | |
107 | |
2376 | 108 double |
109 octave_matrix::double_value (bool) const | |
110 { | |
4102 | 111 double retval = lo_ieee_nan_value (); |
2376 | 112 |
4645 | 113 if (numel () > 0) |
4455 | 114 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
115 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
116 "real matrix", "real scalar"); |
4455 | 117 |
118 retval = matrix (0, 0); | |
119 } | |
2376 | 120 else |
121 gripe_invalid_conversion ("real matrix", "real scalar"); | |
122 | |
123 return retval; | |
124 } | |
125 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
126 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 octave_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
128 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
129 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
130 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
131 if (numel () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
133 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
134 "real matrix", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
135 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
138 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
139 gripe_invalid_conversion ("real matrix", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
140 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
141 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
142 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
143 |
5775 | 144 // FIXME |
4513 | 145 |
146 Matrix | |
147 octave_matrix::matrix_value (bool) const | |
148 { | |
149 return matrix.matrix_value (); | |
150 } | |
151 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
152 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
153 octave_matrix::float_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
154 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
155 return FloatMatrix (matrix.matrix_value ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
156 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
157 |
2376 | 158 Complex |
159 octave_matrix::complex_value (bool) const | |
160 { | |
4102 | 161 double tmp = lo_ieee_nan_value (); |
162 | |
163 Complex retval (tmp, tmp); | |
2376 | 164 |
4455 | 165 if (rows () > 0 && columns () > 0) |
166 { | |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
167 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
168 "real matrix", "complex scalar"); |
4455 | 169 |
170 retval = matrix (0, 0); | |
171 } | |
2376 | 172 else |
173 gripe_invalid_conversion ("real matrix", "complex scalar"); | |
174 | |
175 return retval; | |
176 } | |
177 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
178 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
179 octave_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
180 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
181 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
182 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
183 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
184 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
185 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
186 { |
14469
29aabe9b37a2
Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
187 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
188 "real matrix", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
189 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
190 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
191 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
192 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
193 gripe_invalid_conversion ("real matrix", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
194 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
195 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
196 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
197 |
5775 | 198 // FIXME |
4513 | 199 |
200 ComplexMatrix | |
201 octave_matrix::complex_matrix_value (bool) const | |
202 { | |
203 return ComplexMatrix (matrix.matrix_value ()); | |
204 } | |
205 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
206 FloatComplexMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
207 octave_matrix::float_complex_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
208 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
209 return FloatComplexMatrix (matrix.matrix_value ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
210 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
211 |
4699 | 212 ComplexNDArray |
213 octave_matrix::complex_array_value (bool) const | |
214 { | |
215 return ComplexNDArray (matrix); | |
216 } | |
217 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
218 FloatComplexNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
219 octave_matrix::float_complex_array_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
220 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
221 return FloatComplexNDArray (matrix); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
222 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
223 |
5898 | 224 boolNDArray |
5943 | 225 octave_matrix::bool_array_value (bool warn) const |
5898 | 226 { |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
227 if (matrix.any_element_is_nan ()) |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
228 gripe_nan_to_logical_conversion (); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
229 else if (warn && matrix.any_element_not_one_or_zero ()) |
5943 | 230 gripe_logical_conversion (); |
231 | |
5898 | 232 return boolNDArray (matrix); |
233 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
234 |
4758 | 235 charNDArray |
236 octave_matrix::char_array_value (bool) const | |
237 { | |
238 charNDArray retval (dims ()); | |
239 | |
5275 | 240 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
241 |
5275 | 242 for (octave_idx_type i = 0; i < nel; i++) |
4758 | 243 retval.elem (i) = static_cast<char>(matrix.elem (i)); |
244 | |
245 return retval; | |
246 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
247 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
248 SparseMatrix |
5164 | 249 octave_matrix::sparse_matrix_value (bool) const |
250 { | |
251 return SparseMatrix (matrix.matrix_value ()); | |
252 } | |
253 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
254 SparseComplexMatrix |
5164 | 255 octave_matrix::sparse_complex_matrix_value (bool) const |
256 { | |
5775 | 257 // FIXME Need a SparseComplexMatrix (Matrix) constructor to make |
5164 | 258 // this function more efficient. Then this should become |
259 // return SparseComplexMatrix (matrix.matrix_value ()); | |
260 return SparseComplexMatrix (sparse_matrix_value ()); | |
261 } | |
262 | |
2376 | 263 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
264 octave_matrix::diag (octave_idx_type k) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
265 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
266 octave_value retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
267 if (k == 0 && matrix.ndims () == 2 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
268 && (matrix.rows () == 1 || matrix.columns () == 1)) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
269 retval = DiagMatrix (DiagArray2<double> (matrix)); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
270 else |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
271 retval = octave_base_matrix<NDArray>::diag (k); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
272 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
273 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
274 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
275 |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
276 octave_value |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
277 octave_matrix::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
278 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
279 octave_value retval; |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
280 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
281 if (matrix.ndims () == 2 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
282 && (matrix.rows () == 1 || matrix.columns () == 1)) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
283 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
284 Matrix mat = matrix.matrix_value (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
285 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
286 retval = mat.diag (m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
287 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
288 else |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
289 error ("diag: expecting vector argument"); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
290 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
291 return retval; |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
292 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
293 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
294 // We override these two functions to allow reshaping both |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
295 // the matrix and the index cache. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
296 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
297 octave_matrix::reshape (const dim_vector& new_dims) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
298 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
299 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
300 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
301 return new octave_matrix (matrix.reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
302 idx_vector (idx_cache->as_array ().reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
303 idx_cache->extent (0))); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
304 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
305 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
306 return octave_base_matrix<NDArray>::reshape (new_dims); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
307 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
308 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
309 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
310 octave_matrix::squeeze (void) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
311 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
312 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
313 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
314 return new octave_matrix (matrix.squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
315 idx_vector (idx_cache->as_array ().squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
316 idx_cache->extent (0))); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
317 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
318 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
319 return octave_base_matrix<NDArray>::squeeze (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
320 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
321 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
322 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
323 octave_matrix::sort (octave_idx_type dim, sortmode mode) const |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
324 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
325 if (idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
326 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
327 // This is a valid index matrix, so sort via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
328 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
329 return octave_lazy_index (*idx_cache).sort (dim, mode); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
330 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
331 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
332 return octave_base_matrix<NDArray>::sort (dim, mode); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
333 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
334 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
335 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
336 octave_matrix::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
337 sortmode mode) const |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
338 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
339 if (idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
340 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
341 // This is a valid index matrix, so sort via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
342 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
343 return octave_lazy_index (*idx_cache).sort (sidx, dim, mode); |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
344 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
345 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
346 return octave_base_matrix<NDArray>::sort (sidx, dim, mode); |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
347 } |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
348 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
349 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
350 octave_matrix::is_sorted (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
351 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
352 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
353 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
354 // This is a valid index matrix, so check via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
355 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
356 return idx_cache->as_array ().is_sorted (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
357 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
358 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
359 return octave_base_matrix<NDArray>::is_sorted (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
360 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
361 Array<octave_idx_type> |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
362 octave_matrix::sort_rows_idx (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
363 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
364 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
365 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
366 // This is a valid index matrix, so sort via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
367 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
368 return octave_lazy_index (*idx_cache).sort_rows_idx (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
369 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
370 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
371 return octave_base_matrix<NDArray>::sort_rows_idx (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
372 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
373 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
374 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
375 octave_matrix::is_sorted_rows (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
376 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
377 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
378 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
379 // This is a valid index matrix, so check via integers because it's |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
380 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
381 return idx_cache->as_array ().is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
382 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
383 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
384 return octave_base_matrix<NDArray>::is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
385 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
386 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
387 octave_value |
5279 | 388 octave_matrix::convert_to_str_internal (bool, bool, char type) const |
2376 | 389 { |
390 octave_value retval; | |
4844 | 391 dim_vector dv = dims (); |
5862 | 392 octave_idx_type nel = dv.numel (); |
393 | |
394 charNDArray chm (dv); | |
2376 | 395 |
5862 | 396 bool warned = false; |
397 | |
398 for (octave_idx_type i = 0; i < nel; i++) | |
2376 | 399 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
400 octave_quit (); |
5862 | 401 |
402 double d = matrix (i); | |
4844 | 403 |
5862 | 404 if (xisnan (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
405 { |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
406 gripe_nan_to_character_conversion (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
407 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
408 } |
5862 | 409 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
410 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
411 int ival = NINT (d); |
4844 | 412 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
413 if (ival < 0 || ival > UCHAR_MAX) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
414 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
415 // FIXME -- is there something |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
416 // better we could do? |
2376 | 417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
418 ival = 0; |
5862 | 419 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
420 if (! warned) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
421 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
422 ::warning ("range error for conversion to character value"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
423 warned = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
424 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
425 } |
2376 | 426 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
427 chm (i) = static_cast<char> (ival); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
428 } |
5862 | 429 } |
2376 | 430 |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9470
diff
changeset
|
431 retval = octave_value (chm, type); |
2376 | 432 |
433 return retval; | |
434 } | |
435 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
436 bool |
6974 | 437 octave_matrix::save_ascii (std::ostream& os) |
4687 | 438 { |
439 dim_vector d = dims (); | |
5958 | 440 |
4687 | 441 if (d.length () > 2) |
442 { | |
443 NDArray tmp = array_value (); | |
444 | |
445 os << "# ndims: " << d.length () << "\n"; | |
446 | |
447 for (int i=0; i < d.length (); i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
448 os << " " << d (i); |
4687 | 449 |
450 os << "\n" << tmp; | |
451 } | |
452 else | |
453 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
454 // Keep this case, rather than use generic code above for backward |
4687 | 455 // compatiability. Makes load_ascii much more complex!! |
456 os << "# rows: " << rows () << "\n" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
457 << "# columns: " << columns () << "\n"; |
4687 | 458 |
5958 | 459 os << matrix_value (); |
4687 | 460 } |
461 | |
462 return true; | |
463 } | |
464 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
465 bool |
4687 | 466 octave_matrix::load_ascii (std::istream& is) |
467 { | |
468 bool success = true; | |
5099 | 469 |
470 string_vector keywords(2); | |
471 | |
472 keywords[0] = "ndims"; | |
473 keywords[1] = "rows"; | |
4687 | 474 |
5099 | 475 std::string kw; |
5275 | 476 octave_idx_type val = 0; |
5099 | 477 |
478 if (extract_keyword (is, keywords, kw, val, true)) | |
4687 | 479 { |
5099 | 480 if (kw == "ndims") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
481 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
482 int mdims = static_cast<int> (val); |
4687 | 483 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
484 if (mdims >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
485 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
486 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
487 dv.resize (mdims); |
4687 | 488 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
489 for (int i = 0; i < mdims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
490 is >> dv(i); |
4687 | 491 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
492 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
493 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
494 NDArray tmp(dv); |
6717 | 495 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
496 is >> tmp; |
5099 | 497 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
498 if (is) |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
499 matrix = tmp; |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
500 else |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
501 { |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
502 error ("load: failed to load matrix constant"); |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
503 success = false; |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
504 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
505 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
506 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
507 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
508 error ("load: failed to read dimensions"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
509 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
510 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
511 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
512 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
513 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
514 error ("load: failed to extract number of dimensions"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
515 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
516 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
517 } |
5099 | 518 else if (kw == "rows") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
519 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
520 octave_idx_type nr = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
521 octave_idx_type nc = 0; |
5099 | 522 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
523 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
524 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
525 if (nr > 0 && nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
526 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
527 Matrix tmp (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
528 is >> tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
529 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
530 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
531 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
532 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
533 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
534 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
535 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
536 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
537 else if (nr == 0 || nc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
538 matrix = Matrix (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
539 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
540 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
541 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
542 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
543 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
544 error ("load: failed to extract number of rows and columns"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
545 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
546 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
547 } |
5099 | 548 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
549 panic_impossible (); |
5099 | 550 } |
551 else | |
552 { | |
553 error ("load: failed to extract number of rows and columns"); | |
554 success = false; | |
4687 | 555 } |
556 | |
557 return success; | |
558 } | |
559 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
560 bool |
4687 | 561 octave_matrix::save_binary (std::ostream& os, bool& save_as_floats) |
562 { | |
563 | |
564 dim_vector d = dims (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14770
diff
changeset
|
565 if (d.length () < 1) |
4687 | 566 return false; |
567 | |
568 // Use negative value for ndims to differentiate with old format!! | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14770
diff
changeset
|
569 int32_t tmp = - d.length (); |
5760 | 570 os.write (reinterpret_cast<char *> (&tmp), 4); |
5275 | 571 for (int i = 0; i < d.length (); i++) |
4687 | 572 { |
573 tmp = d(i); | |
5760 | 574 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 575 } |
576 | |
577 NDArray m = array_value (); | |
578 save_type st = LS_DOUBLE; | |
579 if (save_as_floats) | |
580 { | |
581 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
582 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
583 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
584 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
585 } |
4687 | 586 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
587 st = LS_FLOAT; |
4687 | 588 } |
5775 | 589 else if (d.numel () > 8192) // FIXME -- make this configurable. |
4687 | 590 { |
591 double max_val, min_val; | |
592 if (m.all_integers (max_val, min_val)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
593 st = get_save_type (max_val, min_val); |
4687 | 594 } |
595 | |
596 const double *mtmp = m.data (); | |
597 write_doubles (os, mtmp, st, d.numel ()); | |
598 | |
599 return true; | |
600 } | |
601 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
602 bool |
4687 | 603 octave_matrix::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
604 oct_mach_info::float_format fmt) |
4687 | 605 { |
606 char tmp; | |
5828 | 607 int32_t mdims; |
5760 | 608 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 609 return false; |
610 if (swap) | |
4944 | 611 swap_bytes<4> (&mdims); |
4687 | 612 if (mdims < 0) |
613 { | |
614 mdims = - mdims; | |
5828 | 615 int32_t di; |
4687 | 616 dim_vector dv; |
617 dv.resize (mdims); | |
618 | |
619 for (int i = 0; i < mdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
620 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
621 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
622 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
623 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
624 swap_bytes<4> (&di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
625 dv(i) = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
626 } |
4687 | 627 |
5157 | 628 // Convert an array with a single dimension to be a row vector. |
629 // Octave should never write files like this, other software | |
630 // might. | |
631 | |
632 if (mdims == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
633 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
634 mdims = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
635 dv.resize (mdims); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
636 dv(1) = dv(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
637 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
638 } |
5157 | 639 |
5760 | 640 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
641 return false; |
4687 | 642 |
643 NDArray m(dv); | |
644 double *re = m.fortran_vec (); | |
5760 | 645 read_doubles (is, re, static_cast<save_type> (tmp), dv.numel (), swap, fmt); |
4687 | 646 if (error_state || ! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
647 return false; |
4687 | 648 matrix = m; |
649 } | |
650 else | |
651 { | |
5828 | 652 int32_t nr, nc; |
4687 | 653 nr = mdims; |
5760 | 654 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
655 return false; |
4687 | 656 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
657 swap_bytes<4> (&nc); |
5760 | 658 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
659 return false; |
4687 | 660 Matrix m (nr, nc); |
661 double *re = m.fortran_vec (); | |
5275 | 662 octave_idx_type len = nr * nc; |
5760 | 663 read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt); |
4687 | 664 if (error_state || ! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
665 return false; |
4687 | 666 matrix = m; |
667 } | |
668 return true; | |
669 } | |
670 | |
671 #if defined (HAVE_HDF5) | |
4944 | 672 |
4687 | 673 bool |
674 octave_matrix::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
675 { | |
4837 | 676 dim_vector dv = dims (); |
677 int empty = save_hdf5_empty (loc_id, name, dv); | |
678 if (empty) | |
4805 | 679 return (empty > 0); |
680 | |
4837 | 681 int rank = dv.length (); |
4687 | 682 hid_t space_hid = -1, data_hid = -1; |
683 bool retval = true; | |
684 NDArray m = array_value (); | |
685 | |
4805 | 686 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
687 | |
4687 | 688 // Octave uses column-major, while HDF5 uses row-major ordering |
4805 | 689 for (int i = 0; i < rank; i++) |
4837 | 690 hdims[i] = dv (rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
691 |
4815 | 692 space_hid = H5Screate_simple (rank, hdims, 0); |
4687 | 693 |
694 if (space_hid < 0) return false; | |
695 | |
696 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
697 | |
698 if (save_as_floats) | |
699 { | |
700 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
701 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
702 warning ("save: some values too large to save as floats --"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
703 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
704 } |
4687 | 705 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
706 save_type_hid = H5T_NATIVE_FLOAT; |
4687 | 707 } |
708 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
709 // hdf5 currently doesn't support float/integer conversions | |
710 else | |
711 { | |
712 double max_val, min_val; | |
713 | |
714 if (m.all_integers (max_val, min_val)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
715 save_type_hid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
716 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
4687 | 717 } |
718 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
719 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
720 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
721 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
722 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
723 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
724 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
725 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
726 #endif |
4687 | 727 if (data_hid < 0) |
728 { | |
729 H5Sclose (space_hid); | |
730 return false; | |
731 } | |
732 | |
733 double *mtmp = m.fortran_vec (); | |
734 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
735 H5P_DEFAULT, mtmp) >= 0; |
4687 | 736 |
737 H5Dclose (data_hid); | |
738 H5Sclose (space_hid); | |
4837 | 739 |
4687 | 740 return retval; |
741 } | |
742 | |
743 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9835
diff
changeset
|
744 octave_matrix::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 745 { |
4837 | 746 bool retval = false; |
747 | |
4805 | 748 dim_vector dv; |
749 int empty = load_hdf5_empty (loc_id, name, dv); | |
750 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
751 matrix.resize (dv); |
4837 | 752 if (empty) |
4805 | 753 return (empty > 0); |
754 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
755 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
756 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
757 #else |
4687 | 758 hid_t data_hid = H5Dopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
759 #endif |
4687 | 760 hid_t space_id = H5Dget_space (data_hid); |
761 | |
762 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
763 |
4687 | 764 if (rank < 1) |
765 { | |
766 H5Sclose (space_id); | |
767 H5Dclose (data_hid); | |
768 return false; | |
769 } | |
770 | |
771 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
772 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
773 | |
774 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
775 | |
776 // Octave uses column-major, while HDF5 uses row-major ordering | |
777 if (rank == 1) | |
778 { | |
779 dv.resize (2); | |
780 dv(0) = 1; | |
781 dv(1) = hdims[0]; | |
782 } | |
783 else | |
784 { | |
785 dv.resize (rank); | |
4815 | 786 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
787 dv(j) = hdims[i]; |
4687 | 788 } |
789 | |
790 NDArray m (dv); | |
791 double *re = m.fortran_vec (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
792 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
793 H5P_DEFAULT, re) >= 0) |
4687 | 794 { |
795 retval = true; | |
796 matrix = m; | |
797 } | |
798 | |
799 H5Sclose (space_id); | |
800 H5Dclose (data_hid); | |
4837 | 801 |
4687 | 802 return retval; |
803 } | |
4944 | 804 |
4687 | 805 #endif |
806 | |
4643 | 807 void |
808 octave_matrix::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
809 bool pr_as_read_syntax) const |
4643 | 810 { |
811 octave_print_internal (os, matrix, pr_as_read_syntax, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
812 current_print_indent_level ()); |
4643 | 813 } |
814 | |
5900 | 815 mxArray * |
816 octave_matrix::as_mxArray (void) const | |
817 { | |
818 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL); | |
819 | |
820 double *pr = static_cast<double *> (retval->get_data ()); | |
821 | |
6686 | 822 mwSize nel = numel (); |
5900 | 823 |
824 const double *p = matrix.data (); | |
825 | |
6686 | 826 for (mwIndex i = 0; i < nel; i++) |
5900 | 827 pr[i] = p[i]; |
828 | |
829 return retval; | |
830 } | |
831 | |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
832 // This uses a smarter strategy for doing the complex->real mappers. We |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
833 // allocate an array for a real result and keep filling it until a complex |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
834 // result is produced. |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
835 static octave_value |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
836 do_rc_map (const NDArray& a, Complex (&fcn) (double)) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
837 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
838 octave_idx_type n = a.numel (); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
839 NoAlias<NDArray> rr (a.dims ()); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
840 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
841 for (octave_idx_type i = 0; i < n; i++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
842 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
843 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
844 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
845 Complex tmp = fcn (a(i)); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
846 if (tmp.imag () == 0.0) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
847 rr(i) = tmp.real (); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
848 else |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
849 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
850 NoAlias<ComplexNDArray> rc (a.dims ()); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
851 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
852 for (octave_idx_type j = 0; j < i; j++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
853 rc(j) = rr(j); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
854 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
855 rc(i) = tmp; |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
856 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
857 for (octave_idx_type j = i+1; j < n; j++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
858 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
859 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
860 |
9824
6631c61a4a4e
fix typos in previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9823
diff
changeset
|
861 rc(j) = fcn (a(j)); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
862 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
863 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
864 return new octave_complex_matrix (rc); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
865 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
866 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
867 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
868 return rr; |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
869 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
870 |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
871 octave_value |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
872 octave_matrix::map (unary_mapper_t umap) const |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
873 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
874 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
875 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
876 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
877 return NDArray (matrix.dims (), 0.0); |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
878 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
879 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
880 case umap_conj: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
881 return matrix; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
882 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
883 // Mappers handled specially. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
884 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
885 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
886 return octave_value (matrix.FCN ()) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
887 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
888 ARRAY_METHOD_MAPPER (abs, abs); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
889 ARRAY_METHOD_MAPPER (isnan, isnan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
890 ARRAY_METHOD_MAPPER (isinf, isinf); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
891 ARRAY_METHOD_MAPPER (finite, isfinite); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
892 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
893 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
894 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
895 return octave_value (matrix.map<TYPE> (FCN)) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
896 |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
897 #define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
898 case umap_ ## UMAP: \ |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
899 return do_rc_map (matrix, FCN) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
900 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
901 RC_ARRAY_MAPPER (acos, Complex, rc_acos); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
902 RC_ARRAY_MAPPER (acosh, Complex, rc_acosh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
903 ARRAY_MAPPER (angle, double, ::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
904 ARRAY_MAPPER (arg, double, ::arg); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
905 RC_ARRAY_MAPPER (asin, Complex, rc_asin); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
906 ARRAY_MAPPER (asinh, double, ::asinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
907 ARRAY_MAPPER (atan, double, ::atan); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
908 RC_ARRAY_MAPPER (atanh, Complex, rc_atanh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
909 ARRAY_MAPPER (erf, double, ::erf); |
9835
1bb1ed717d2f
implement built-in erfinv
Jaroslav Hajek <highegg@gmail.com>
parents:
9824
diff
changeset
|
910 ARRAY_MAPPER (erfinv, double, ::erfinv); |
14770
cb85e836d035
New function: erfcinv (bug #36607)
Axel Mathéi <axel.mathei@gmail.com>
parents:
14557
diff
changeset
|
911 ARRAY_MAPPER (erfcinv, double, ::erfcinv); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
912 ARRAY_MAPPER (erfc, double, ::erfc); |
10391
59e34bcdff13
implement built-in erfcx
Jaroslav Hajek <highegg@gmail.com>
parents:
10339
diff
changeset
|
913 ARRAY_MAPPER (erfcx, double, ::erfcx); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
914 ARRAY_MAPPER (gamma, double, xgamma); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
915 RC_ARRAY_MAPPER (lgamma, Complex, rc_lgamma); |
10414
2a8b1db1e2ca
implement built-in cbrt
Jaroslav Hajek <highegg@gmail.com>
parents:
10391
diff
changeset
|
916 ARRAY_MAPPER (cbrt, double, ::cbrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
917 ARRAY_MAPPER (ceil, double, ::ceil); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
918 ARRAY_MAPPER (cos, double, ::cos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
919 ARRAY_MAPPER (cosh, double, ::cosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
920 ARRAY_MAPPER (exp, double, ::exp); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
921 ARRAY_MAPPER (expm1, double, ::expm1); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
922 ARRAY_MAPPER (fix, double, ::fix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
923 ARRAY_MAPPER (floor, double, ::floor); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
924 RC_ARRAY_MAPPER (log, Complex, rc_log); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
925 RC_ARRAY_MAPPER (log2, Complex, rc_log2); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
926 RC_ARRAY_MAPPER (log10, Complex, rc_log10); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
927 RC_ARRAY_MAPPER (log1p, Complex, rc_log1p); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
928 ARRAY_MAPPER (round, double, xround); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
929 ARRAY_MAPPER (roundb, double, xroundb); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
930 ARRAY_MAPPER (signum, double, ::signum); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
931 ARRAY_MAPPER (sin, double, ::sin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
932 ARRAY_MAPPER (sinh, double, ::sinh); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
933 RC_ARRAY_MAPPER (sqrt, Complex, rc_sqrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
934 ARRAY_MAPPER (tan, double, ::tan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
935 ARRAY_MAPPER (tanh, double, ::tanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
936 ARRAY_MAPPER (isna, bool, octave_is_NA); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
937 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
938 default: |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
939 if (umap >= umap_xisalnum && umap <= umap_xtoupper) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
940 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
941 octave_value str_conv = convert_to_str (true, true); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
942 return error_state ? octave_value () : str_conv.map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
943 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
944 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
945 return octave_base_value::map (umap); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
946 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
947 } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
948 |
4901 | 949 DEFUN (double, args, , |
950 "-*- texinfo -*-\n\ | |
951 @deftypefn {Built-in Function} {} double (@var{x})\n\ | |
952 Convert @var{x} to double precision type.\n\ | |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9184
diff
changeset
|
953 @seealso{single}\n\ |
4901 | 954 @end deftypefn") |
955 { | |
7004 | 956 // The OCTAVE_TYPE_CONV_BODY3 macro declares retval, so they go |
957 // inside their own scopes, and we don't declare retval here to | |
958 // avoid a shadowed declaration warning. | |
959 | |
9184 | 960 if (args.length () == 1) |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
961 { |
9184 | 962 if (args(0).is_perm_matrix ()) |
963 { | |
964 OCTAVE_TYPE_CONV_BODY3 (double, octave_perm_matrix, octave_scalar); | |
965 } | |
966 else if (args(0).is_diag_matrix ()) | |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
967 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
968 if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
969 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
970 OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_diag_matrix, octave_complex); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
971 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
972 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
973 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
974 OCTAVE_TYPE_CONV_BODY3 (double, octave_diag_matrix, octave_scalar); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
975 } |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
976 } |
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
977 else if (args(0).is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
978 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
979 if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
980 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
981 OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_complex_matrix, octave_complex); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
982 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
983 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
984 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
985 OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_matrix, octave_scalar); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
986 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
987 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
988 else if (args(0).is_complex_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
989 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
990 OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_matrix, octave_complex); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
991 } |
7004 | 992 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
993 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
994 OCTAVE_TYPE_CONV_BODY3 (double, octave_matrix, octave_scalar); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
995 } |
7004 | 996 } |
997 else | |
998 print_usage (); | |
999 | |
1000 return octave_value (); | |
4901 | 1001 } |
12818
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1002 |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1003 /* |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1004 %!assert (class (double (single (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1005 %!assert (class (double (single (1 + i))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1006 %!assert (class (double (int8 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1007 %!assert (class (double (uint8 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1008 %!assert (class (double (int16 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1009 %!assert (class (double (uint16 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1010 %!assert (class (double (int32 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1011 %!assert (class (double (uint32 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1012 %!assert (class (double (int64 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1013 %!assert (class (double (uint64 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1014 %!assert (class (double (true)), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1015 %!assert (class (double ("A")), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1016 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1017 %! x = sparse (logical ([1 0; 0 1])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1018 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1019 %! assert (class (x), "logical"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1020 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1021 %! assert (issparse (y)); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1022 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1023 %! x = diag (single ([1 3 2])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1024 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1025 %! assert (class (x), "single"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1026 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1027 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1028 %! x = diag (single ([i 3 2])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1029 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1030 %! assert (class (x), "single"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1031 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1032 */ |