Mercurial > jwe > octave
annotate libinterp/octave-value/ov-re-mat.cc @ 19861:19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Try to wrap long lines to < 80 characters.
Use GNU style and don't indent first brace of function definition.
"case" statement is aligned flush left with brace of switch stmt.
Remove trailing '\' line continuation from the end of #define macros.
Use 2 spaces for indent.
* files-dock-widget.cc, history-dock-widget.cc, main-window.cc, octave-cmd.cc,
octave-dock-widget.cc, octave-gui.cc, resource-manager.cc, settings-dialog.cc,
shortcut-manager.cc, welcome-wizard.cc, workspace-view.cc, cellfun.cc, data.cc,
debug.cc, debug.h, dirfns.cc, error.h, file-io.cc, gl-render.cc, gl-render.h,
gl2ps-renderer.h, graphics.cc, graphics.in.h, help.cc, input.cc, load-path.cc,
load-path.h, lookup.cc, lu.cc, oct-stream.cc, octave-default-image.h,
ordschur.cc, pr-output.cc, qz.cc, strfns.cc, symtab.cc, symtab.h, sysdep.cc,
variables.cc, zfstream.h, __fltk_uigetfile__.cc, __init_fltk__.cc,
__magick_read__.cc, __osmesa_print__.cc, audiodevinfo.cc, ov-classdef.cc,
ov-classdef.h, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-java.cc,
ov-range.cc, ov-re-mat.cc, ov-usr-fcn.h, ov.cc, op-int.h, options-usage.h,
pt-eval.cc, Array-C.cc, Array-fC.cc, Array.cc, Array.h, PermMatrix.cc,
Sparse.cc, chMatrix.h, dSparse.cc, dim-vector.h, bsxfun-decl.h, bsxfun-defs.cc,
oct-norm.cc, Sparse-op-defs.h, oct-inttypes.cc, oct-inttypes.h, main.in.cc,
mkoctfile.in.cc: Cleanup C++ code to follow Octave coding conventions.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Feb 2015 11:55:49 -0800 |
parents | 4197fc428c7d |
children | 09ed6f7538dd |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
3503 | 28 #include <iostream> |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
29 #include <limits> |
4726 | 30 #include <vector> |
2901 | 31 |
4944 | 32 #include "data-conv.h" |
2376 | 33 #include "lo-ieee.h" |
34 #include "lo-utils.h" | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
35 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
36 #include "lo-mappers.h" |
4944 | 37 #include "mach-info.h" |
2376 | 38 #include "mx-base.h" |
4153 | 39 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
40 #include "oct-locbuf.h" |
2376 | 41 |
4901 | 42 #include "defun.h" |
2376 | 43 #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
|
44 #include "mxarray.h" |
2376 | 45 #include "oct-obj.h" |
2979 | 46 #include "oct-lvalue.h" |
4944 | 47 #include "oct-stream.h" |
2410 | 48 #include "ops.h" |
3219 | 49 #include "ov-base.h" |
50 #include "ov-base-mat.h" | |
51 #include "ov-base-mat.cc" | |
2410 | 52 #include "ov-scalar.h" |
2376 | 53 #include "ov-re-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
54 #include "ov-flt-re-mat.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
55 #include "ov-complex.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
56 #include "ov-cx-mat.h" |
7004 | 57 #include "ov-re-sparse.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
58 #include "ov-re-diag.h" |
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
59 #include "ov-cx-diag.h" |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
60 #include "ov-lazy-idx.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
61 #include "ov-perm.h" |
4901 | 62 #include "ov-type-conv.h" |
2376 | 63 #include "pr-output.h" |
2948 | 64 #include "variables.h" |
2376 | 65 |
4687 | 66 #include "byte-swap.h" |
67 #include "ls-oct-ascii.h" | |
68 #include "ls-utils.h" | |
4805 | 69 #include "ls-hdf5.h" |
4687 | 70 |
4513 | 71 template class octave_base_matrix<NDArray>; |
2376 | 72 |
2477 | 73 |
4612 | 74 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_matrix, "matrix", "double"); |
2376 | 75 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
76 static octave_base_value * |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
77 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
|
78 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
79 CAST_CONV_ARG (const octave_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
80 |
8754
900a5bf52309
Fix invalid conversion error on implicit demotion of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
81 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
|
82 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
83 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
84 octave_base_value::type_conv_info |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
85 octave_matrix::numeric_demotion_function (void) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
86 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
87 return octave_base_value::type_conv_info |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 (default_numeric_demotion_function, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 octave_float_matrix::static_type_id ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
90 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
91 |
5759 | 92 octave_base_value * |
2410 | 93 octave_matrix::try_narrowing_conversion (void) |
94 { | |
5759 | 95 octave_base_value *retval = 0; |
2410 | 96 |
4513 | 97 if (matrix.nelem () == 1) |
98 retval = new octave_scalar (matrix (0)); | |
2410 | 99 |
100 return retval; | |
101 } | |
102 | |
2376 | 103 double |
104 octave_matrix::double_value (bool) const | |
105 { | |
4102 | 106 double retval = lo_ieee_nan_value (); |
2376 | 107 |
4645 | 108 if (numel () > 0) |
4455 | 109 { |
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
|
110 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
111 "real matrix", "real scalar"); |
4455 | 112 |
113 retval = matrix (0, 0); | |
114 } | |
2376 | 115 else |
116 gripe_invalid_conversion ("real matrix", "real scalar"); | |
117 | |
118 return retval; | |
119 } | |
120 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
121 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
122 octave_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
123 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
124 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
125 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
126 if (numel () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 { |
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
|
128 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
129 "real matrix", "real scalar"); |
7789
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 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
133 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
134 gripe_invalid_conversion ("real matrix", "real scalar"); |
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 return retval; |
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 |
5775 | 139 // FIXME |
4513 | 140 |
141 Matrix | |
142 octave_matrix::matrix_value (bool) const | |
143 { | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
144 return Matrix (matrix); |
4513 | 145 } |
146 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
147 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
148 octave_matrix::float_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
150 return FloatMatrix (Matrix (matrix)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
151 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
152 |
2376 | 153 Complex |
154 octave_matrix::complex_value (bool) const | |
155 { | |
4102 | 156 double tmp = lo_ieee_nan_value (); |
157 | |
158 Complex retval (tmp, tmp); | |
2376 | 159 |
4455 | 160 if (rows () > 0 && columns () > 0) |
161 { | |
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
|
162 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
163 "real matrix", "complex scalar"); |
4455 | 164 |
165 retval = matrix (0, 0); | |
166 } | |
2376 | 167 else |
168 gripe_invalid_conversion ("real matrix", "complex scalar"); | |
169 | |
170 return retval; | |
171 } | |
172 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
173 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
174 octave_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
175 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
176 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
177 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
178 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
179 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
180 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
181 { |
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
|
182 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
183 "real matrix", "complex scalar"); |
7789
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 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
186 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
187 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
188 gripe_invalid_conversion ("real matrix", "complex scalar"); |
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 return retval; |
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 |
5775 | 193 // FIXME |
4513 | 194 |
195 ComplexMatrix | |
196 octave_matrix::complex_matrix_value (bool) const | |
197 { | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
198 return ComplexMatrix (Matrix (matrix)); |
4513 | 199 } |
200 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
201 FloatComplexMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
202 octave_matrix::float_complex_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
203 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
204 return FloatComplexMatrix (Matrix (matrix)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
205 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
206 |
4699 | 207 ComplexNDArray |
208 octave_matrix::complex_array_value (bool) const | |
209 { | |
210 return ComplexNDArray (matrix); | |
211 } | |
212 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
213 FloatComplexNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
214 octave_matrix::float_complex_array_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
215 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
216 return FloatComplexNDArray (matrix); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
217 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
218 |
5898 | 219 boolNDArray |
5943 | 220 octave_matrix::bool_array_value (bool warn) const |
5898 | 221 { |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
222 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
|
223 gripe_nan_to_logical_conversion (); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
224 else if (warn && matrix.any_element_not_one_or_zero ()) |
5943 | 225 gripe_logical_conversion (); |
226 | |
5898 | 227 return boolNDArray (matrix); |
228 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
229 |
4758 | 230 charNDArray |
231 octave_matrix::char_array_value (bool) const | |
232 { | |
233 charNDArray retval (dims ()); | |
234 | |
5275 | 235 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
236 |
5275 | 237 for (octave_idx_type i = 0; i < nel; i++) |
4758 | 238 retval.elem (i) = static_cast<char>(matrix.elem (i)); |
239 | |
240 return retval; | |
241 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
242 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
243 SparseMatrix |
5164 | 244 octave_matrix::sparse_matrix_value (bool) const |
245 { | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
246 return SparseMatrix (Matrix (matrix)); |
5164 | 247 } |
248 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
249 SparseComplexMatrix |
5164 | 250 octave_matrix::sparse_complex_matrix_value (bool) const |
251 { | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
252 // FIXME: Need a SparseComplexMatrix (Matrix) constructor to make |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
253 // this function more efficient. Then this should become |
5164 | 254 // return SparseComplexMatrix (matrix.matrix_value ()); |
255 return SparseComplexMatrix (sparse_matrix_value ()); | |
256 } | |
257 | |
2376 | 258 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
259 octave_matrix::diag (octave_idx_type k) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
260 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
261 octave_value retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
262 if (k == 0 && matrix.ndims () == 2 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
263 && (matrix.rows () == 1 || matrix.columns () == 1)) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
264 retval = DiagMatrix (DiagArray2<double> (matrix)); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
265 else |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
266 retval = octave_base_matrix<NDArray>::diag (k); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
267 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
268 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
269 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
270 |
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
|
271 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
|
272 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
|
273 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14469
diff
changeset
|
274 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
|
275 |
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 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
|
277 && (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
|
278 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
279 Matrix mat (matrix); |
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
|
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 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
|
282 } |
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 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
|
284 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
|
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 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
|
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 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
289 // We override these two functions to allow reshaping both |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
290 // the matrix and the index cache. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
291 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
292 octave_matrix::reshape (const dim_vector& new_dims) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
293 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
294 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
295 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
296 return new octave_matrix (matrix.reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
297 idx_vector (idx_cache->as_array ().reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
298 idx_cache->extent (0))); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
299 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
300 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
301 return octave_base_matrix<NDArray>::reshape (new_dims); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
302 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
303 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
304 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
305 octave_matrix::squeeze (void) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
306 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
307 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
308 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
309 return new octave_matrix (matrix.squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
310 idx_vector (idx_cache->as_array ().squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
311 idx_cache->extent (0))); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
312 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
313 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
314 return octave_base_matrix<NDArray>::squeeze (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
315 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
316 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
317 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
318 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
|
319 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
320 if (idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
321 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
322 // 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
|
323 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
324 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
|
325 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
326 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
327 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
|
328 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
329 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
330 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
331 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
|
332 sortmode mode) const |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
333 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
334 if (idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
335 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
336 // 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
|
337 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
338 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
|
339 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
340 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
341 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
|
342 } |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
343 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
344 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
345 octave_matrix::is_sorted (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
346 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
347 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
348 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
349 // 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
|
350 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
351 return idx_cache->as_array ().is_sorted (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
352 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
353 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
354 return octave_base_matrix<NDArray>::is_sorted (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
355 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
356 Array<octave_idx_type> |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
357 octave_matrix::sort_rows_idx (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
358 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
359 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
360 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
361 // 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
|
362 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
363 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
|
364 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
365 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
366 return octave_base_matrix<NDArray>::sort_rows_idx (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
367 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
368 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
369 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
370 octave_matrix::is_sorted_rows (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
371 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
372 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
373 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
374 // 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
|
375 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
376 return idx_cache->as_array ().is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
377 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
378 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
379 return octave_base_matrix<NDArray>::is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
380 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
381 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
382 octave_value |
5279 | 383 octave_matrix::convert_to_str_internal (bool, bool, char type) const |
2376 | 384 { |
385 octave_value retval; | |
4844 | 386 dim_vector dv = dims (); |
5862 | 387 octave_idx_type nel = dv.numel (); |
388 | |
389 charNDArray chm (dv); | |
2376 | 390 |
5862 | 391 bool warned = false; |
392 | |
393 for (octave_idx_type i = 0; i < nel; i++) | |
2376 | 394 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
395 octave_quit (); |
5862 | 396 |
397 double d = matrix (i); | |
4844 | 398 |
5862 | 399 if (xisnan (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
400 { |
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
|
401 gripe_nan_to_character_conversion (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
402 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
403 } |
5862 | 404 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
406 int ival = NINT (d); |
4844 | 407 |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
408 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
409 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
410 // FIXME: is there something better we could do? |
2376 | 411 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
412 ival = 0; |
5862 | 413 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
414 if (! warned) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
415 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
416 ::warning ("range error for conversion to character value"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
417 warned = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
418 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
419 } |
2376 | 420 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
421 chm (i) = static_cast<char> (ival); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
422 } |
5862 | 423 } |
2376 | 424 |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9470
diff
changeset
|
425 retval = octave_value (chm, type); |
2376 | 426 |
427 return retval; | |
428 } | |
429 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
430 bool |
6974 | 431 octave_matrix::save_ascii (std::ostream& os) |
4687 | 432 { |
433 dim_vector d = dims (); | |
5958 | 434 |
4687 | 435 if (d.length () > 2) |
436 { | |
437 NDArray tmp = array_value (); | |
438 | |
439 os << "# ndims: " << d.length () << "\n"; | |
440 | |
441 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
|
442 os << " " << d (i); |
4687 | 443 |
444 os << "\n" << tmp; | |
445 } | |
446 else | |
447 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
448 // Keep this case, rather than use generic code above for backward |
4687 | 449 // compatiability. Makes load_ascii much more complex!! |
450 os << "# rows: " << rows () << "\n" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
451 << "# columns: " << columns () << "\n"; |
4687 | 452 |
5958 | 453 os << matrix_value (); |
4687 | 454 } |
455 | |
456 return true; | |
457 } | |
458 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
459 bool |
4687 | 460 octave_matrix::load_ascii (std::istream& is) |
461 { | |
462 bool success = true; | |
5099 | 463 |
464 string_vector keywords(2); | |
465 | |
466 keywords[0] = "ndims"; | |
467 keywords[1] = "rows"; | |
4687 | 468 |
5099 | 469 std::string kw; |
5275 | 470 octave_idx_type val = 0; |
5099 | 471 |
472 if (extract_keyword (is, keywords, kw, val, true)) | |
4687 | 473 { |
5099 | 474 if (kw == "ndims") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
475 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
476 int mdims = static_cast<int> (val); |
4687 | 477 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
478 if (mdims >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
479 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
480 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
481 dv.resize (mdims); |
4687 | 482 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
483 for (int i = 0; i < mdims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
484 is >> dv(i); |
4687 | 485 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
486 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
487 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
488 NDArray tmp(dv); |
6717 | 489 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
490 is >> tmp; |
5099 | 491 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
492 if (is) |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
493 matrix = tmp; |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
494 else |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
495 { |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
496 error ("load: failed to load matrix constant"); |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
497 success = false; |
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
498 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
499 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
500 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
501 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
502 error ("load: failed to read dimensions"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
503 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
504 } |
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 extract number of 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 } |
5099 | 512 else if (kw == "rows") |
10315
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 octave_idx_type nr = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
515 octave_idx_type nc = 0; |
5099 | 516 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
517 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
|
518 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
519 if (nr > 0 && nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
520 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
521 Matrix tmp (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
522 is >> tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
523 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
524 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
525 else |
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 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
528 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
529 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
530 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
531 else if (nr == 0 || nc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
532 matrix = Matrix (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
533 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
534 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
535 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
536 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
537 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
538 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
|
539 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
540 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
541 } |
5099 | 542 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
543 panic_impossible (); |
5099 | 544 } |
545 else | |
546 { | |
547 error ("load: failed to extract number of rows and columns"); | |
548 success = false; | |
4687 | 549 } |
550 | |
551 return success; | |
552 } | |
553 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
554 bool |
4687 | 555 octave_matrix::save_binary (std::ostream& os, bool& save_as_floats) |
556 { | |
557 | |
558 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
|
559 if (d.length () < 1) |
4687 | 560 return false; |
561 | |
562 // 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
|
563 int32_t tmp = - d.length (); |
5760 | 564 os.write (reinterpret_cast<char *> (&tmp), 4); |
5275 | 565 for (int i = 0; i < d.length (); i++) |
4687 | 566 { |
567 tmp = d(i); | |
5760 | 568 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 569 } |
570 | |
571 NDArray m = array_value (); | |
572 save_type st = LS_DOUBLE; | |
573 if (save_as_floats) | |
574 { | |
575 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
576 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
577 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
|
578 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
579 } |
4687 | 580 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
581 st = LS_FLOAT; |
4687 | 582 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
583 else if (d.numel () > 8192) // FIXME: make this configurable. |
4687 | 584 { |
585 double max_val, min_val; | |
586 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
|
587 st = get_save_type (max_val, min_val); |
4687 | 588 } |
589 | |
590 const double *mtmp = m.data (); | |
591 write_doubles (os, mtmp, st, d.numel ()); | |
592 | |
593 return true; | |
594 } | |
595 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
596 bool |
4687 | 597 octave_matrix::load_binary (std::istream& is, bool swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
598 oct_mach_info::float_format fmt) |
4687 | 599 { |
600 char tmp; | |
5828 | 601 int32_t mdims; |
5760 | 602 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 603 return false; |
604 if (swap) | |
4944 | 605 swap_bytes<4> (&mdims); |
4687 | 606 if (mdims < 0) |
607 { | |
608 mdims = - mdims; | |
5828 | 609 int32_t di; |
4687 | 610 dim_vector dv; |
611 dv.resize (mdims); | |
612 | |
613 for (int i = 0; i < mdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
614 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
615 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
616 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
617 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
618 swap_bytes<4> (&di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
619 dv(i) = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
620 } |
4687 | 621 |
5157 | 622 // Convert an array with a single dimension to be a row vector. |
623 // Octave should never write files like this, other software | |
624 // might. | |
625 | |
626 if (mdims == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
627 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
628 mdims = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
629 dv.resize (mdims); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
630 dv(1) = dv(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
631 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
632 } |
5157 | 633 |
5760 | 634 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
|
635 return false; |
4687 | 636 |
637 NDArray m(dv); | |
638 double *re = m.fortran_vec (); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
639 read_doubles (is, re, static_cast<save_type> (tmp), dv.numel (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
640 swap, fmt); |
4687 | 641 if (error_state || ! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
642 return false; |
4687 | 643 matrix = m; |
644 } | |
645 else | |
646 { | |
5828 | 647 int32_t nr, nc; |
4687 | 648 nr = mdims; |
5760 | 649 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
|
650 return false; |
4687 | 651 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
652 swap_bytes<4> (&nc); |
5760 | 653 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
|
654 return false; |
4687 | 655 Matrix m (nr, nc); |
656 double *re = m.fortran_vec (); | |
5275 | 657 octave_idx_type len = nr * nc; |
5760 | 658 read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt); |
4687 | 659 if (error_state || ! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
660 return false; |
4687 | 661 matrix = m; |
662 } | |
663 return true; | |
664 } | |
665 | |
666 #if defined (HAVE_HDF5) | |
4944 | 667 |
4687 | 668 bool |
669 octave_matrix::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
670 { | |
4837 | 671 dim_vector dv = dims (); |
672 int empty = save_hdf5_empty (loc_id, name, dv); | |
673 if (empty) | |
4805 | 674 return (empty > 0); |
675 | |
4837 | 676 int rank = dv.length (); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
677 hid_t space_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
678 space_hid = data_hid = -1; |
4687 | 679 bool retval = true; |
680 NDArray m = array_value (); | |
681 | |
4805 | 682 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
683 | |
4687 | 684 // Octave uses column-major, while HDF5 uses row-major ordering |
4805 | 685 for (int i = 0; i < rank; i++) |
4837 | 686 hdims[i] = dv (rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
687 |
4815 | 688 space_hid = H5Screate_simple (rank, hdims, 0); |
4687 | 689 |
690 if (space_hid < 0) return false; | |
691 | |
692 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
693 | |
694 if (save_as_floats) | |
695 { | |
696 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
697 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
698 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
|
699 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
700 } |
4687 | 701 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
702 save_type_hid = H5T_NATIVE_FLOAT; |
4687 | 703 } |
704 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
705 // hdf5 currently doesn't support float/integer conversions | |
706 else | |
707 { | |
708 double max_val, min_val; | |
709 | |
710 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
|
711 save_type_hid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
712 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
4687 | 713 } |
714 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
715 |
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
|
716 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
717 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
|
718 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
|
719 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
720 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
|
721 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
|
722 #endif |
4687 | 723 if (data_hid < 0) |
724 { | |
725 H5Sclose (space_hid); | |
726 return false; | |
727 } | |
728 | |
729 double *mtmp = m.fortran_vec (); | |
730 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
|
731 H5P_DEFAULT, mtmp) >= 0; |
4687 | 732 |
733 H5Dclose (data_hid); | |
734 H5Sclose (space_hid); | |
4837 | 735 |
4687 | 736 return retval; |
737 } | |
738 | |
739 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9835
diff
changeset
|
740 octave_matrix::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 741 { |
4837 | 742 bool retval = false; |
743 | |
4805 | 744 dim_vector dv; |
745 int empty = load_hdf5_empty (loc_id, name, dv); | |
746 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
|
747 matrix.resize (dv); |
4837 | 748 if (empty) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
749 return (empty > 0); |
4805 | 750 |
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
|
751 #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
|
752 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
|
753 #else |
4687 | 754 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
|
755 #endif |
4687 | 756 hid_t space_id = H5Dget_space (data_hid); |
757 | |
758 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
|
759 |
4687 | 760 if (rank < 1) |
761 { | |
762 H5Sclose (space_id); | |
763 H5Dclose (data_hid); | |
764 return false; | |
765 } | |
766 | |
767 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
768 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
769 | |
770 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
771 | |
772 // Octave uses column-major, while HDF5 uses row-major ordering | |
773 if (rank == 1) | |
774 { | |
775 dv.resize (2); | |
776 dv(0) = 1; | |
777 dv(1) = hdims[0]; | |
778 } | |
779 else | |
780 { | |
781 dv.resize (rank); | |
4815 | 782 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
|
783 dv(j) = hdims[i]; |
4687 | 784 } |
785 | |
786 NDArray m (dv); | |
787 double *re = m.fortran_vec (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
788 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
|
789 H5P_DEFAULT, re) >= 0) |
4687 | 790 { |
791 retval = true; | |
792 matrix = m; | |
793 } | |
794 | |
795 H5Sclose (space_id); | |
796 H5Dclose (data_hid); | |
4837 | 797 |
4687 | 798 return retval; |
799 } | |
4944 | 800 |
4687 | 801 #endif |
802 | |
4643 | 803 void |
804 octave_matrix::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
805 bool pr_as_read_syntax) const |
4643 | 806 { |
807 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
|
808 current_print_indent_level ()); |
4643 | 809 } |
810 | |
5900 | 811 mxArray * |
812 octave_matrix::as_mxArray (void) const | |
813 { | |
814 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL); | |
815 | |
816 double *pr = static_cast<double *> (retval->get_data ()); | |
817 | |
6686 | 818 mwSize nel = numel (); |
5900 | 819 |
820 const double *p = matrix.data (); | |
821 | |
6686 | 822 for (mwIndex i = 0; i < nel; i++) |
5900 | 823 pr[i] = p[i]; |
824 | |
825 return retval; | |
826 } | |
827 | |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
828 // 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
|
829 // 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
|
830 // result is produced. |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
831 static octave_value |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
832 do_rc_map (const NDArray& a, Complex (&fcn) (double)) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
833 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
834 octave_idx_type n = a.numel (); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
835 NoAlias<NDArray> rr (a.dims ()); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
836 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
837 for (octave_idx_type i = 0; i < n; i++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
838 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
839 octave_quit (); |
9823
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 Complex tmp = fcn (a(i)); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
842 if (tmp.imag () == 0.0) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
843 rr(i) = tmp.real (); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
844 else |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
845 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
846 NoAlias<ComplexNDArray> rc (a.dims ()); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
847 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
848 for (octave_idx_type j = 0; j < i; j++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
849 rc(j) = rr(j); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
850 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
851 rc(i) = tmp; |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
852 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
853 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
|
854 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
855 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
856 |
9824
6631c61a4a4e
fix typos in previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9823
diff
changeset
|
857 rc(j) = fcn (a(j)); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
858 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
859 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
860 return new octave_complex_matrix (rc); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
861 } |
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 rr; |
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 |
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
|
867 octave_value |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
868 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
|
869 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
870 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
871 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
872 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
873 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
|
874 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
875 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
876 case umap_conj: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
877 return matrix; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
878 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
879 // Mappers handled specially. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
880 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
881 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
882 return octave_value (matrix.FCN ()) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
883 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
884 ARRAY_METHOD_MAPPER (abs, abs); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
885 ARRAY_METHOD_MAPPER (isnan, isnan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
886 ARRAY_METHOD_MAPPER (isinf, isinf); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
887 ARRAY_METHOD_MAPPER (finite, isfinite); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
888 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
889 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
890 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
891 return octave_value (matrix.map<TYPE> (FCN)) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
892 |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
893 #define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
894 case umap_ ## UMAP: \ |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
895 return do_rc_map (matrix, FCN) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
896 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
897 RC_ARRAY_MAPPER (acos, Complex, rc_acos); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
898 RC_ARRAY_MAPPER (acosh, Complex, rc_acosh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
899 ARRAY_MAPPER (angle, double, ::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
900 ARRAY_MAPPER (arg, double, ::arg); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
901 RC_ARRAY_MAPPER (asin, Complex, rc_asin); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
902 ARRAY_MAPPER (asinh, double, ::asinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
903 ARRAY_MAPPER (atan, double, ::atan); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
904 RC_ARRAY_MAPPER (atanh, Complex, rc_atanh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
905 ARRAY_MAPPER (erf, double, ::erf); |
9835
1bb1ed717d2f
implement built-in erfinv
Jaroslav Hajek <highegg@gmail.com>
parents:
9824
diff
changeset
|
906 ARRAY_MAPPER (erfinv, double, ::erfinv); |
14770
cb85e836d035
New function: erfcinv (bug #36607)
Axel Mathéi <axel.mathei@gmail.com>
parents:
14557
diff
changeset
|
907 ARRAY_MAPPER (erfcinv, double, ::erfcinv); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
908 ARRAY_MAPPER (erfc, double, ::erfc); |
10391
59e34bcdff13
implement built-in erfcx
Jaroslav Hajek <highegg@gmail.com>
parents:
10339
diff
changeset
|
909 ARRAY_MAPPER (erfcx, double, ::erfcx); |
15696
2fac72a256ce
Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents:
15487
diff
changeset
|
910 ARRAY_MAPPER (erfi, double, ::erfi); |
2fac72a256ce
Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents:
15487
diff
changeset
|
911 ARRAY_MAPPER (dawson, double, ::dawson); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
912 ARRAY_MAPPER (gamma, double, xgamma); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
913 RC_ARRAY_MAPPER (lgamma, Complex, rc_lgamma); |
10414
2a8b1db1e2ca
implement built-in cbrt
Jaroslav Hajek <highegg@gmail.com>
parents:
10391
diff
changeset
|
914 ARRAY_MAPPER (cbrt, double, ::cbrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
915 ARRAY_MAPPER (ceil, double, ::ceil); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
916 ARRAY_MAPPER (cos, double, ::cos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
917 ARRAY_MAPPER (cosh, double, ::cosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
918 ARRAY_MAPPER (exp, double, ::exp); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
919 ARRAY_MAPPER (expm1, double, ::expm1); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
920 ARRAY_MAPPER (fix, double, ::fix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
921 ARRAY_MAPPER (floor, double, ::floor); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
922 RC_ARRAY_MAPPER (log, Complex, rc_log); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
923 RC_ARRAY_MAPPER (log2, Complex, rc_log2); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
924 RC_ARRAY_MAPPER (log10, Complex, rc_log10); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
925 RC_ARRAY_MAPPER (log1p, Complex, rc_log1p); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
926 ARRAY_MAPPER (round, double, xround); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
927 ARRAY_MAPPER (roundb, double, xroundb); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
928 ARRAY_MAPPER (signum, double, ::signum); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
929 ARRAY_MAPPER (sin, double, ::sin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
930 ARRAY_MAPPER (sinh, double, ::sinh); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
931 RC_ARRAY_MAPPER (sqrt, Complex, rc_sqrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
932 ARRAY_MAPPER (tan, double, ::tan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
933 ARRAY_MAPPER (tanh, double, ::tanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
934 ARRAY_MAPPER (isna, bool, octave_is_NA); |
15487
ecf5be238b4a
provide signbit mapper for real values
John W. Eaton <jwe@octave.org>
parents:
15215
diff
changeset
|
935 ARRAY_MAPPER (xsignbit, double, xsignbit); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
936 |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
937 // Special cases for Matlab compatibility. |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
938 case umap_xtolower: |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
939 case umap_xtoupper: |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
940 return matrix; |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
941 |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
942 case umap_xisalnum: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
943 case umap_xisalpha: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
944 case umap_xisascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
945 case umap_xiscntrl: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
946 case umap_xisdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
947 case umap_xisgraph: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
948 case umap_xislower: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
949 case umap_xisprint: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
950 case umap_xispunct: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
951 case umap_xisspace: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
952 case umap_xisupper: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
953 case umap_xisxdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
954 case umap_xtoascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
955 { |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
956 octave_value str_conv = convert_to_str (true, true); |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
957 return error_state ? octave_value () : str_conv.map (umap); |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
958 } |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
959 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
960 default: |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
961 return octave_base_value::map (umap); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
962 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
963 } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
964 |
4901 | 965 DEFUN (double, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
966 "-*- texinfo -*-\n\ |
4901 | 967 @deftypefn {Built-in Function} {} double (@var{x})\n\ |
968 Convert @var{x} to double precision type.\n\ | |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9184
diff
changeset
|
969 @seealso{single}\n\ |
4901 | 970 @end deftypefn") |
971 { | |
7004 | 972 // The OCTAVE_TYPE_CONV_BODY3 macro declares retval, so they go |
973 // inside their own scopes, and we don't declare retval here to | |
974 // avoid a shadowed declaration warning. | |
975 | |
9184 | 976 if (args.length () == 1) |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
977 { |
9184 | 978 if (args(0).is_perm_matrix ()) |
979 { | |
980 OCTAVE_TYPE_CONV_BODY3 (double, octave_perm_matrix, octave_scalar); | |
981 } | |
982 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
|
983 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
984 if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
985 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
986 OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_diag_matrix, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
987 octave_complex); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
988 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
989 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
990 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
991 OCTAVE_TYPE_CONV_BODY3 (double, octave_diag_matrix, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
992 octave_scalar); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
993 } |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
994 } |
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
995 else if (args(0).is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
996 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
997 if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
998 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
999 OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_complex_matrix, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1000 octave_complex); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1001 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1002 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1003 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1004 OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_matrix, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1005 octave_scalar); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1006 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1007 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
1008 else if (args(0).is_complex_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1009 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1010 OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_matrix, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1011 octave_complex); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1012 } |
7004 | 1013 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1014 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
1015 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
|
1016 } |
7004 | 1017 } |
1018 else | |
1019 print_usage (); | |
1020 | |
1021 return octave_value (); | |
4901 | 1022 } |
12818
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1023 |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1024 /* |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1025 %!assert (class (double (single (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1026 %!assert (class (double (single (1 + i))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1027 %!assert (class (double (int8 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1028 %!assert (class (double (uint8 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1029 %!assert (class (double (int16 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1030 %!assert (class (double (uint16 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1031 %!assert (class (double (int32 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1032 %!assert (class (double (uint32 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1033 %!assert (class (double (int64 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1034 %!assert (class (double (uint64 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1035 %!assert (class (double (true)), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1036 %!assert (class (double ("A")), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1037 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1038 %! x = sparse (logical ([1 0; 0 1])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1039 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1040 %! assert (class (x), "logical"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1041 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1042 %! assert (issparse (y)); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1043 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1044 %! x = diag (single ([1 3 2])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1045 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1046 %! assert (class (x), "single"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1047 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1048 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1049 %! x = diag (single ([i 3 2])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1050 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1051 %! assert (class (x), "single"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1052 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1053 */ |