GNU Octave  9.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 Friends Macros Pages
xnorm.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2008-2024 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 
97 {
98  octave_value retval;
99 
100  bool iscomplex = x.iscomplex ();
101  bool issparse = x.issparse ();
102  bool isfloat = x.is_single_type ();
103 
104  if (! isfloat && ! x.is_double_type ())
105  err_wrong_type_arg ("xcolnorms", x);
106 
107  if (issparse)
108  {
109  if (iscomplex)
110  retval = octave::xcolnorms (x.sparse_complex_matrix_value (),
111  p.double_value ());
112  else
113  retval = octave::xcolnorms (x.sparse_matrix_value (),
114  p.double_value ());
115  }
116  else
117  {
118  if (isfloat & iscomplex)
119  retval = octave::xcolnorms (x.float_complex_matrix_value (),
120  p.float_value ());
121  else if (isfloat)
122  retval = octave::xcolnorms (x.float_matrix_value (),
123  p.float_value ());
124  else if (iscomplex)
125  retval = octave::xcolnorms (x.complex_matrix_value (),
126  p.double_value ());
127  else
128  retval = octave::xcolnorms (x.matrix_value (),
129  p.double_value ());
130  }
131 
132  return retval;
133 }
134 
137 {
138  octave_value retval;
139 
140  bool iscomplex = x.iscomplex ();
141  bool issparse = x.issparse ();
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 = octave::xrownorms (x.sparse_complex_matrix_value (),
151  p.double_value ());
152  else
153  retval = octave::xrownorms (x.sparse_matrix_value (),
154  p.double_value ());
155  }
156  else
157  {
158  if (isfloat & iscomplex)
159  retval = octave::xrownorms (x.float_complex_matrix_value (),
160  p.float_value ());
161  else if (isfloat)
162  retval = octave::xrownorms (x.float_matrix_value (),
163  p.float_value ());
164  else if (iscomplex)
165  retval = octave::xrownorms (x.complex_matrix_value (),
166  p.double_value ());
167  else
168  retval = octave::xrownorms (x.matrix_value (),
169  p.double_value ());
170  }
171 
172  return retval;
173 }
174 
177 {
178  octave_value retval;
179 
180  bool iscomplex = x.iscomplex ();
181  bool issparse = x.issparse ();
182  bool isfloat = x.is_single_type ();
183 
184  if (! isfloat && ! x.is_double_type ())
185  err_wrong_type_arg ("xfrobnorm", x);
186 
187  if (issparse)
188  {
189  if (iscomplex)
190  retval = octave::xfrobnorm (x.sparse_complex_matrix_value ());
191  else
192  retval = octave::xfrobnorm (x.sparse_matrix_value ());
193  }
194  else
195  {
196  if (isfloat & iscomplex)
197  retval = octave::xfrobnorm (x.float_complex_matrix_value ());
198  else if (isfloat)
199  retval = octave::xfrobnorm (x.float_matrix_value ());
200  else if (iscomplex)
201  retval = octave::xfrobnorm (x.complex_matrix_value ());
202  else
203  retval = octave::xfrobnorm (x.matrix_value ());
204  }
205 
206  return retval;
207 }
208 
209 OCTAVE_END_NAMESPACE(octave)
bool isvector(const dim_vector &dim)
Definition: Array-util.cc:140
float float_value(bool frc_str_conv=false) const
Definition: ov.h:844
double double_value(bool frc_str_conv=false) const
Definition: ov.h:841
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:96
octave_value xfrobnorm(const octave_value &x)
Definition: xnorm.cc:176
octave_value xrownorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:136
octave_value xnorm(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:38