xnorm.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 VZLU Prague, a.s.
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 // author: Jaroslav Hajek <highegg@gmail.com>
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028 
00029 #include <cassert>
00030 #include <cfloat>
00031 #include <cmath>
00032 
00033 #include "oct-norm.h"
00034 
00035 #include "error.h"
00036 #include "xnorm.h"
00037 #include "ov.h"
00038 #include "gripes.h"
00039 
00040 octave_value xnorm (const octave_value& x, const octave_value& p)
00041 {
00042   octave_value retval;
00043 
00044   bool isvector = (x.columns () == 1 || x.rows () == 1);
00045   bool iscomplex = x.is_complex_type ();
00046   bool issparse = x.is_sparse_type ();
00047   bool isfloat = x.is_single_type ();
00048 
00049   if (isfloat || x.is_double_type ())
00050     {
00051       if (isvector)
00052         {
00053           if (isfloat & iscomplex)
00054             retval = xnorm (x.float_complex_column_vector_value (),
00055                             p.float_value ());
00056           else if (isfloat)
00057             retval = xnorm (x.float_column_vector_value (),
00058                             p.float_value ());
00059           else if (iscomplex)
00060             retval = xnorm (x.complex_column_vector_value (),
00061                             p.double_value ());
00062           else
00063             retval = xnorm (x.column_vector_value (),
00064                             p.double_value ());
00065         }
00066       else if (issparse)
00067         {
00068           if (iscomplex)
00069             retval = xnorm (x.sparse_complex_matrix_value (),
00070                             p.double_value ());
00071           else
00072             retval = xnorm (x.sparse_matrix_value (),
00073                             p.double_value ());
00074         }
00075       else
00076         {
00077           if (isfloat & iscomplex)
00078             retval = xnorm (x.float_complex_matrix_value (),
00079                             p.float_value ());
00080           else if (isfloat)
00081             retval = xnorm (x.float_matrix_value (),
00082                             p.float_value ());
00083           else if (iscomplex)
00084             retval = xnorm (x.complex_matrix_value (),
00085                             p.double_value ());
00086           else
00087             retval = xnorm (x.matrix_value (),
00088                             p.double_value ());
00089         }
00090     }
00091   else
00092     gripe_wrong_type_arg ("xnorm", x, true);
00093 
00094   return retval;
00095 }
00096 
00097 octave_value xcolnorms (const octave_value& x, const octave_value& p)
00098 {
00099   octave_value retval;
00100 
00101   bool iscomplex = x.is_complex_type ();
00102   bool issparse = x.is_sparse_type ();
00103   bool isfloat = x.is_single_type ();
00104 
00105   if (isfloat || x.is_double_type ())
00106     {
00107       if (issparse)
00108         {
00109           if (iscomplex)
00110             retval = xcolnorms (x.sparse_complex_matrix_value (),
00111                                 p.double_value ());
00112           else
00113             retval = xcolnorms (x.sparse_matrix_value (),
00114                                 p.double_value ());
00115         }
00116       else
00117         {
00118           if (isfloat & iscomplex)
00119             retval = xcolnorms (x.float_complex_matrix_value (),
00120                                 p.float_value ());
00121           else if (isfloat)
00122             retval = xcolnorms (x.float_matrix_value (),
00123                                 p.float_value ());
00124           else if (iscomplex)
00125             retval = xcolnorms (x.complex_matrix_value (),
00126                                 p.double_value ());
00127           else
00128             retval = xcolnorms (x.matrix_value (),
00129                                 p.double_value ());
00130         }
00131     }
00132   else
00133     gripe_wrong_type_arg ("xcolnorms", x, true);
00134 
00135   return retval;
00136 }
00137 
00138 octave_value xrownorms (const octave_value& x, const octave_value& p)
00139 {
00140   octave_value retval;
00141 
00142   bool iscomplex = x.is_complex_type ();
00143   bool issparse = x.is_sparse_type ();
00144   bool isfloat = x.is_single_type ();
00145 
00146   if (isfloat || x.is_double_type ())
00147     {
00148       if (issparse)
00149         {
00150           if (iscomplex)
00151             retval = xrownorms (x.sparse_complex_matrix_value (),
00152                                 p.double_value ());
00153           else
00154             retval = xrownorms (x.sparse_matrix_value (),
00155                                 p.double_value ());
00156         }
00157       else
00158         {
00159           if (isfloat & iscomplex)
00160             retval = xrownorms (x.float_complex_matrix_value (),
00161                                 p.float_value ());
00162           else if (isfloat)
00163             retval = xrownorms (x.float_matrix_value (),
00164                                 p.float_value ());
00165           else if (iscomplex)
00166             retval = xrownorms (x.complex_matrix_value (),
00167                                 p.double_value ());
00168           else
00169             retval = xrownorms (x.matrix_value (),
00170                                 p.double_value ());
00171         }
00172     }
00173   else
00174     gripe_wrong_type_arg ("xrownorms", x, true);
00175 
00176   return retval;
00177 }
00178 
00179 octave_value xfrobnorm (const octave_value& x)
00180 {
00181   octave_value retval;
00182 
00183   bool iscomplex = x.is_complex_type ();
00184   bool issparse = x.is_sparse_type ();
00185   bool isfloat = x.is_single_type ();
00186 
00187   if (isfloat || x.is_double_type ())
00188     {
00189       if (issparse)
00190         {
00191           if (iscomplex)
00192             retval = xfrobnorm (x.sparse_complex_matrix_value ());
00193           else
00194             retval = xfrobnorm (x.sparse_matrix_value ());
00195         }
00196       else
00197         {
00198           if (isfloat & iscomplex)
00199             retval = xfrobnorm (x.float_complex_matrix_value ());
00200           else if (isfloat)
00201             retval = xfrobnorm (x.float_matrix_value ());
00202           else if (iscomplex)
00203             retval = xfrobnorm (x.complex_matrix_value ());
00204           else
00205             retval = xfrobnorm (x.matrix_value ());
00206         }
00207     }
00208   else
00209     gripe_wrong_type_arg ("xfrobnorm", x, true);
00210 
00211   return retval;
00212 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines