From 65caa40a3d792dbbd28b3f47de2a87efea58bb24 Mon Sep 17 00:00:00 2001 From: Chen-Pang He Date: Mon, 10 Sep 2012 06:29:02 +0800 Subject: Implement packed triangular solver. --- blas/PackedTriangularSolverVector.h | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 blas/PackedTriangularSolverVector.h (limited to 'blas/PackedTriangularSolverVector.h') diff --git a/blas/PackedTriangularSolverVector.h b/blas/PackedTriangularSolverVector.h new file mode 100644 index 000000000..5c0bb4bd6 --- /dev/null +++ b/blas/PackedTriangularSolverVector.h @@ -0,0 +1,88 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2012 Chen-Pang He +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PACKED_TRIANGULAR_SOLVER_VECTOR_H +#define EIGEN_PACKED_TRIANGULAR_SOLVER_VECTOR_H + +namespace internal { + +template +struct packed_triangular_solve_vector; + +// forward and backward substitution, row-major, rhs is a vector +template +struct packed_triangular_solve_vector +{ + enum { + IsLower = (Mode&Lower)==Lower + }; + static void run(Index size, const LhsScalar* lhs, RhsScalar* rhs) + { + internal::conj_if cj; + typedef Map > LhsMap; + typedef typename conj_expr_if::type ConjLhsType; + + lhs += IsLower ? 0 : (size*(size+1)>>1)-1; + for(Index pi=0; pi0) + rhs[i] -= (ConjLhsType(LhsMap(lhs+s,pi)) + .cwiseProduct(Map >(rhs+(IsLower ? 0 : i+1),pi))).sum(); + if (!(Mode & UnitDiag)) + rhs[i] /= cj(lhs[IsLower ? i : 0]); + IsLower ? lhs += pi+1 : lhs -= pi+2; + } + } +}; + +// forward and backward substitution, column-major, rhs is a vector +template +struct packed_triangular_solve_vector +{ + enum { + IsLower = (Mode&Lower)==Lower + }; + static void run(Index size, const LhsScalar* lhs, RhsScalar* rhs) + { + internal::conj_if cj; + typedef Map > LhsMap; + typedef typename conj_expr_if::type ConjLhsType; + + lhs += IsLower ? 0 : size*(size-1)>>1; + for(Index pi=0; pi0) + Map >(rhs+(IsLower? i+1 : 0),r) -= + rhs[i] * ConjLhsType(LhsMap(lhs+(IsLower? 1 : 0),r)); + IsLower ? lhs += size-pi : lhs -= r; + } + } +}; + +template +struct packed_triangular_solve_vector +{ + static void run(Index size, const LhsScalar* lhs, RhsScalar* rhs) + { + packed_triangular_solve_vector::run(size, lhs, rhs); + } +}; + +} // end namespace internal + +#endif // EIGEN_PACKED_TRIANGULAR_SOLVER_VECTOR_H -- cgit v1.2.3