GNU Octave  4.0.0
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-2015 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 #ifdef 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 "gripes.h"
39 
41 {
42  octave_value retval;
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  {
51  if (x.is_empty ())
52  retval = octave_value (0);
53  else if (isvector)
54  {
55  if (isfloat & iscomplex)
57  p.float_value ());
58  else if (isfloat)
59  retval = xnorm (x.float_column_vector_value (),
60  p.float_value ());
61  else if (iscomplex)
62  retval = xnorm (x.complex_column_vector_value (),
63  p.double_value ());
64  else
65  retval = xnorm (x.column_vector_value (),
66  p.double_value ());
67  }
68  else if (issparse)
69  {
70  if (iscomplex)
71  retval = xnorm (x.sparse_complex_matrix_value (),
72  p.double_value ());
73  else
74  retval = xnorm (x.sparse_matrix_value (),
75  p.double_value ());
76  }
77  else
78  {
79  if (isfloat & iscomplex)
80  retval = xnorm (x.float_complex_matrix_value (),
81  p.float_value ());
82  else if (isfloat)
83  retval = xnorm (x.float_matrix_value (),
84  p.float_value ());
85  else if (iscomplex)
86  retval = xnorm (x.complex_matrix_value (),
87  p.double_value ());
88  else
89  retval = xnorm (x.matrix_value (),
90  p.double_value ());
91  }
92  }
93  else
94  gripe_wrong_type_arg ("xnorm", x, true);
95 
96  return retval;
97 }
98 
100 {
101  octave_value retval;
102 
103  bool iscomplex = x.is_complex_type ();
104  bool issparse = x.is_sparse_type ();
105  bool isfloat = x.is_single_type ();
106 
107  if (isfloat || x.is_double_type ())
108  {
109  if (issparse)
110  {
111  if (iscomplex)
112  retval = xcolnorms (x.sparse_complex_matrix_value (),
113  p.double_value ());
114  else
115  retval = xcolnorms (x.sparse_matrix_value (),
116  p.double_value ());
117  }
118  else
119  {
120  if (isfloat & iscomplex)
121  retval = xcolnorms (x.float_complex_matrix_value (),
122  p.float_value ());
123  else if (isfloat)
124  retval = xcolnorms (x.float_matrix_value (),
125  p.float_value ());
126  else if (iscomplex)
127  retval = xcolnorms (x.complex_matrix_value (),
128  p.double_value ());
129  else
130  retval = xcolnorms (x.matrix_value (),
131  p.double_value ());
132  }
133  }
134  else
135  gripe_wrong_type_arg ("xcolnorms", x, true);
136 
137  return retval;
138 }
139 
141 {
142  octave_value retval;
143 
144  bool iscomplex = x.is_complex_type ();
145  bool issparse = x.is_sparse_type ();
146  bool isfloat = x.is_single_type ();
147 
148  if (isfloat || x.is_double_type ())
149  {
150  if (issparse)
151  {
152  if (iscomplex)
153  retval = xrownorms (x.sparse_complex_matrix_value (),
154  p.double_value ());
155  else
156  retval = xrownorms (x.sparse_matrix_value (),
157  p.double_value ());
158  }
159  else
160  {
161  if (isfloat & iscomplex)
162  retval = xrownorms (x.float_complex_matrix_value (),
163  p.float_value ());
164  else if (isfloat)
165  retval = xrownorms (x.float_matrix_value (),
166  p.float_value ());
167  else if (iscomplex)
168  retval = xrownorms (x.complex_matrix_value (),
169  p.double_value ());
170  else
171  retval = xrownorms (x.matrix_value (),
172  p.double_value ());
173  }
174  }
175  else
176  gripe_wrong_type_arg ("xrownorms", x, true);
177 
178  return retval;
179 }
180 
182 {
183  octave_value retval;
184 
185  bool iscomplex = x.is_complex_type ();
186  bool issparse = x.is_sparse_type ();
187  bool isfloat = x.is_single_type ();
188 
189  if (isfloat || x.is_double_type ())
190  {
191  if (issparse)
192  {
193  if (iscomplex)
194  retval = xfrobnorm (x.sparse_complex_matrix_value ());
195  else
196  retval = xfrobnorm (x.sparse_matrix_value ());
197  }
198  else
199  {
200  if (isfloat & iscomplex)
201  retval = xfrobnorm (x.float_complex_matrix_value ());
202  else if (isfloat)
203  retval = xfrobnorm (x.float_matrix_value ());
204  else if (iscomplex)
205  retval = xfrobnorm (x.complex_matrix_value ());
206  else
207  retval = xfrobnorm (x.matrix_value ());
208  }
209  }
210  else
211  gripe_wrong_type_arg ("xfrobnorm", x, true);
212 
213  return retval;
214 }
ColumnVector column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1658
void gripe_wrong_type_arg(const char *name, const char *s, bool is_error)
Definition: gripes.cc:135
octave_idx_type rows(void) const
Definition: ov.h:473
FloatComplexMatrix float_complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:795
FloatColumnVector float_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1869
float float_value(bool frc_str_conv=false) const
Definition: ov.h:762
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:181
bool isvector(const T &array)
octave_idx_type columns(void) const
Definition: ov.h:475
octave_value xrownorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:140
bool is_sparse_type(void) const
Definition: ov.h:666
bool is_double_type(void) const
Definition: ov.h:608
bool is_complex_type(void) const
Definition: ov.h:654
octave_value xcolnorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:99
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:824
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:773
bool is_empty(void) const
Definition: ov.h:526
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:791
FloatComplexColumnVector float_complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1877
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:776
ComplexColumnVector complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1666
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:820
bool is_single_type(void) const
Definition: ov.h:611
double double_value(bool frc_str_conv=false) const
Definition: ov.h:759
F77_RET_T const double * x