level1_cplx_impl.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "common.h"
00026 
00027 struct scalar_norm1_op {
00028   typedef RealScalar result_type;
00029   EIGEN_EMPTY_STRUCT_CTOR(scalar_norm1_op)
00030   inline RealScalar operator() (const Scalar& a) const { return internal::norm1(a); }
00031 };
00032 namespace Eigen {
00033   namespace internal {
00034     template<> struct functor_traits<scalar_norm1_op >
00035     {
00036       enum { Cost = 3 * NumTraits<Scalar>::AddCost, PacketAccess = 0 };
00037     };
00038   }
00039 }
00040 
00041 // computes the sum of magnitudes of all vector elements or, for a complex vector x, the sum
00042 // res = |Rex1| + |Imx1| + |Rex2| + |Imx2| + ... + |Rexn| + |Imxn|, where x is a vector of order n
00043 RealScalar EIGEN_CAT(EIGEN_CAT(REAL_SCALAR_SUFFIX,SCALAR_SUFFIX),asum_)(int *n, RealScalar *px, int *incx)
00044 {
00045 //   std::cerr << "__asum " << *n << " " << *incx << "\n";
00046   Complex* x = reinterpret_cast<Complex*>(px);
00047 
00048   if(*n<=0) return 0;
00049 
00050   if(*incx==1)  return vector(x,*n).unaryExpr<scalar_norm1_op>().sum();
00051   else          return vector(x,*n,std::abs(*incx)).unaryExpr<scalar_norm1_op>().sum();
00052 }
00053 
00054 // computes a dot product of a conjugated vector with another vector.
00055 int EIGEN_BLAS_FUNC(dotcw)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar* pres)
00056 {
00057 //   std::cerr << "_dotc " << *n << " " << *incx << " " << *incy << "\n";
00058 
00059   if(*n<=0) return 0;
00060 
00061   Scalar* x = reinterpret_cast<Scalar*>(px);
00062   Scalar* y = reinterpret_cast<Scalar*>(py);
00063   Scalar* res = reinterpret_cast<Scalar*>(pres);
00064 
00065   if(*incx==1 && *incy==1)    *res = (vector(x,*n).dot(vector(y,*n)));
00066   else if(*incx>0 && *incy>0) *res = (vector(x,*n,*incx).dot(vector(y,*n,*incy)));
00067   else if(*incx<0 && *incy>0) *res = (vector(x,*n,-*incx).reverse().dot(vector(y,*n,*incy)));
00068   else if(*incx>0 && *incy<0) *res = (vector(x,*n,*incx).dot(vector(y,*n,-*incy).reverse()));
00069   else if(*incx<0 && *incy<0) *res = (vector(x,*n,-*incx).reverse().dot(vector(y,*n,-*incy).reverse()));
00070   return 0;
00071 }
00072 
00073 // computes a vector-vector dot product without complex conjugation.
00074 int EIGEN_BLAS_FUNC(dotuw)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar* pres)
00075 {
00076 //   std::cerr << "_dotu " << *n << " " << *incx << " " << *incy << "\n";
00077 
00078   if(*n<=0) return 0;
00079 
00080   Scalar* x = reinterpret_cast<Scalar*>(px);
00081   Scalar* y = reinterpret_cast<Scalar*>(py);
00082   Scalar* res = reinterpret_cast<Scalar*>(pres);
00083 
00084   if(*incx==1 && *incy==1)    *res = (vector(x,*n).cwiseProduct(vector(y,*n))).sum();
00085   else if(*incx>0 && *incy>0) *res = (vector(x,*n,*incx).cwiseProduct(vector(y,*n,*incy))).sum();
00086   else if(*incx<0 && *incy>0) *res = (vector(x,*n,-*incx).reverse().cwiseProduct(vector(y,*n,*incy))).sum();
00087   else if(*incx>0 && *incy<0) *res = (vector(x,*n,*incx).cwiseProduct(vector(y,*n,-*incy).reverse())).sum();
00088   else if(*incx<0 && *incy<0) *res = (vector(x,*n,-*incx).reverse().cwiseProduct(vector(y,*n,-*incy).reverse())).sum();
00089   return 0;
00090 }
00091 
00092 RealScalar EIGEN_CAT(EIGEN_CAT(REAL_SCALAR_SUFFIX,SCALAR_SUFFIX),nrm2_)(int *n, RealScalar *px, int *incx)
00093 {
00094 //   std::cerr << "__nrm2 " << *n << " " << *incx << "\n";
00095   if(*n<=0) return 0;
00096 
00097   Scalar* x = reinterpret_cast<Scalar*>(px);
00098 
00099   if(*incx==1)
00100     return vector(x,*n).stableNorm();
00101 
00102   return vector(x,*n,*incx).stableNorm();
00103 }
00104 
00105 int EIGEN_CAT(EIGEN_CAT(SCALAR_SUFFIX,REAL_SCALAR_SUFFIX),rot_)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
00106 {
00107   if(*n<=0) return 0;
00108 
00109   Scalar* x = reinterpret_cast<Scalar*>(px);
00110   Scalar* y = reinterpret_cast<Scalar*>(py);
00111   RealScalar c = *pc;
00112   RealScalar s = *ps;
00113 
00114   StridedVectorType vx(vector(x,*n,std::abs(*incx)));
00115   StridedVectorType vy(vector(y,*n,std::abs(*incy)));
00116 
00117   Reverse<StridedVectorType> rvx(vx);
00118   Reverse<StridedVectorType> rvy(vy);
00119 
00120   // TODO implement mixed real-scalar rotations
00121        if(*incx<0 && *incy>0) internal::apply_rotation_in_the_plane(rvx, vy, JacobiRotation<Scalar>(c,s));
00122   else if(*incx>0 && *incy<0) internal::apply_rotation_in_the_plane(vx, rvy, JacobiRotation<Scalar>(c,s));
00123   else                        internal::apply_rotation_in_the_plane(vx, vy,  JacobiRotation<Scalar>(c,s));
00124 
00125   return 0;
00126 }
00127 
00128 int EIGEN_CAT(EIGEN_CAT(SCALAR_SUFFIX,REAL_SCALAR_SUFFIX),scal_)(int *n, RealScalar *palpha, RealScalar *px, int *incx)
00129 {
00130   if(*n<=0) return 0;
00131 
00132   Scalar* x = reinterpret_cast<Scalar*>(px);
00133   RealScalar alpha = *palpha;
00134 
00135 //   std::cerr << "__scal " << *n << " " << alpha << " " << *incx << "\n";
00136 
00137   if(*incx==1)  vector(x,*n) *= alpha;
00138   else          vector(x,*n,std::abs(*incx)) *= alpha;
00139 
00140   return 0;
00141 }
00142 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:38