GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
octave-value
ov-flt-re-diag.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2008-2013 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
.
extract_diag
().
map
<
FloatComplex
>
107
(
rc_sqrt
);
108
FloatComplexDiagMatrix
retval (tmp);
109
retval.resize (
matrix
.
rows
(),
matrix
.
columns
());
110
return
retval;
111
}
112
default
:
113
return
to_dense
().
map
(umap);
114
}
115
}
116
117
bool
118
octave_float_diag_matrix::save_binary
(std::ostream& os,
119
bool
&
/* save_as_floats*/
)
120
{
121
122
int32_t r =
matrix
.
rows
(), c =
matrix
.
cols
();
123
os.write (reinterpret_cast<char *> (&r), 4);
124
os.write (reinterpret_cast<char *> (&c), 4);
125
126
FloatMatrix
m =
FloatMatrix
(
matrix
.
extract_diag
());
127
save_type
st =
LS_FLOAT
;
128
if
(
matrix
.
length
() > 8192)
// FIXME: make this configurable.
129
{
130
float
max_val, min_val;
131
if
(m.
all_integers
(max_val, min_val))
132
st =
get_save_type
(max_val, min_val);
133
}
134
135
const
float
*mtmp = m.
data
();
136
write_floats
(os, mtmp, st, m.
numel
());
137
138
return
true
;
139
}
140
141
bool
142
octave_float_diag_matrix::load_binary
(std::istream& is,
bool
swap,
143
oct_mach_info::float_format
fmt)
144
{
145
int32_t r, c;
146
char
tmp;
147
if
(! (is.read (reinterpret_cast<char *> (&r), 4)
148
&& is.read (reinterpret_cast<char *> (&c), 4)
149
&& is.read (reinterpret_cast<char *> (&tmp), 1)))
150
return
false
;
151
if
(swap)
152
{
153
swap_bytes<4>
(&r);
154
swap_bytes<4>
(&c);
155
}
156
157
FloatDiagMatrix
m (r, c);
158
float
*re = m.
fortran_vec
();
159
octave_idx_type
len = m.
length
();
160
read_floats
(is, re, static_cast<save_type> (tmp), len, swap, fmt);
161
if
(
error_state
|| ! is)
162
return
false
;
163
matrix
= m;
164
165
return
true
;
166
}
167
168
bool
169
octave_float_diag_matrix::chk_valid_scalar
(
const
octave_value
& val,
170
float
&
x
)
const
171
{
172
bool
retval = val.
is_real_scalar
();
173
if
(retval)
174
x = val.
float_value
();
175
return
retval;
176
}
Generated on Mon Dec 30 2013 03:04:33 for GNU Octave by
1.8.1.2