comparison libinterp/octave-value/ov-flt-re-diag.cc @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/octave-value/ov-flt-re-diag.cc@46b19589b593
children 0a0912a9ab6e
comparison
equal deleted inserted replaced
15194:0f0b795044c3 15195:2fc554ffbc28
1 /*
2
3 Copyright (C) 2008-2012 Jaroslav Hajek
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "byte-swap.h"
28
29 #include "ov-flt-re-diag.h"
30 #include "ov-base-diag.cc"
31 #include "ov-float.h"
32 #include "ov-flt-re-mat.h"
33 #include "ls-utils.h"
34
35 template class octave_base_diag<FloatDiagMatrix, FloatMatrix>;
36
37 DEFINE_OCTAVE_ALLOCATOR (octave_float_diag_matrix);
38
39 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_float_diag_matrix,
40 "float diagonal matrix", "single");
41
42 static octave_base_value *
43 default_numeric_conversion_function (const octave_base_value& a)
44 {
45 CAST_CONV_ARG (const octave_float_diag_matrix&);
46
47 return new octave_float_matrix (v.float_matrix_value ());
48 }
49
50 octave_base_value::type_conv_info
51 octave_float_diag_matrix::numeric_conversion_function (void) const
52 {
53 return octave_base_value::type_conv_info (default_numeric_conversion_function,
54 octave_float_matrix::static_type_id ());
55 }
56
57 octave_base_value *
58 octave_float_diag_matrix::try_narrowing_conversion (void)
59 {
60 octave_base_value *retval = 0;
61
62 if (matrix.nelem () == 1)
63 retval = new octave_float_scalar (matrix (0, 0));
64
65 return retval;
66 }
67
68 DiagMatrix
69 octave_float_diag_matrix::diag_matrix_value (bool) const
70 {
71 return DiagMatrix (matrix);
72 }
73
74 FloatDiagMatrix
75 octave_float_diag_matrix::float_diag_matrix_value (bool) const
76 {
77 return matrix;
78 }
79
80 ComplexDiagMatrix
81 octave_float_diag_matrix::complex_diag_matrix_value (bool) const
82 {
83 return ComplexDiagMatrix (matrix);
84 }
85
86 FloatComplexDiagMatrix
87 octave_float_diag_matrix::float_complex_diag_matrix_value (bool) const
88 {
89 return FloatComplexDiagMatrix (matrix);
90 }
91
92 octave_value
93 octave_float_diag_matrix::map (unary_mapper_t umap) const
94 {
95 switch (umap)
96 {
97 case umap_abs:
98 return matrix.abs ();
99 case umap_real:
100 case umap_conj:
101 return matrix;
102 case umap_imag:
103 return DiagMatrix (matrix.rows (), matrix.cols (), 0.0);
104 case umap_sqrt:
105 {
106 FloatComplexColumnVector tmp = matrix.diag ().map<FloatComplex> (rc_sqrt);
107 FloatComplexDiagMatrix retval (tmp);
108 retval.resize (matrix.rows (), matrix.columns ());
109 return retval;
110 }
111 default:
112 return to_dense ().map (umap);
113 }
114 }
115
116 bool
117 octave_float_diag_matrix::save_binary (std::ostream& os,
118 bool& /* save_as_floats*/)
119 {
120
121 int32_t r = matrix.rows (), c = matrix.cols ();
122 os.write (reinterpret_cast<char *> (&r), 4);
123 os.write (reinterpret_cast<char *> (&c), 4);
124
125 FloatMatrix m = FloatMatrix (matrix.diag ());
126 save_type st = LS_FLOAT;
127 if (matrix.length () > 8192) // FIXME -- make this configurable.
128 {
129 float max_val, min_val;
130 if (m.all_integers (max_val, min_val))
131 st = get_save_type (max_val, min_val);
132 }
133
134 const float *mtmp = m.data ();
135 write_floats (os, mtmp, st, m.numel ());
136
137 return true;
138 }
139
140 bool
141 octave_float_diag_matrix::load_binary (std::istream& is, bool swap,
142 oct_mach_info::float_format fmt)
143 {
144 int32_t r, c;
145 char tmp;
146 if (! (is.read (reinterpret_cast<char *> (&r), 4)
147 && is.read (reinterpret_cast<char *> (&c), 4)
148 && is.read (reinterpret_cast<char *> (&tmp), 1)))
149 return false;
150 if (swap)
151 {
152 swap_bytes<4> (&r);
153 swap_bytes<4> (&c);
154 }
155
156 FloatDiagMatrix m (r, c);
157 float *re = m.fortran_vec ();
158 octave_idx_type len = m.length ();
159 read_floats (is, re, static_cast<save_type> (tmp), len, swap, fmt);
160 if (error_state || ! is)
161 return false;
162 matrix = m;
163
164 return true;
165 }
166
167 bool
168 octave_float_diag_matrix::chk_valid_scalar (const octave_value& val,
169 float& x) const
170 {
171 bool retval = val.is_real_scalar ();
172 if (retval)
173 x = val.float_value ();
174 return retval;
175 }