annotate src/ov-re-mat.cc @ 16062:cc5a7d1233f3 stable rc-3-6-4-2

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