From 3642ca4d465f347188e155aab4464b6e814855cb Mon Sep 17 00:00:00 2001 From: Chen-Pang He Date: Sun, 9 Sep 2012 23:34:45 +0800 Subject: Implement packed triangular matrix-vector product. --- blas/PackedTriangularMatrixVector.h | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 blas/PackedTriangularMatrixVector.h (limited to 'blas/PackedTriangularMatrixVector.h') diff --git a/blas/PackedTriangularMatrixVector.h b/blas/PackedTriangularMatrixVector.h new file mode 100644 index 000000000..e9886d56f --- /dev/null +++ b/blas/PackedTriangularMatrixVector.h @@ -0,0 +1,79 @@ +// 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_MATRIX_VECTOR_H +#define EIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H + +namespace internal { + +template +struct packed_triangular_matrix_vector_product; + +template +struct packed_triangular_matrix_vector_product +{ + typedef typename scalar_product_traits::ReturnType ResScalar; + enum { + IsLower = (Mode & Lower) ==Lower, + HasUnitDiag = (Mode & UnitDiag)==UnitDiag, + HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag + }; + static void run(Index size, const LhsScalar* lhs, const RhsScalar* rhs, ResScalar* res, ResScalar alpha) + { + internal::conj_if cj; + typedef Map > LhsMap; + typedef typename conj_expr_if::type ConjLhsType; + typedef Map > ResMap; + + for (Index i=0; i0)) + ResMap(res+(IsLower ? s+i : 0),r) += alpha * cj(rhs[i]) * ConjLhsType(LhsMap(lhs+s,r)); + if (HasUnitDiag) + res[i] += alpha * cj(rhs[i]); + lhs += IsLower ? size-i: i+1; + } + }; +}; + +template +struct packed_triangular_matrix_vector_product +{ + typedef typename scalar_product_traits::ReturnType ResScalar; + enum { + IsLower = (Mode & Lower) ==Lower, + HasUnitDiag = (Mode & UnitDiag)==UnitDiag, + HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag + }; + static void run(Index size, const LhsScalar* lhs, const RhsScalar* rhs, ResScalar* res, ResScalar alpha) + { + internal::conj_if cj; + typedef Map > LhsMap; + typedef typename conj_expr_if::type ConjLhsType; + typedef Map > RhsMap; + typedef typename conj_expr_if::type ConjRhsType; + + for (Index i=0; i0)) + res[i] += alpha * (ConjLhsType(LhsMap(lhs+s,r)).cwiseProduct(ConjRhsType(RhsMap(rhs+(IsLower ? 0 : s+i),r)))).sum(); + if (HasUnitDiag) + res[i] += alpha * cj(rhs[i]); + lhs += IsLower ? i+1 : size-i; + } + }; +}; + +} // end namespace internal + +#endif // EIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H -- cgit v1.2.3