PackedTriangularSolverVector.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_SOLVER_VECTOR_H
11 #define EIGEN_PACKED_TRIANGULAR_SOLVER_VECTOR_H
12 
13 namespace Eigen {
14 namespace internal {
15 
16 template <typename LhsScalar, typename RhsScalar, typename Index, int Side, int Mode, bool Conjugate, int StorageOrder>
18 
19 // forward and backward substitution, row-major, rhs is a vector
20 template <typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate>
21 struct packed_triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Conjugate, RowMajor> {
22  enum { IsLower = (Mode & Lower) == Lower };
23  static void run(Index size, const LhsScalar* lhs, RhsScalar* rhs) {
26  typedef typename conj_expr_if<Conjugate, LhsMap>::type ConjLhsType;
27 
28  lhs += IsLower ? 0 : (size * (size + 1) >> 1) - 1;
29  for (Index pi = 0; pi < size; ++pi) {
30  Index i = IsLower ? pi : size - pi - 1;
31  Index s = IsLower ? 0 : 1;
32  if (pi > 0)
33  rhs[i] -= (ConjLhsType(LhsMap(lhs + s, pi))
34  .cwiseProduct(Map<const Matrix<RhsScalar, Dynamic, 1> >(rhs + (IsLower ? 0 : i + 1), pi)))
35  .sum();
36  if (!(Mode & UnitDiag)) rhs[i] /= cj(lhs[IsLower ? i : 0]);
37  IsLower ? lhs += pi + 1 : lhs -= pi + 2;
38  }
39  }
40 };
41 
42 // forward and backward substitution, column-major, rhs is a vector
43 template <typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate>
44 struct packed_triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft, Mode, Conjugate, ColMajor> {
45  enum { IsLower = (Mode & Lower) == Lower };
46  static void run(Index size, const LhsScalar* lhs, RhsScalar* rhs) {
49  typedef typename conj_expr_if<Conjugate, LhsMap>::type ConjLhsType;
50 
51  lhs += IsLower ? 0 : size * (size - 1) >> 1;
52  for (Index pi = 0; pi < size; ++pi) {
53  Index i = IsLower ? pi : size - pi - 1;
54  Index r = size - pi - 1;
55  if (!(Mode & UnitDiag)) rhs[i] /= cj(lhs[IsLower ? 0 : i]);
56  if (r > 0)
57  Map<Matrix<RhsScalar, Dynamic, 1> >(rhs + (IsLower ? i + 1 : 0), r) -=
58  rhs[i] * ConjLhsType(LhsMap(lhs + (IsLower ? 1 : 0), r));
59  IsLower ? lhs += size - pi : lhs -= r;
60  }
61  }
62 };
63 
64 template <typename LhsScalar, typename RhsScalar, typename Index, int Mode, bool Conjugate, int StorageOrder>
65 struct packed_triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheRight, Mode, Conjugate, StorageOrder> {
66  static void run(Index size, const LhsScalar* lhs, RhsScalar* rhs) {
67  packed_triangular_solve_vector<LhsScalar, RhsScalar, Index, OnTheLeft,
68  ((Mode & Upper) == Upper ? Lower : Upper) | (Mode & UnitDiag), Conjugate,
69  StorageOrder == RowMajor ? ColMajor : RowMajor>::run(size, lhs, rhs);
70  }
71 };
72 
73 } // namespace internal
74 } // namespace Eigen
75 
76 #endif // EIGEN_PACKED_TRIANGULAR_SOLVER_VECTOR_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Definition: ForwardDeclarations.h:102
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
@ UnitDiag
Definition: Constants.h:215
@ Lower
Definition: Constants.h:211
@ Upper
Definition: Constants.h:213
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
@ OnTheLeft
Definition: Constants.h:331
@ OnTheRight
Definition: Constants.h:333
RealScalar s
Definition: level1_cplx_impl.h:130
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
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
r
Definition: UniformPSDSelfTest.py:20
const Mdouble pi
Definition: ExtendedMath.h:23
Definition: Eigen_Colamd.h:49
Definition: ConjHelper.h:42
static void run(Index size, const LhsScalar *lhs, RhsScalar *rhs)
Definition: PackedTriangularSolverVector.h:66
static void run(Index size, const LhsScalar *lhs, RhsScalar *rhs)
Definition: PackedTriangularSolverVector.h:46
static void run(Index size, const LhsScalar *lhs, RhsScalar *rhs)
Definition: PackedTriangularSolverVector.h:23
Definition: PackedTriangularSolverVector.h:17