GNU Octave  3.8.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-2013 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 <[email protected]>
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 (isvector)
52  {
53  if (isfloat & iscomplex)
55  p.float_value ());
56  else if (isfloat)
57  retval = xnorm (x.float_column_vector_value (),
58  p.float_value ());
59  else if (iscomplex)
60  retval = xnorm (x.complex_column_vector_value (),
61  p.double_value ());
62  else
63  retval = xnorm (x.column_vector_value (),
64  p.double_value ());
65  }
66  else if (issparse)
67  {
68  if (iscomplex)
69  retval = xnorm (x.sparse_complex_matrix_value (),
70  p.double_value ());
71  else
72  retval = xnorm (x.sparse_matrix_value (),
73  p.double_value ());
74  }
75  else
76  {
77  if (isfloat & iscomplex)
78  retval = xnorm (x.float_complex_matrix_value (),
79  p.float_value ());
80  else if (isfloat)
81  retval = xnorm (x.float_matrix_value (),
82  p.float_value ());
83  else if (iscomplex)
84  retval = xnorm (x.complex_matrix_value (),
85  p.double_value ());
86  else
87  retval = xnorm (x.matrix_value (),
88  p.double_value ());
89  }
90  }
91  else
92  gripe_wrong_type_arg ("xnorm", x, true);
93 
94  return retval;
95 }
96 
98 {
99  octave_value retval;
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  {
107  if (issparse)
108  {
109  if (iscomplex)
110  retval = xcolnorms (x.sparse_complex_matrix_value (),
111  p.double_value ());
112  else
113  retval = xcolnorms (x.sparse_matrix_value (),
114  p.double_value ());
115  }
116  else
117  {
118  if (isfloat & iscomplex)
119  retval = xcolnorms (x.float_complex_matrix_value (),
120  p.float_value ());
121  else if (isfloat)
122  retval = xcolnorms (x.float_matrix_value (),
123  p.float_value ());
124  else if (iscomplex)
125  retval = xcolnorms (x.complex_matrix_value (),
126  p.double_value ());
127  else
128  retval = xcolnorms (x.matrix_value (),
129  p.double_value ());
130  }
131  }
132  else
133  gripe_wrong_type_arg ("xcolnorms", x, true);
134 
135  return retval;
136 }
137 
139 {
140  octave_value retval;
141 
142  bool iscomplex = x.is_complex_type ();
143  bool issparse = x.is_sparse_type ();
144  bool isfloat = x.is_single_type ();
145 
146  if (isfloat || x.is_double_type ())
147  {
148  if (issparse)
149  {
150  if (iscomplex)
151  retval = xrownorms (x.sparse_complex_matrix_value (),
152  p.double_value ());
153  else
154  retval = xrownorms (x.sparse_matrix_value (),
155  p.double_value ());
156  }
157  else
158  {
159  if (isfloat & iscomplex)
160  retval = xrownorms (x.float_complex_matrix_value (),
161  p.float_value ());
162  else if (isfloat)
163  retval = xrownorms (x.float_matrix_value (),
164  p.float_value ());
165  else if (iscomplex)
166  retval = xrownorms (x.complex_matrix_value (),
167  p.double_value ());
168  else
169  retval = xrownorms (x.matrix_value (),
170  p.double_value ());
171  }
172  }
173  else
174  gripe_wrong_type_arg ("xrownorms", x, true);
175 
176  return retval;
177 }
178 
180 {
181  octave_value retval;
182 
183  bool iscomplex = x.is_complex_type ();
184  bool issparse = x.is_sparse_type ();
185  bool isfloat = x.is_single_type ();
186 
187  if (isfloat || x.is_double_type ())
188  {
189  if (issparse)
190  {
191  if (iscomplex)
192  retval = xfrobnorm (x.sparse_complex_matrix_value ());
193  else
194  retval = xfrobnorm (x.sparse_matrix_value ());
195  }
196  else
197  {
198  if (isfloat & iscomplex)
199  retval = xfrobnorm (x.float_complex_matrix_value ());
200  else if (isfloat)
201  retval = xfrobnorm (x.float_matrix_value ());
202  else if (iscomplex)
203  retval = xfrobnorm (x.complex_matrix_value ());
204  else
205  retval = xfrobnorm (x.matrix_value ());
206  }
207  }
208  else
209  gripe_wrong_type_arg ("xfrobnorm", x, true);
210 
211  return retval;
212 }