PackedTriangularMatrixVector.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) 2012 Chen-Pang He <jdh8@ms63.hinet.net>
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 #ifndef EIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H
11 #define EIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H
12 
13 namespace Eigen {
14 namespace internal {
15 
16 template <typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs,
17  int StorageOrder>
19 
20 template <typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs>
21 struct packed_triangular_matrix_vector_product<Index, Mode, LhsScalar, ConjLhs, RhsScalar, ConjRhs, ColMajor> {
23  enum {
24  IsLower = (Mode & Lower) == Lower,
25  HasUnitDiag = (Mode & UnitDiag) == UnitDiag,
26  HasZeroDiag = (Mode & ZeroDiag) == ZeroDiag
27  };
28  static void run(Index size, const LhsScalar* lhs, const RhsScalar* rhs, ResScalar* res, ResScalar alpha) {
31  typedef typename conj_expr_if<ConjLhs, LhsMap>::type ConjLhsType;
32  typedef Map<Matrix<ResScalar, Dynamic, 1> > ResMap;
33 
34  for (Index i = 0; i < size; ++i) {
35  Index s = IsLower && (HasUnitDiag || HasZeroDiag) ? 1 : 0;
36  Index r = IsLower ? size - i : i + 1;
37  if (!(HasUnitDiag || HasZeroDiag) || (--r > 0)) {
38  ResMap(res + (IsLower ? s + i : 0), r) += alpha * cj(rhs[i]) * ConjLhsType(LhsMap(lhs + s, r));
39  }
40  if (HasUnitDiag) {
41  res[i] += alpha * cj(rhs[i]);
42  }
43  lhs += IsLower ? size - i : i + 1;
44  }
45  };
46 };
47 
48 template <typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs>
49 struct packed_triangular_matrix_vector_product<Index, Mode, LhsScalar, ConjLhs, RhsScalar, ConjRhs, RowMajor> {
51  enum {
52  IsLower = (Mode & Lower) == Lower,
53  HasUnitDiag = (Mode & UnitDiag) == UnitDiag,
54  HasZeroDiag = (Mode & ZeroDiag) == ZeroDiag
55  };
56  static void run(Index size, const LhsScalar* lhs, const RhsScalar* rhs, ResScalar* res, ResScalar alpha) {
59  typedef typename conj_expr_if<ConjLhs, LhsMap>::type ConjLhsType;
61  typedef typename conj_expr_if<ConjRhs, RhsMap>::type ConjRhsType;
62 
63  for (Index i = 0; i < size; ++i) {
64  Index s = !IsLower && (HasUnitDiag || HasZeroDiag) ? 1 : 0;
65  Index r = IsLower ? i + 1 : size - i;
66  if (!(HasUnitDiag || HasZeroDiag) || (--r > 0)) {
67  res[i] +=
68  alpha *
69  (ConjLhsType(LhsMap(lhs + s, r)).cwiseProduct(ConjRhsType(RhsMap(rhs + (IsLower ? 0 : s + i), r)))).sum();
70  }
71  if (HasUnitDiag) {
72  res[i] += alpha * cj(rhs[i]);
73  }
74  lhs += IsLower ? i + 1 : size - i;
75  }
76  };
77 };
78 
79 } // namespace internal
80 } // namespace Eigen
81 
82 #endif // EIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
@ UnitDiag
Definition: Constants.h:215
@ ZeroDiag
Definition: Constants.h:217
@ Lower
Definition: Constants.h:211
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
RealScalar s
Definition: level1_cplx_impl.h:130
RealScalar alpha
Definition: level1_cplx_impl.h:151
std::conditional<!Cond, const T &, CwiseUnaryOp< scalar_conjugate_op< typename traits< T >::Scalar >, T > > conj_expr_if
Definition: SelfadjointRank2Update.h:52
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
r
Definition: UniformPSDSelfTest.py:20
Definition: Eigen_Colamd.h:49
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:1043
Definition: ConjHelper.h:42
ScalarBinaryOpTraits< LhsScalar, RhsScalar >::ReturnType ResScalar
Definition: PackedTriangularMatrixVector.h:50
static void run(Index size, const LhsScalar *lhs, const RhsScalar *rhs, ResScalar *res, ResScalar alpha)
Definition: PackedTriangularMatrixVector.h:56
static void run(Index size, const LhsScalar *lhs, const RhsScalar *rhs, ResScalar *res, ResScalar alpha)
Definition: PackedTriangularMatrixVector.h:28
ScalarBinaryOpTraits< LhsScalar, RhsScalar >::ReturnType ResScalar
Definition: PackedTriangularMatrixVector.h:22
Definition: PackedTriangularMatrixVector.h:18