GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
xnorm.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2017 VZLU Prague, a.s.
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 // author: Jaroslav Hajek <highegg@gmail.com>
24 
25 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include <cassert>
30 #include <cfloat>
31 #include <cmath>
32 
33 #include "oct-norm.h"
34 
35 #include "error.h"
36 #include "xnorm.h"
37 #include "ov.h"
38 #include "errwarn.h"
39 
41 {
43 
44  bool isvector = (x.columns () == 1 || x.rows () == 1);
45  bool iscomplex = x.is_complex_type ();
46  bool issparse = x.is_sparse_type ();
47  bool isfloat = x.is_single_type ();
48 
49  if (! isfloat && ! x.is_double_type ())
50  err_wrong_type_arg ("xnorm", x);
51 
52  if (x.is_empty ())
53  retval = octave_value (0);
54  else if (isvector)
55  {
56  if (isfloat & iscomplex)
58  p.float_value ());
59  else if (isfloat)
60  retval = xnorm (x.float_column_vector_value (),
61  p.float_value ());
62  else if (iscomplex)
63  retval = xnorm (x.complex_column_vector_value (),
64  p.double_value ());
65  else
66  retval = xnorm (x.column_vector_value (),
67  p.double_value ());
68  }
69  else if (issparse)
70  {
71  if (iscomplex)
72  retval = xnorm (x.sparse_complex_matrix_value (),
73  p.double_value ());
74  else
75  retval = xnorm (x.sparse_matrix_value (),
76  p.double_value ());
77  }
78  else
79  {
80  if (isfloat & iscomplex)
81  retval = xnorm (x.float_complex_matrix_value (),
82  p.float_value ());
83  else if (isfloat)
84  retval = xnorm (x.float_matrix_value (),
85  p.float_value ());
86  else if (iscomplex)
87  retval = xnorm (x.complex_matrix_value (),
88  p.double_value ());
89  else
90  retval = xnorm (x.matrix_value (),
91  p.double_value ());
92  }
93 
94  return retval;
95 }
96 
98 {
100 
101  bool iscomplex = x.is_complex_type ();
102  bool issparse = x.is_sparse_type ();
103  bool isfloat = x.is_single_type ();
104 
105  if (! isfloat && ! x.is_double_type ())
106  err_wrong_type_arg ("xcolnorms", x);
107 
108  if (issparse)
109  {
110  if (iscomplex)
111  retval = xcolnorms (x.sparse_complex_matrix_value (),
112  p.double_value ());
113  else
114  retval = xcolnorms (x.sparse_matrix_value (),
115  p.double_value ());
116  }
117  else
118  {
119  if (isfloat & iscomplex)
120  retval = xcolnorms (x.float_complex_matrix_value (),
121  p.float_value ());
122  else if (isfloat)
123  retval = xcolnorms (x.float_matrix_value (),
124  p.float_value ());
125  else if (iscomplex)
126  retval = xcolnorms (x.complex_matrix_value (),
127  p.double_value ());
128  else
129  retval = xcolnorms (x.matrix_value (),
130  p.double_value ());
131  }
132 
133  return retval;
134 }
135 
137 {
139 
140  bool iscomplex = x.is_complex_type ();
141  bool issparse = x.is_sparse_type ();
142  bool isfloat = x.is_single_type ();
143 
144  if (! isfloat && ! x.is_double_type ())
145  err_wrong_type_arg ("xrownorms", x);
146 
147  if (issparse)
148  {
149  if (iscomplex)
150  retval = xrownorms (x.sparse_complex_matrix_value (),
151  p.double_value ());
152  else
153  retval = xrownorms (x.sparse_matrix_value (),
154  p.double_value ());
155  }
156  else
157  {
158  if (isfloat & iscomplex)
159  retval = xrownorms (x.float_complex_matrix_value (),
160  p.float_value ());
161  else if (isfloat)
162  retval = xrownorms (x.float_matrix_value (),
163  p.float_value ());
164  else if (iscomplex)
165  retval = xrownorms (x.complex_matrix_value (),
166  p.double_value ());
167  else
168  retval = xrownorms (x.matrix_value (),
169  p.double_value ());
170  }
171 
172  return retval;
173 }
174 
176 {
178 
179  bool iscomplex = x.is_complex_type ();
180  bool issparse = x.is_sparse_type ();
181  bool isfloat = x.is_single_type ();
182 
183  if (! isfloat && ! x.is_double_type ())
184  err_wrong_type_arg ("xfrobnorm", x);
185 
186  if (issparse)
187  {
188  if (iscomplex)
189  retval = xfrobnorm (x.sparse_complex_matrix_value ());
190  else
191  retval = xfrobnorm (x.sparse_matrix_value ());
192  }
193  else
194  {
195  if (isfloat & iscomplex)
196  retval = xfrobnorm (x.float_complex_matrix_value ());
197  else if (isfloat)
198  retval = xfrobnorm (x.float_matrix_value ());
199  else if (iscomplex)
200  retval = xfrobnorm (x.complex_matrix_value ());
201  else
202  retval = xfrobnorm (x.matrix_value ());
203  }
204 
205  return retval;
206 }
ColumnVector column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1766
octave_idx_type rows(void) const
Definition: ov.h:489
FloatComplexMatrix float_complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:809
FloatColumnVector float_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1959
float float_value(bool frc_str_conv=false) const
Definition: ov.h:778
octave_value xnorm(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:40
octave_value xfrobnorm(const octave_value &x)
Definition: xnorm.cc:175
bool isvector(const T &array)
octave_idx_type columns(void) const
Definition: ov.h:491
octave_value xrownorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:136
bool is_sparse_type(void) const
Definition: ov.h:682
OCTAVE_EXPORT octave_value_list isfloat
Definition: data.cc:3327
bool is_double_type(void) const
Definition: ov.h:624
bool is_complex_type(void) const
Definition: ov.h:670
octave_value retval
Definition: data.cc:6294
octave_value xcolnorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:97
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:838
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:787
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:156
bool is_empty(void) const
Definition: ov.h:542
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:805
p
Definition: lu.cc:138
FloatComplexColumnVector float_complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1967
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:790
ComplexColumnVector complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1774
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:834
bool is_single_type(void) const
Definition: ov.h:627
double double_value(bool frc_str_conv=false) const
Definition: ov.h:775
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x