Mercurial > jwe > octave
annotate libinterp/octave-value/ov-re-mat.cc @ 21100:e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
* libinterp/corefcn/errwarn.h, libinterp/corefcn/errwarn.cc: New header and .cc
file with common errors and warnings for libinterp.
* libinterp/corefcn/module.mk: Add errwarn.h, errwarn.cc to build system.
* liboctave/util/lo-array-errwarn.h, liboctave/util/lo-array-errwarn.cc: New
header and .cc file with common errors and warnings for liboctave.
* liboctave/util/module.mk: Add lo-array-errwarn.h, lo-array-errwarn.cc to
build system.
* lo-array-gripes.h: #include "lo-array-errwarn.h" for access to class
index_exception. Remove const char *error_id_XXX prototypes.
* lo-array-gripes.cc: Remove const char *error_id_XXX initializations.
Remove index_exception method definitions.
* Cell.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, betainc.cc, cellfun.cc,
daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, det.cc,
dirfns.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, find.cc, gammainc.cc, gcd.cc,
getgrent.cc, getpwent.cc, graphics.in.h, help.cc, hess.cc, hex2num.cc,
input.cc, inv.cc, jit-typeinfo.cc, load-save.cc, lookup.cc, ls-hdf5.cc,
ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc,
lsode.cc, lu.cc, luinc.cc, max.cc, mgorth.cc, oct-hist.cc, oct-procbuf.cc,
oct-stream.cc, oct.h, pager.cc, pinv.cc, pr-output.cc, quad.cc, qz.cc, rand.cc,
rcond.cc, regexp.cc, schur.cc, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc,
spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, syscalls.cc, typecast.cc, utils.cc, variables.cc, xdiv.cc,
xnorm.cc, xpow.cc, __eigs__.cc, __glpk__.cc, __magick_read__.cc,
__osmesa_print__.cc, audiodevinfo.cc, audioread.cc, chol.cc, dmperm.cc,
fftw.cc, qr.cc, symbfact.cc, symrcm.cc, ov-base-diag.cc, ov-base-int.cc,
ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc,
ov-ch-mat.cc, ov-class.cc, ov-complex.cc, ov-complex.h, ov-cs-list.cc,
ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h,
ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-mex-fcn.cc, ov-perm.cc,
ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h,
ov-str-mat.cc, ov-struct.cc, ov-type-conv.h, ov-uint16.cc, ov-uint32.cc,
ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dms-template.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fdm.cc,
op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc,
op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc,
op-float-conv.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int-conv.cc,
op-int.h, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc,
op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-cm.cc,
op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc,
op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc,
op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc,
op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc,
op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
ops.h, lex.ll, pt-assign.cc, pt-eval.cc, pt-idx.cc, pt-loop.cc, pt-mat.cc,
pt-stmt.cc, Array-util.cc, Array-util.h, Array.cc, CColVector.cc,
CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc,
DiagArray2.cc, MDiagArray2.cc, MSparse.cc, PermMatrix.cc, Range.cc, Sparse.cc,
dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
dSparse.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc,
fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc,
fRowVector.cc, idx-vector.cc, CmplxGEPBAL.cc, dbleGEPBAL.cc, fCmplxGEPBAL.cc,
floatGEPBAL.cc, Sparse-diag-op-defs.h, Sparse-op-defs.h, Sparse-perm-op-defs.h,
mx-inlines.cc, mx-op-defs.h, oct-binmap.h:
Replace 'include "gripes.h"' with 'include "errwarn.h". Change all gripe_XXX
to err_XXX or warn_XXX or errwarn_XXX.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Jan 2016 18:28:06 -0800 |
parents | 6176560b03d9 |
children | dfcb9d74b253 |
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" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
43 #include "errwarn.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" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
45 #include "ovl.h" |
2979 | 46 #include "oct-lvalue.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
47 #include "oct-hdf5.h" |
4944 | 48 #include "oct-stream.h" |
2410 | 49 #include "ops.h" |
3219 | 50 #include "ov-base.h" |
51 #include "ov-base-mat.h" | |
52 #include "ov-base-mat.cc" | |
2410 | 53 #include "ov-scalar.h" |
2376 | 54 #include "ov-re-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
55 #include "ov-flt-re-mat.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
56 #include "ov-complex.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
57 #include "ov-cx-mat.h" |
7004 | 58 #include "ov-re-sparse.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
59 #include "ov-re-diag.h" |
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
60 #include "ov-cx-diag.h" |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
61 #include "ov-lazy-idx.h" |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
62 #include "ov-perm.h" |
4901 | 63 #include "ov-type-conv.h" |
2376 | 64 #include "pr-output.h" |
2948 | 65 #include "variables.h" |
2376 | 66 |
4687 | 67 #include "byte-swap.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
68 #include "ls-oct-text.h" |
4687 | 69 #include "ls-utils.h" |
4805 | 70 #include "ls-hdf5.h" |
4687 | 71 |
4513 | 72 template class octave_base_matrix<NDArray>; |
2376 | 73 |
2477 | 74 |
4612 | 75 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_matrix, "matrix", "double"); |
2376 | 76 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
77 static octave_base_value * |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
78 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
|
79 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
80 CAST_CONV_ARG (const octave_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
81 |
8754
900a5bf52309
Fix invalid conversion error on implicit demotion of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
82 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
|
83 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
84 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
85 octave_base_value::type_conv_info |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
86 octave_matrix::numeric_demotion_function (void) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
87 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 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
|
89 (default_numeric_demotion_function, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
90 octave_float_matrix::static_type_id ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
91 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
92 |
5759 | 93 octave_base_value * |
2410 | 94 octave_matrix::try_narrowing_conversion (void) |
95 { | |
5759 | 96 octave_base_value *retval = 0; |
2410 | 97 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
98 if (matrix.numel () == 1) |
4513 | 99 retval = new octave_scalar (matrix (0)); |
2410 | 100 |
101 return retval; | |
102 } | |
103 | |
2376 | 104 double |
105 octave_matrix::double_value (bool) const | |
106 { | |
4102 | 107 double retval = lo_ieee_nan_value (); |
2376 | 108 |
4645 | 109 if (numel () > 0) |
4455 | 110 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
111 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
112 "real matrix", "real scalar"); |
4455 | 113 |
114 retval = matrix (0, 0); | |
115 } | |
2376 | 116 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
117 err_invalid_conversion ("real matrix", "real scalar"); |
2376 | 118 |
119 return retval; | |
120 } | |
121 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
122 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
123 octave_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
124 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
125 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
126 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 if (numel () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
128 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
129 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
130 "real matrix", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
131 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
133 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
134 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
135 err_invalid_conversion ("real matrix", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
138 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
139 |
5775 | 140 // FIXME |
4513 | 141 |
142 Matrix | |
143 octave_matrix::matrix_value (bool) const | |
144 { | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
145 return Matrix (matrix); |
4513 | 146 } |
147 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
148 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 octave_matrix::float_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
150 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
151 return FloatMatrix (Matrix (matrix)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
152 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
153 |
2376 | 154 Complex |
155 octave_matrix::complex_value (bool) const | |
156 { | |
4102 | 157 double tmp = lo_ieee_nan_value (); |
158 | |
159 Complex retval (tmp, tmp); | |
2376 | 160 |
4455 | 161 if (rows () > 0 && columns () > 0) |
162 { | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
163 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
164 "real matrix", "complex scalar"); |
4455 | 165 |
166 retval = matrix (0, 0); | |
167 } | |
2376 | 168 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
169 err_invalid_conversion ("real matrix", "complex scalar"); |
2376 | 170 |
171 return retval; | |
172 } | |
173 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
174 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
175 octave_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
176 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
177 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
178 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
179 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
180 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
181 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
182 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
183 warn_implicit_conversion ("Octave:array-to-scalar", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
184 "real matrix", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
185 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
186 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
187 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
188 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
189 err_invalid_conversion ("real matrix", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
190 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
191 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
192 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
193 |
5775 | 194 // FIXME |
4513 | 195 |
196 ComplexMatrix | |
197 octave_matrix::complex_matrix_value (bool) const | |
198 { | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
199 return ComplexMatrix (Matrix (matrix)); |
4513 | 200 } |
201 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
202 FloatComplexMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
203 octave_matrix::float_complex_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
204 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
205 return FloatComplexMatrix (Matrix (matrix)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
206 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
207 |
4699 | 208 ComplexNDArray |
209 octave_matrix::complex_array_value (bool) const | |
210 { | |
211 return ComplexNDArray (matrix); | |
212 } | |
213 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
214 FloatComplexNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
215 octave_matrix::float_complex_array_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
216 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
217 return FloatComplexNDArray (matrix); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
218 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
219 |
5898 | 220 boolNDArray |
5943 | 221 octave_matrix::bool_array_value (bool warn) const |
5898 | 222 { |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
223 if (matrix.any_element_is_nan ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
224 err_nan_to_logical_conversion (); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
225 else if (warn && matrix.any_element_not_one_or_zero ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
226 warn_logical_conversion (); |
5943 | 227 |
5898 | 228 return boolNDArray (matrix); |
229 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
230 |
4758 | 231 charNDArray |
232 octave_matrix::char_array_value (bool) const | |
233 { | |
234 charNDArray retval (dims ()); | |
235 | |
5275 | 236 octave_idx_type nel = numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
237 |
5275 | 238 for (octave_idx_type i = 0; i < nel; i++) |
4758 | 239 retval.elem (i) = static_cast<char>(matrix.elem (i)); |
240 | |
241 return retval; | |
242 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
243 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
244 SparseMatrix |
5164 | 245 octave_matrix::sparse_matrix_value (bool) const |
246 { | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
18200
diff
changeset
|
247 return SparseMatrix (Matrix (matrix)); |
5164 | 248 } |
249 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
250 SparseComplexMatrix |
5164 | 251 octave_matrix::sparse_complex_matrix_value (bool) const |
252 { | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
253 // 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
|
254 // this function more efficient. Then this should become |
5164 | 255 // return SparseComplexMatrix (matrix.matrix_value ()); |
256 return SparseComplexMatrix (sparse_matrix_value ()); | |
257 } | |
258 | |
2376 | 259 octave_value |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
260 octave_matrix::diag (octave_idx_type k) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
261 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
262 octave_value retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
263 if (k == 0 && matrix.ndims () == 2 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
264 && (matrix.rows () == 1 || matrix.columns () == 1)) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
265 retval = DiagMatrix (DiagArray2<double> (matrix)); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
266 else |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
267 retval = octave_base_matrix<NDArray>::diag (k); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
268 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
269 return retval; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
270 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
271 |
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
|
272 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
|
273 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
|
274 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
275 if (matrix.ndims () != 2 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
276 || (matrix.rows () != 1 && matrix.columns () != 1)) |
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
|
277 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
|
278 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
279 Matrix mat (matrix); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
280 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
281 return mat.diag (m, n); |
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
|
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 |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
284 // We override these two functions to allow reshaping both |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
285 // the matrix and the index cache. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
286 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
287 octave_matrix::reshape (const dim_vector& new_dims) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
288 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
289 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
290 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
291 return new octave_matrix (matrix.reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
292 idx_vector (idx_cache->as_array ().reshape (new_dims), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
293 idx_cache->extent (0))); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
294 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
295 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
296 return octave_base_matrix<NDArray>::reshape (new_dims); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
297 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
298 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
299 octave_value |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
300 octave_matrix::squeeze (void) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
301 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
302 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
303 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
304 return new octave_matrix (matrix.squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
305 idx_vector (idx_cache->as_array ().squeeze (), |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
306 idx_cache->extent (0))); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
307 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
308 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
309 return octave_base_matrix<NDArray>::squeeze (); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
310 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
311 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
312 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
313 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
|
314 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
315 if (idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
316 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
317 // 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
|
318 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
319 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
|
320 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
321 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
322 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
|
323 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
324 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
325 octave_value |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
326 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
|
327 sortmode mode) const |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
328 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
329 if (idx_cache) |
10273
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
330 { |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
331 // 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
|
332 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
333 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
|
334 } |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
335 else |
3a8c13b71612
implement special-case optimization for sort of index vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
336 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
|
337 } |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
338 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
339 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
340 octave_matrix::is_sorted (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
341 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
342 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
343 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
344 // 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
|
345 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
346 return idx_cache->as_array ().is_sorted (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
347 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
348 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
349 return octave_base_matrix<NDArray>::is_sorted (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
350 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
351 Array<octave_idx_type> |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
352 octave_matrix::sort_rows_idx (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
353 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
354 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
355 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
356 // 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
|
357 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
358 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
|
359 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
360 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
361 return octave_base_matrix<NDArray>::sort_rows_idx (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
362 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
363 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
364 sortmode |
10339
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
365 octave_matrix::is_sorted_rows (sortmode mode) const |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
366 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
367 if (idx_cache) |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
368 { |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
369 // 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
|
370 // generally more efficient. |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
371 return idx_cache->as_array ().is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
372 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
373 else |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
374 return octave_base_matrix<NDArray>::is_sorted_rows (mode); |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
375 } |
de2d43bcb083
optimize some lazy index operations
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
376 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
377 octave_value |
5279 | 378 octave_matrix::convert_to_str_internal (bool, bool, char type) const |
2376 | 379 { |
380 octave_value retval; | |
4844 | 381 dim_vector dv = dims (); |
5862 | 382 octave_idx_type nel = dv.numel (); |
383 | |
384 charNDArray chm (dv); | |
2376 | 385 |
5862 | 386 bool warned = false; |
387 | |
388 for (octave_idx_type i = 0; i < nel; i++) | |
2376 | 389 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
390 octave_quit (); |
5862 | 391 |
392 double d = matrix (i); | |
4844 | 393 |
5862 | 394 if (xisnan (d)) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
395 err_nan_to_character_conversion (); |
5862 | 396 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
397 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
398 int ival = NINT (d); |
4844 | 399 |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
400 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
|
401 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
402 // FIXME: is there something better we could do? |
2376 | 403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
404 ival = 0; |
5862 | 405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
406 if (! warned) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
407 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
408 ::warning ("range error for conversion to character value"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
409 warned = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
410 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
411 } |
2376 | 412 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
413 chm (i) = static_cast<char> (ival); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
414 } |
5862 | 415 } |
2376 | 416 |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9470
diff
changeset
|
417 retval = octave_value (chm, type); |
2376 | 418 |
419 return retval; | |
420 } | |
421 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
422 bool |
6974 | 423 octave_matrix::save_ascii (std::ostream& os) |
4687 | 424 { |
425 dim_vector d = dims (); | |
5958 | 426 |
4687 | 427 if (d.length () > 2) |
428 { | |
429 NDArray tmp = array_value (); | |
430 | |
431 os << "# ndims: " << d.length () << "\n"; | |
432 | |
433 for (int i=0; i < d.length (); i++) | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
434 os << " " << d(i); |
4687 | 435 |
436 os << "\n" << tmp; | |
437 } | |
438 else | |
439 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
440 // Keep this case, rather than use generic code above for backward |
20449
df4165dfc676
maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
441 // compatibility. Makes load_ascii much more complex!! |
4687 | 442 os << "# rows: " << rows () << "\n" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
443 << "# columns: " << columns () << "\n"; |
4687 | 444 |
5958 | 445 os << matrix_value (); |
4687 | 446 } |
447 | |
448 return true; | |
449 } | |
450 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
451 bool |
4687 | 452 octave_matrix::load_ascii (std::istream& is) |
453 { | |
454 bool success = true; | |
5099 | 455 |
456 string_vector keywords(2); | |
457 | |
458 keywords[0] = "ndims"; | |
459 keywords[1] = "rows"; | |
4687 | 460 |
5099 | 461 std::string kw; |
5275 | 462 octave_idx_type val = 0; |
5099 | 463 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
464 if (! extract_keyword (is, keywords, kw, val, true)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
465 error ("load: failed to extract number of rows and columns"); |
4687 | 466 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
467 if (kw == "ndims") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
468 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
469 int mdims = static_cast<int> (val); |
4687 | 470 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
471 if (mdims < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
472 error ("load: failed to extract number of dimensions"); |
5099 | 473 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
474 dim_vector dv; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
475 dv.resize (mdims); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
476 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
477 for (int i = 0; i < mdims; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
478 is >> dv(i); |
5099 | 479 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
480 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
481 error ("load: failed to read dimensions"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
482 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
483 NDArray tmp(dv); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
484 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
485 is >> tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
486 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
487 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
488 error ("load: failed to load matrix constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
489 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
490 matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
491 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
492 else if (kw == "rows") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
493 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
494 octave_idx_type nr = val; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
495 octave_idx_type nc = 0; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
496 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
497 if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
498 error ("load: failed to extract number of rows and columns"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
499 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
500 if (nr > 0 && nc > 0) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
501 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
502 Matrix tmp (nr, nc); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
503 is >> tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
504 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
505 error ("load: failed to load matrix constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
506 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
507 matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
508 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
509 else if (nr == 0 || nc == 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
510 matrix = Matrix (nr, nc); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
511 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
512 panic_impossible (); |
5099 | 513 } |
514 else | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
515 panic_impossible (); |
4687 | 516 |
517 return success; | |
518 } | |
519 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
520 bool |
4687 | 521 octave_matrix::save_binary (std::ostream& os, bool& save_as_floats) |
522 { | |
523 | |
524 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
|
525 if (d.length () < 1) |
4687 | 526 return false; |
527 | |
528 // 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
|
529 int32_t tmp = - d.length (); |
5760 | 530 os.write (reinterpret_cast<char *> (&tmp), 4); |
5275 | 531 for (int i = 0; i < d.length (); i++) |
4687 | 532 { |
533 tmp = d(i); | |
5760 | 534 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 535 } |
536 | |
537 NDArray m = array_value (); | |
538 save_type st = LS_DOUBLE; | |
539 if (save_as_floats) | |
540 { | |
541 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
542 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
543 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
|
544 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
545 } |
4687 | 546 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
547 st = LS_FLOAT; |
4687 | 548 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
549 else if (d.numel () > 8192) // FIXME: make this configurable. |
4687 | 550 { |
551 double max_val, min_val; | |
552 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
|
553 st = get_save_type (max_val, min_val); |
4687 | 554 } |
555 | |
556 const double *mtmp = m.data (); | |
557 write_doubles (os, mtmp, st, d.numel ()); | |
558 | |
559 return true; | |
560 } | |
561 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
562 bool |
4687 | 563 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
|
564 oct_mach_info::float_format fmt) |
4687 | 565 { |
566 char tmp; | |
5828 | 567 int32_t mdims; |
5760 | 568 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 569 return false; |
570 if (swap) | |
4944 | 571 swap_bytes<4> (&mdims); |
4687 | 572 if (mdims < 0) |
573 { | |
574 mdims = - mdims; | |
5828 | 575 int32_t di; |
4687 | 576 dim_vector dv; |
577 dv.resize (mdims); | |
578 | |
579 for (int i = 0; i < mdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
580 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
581 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
582 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
583 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
584 swap_bytes<4> (&di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
585 dv(i) = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
586 } |
4687 | 587 |
5157 | 588 // Convert an array with a single dimension to be a row vector. |
589 // Octave should never write files like this, other software | |
590 // might. | |
591 | |
592 if (mdims == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
593 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
594 mdims = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
595 dv.resize (mdims); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
596 dv(1) = dv(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
597 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
598 } |
5157 | 599 |
5760 | 600 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
|
601 return false; |
4687 | 602 |
603 NDArray m(dv); | |
604 double *re = m.fortran_vec (); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
605 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
|
606 swap, fmt); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
607 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
608 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
609 return false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
610 |
4687 | 611 matrix = m; |
612 } | |
613 else | |
614 { | |
5828 | 615 int32_t nr, nc; |
4687 | 616 nr = mdims; |
5760 | 617 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
|
618 return false; |
4687 | 619 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
620 swap_bytes<4> (&nc); |
5760 | 621 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
|
622 return false; |
4687 | 623 Matrix m (nr, nc); |
624 double *re = m.fortran_vec (); | |
5275 | 625 octave_idx_type len = nr * nc; |
5760 | 626 read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
627 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
628 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
629 return false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
630 |
4687 | 631 matrix = m; |
632 } | |
633 return true; | |
634 } | |
635 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
636 bool |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
637 octave_matrix::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
638 { |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
639 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
640 |
4687 | 641 #if defined (HAVE_HDF5) |
4944 | 642 |
4837 | 643 dim_vector dv = dims (); |
644 int empty = save_hdf5_empty (loc_id, name, dv); | |
645 if (empty) | |
4805 | 646 return (empty > 0); |
647 | |
4837 | 648 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
|
649 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
|
650 space_hid = data_hid = -1; |
4687 | 651 NDArray m = array_value (); |
652 | |
4805 | 653 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
654 | |
4687 | 655 // Octave uses column-major, while HDF5 uses row-major ordering |
4805 | 656 for (int i = 0; i < rank; i++) |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
657 hdims[i] = dv(rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
658 |
4815 | 659 space_hid = H5Screate_simple (rank, hdims, 0); |
4687 | 660 |
661 if (space_hid < 0) return false; | |
662 | |
663 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
664 | |
665 if (save_as_floats) | |
666 { | |
667 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
668 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
669 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
|
670 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
671 } |
4687 | 672 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
673 save_type_hid = H5T_NATIVE_FLOAT; |
4687 | 674 } |
675 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
676 // hdf5 currently doesn't support float/integer conversions | |
677 else | |
678 { | |
679 double max_val, min_val; | |
680 | |
681 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
|
682 save_type_hid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
683 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
4687 | 684 } |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
20941
diff
changeset
|
685 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
686 |
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
|
687 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
688 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
689 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
690 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
691 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
692 octave_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
|
693 #endif |
4687 | 694 if (data_hid < 0) |
695 { | |
696 H5Sclose (space_hid); | |
697 return false; | |
698 } | |
699 | |
700 double *mtmp = m.fortran_vec (); | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
701 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
702 octave_H5P_DEFAULT, mtmp) >= 0; |
4687 | 703 |
704 H5Dclose (data_hid); | |
705 H5Sclose (space_hid); | |
4837 | 706 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
707 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
708 gripe_save ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
709 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
710 |
4687 | 711 return retval; |
712 } | |
713 | |
714 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
715 octave_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 716 { |
4837 | 717 bool retval = false; |
718 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
719 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
720 |
4805 | 721 dim_vector dv; |
722 int empty = load_hdf5_empty (loc_id, name, dv); | |
723 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
|
724 matrix.resize (dv); |
4837 | 725 if (empty) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
726 return (empty > 0); |
4805 | 727 |
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
|
728 #if HAVE_HDF5_18 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
729 hid_t data_hid = H5Dopen (loc_id, name, octave_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
|
730 #else |
4687 | 731 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
|
732 #endif |
4687 | 733 hid_t space_id = H5Dget_space (data_hid); |
734 | |
735 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
|
736 |
4687 | 737 if (rank < 1) |
738 { | |
739 H5Sclose (space_id); | |
740 H5Dclose (data_hid); | |
741 return false; | |
742 } | |
743 | |
744 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
745 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
746 | |
747 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
748 | |
749 // Octave uses column-major, while HDF5 uses row-major ordering | |
750 if (rank == 1) | |
751 { | |
752 dv.resize (2); | |
753 dv(0) = 1; | |
754 dv(1) = hdims[0]; | |
755 } | |
756 else | |
757 { | |
758 dv.resize (rank); | |
4815 | 759 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
|
760 dv(j) = hdims[i]; |
4687 | 761 } |
762 | |
763 NDArray m (dv); | |
764 double *re = m.fortran_vec (); | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
765 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
766 octave_H5P_DEFAULT, re) >= 0) |
4687 | 767 { |
768 retval = true; | |
769 matrix = m; | |
770 } | |
771 | |
772 H5Sclose (space_id); | |
773 H5Dclose (data_hid); | |
4837 | 774 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
775 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
776 gripe_load ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
777 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19861
diff
changeset
|
778 |
4687 | 779 return retval; |
780 } | |
4944 | 781 |
4643 | 782 void |
783 octave_matrix::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
784 bool pr_as_read_syntax) const |
4643 | 785 { |
786 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
|
787 current_print_indent_level ()); |
4643 | 788 } |
789 | |
5900 | 790 mxArray * |
791 octave_matrix::as_mxArray (void) const | |
792 { | |
793 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxREAL); | |
794 | |
795 double *pr = static_cast<double *> (retval->get_data ()); | |
796 | |
6686 | 797 mwSize nel = numel (); |
5900 | 798 |
799 const double *p = matrix.data (); | |
800 | |
6686 | 801 for (mwIndex i = 0; i < nel; i++) |
5900 | 802 pr[i] = p[i]; |
803 | |
804 return retval; | |
805 } | |
806 | |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
807 // 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
|
808 // 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
|
809 // result is produced. |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
810 static octave_value |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
811 do_rc_map (const NDArray& a, Complex (&fcn) (double)) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
812 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
813 octave_idx_type n = a.numel (); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
814 NoAlias<NDArray> rr (a.dims ()); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
815 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
816 for (octave_idx_type i = 0; i < n; i++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
817 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
818 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
819 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
820 Complex tmp = fcn (a(i)); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
821 if (tmp.imag () == 0.0) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
822 rr(i) = tmp.real (); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
823 else |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
824 { |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
825 NoAlias<ComplexNDArray> rc (a.dims ()); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
826 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
827 for (octave_idx_type j = 0; j < i; j++) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
828 rc(j) = rr(j); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
829 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
830 rc(i) = tmp; |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
831 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
832 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
|
833 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
834 octave_quit (); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
835 |
9824
6631c61a4a4e
fix typos in previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9823
diff
changeset
|
836 rc(j) = fcn (a(j)); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
837 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
838 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
839 return new octave_complex_matrix (rc); |
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 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
842 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
843 return rr; |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
844 } |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
845 |
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
|
846 octave_value |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
847 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
|
848 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
849 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
850 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
851 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
852 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
|
853 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
854 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
855 case umap_conj: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
856 return matrix; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
857 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
858 // Mappers handled specially. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
859 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
860 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
861 return octave_value (matrix.FCN ()) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
862 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
863 ARRAY_METHOD_MAPPER (abs, abs); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
864 ARRAY_METHOD_MAPPER (isnan, isnan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
865 ARRAY_METHOD_MAPPER (isinf, isinf); |
21013
7f4c6d594e3d
Finish renaming mapper function finite to isfinite.
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
866 ARRAY_METHOD_MAPPER (isfinite, isfinite); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
867 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
868 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
869 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
870 return octave_value (matrix.map<TYPE> (FCN)) |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
871 |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
872 #define RC_ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
873 case umap_ ## UMAP: \ |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
874 return do_rc_map (matrix, FCN) |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
875 |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
876 RC_ARRAY_MAPPER (acos, Complex, rc_acos); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
877 RC_ARRAY_MAPPER (acosh, Complex, rc_acosh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
878 ARRAY_MAPPER (angle, double, ::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
879 ARRAY_MAPPER (arg, double, ::arg); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
880 RC_ARRAY_MAPPER (asin, Complex, rc_asin); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
881 ARRAY_MAPPER (asinh, double, ::asinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
882 ARRAY_MAPPER (atan, double, ::atan); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
883 RC_ARRAY_MAPPER (atanh, Complex, rc_atanh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
884 ARRAY_MAPPER (erf, double, ::erf); |
9835
1bb1ed717d2f
implement built-in erfinv
Jaroslav Hajek <highegg@gmail.com>
parents:
9824
diff
changeset
|
885 ARRAY_MAPPER (erfinv, double, ::erfinv); |
14770
cb85e836d035
New function: erfcinv (bug #36607)
Axel Mathéi <axel.mathei@gmail.com>
parents:
14557
diff
changeset
|
886 ARRAY_MAPPER (erfcinv, double, ::erfcinv); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
887 ARRAY_MAPPER (erfc, double, ::erfc); |
10391
59e34bcdff13
implement built-in erfcx
Jaroslav Hajek <highegg@gmail.com>
parents:
10339
diff
changeset
|
888 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
|
889 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
|
890 ARRAY_MAPPER (dawson, double, ::dawson); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
891 ARRAY_MAPPER (gamma, double, xgamma); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
892 RC_ARRAY_MAPPER (lgamma, Complex, rc_lgamma); |
10414
2a8b1db1e2ca
implement built-in cbrt
Jaroslav Hajek <highegg@gmail.com>
parents:
10391
diff
changeset
|
893 ARRAY_MAPPER (cbrt, double, ::cbrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
894 ARRAY_MAPPER (ceil, double, ::ceil); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
895 ARRAY_MAPPER (cos, double, ::cos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
896 ARRAY_MAPPER (cosh, double, ::cosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
897 ARRAY_MAPPER (exp, double, ::exp); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
898 ARRAY_MAPPER (expm1, double, ::expm1); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
899 ARRAY_MAPPER (fix, double, ::fix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
900 ARRAY_MAPPER (floor, double, ::floor); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
901 RC_ARRAY_MAPPER (log, Complex, rc_log); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
902 RC_ARRAY_MAPPER (log2, Complex, rc_log2); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
903 RC_ARRAY_MAPPER (log10, Complex, rc_log10); |
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
904 RC_ARRAY_MAPPER (log1p, Complex, rc_log1p); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
905 ARRAY_MAPPER (round, double, xround); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
906 ARRAY_MAPPER (roundb, double, xroundb); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
907 ARRAY_MAPPER (signum, double, ::signum); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
908 ARRAY_MAPPER (sin, double, ::sin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
909 ARRAY_MAPPER (sinh, double, ::sinh); |
9823
9b62f2d8de6d
improve r->c mapper strategy
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
910 RC_ARRAY_MAPPER (sqrt, Complex, rc_sqrt); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
911 ARRAY_MAPPER (tan, double, ::tan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
912 ARRAY_MAPPER (tanh, double, ::tanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
913 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
|
914 ARRAY_MAPPER (xsignbit, double, xsignbit); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
915 |
18196
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
916 // 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
|
917 case umap_xtolower: |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
918 case umap_xtoupper: |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
919 return matrix; |
1b6db9303933
allow toupper and tolower to handle numeric values (bug #33537)
John W. Eaton <jwe@octave.org>
parents:
18100
diff
changeset
|
920 |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
921 case umap_xisalnum: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
922 case umap_xisalpha: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
923 case umap_xisascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
924 case umap_xiscntrl: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
925 case umap_xisdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
926 case umap_xisgraph: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
927 case umap_xislower: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
928 case umap_xisprint: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
929 case umap_xispunct: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
930 case umap_xisspace: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
931 case umap_xisupper: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
932 case umap_xisxdigit: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
933 case umap_xtoascii: |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
934 { |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
935 octave_value str_conv = convert_to_str (true, true); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
936 return str_conv.map (umap); |
18197
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
937 } |
0d5721873d6b
avoid some tests that rely on ordering of enum values
John W. Eaton <jwe@octave.org>
parents:
18196
diff
changeset
|
938 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
939 default: |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
940 return octave_base_value::map (umap); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
941 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
942 } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
943 |
4901 | 944 DEFUN (double, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
945 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
946 @deftypefn {} {} double (@var{x})\n\ |
4901 | 947 Convert @var{x} to double precision type.\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9184
diff
changeset
|
948 @seealso{single}\n\ |
4901 | 949 @end deftypefn") |
950 { | |
7004 | 951 // The OCTAVE_TYPE_CONV_BODY3 macro declares retval, so they go |
952 // inside their own scopes, and we don't declare retval here to | |
953 // avoid a shadowed declaration warning. | |
954 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
955 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
956 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
957 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
958 if (args(0).is_perm_matrix ()) |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
959 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
960 OCTAVE_TYPE_CONV_BODY3 (double, octave_perm_matrix, octave_scalar); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
961 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
962 else if (args(0).is_diag_matrix ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
963 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
964 if (args(0).is_complex_type ()) |
8399
c1bada868690
alow single/double conversion of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
965 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
966 OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_diag_matrix, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
967 octave_complex); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
968 } |
7004 | 969 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
970 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
971 OCTAVE_TYPE_CONV_BODY3 (double, octave_diag_matrix, |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
972 octave_scalar); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10273
diff
changeset
|
973 } |
7004 | 974 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
975 else if (args(0).is_sparse_type ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
976 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
977 if (args(0).is_complex_type ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
978 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
979 OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_complex_matrix, |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
980 octave_complex); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
981 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
982 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
983 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
984 OCTAVE_TYPE_CONV_BODY3 (double, octave_sparse_matrix, |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
985 octave_scalar); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
986 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
987 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
988 else if (args(0).is_complex_type ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
989 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
990 OCTAVE_TYPE_CONV_BODY3 (double, octave_complex_matrix, |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
991 octave_complex); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
992 } |
7004 | 993 else |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
994 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
995 OCTAVE_TYPE_CONV_BODY3 (double, octave_matrix, octave_scalar); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
996 } |
7004 | 997 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
998 return ovl (); |
4901 | 999 } |
12818
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1000 |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1001 /* |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1002 %!assert (class (double (single (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1003 %!assert (class (double (single (1 + i))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1004 %!assert (class (double (int8 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1005 %!assert (class (double (uint8 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1006 %!assert (class (double (int16 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1007 %!assert (class (double (uint16 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1008 %!assert (class (double (int32 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1009 %!assert (class (double (uint32 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1010 %!assert (class (double (int64 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1011 %!assert (class (double (uint64 (1))), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1012 %!assert (class (double (true)), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1013 %!assert (class (double ("A")), "double") |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1014 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1015 %! x = sparse (logical ([1 0; 0 1])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1016 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1017 %! assert (class (x), "logical"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1018 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1019 %! assert (issparse (y)); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1020 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1021 %! x = diag (single ([1 3 2])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1022 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1023 %! assert (class (x), "single"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1024 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1025 %!test |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1026 %! x = diag (single ([i 3 2])); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1027 %! y = double (x); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1028 %! assert (class (x), "single"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1029 %! assert (class (y), "double"); |
ce07cb58ff61
codesprint: Add tests for double()
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1030 */ |