// This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // // Copyright (C) 2008 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #ifndef EIGEN_SPARSETRIANGULARSOLVER_H #define EIGEN_SPARSETRIANGULARSOLVER_H template struct ei_inverse_product_selector; // forward substitution, row-major template struct ei_inverse_product_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, const Rhs& rhs, Rhs& res) { for(int col=0 ; col struct ei_inverse_product_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, const Rhs& rhs, Rhs& res) { for(int col=0 ; col=0 ; --i) { Scalar tmp = rhs.coeff(i,col); typename Lhs::InnerIterator it(lhs, i); for(++it; it; ++it) { tmp -= it.value() * res.coeff(it.index(),col); } if (Lhs::Flags & UnitDiagBit) res.coeffRef(i,col) = tmp; else { typename Lhs::InnerIterator it(lhs, i); ei_assert(it.index() == i); res.coeffRef(i,col) = tmp/it.value(); } } } } }; // forward substitution, col-major template struct ei_inverse_product_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, const Rhs& rhs, Rhs& res) { // NOTE we could avoid this copy using an in-place API res = rhs; for(int col=0 ; col struct ei_inverse_product_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, const Rhs& rhs, Rhs& res) { // NOTE we could avoid this copy using an in-place API res = rhs; for(int col=0 ; col=0; --i) { if(!(Lhs::Flags & UnitDiagBit)) { // FIXME lhs.coeff(i,i) might not be always efficient while it must simply be the // last element of the column ! res.coeffRef(i,col) /= lhs.coeff(i,i); } Scalar tmp = res.coeffRef(i,col); typename Lhs::InnerIterator it(lhs, i); for(; it && it.index() template OtherDerived SparseMatrixBase::inverseProduct(const MatrixBase& other) const { ei_assert(derived().cols() == other.rows()); ei_assert(!(Flags & ZeroDiagBit)); ei_assert(Flags & (UpperTriangularBit|LowerTriangularBit)); OtherDerived res(other.rows(), other.cols()); ei_inverse_product_selector::run(derived(), other.derived(), res); return res; } #endif // EIGEN_SPARSETRIANGULARSOLVER_H