GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
xnorm.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2008-2021 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  bool isvector = (x.columns () == 1 || x.rows () == 1);
41  bool iscomplex = x.iscomplex ();
42  bool issparse = x.issparse ();
43  bool isfloat = x.is_single_type ();
44 
45  if (! isfloat && ! x.is_double_type ())
46  err_wrong_type_arg ("xnorm", x);
47 
48  if (x.isempty ())
49  retval = octave_value (0);
50  else if (isvector)
51  {
52  if (isfloat & iscomplex)
53  retval = xnorm (x.float_complex_column_vector_value (),
54  p.float_value ());
55  else if (isfloat)
56  retval = xnorm (x.float_column_vector_value (),
57  p.float_value ());
58  else if (iscomplex)
59  retval = xnorm (x.complex_column_vector_value (),
60  p.double_value ());
61  else
62  retval = xnorm (x.column_vector_value (),
63  p.double_value ());
64  }
65  else if (issparse)
66  {
67  if (iscomplex)
68  retval = xnorm (x.sparse_complex_matrix_value (),
69  p.double_value ());
70  else
71  retval = xnorm (x.sparse_matrix_value (),
72  p.double_value ());
73  }
74  else
75  {
76  if (isfloat & iscomplex)
77  retval = xnorm (x.float_complex_matrix_value (),
78  p.float_value ());
79  else if (isfloat)
80  retval = xnorm (x.float_matrix_value (),
81  p.float_value ());
82  else if (iscomplex)
83  retval = xnorm (x.complex_matrix_value (),
84  p.double_value ());
85  else
86  retval = xnorm (x.matrix_value (),
87  p.double_value ());
88  }
89 
90  return retval;
91 }
92 
94 {
96 
97  bool iscomplex = x.iscomplex ();
98  bool issparse = x.issparse ();
99  bool isfloat = x.is_single_type ();
100 
101  if (! isfloat && ! x.is_double_type ())
102  err_wrong_type_arg ("xcolnorms", x);
103 
104  if (issparse)
105  {
106  if (iscomplex)
107  retval = xcolnorms (x.sparse_complex_matrix_value (),
108  p.double_value ());
109  else
110  retval = xcolnorms (x.sparse_matrix_value (),
111  p.double_value ());
112  }
113  else
114  {
115  if (isfloat & iscomplex)
116  retval = xcolnorms (x.float_complex_matrix_value (),
117  p.float_value ());
118  else if (isfloat)
119  retval = xcolnorms (x.float_matrix_value (),
120  p.float_value ());
121  else if (iscomplex)
122  retval = xcolnorms (x.complex_matrix_value (),
123  p.double_value ());
124  else
125  retval = xcolnorms (x.matrix_value (),
126  p.double_value ());
127  }
128 
129  return retval;
130 }
131 
133 {
135 
136  bool iscomplex = x.iscomplex ();
137  bool issparse = x.issparse ();
138  bool isfloat = x.is_single_type ();
139 
140  if (! isfloat && ! x.is_double_type ())
141  err_wrong_type_arg ("xrownorms", x);
142 
143  if (issparse)
144  {
145  if (iscomplex)
146  retval = xrownorms (x.sparse_complex_matrix_value (),
147  p.double_value ());
148  else
149  retval = xrownorms (x.sparse_matrix_value (),
150  p.double_value ());
151  }
152  else
153  {
154  if (isfloat & iscomplex)
155  retval = xrownorms (x.float_complex_matrix_value (),
156  p.float_value ());
157  else if (isfloat)
158  retval = xrownorms (x.float_matrix_value (),
159  p.float_value ());
160  else if (iscomplex)
161  retval = xrownorms (x.complex_matrix_value (),
162  p.double_value ());
163  else
164  retval = xrownorms (x.matrix_value (),
165  p.double_value ());
166  }
167 
168  return retval;
169 }
170 
172 {
174 
175  bool iscomplex = x.iscomplex ();
176  bool issparse = x.issparse ();
177  bool isfloat = x.is_single_type ();
178 
179  if (! isfloat && ! x.is_double_type ())
180  err_wrong_type_arg ("xfrobnorm", x);
181 
182  if (issparse)
183  {
184  if (iscomplex)
185  retval = xfrobnorm (x.sparse_complex_matrix_value ());
186  else
187  retval = xfrobnorm (x.sparse_matrix_value ());
188  }
189  else
190  {
191  if (isfloat & iscomplex)
192  retval = xfrobnorm (x.float_complex_matrix_value ());
193  else if (isfloat)
194  retval = xfrobnorm (x.float_matrix_value ());
195  else if (iscomplex)
196  retval = xfrobnorm (x.complex_matrix_value ());
197  else
198  retval = xfrobnorm (x.matrix_value ());
199  }
200 
201  return retval;
202 }
bool isvector(const dim_vector &dim)
Definition: Array-util.cc:140
float float_value(bool frc_str_conv=false) const
Definition: ov.h:797
double double_value(bool frc_str_conv=false) const
Definition: ov.h:794
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:166
F77_RET_T const F77_DBLE * x
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
octave_value xcolnorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:93
octave_value xfrobnorm(const octave_value &x)
Definition: xnorm.cc:171
octave_value xrownorms(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:132
octave_value xnorm(const octave_value &x, const octave_value &p)
Definition: xnorm.cc:36