level1_cplx_impl.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "common.h"
11 
15  inline RealScalar operator() (const Scalar& a) const { return numext::norm1(a); }
16 };
17 namespace Eigen {
18  namespace internal {
19  template<> struct functor_traits<scalar_norm1_op >
20  {
22  };
23  }
24 }
25 
26 // computes the sum of magnitudes of all vector elements or, for a complex vector x, the sum
27 // res = |Rex1| + |Imx1| + |Rex2| + |Imx2| + ... + |Rexn| + |Imxn|, where x is a vector of order n
29 {
30 // std::cerr << "__asum " << *n << " " << *incx << "\n";
31  Complex* x = reinterpret_cast<Complex*>(px);
32 
33  if(*n<=0) return 0;
34 
35  if(*incx==1) return make_vector(x,*n).unaryExpr<scalar_norm1_op>().sum();
36  else return make_vector(x,*n,std::abs(*incx)).unaryExpr<scalar_norm1_op>().sum();
37 }
38 
39 int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amax))(int *n, RealScalar *px, int *incx)
40 {
41  if(*n<=0) return 0;
42  Scalar* x = reinterpret_cast<Scalar*>(px);
43 
45  if(*incx==1) make_vector(x,*n).unaryExpr<scalar_norm1_op>().maxCoeff(&ret);
46  else make_vector(x,*n,std::abs(*incx)).unaryExpr<scalar_norm1_op>().maxCoeff(&ret);
47  return int(ret)+1;
48 }
49 
50 int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amin))(int *n, RealScalar *px, int *incx)
51 {
52  if(*n<=0) return 0;
53  Scalar* x = reinterpret_cast<Scalar*>(px);
54 
56  if(*incx==1) make_vector(x,*n).unaryExpr<scalar_norm1_op>().minCoeff(&ret);
57  else make_vector(x,*n,std::abs(*incx)).unaryExpr<scalar_norm1_op>().minCoeff(&ret);
58  return int(ret)+1;
59 }
60 
61 // computes a dot product of a conjugated vector with another vector.
62 int EIGEN_BLAS_FUNC(dotcw)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar* pres)
63 {
64 // std::cerr << "_dotc " << *n << " " << *incx << " " << *incy << "\n";
65  Scalar* res = reinterpret_cast<Scalar*>(pres);
66 
67  if(*n<=0)
68  {
69  *res = Scalar(0);
70  return 0;
71  }
72 
73  Scalar* x = reinterpret_cast<Scalar*>(px);
74  Scalar* y = reinterpret_cast<Scalar*>(py);
75 
76  if(*incx==1 && *incy==1) *res = (make_vector(x,*n).dot(make_vector(y,*n)));
77  else if(*incx>0 && *incy>0) *res = (make_vector(x,*n,*incx).dot(make_vector(y,*n,*incy)));
78  else if(*incx<0 && *incy>0) *res = (make_vector(x,*n,-*incx).reverse().dot(make_vector(y,*n,*incy)));
79  else if(*incx>0 && *incy<0) *res = (make_vector(x,*n,*incx).dot(make_vector(y,*n,-*incy).reverse()));
80  else if(*incx<0 && *incy<0) *res = (make_vector(x,*n,-*incx).reverse().dot(make_vector(y,*n,-*incy).reverse()));
81  return 0;
82 }
83 
84 // computes a vector-vector dot product without complex conjugation.
85 int EIGEN_BLAS_FUNC(dotuw)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar* pres)
86 {
87  Scalar* res = reinterpret_cast<Scalar*>(pres);
88 
89  if(*n<=0)
90  {
91  *res = Scalar(0);
92  return 0;
93  }
94 
95  Scalar* x = reinterpret_cast<Scalar*>(px);
96  Scalar* y = reinterpret_cast<Scalar*>(py);
97 
98  if(*incx==1 && *incy==1) *res = (make_vector(x,*n).cwiseProduct(make_vector(y,*n))).sum();
99  else if(*incx>0 && *incy>0) *res = (make_vector(x,*n,*incx).cwiseProduct(make_vector(y,*n,*incy))).sum();
100  else if(*incx<0 && *incy>0) *res = (make_vector(x,*n,-*incx).reverse().cwiseProduct(make_vector(y,*n,*incy))).sum();
101  else if(*incx>0 && *incy<0) *res = (make_vector(x,*n,*incx).cwiseProduct(make_vector(y,*n,-*incy).reverse())).sum();
102  else if(*incx<0 && *incy<0) *res = (make_vector(x,*n,-*incx).reverse().cwiseProduct(make_vector(y,*n,-*incy).reverse())).sum();
103  return 0;
104 }
105 
107 {
108 // std::cerr << "__nrm2 " << *n << " " << *incx << "\n";
109  if(*n<=0) return 0;
110 
111  Scalar* x = reinterpret_cast<Scalar*>(px);
112 
113  if(*incx==1)
114  return make_vector(x,*n).stableNorm();
115 
116  return make_vector(x,*n,*incx).stableNorm();
117 }
118 
120 {
121  if(*n<=0) return 0;
122 
123  Scalar* x = reinterpret_cast<Scalar*>(px);
124  Scalar* y = reinterpret_cast<Scalar*>(py);
127 
130 
133 
134  // TODO implement mixed real-scalar rotations
138 
139  return 0;
140 }
141 
143 {
144  if(*n<=0) return 0;
145 
146  Scalar* x = reinterpret_cast<Scalar*>(px);
148 
149 // std::cerr << "__scal " << *n << " " << alpha << " " << *incx << "\n";
150 
151  if(*incx==1) make_vector(x,*n) *= alpha;
152  else make_vector(x,*n,std::abs(*incx)) *= alpha;
153 
154  return 0;
155 }
EIGEN_EMPTY_STRUCT_CTOR
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition: XprHelper.h:22
Complex
std::complex< RealScalar > Complex
Definition: gtsam/3rdparty/Eigen/blas/common.h:94
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
alpha
RealScalar alpha
Definition: level1_cplx_impl.h:147
s
RealScalar s
Definition: level1_cplx_impl.h:126
dotcw
int EIGEN_BLAS_FUNC() dotcw(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pres)
Definition: level1_cplx_impl.h:62
asum
RealScalar EIGEN_BLAS_FUNC() asum(int *n, RealScalar *px, int *incx)
Definition: level1_real_impl.h:14
ret
DenseIndex ret
Definition: level1_cplx_impl.h:44
scalar_norm1_op
Definition: level1_cplx_impl.h:12
res
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
rvx
Reverse< StridedVectorType > rvx(vx)
scal
int EIGEN_BLAS_FUNC() scal(int *n, RealScalar *palpha, RealScalar *px, int *incx)
Definition: level1_impl.h:117
Eigen::JacobiRotation
Rotation given by a cosine-sine pair.
Definition: ForwardDeclarations.h:283
make_vector
if incx return make_vector(x, *n).unaryExpr< scalar_norm1_op >().sum()
rot
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
Definition: level1_real_impl.h:79
n
int n
Definition: BiCGSTAB_simple.cpp:1
common.h
incy
int RealScalar int RealScalar int * incy
Definition: level1_cplx_impl.h:119
vy
StridedVectorType vy(make_vector(y, *n, std::abs(*incy)))
rvy
Reverse< StridedVectorType > rvy(vy)
x
Scalar * x
Definition: level1_cplx_impl.h:42
EIGEN_CAT
RealScalar EIGEN_CAT(REAL_SCALAR_SUFFIX, EIGEN_BLAS_FUNC(asum))(int *n
Eigen::Reverse
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:63
incx
RealScalar RealScalar int * incx
Definition: level1_cplx_impl.h:29
nrm2
Scalar EIGEN_BLAS_FUNC() nrm2(int *n, RealScalar *px, int *incx)
Definition: level1_real_impl.h:68
Eigen::internal::functor_traits::PacketAccess
@ PacketAccess
Definition: XprHelper.h:180
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
pc
int RealScalar int RealScalar int RealScalar * pc
Definition: level1_cplx_impl.h:119
y
Scalar * y
Definition: level1_cplx_impl.h:124
RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:47
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
c
RealScalar c
Definition: level1_cplx_impl.h:125
Eigen::internal::functor_traits::Cost
@ Cost
Definition: XprHelper.h:179
Eigen::DenseIndex
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: Meta.h:66
scalar_norm1_op::result_type
RealScalar result_type
Definition: level1_cplx_impl.h:13
REAL_SCALAR_SUFFIX
#define REAL_SCALAR_SUFFIX
Definition: blas/complex_double.cpp:13
ps
int RealScalar int RealScalar int RealScalar RealScalar * ps
Definition: level1_cplx_impl.h:120
EIGEN_BLAS_FUNC
int EIGEN_BLAS_FUNC(EIGEN_CAT(REAL_SCALAR_SUFFIX, rot))(int *n
abs
#define abs(x)
Definition: datatypes.h:17
Eigen::internal::functor_traits
Definition: XprHelper.h:175
py
int RealScalar int RealScalar * py
Definition: level1_cplx_impl.h:119
internal
Definition: BandTriangularSolver.h:13
reverse
void reverse(const MatrixType &m)
Definition: array_reverse.cpp:16
int
return int(ret)+1
palpha
int RealScalar * palpha
Definition: level1_cplx_impl.h:142
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::internal::apply_rotation_in_the_plane
EIGEN_DEVICE_FUNC void apply_rotation_in_the_plane(DenseBase< VectorX > &xpr_x, DenseBase< VectorY > &xpr_y, const JacobiRotation< OtherScalar > &j)
Definition: Jacobi.h:453
dotuw
int EIGEN_BLAS_FUNC() dotuw(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pres)
Definition: level1_cplx_impl.h:85
vx
StridedVectorType vx(make_vector(x, *n, std::abs(*incx)))
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
px
RealScalar RealScalar * px
Definition: level1_cplx_impl.h:28


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:33:06