GNU Octave  8.1.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-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "oct-norm.h"
31 
32 #include "errwarn.h"
33 #include "ov.h"
34 #include "xnorm.h"
35 
37 
39 {
40  octave_value retval;
41 
42  bool isvector = (x.columns () == 1 || x.rows () == 1);
43  bool iscomplex = x.iscomplex ();
44  bool issparse = x.issparse ();
45  bool isfloat = x.is_single_type ();
46 
47  if (! isfloat && ! x.is_double_type ())
48  err_wrong_type_arg ("xnorm", x);
49 
50  if (x.isempty ())
51  retval = octave_value (0);
52  else if (isvector)
53  {
54  if (isfloat & iscomplex)
55  retval = octave::xnorm (x.float_complex_column_vector_value (),
56  p.float_value ());
57  else if (isfloat)
58  retval = octave::xnorm (x.float_column_vector_value (),
59  p.float_value ());
60  else if (iscomplex)
61  retval = octave::xnorm (x.complex_column_vector_value (),
62  p.double_value ());
63  else
64  retval = octave::xnorm (x.column_vector_value (),
65  p.double_value ());
66  }
67  else if (issparse)
68  {
69  if (iscomplex)
70  retval = octave::xnorm (x.sparse_complex_matrix_value (),
71  p.double_value ());
72  else
73  retval = octave::xnorm (x.sparse_matrix_value (),
74  p.double_value ());
75  }
76  else
77  {
78  if (isfloat & iscomplex)
79  retval = octave::xnorm (x.float_complex_matrix_value (),
80  p.float_value ());
81  else if (isfloat)
82  retval = octave::xnorm (x.float_matrix_value (),
83  p.float_value ());
84  else if (iscomplex)
85  retval = octave::xnorm (x.complex_matrix_value (),
86  p.double_value ());
87  else
88  retval = octave::xnorm (x.matrix_value (),
89  p.double_value ());
90  }
91 
92  return retval;
93 }
94 
96 {
97  octave_value retval;
98 
99  bool iscomplex = x.iscomplex ();
100  bool issparse = x.issparse ();
101  bool isfloat = x.is_single_type ();
102 
103  if (! isfloat && ! x.is_double_type ())
104  err_wrong_type_arg ("xcolnorms", x);
105 
106  if (issparse)
107  {
108  if (iscomplex)
109  retval = octave::xcolnorms (x.sparse_complex_matrix_value (),
110  p.double_value ());
111  else
112  retval = octave::xcolnorms (x.sparse_matrix_value (),
113  p.double_value ());
114  }
115  else
116  {
117  if (isfloat & iscomplex)
118  retval = octave::xcolnorms (x.float_complex_matrix_value (),
119  p.float_value ());
120  else if (isfloat)
121  retval = octave::xcolnorms (x.float_matrix_value (),
122  p.float_value ());
123  else if (iscomplex)
124  retval = octave::xcolnorms (x.complex_matrix_value (),
125  p.double_value ());
126  else
127  retval = octave::xcolnorms (x.matrix_value (),
128  p.double_value ());
129  }
130 
131  return retval;
132 }
133 
135 {
136  octave_value retval;
137 
138  bool iscomplex = x.iscomplex ();
139  bool issparse = x.issparse ();
140  bool isfloat = x.is_single_type ();
141 
142  if (! isfloat && ! x.is_double_type ())
143  err_wrong_type_arg ("xrownorms", x);
144 
145  if (issparse)
146  {
147  if (iscomplex)
148  retval = octave::xrownorms (x.sparse_complex_matrix_value (),
149  p.double_value ());
150  else
151  retval = octave::xrownorms (x.sparse_matrix_value (),
152  p.double_value ());
153  }
154  else
155  {
156  if (isfloat & iscomplex)
157  retval = octave::xrownorms (x.float_complex_matrix_value (),
158  p.float_value ());
159  else if (isfloat)
160  retval = octave::xrownorms (x.float_matrix_value (),
161  p.float_value ());
162  else if (iscomplex)
163  retval = octave::xrownorms (x.complex_matrix_value (),
164  p.double_value ());
165  else
166  retval = octave::xrownorms (x.matrix_value (),
167  p.double_value ());
168  }
169 
170  return retval;
171 }
172 
174 {
175  octave_value retval;
176 
177  bool iscomplex = x.iscomplex ();
178  bool issparse = x.issparse ();
179  bool isfloat = x.is_single_type ();
180 
181  if (! isfloat && ! x.is_double_type ())
182  err_wrong_type_arg ("xfrobnorm", x);
183 
184  if (issparse)
185  {
186  if (iscomplex)
187  retval = octave::xfrobnorm (x.sparse_complex_matrix_value ());
188  else
189  retval = octave::xfrobnorm (x.sparse_matrix_value ());
190  }
191  else
192  {
193  if (isfloat & iscomplex)
194  retval = octave::xfrobnorm (x.float_complex_matrix_value ());
195  else if (isfloat)
196  retval = octave::xfrobnorm (x.float_matrix_value ());
197  else if (iscomplex)
198  retval = octave::xfrobnorm (x.complex_matrix_value ());
199  else
200  retval = octave::xfrobnorm (x.matrix_value ());
201  }
202 
203  return retval;
204 }
205 
bool isvector(const dim_vector &dim)
Definition: Array-util.cc:140
OCTAVE_END_NAMESPACE(octave)
float float_value(bool frc_str_conv=false) const
Definition: ov.h:889
double double_value(bool frc_str_conv=false) const
Definition: ov.h:886
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:166
F77_RET_T const F77_DBLE * x
octave_value xcolnorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:95
octave_value xfrobnorm(const octave_value &x)
Definition: xnorm.cc:173
octave_value xrownorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:134
octave_value xnorm(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:38