mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-12 17:33:15 +08:00
Split LU/Inverse.h to Core/Inverse.h for the generic Inverse expression, and LU/InverseImpl.h for the dense implementation of dense.inverse()
This commit is contained in:
parent
1e0c2f6ddb
commit
cbc572caf7
@ -365,6 +365,7 @@ using std::ptrdiff_t;
|
|||||||
#include "src/Core/GeneralProduct.h"
|
#include "src/Core/GeneralProduct.h"
|
||||||
#ifdef EIGEN_ENABLE_EVALUATORS
|
#ifdef EIGEN_ENABLE_EVALUATORS
|
||||||
#include "src/Core/Solve.h"
|
#include "src/Core/Solve.h"
|
||||||
|
#include "src/Core/Inverse.h"
|
||||||
#endif
|
#endif
|
||||||
#include "src/Core/TriangularMatrix.h"
|
#include "src/Core/TriangularMatrix.h"
|
||||||
#include "src/Core/SelfAdjointView.h"
|
#include "src/Core/SelfAdjointView.h"
|
||||||
|
2
Eigen/LU
2
Eigen/LU
@ -25,7 +25,7 @@
|
|||||||
#include "src/LU/PartialPivLU_MKL.h"
|
#include "src/LU/PartialPivLU_MKL.h"
|
||||||
#endif
|
#endif
|
||||||
#include "src/LU/Determinant.h"
|
#include "src/LU/Determinant.h"
|
||||||
#include "src/LU/Inverse.h"
|
#include "src/LU/InverseImpl.h"
|
||||||
|
|
||||||
#if defined EIGEN_VECTORIZE_SSE
|
#if defined EIGEN_VECTORIZE_SSE
|
||||||
#include "src/LU/arch/Inverse_SSE.h"
|
#include "src/LU/arch/Inverse_SSE.h"
|
||||||
|
131
Eigen/src/Core/Inverse.h
Normal file
131
Eigen/src/Core/Inverse.h
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
// This file is part of Eigen, a lightweight C++ template library
|
||||||
|
// for linear algebra.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||||
|
//
|
||||||
|
// 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_INVERSE_H
|
||||||
|
#define EIGEN_INVERSE_H
|
||||||
|
|
||||||
|
namespace Eigen {
|
||||||
|
|
||||||
|
#ifdef EIGEN_TEST_EVALUATORS
|
||||||
|
|
||||||
|
// TODO move the general declaration in Core, and rename this file DenseInverseImpl.h, or something like this...
|
||||||
|
|
||||||
|
template<typename XprType,typename StorageKind> class InverseImpl;
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
template<typename XprType>
|
||||||
|
struct traits<Inverse<XprType> >
|
||||||
|
: traits<typename XprType::PlainObject>
|
||||||
|
{
|
||||||
|
typedef typename XprType::PlainObject PlainObject;
|
||||||
|
typedef traits<PlainObject> BaseTraits;
|
||||||
|
enum {
|
||||||
|
Flags = BaseTraits::Flags & RowMajorBit,
|
||||||
|
CoeffReadCost = Dynamic
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace internal
|
||||||
|
|
||||||
|
/** \class Inverse
|
||||||
|
*
|
||||||
|
* \brief Expression of the inverse of another expression
|
||||||
|
*
|
||||||
|
* \tparam XprType the type of the expression we are taking the inverse
|
||||||
|
*
|
||||||
|
* This class represents an abstract expression of A.inverse()
|
||||||
|
* and most of the time this is the only way it is used.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template<typename XprType>
|
||||||
|
class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename XprType::Index Index;
|
||||||
|
typedef typename XprType::PlainObject PlainObject;
|
||||||
|
typedef typename internal::nested<XprType>::type XprTypeNested;
|
||||||
|
typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned;
|
||||||
|
|
||||||
|
Inverse(const XprType &xpr)
|
||||||
|
: m_xpr(xpr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); }
|
||||||
|
EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); }
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
XprTypeNested &m_xpr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \internal
|
||||||
|
* Specialization of the Inverse expression for dense expressions.
|
||||||
|
* Direct access to the coefficients are discared.
|
||||||
|
* FIXME this intermediate class is probably not needed anymore.
|
||||||
|
*/
|
||||||
|
template<typename XprType>
|
||||||
|
class InverseImpl<XprType,Dense>
|
||||||
|
: public MatrixBase<Inverse<XprType> >
|
||||||
|
{
|
||||||
|
typedef Inverse<XprType> Derived;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef MatrixBase<Derived> Base;
|
||||||
|
EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Scalar coeff(Index row, Index col) const;
|
||||||
|
Scalar coeff(Index i) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
/** \internal
|
||||||
|
* \brief Default evaluator for Inverse expression.
|
||||||
|
*
|
||||||
|
* This default evaluator for Inverse expression simply evaluate the inverse into a temporary
|
||||||
|
* by a call to internal::call_assignment_no_alias.
|
||||||
|
* Therefore, inverse implementers only have to specialize Assignment<Dst,Inverse<...>, ...> for
|
||||||
|
* there own nested expression.
|
||||||
|
*
|
||||||
|
* \sa class Inverse
|
||||||
|
*/
|
||||||
|
template<typename XprType>
|
||||||
|
struct evaluator<Inverse<XprType> >
|
||||||
|
: public evaluator<typename Inverse<XprType>::PlainObject>::type
|
||||||
|
{
|
||||||
|
typedef Inverse<XprType> InverseType;
|
||||||
|
typedef typename InverseType::PlainObject PlainObject;
|
||||||
|
typedef typename evaluator<PlainObject>::type Base;
|
||||||
|
|
||||||
|
typedef evaluator type;
|
||||||
|
typedef evaluator nestedType;
|
||||||
|
|
||||||
|
evaluator(const InverseType& inv_xpr)
|
||||||
|
: m_result(inv_xpr.rows(), inv_xpr.cols())
|
||||||
|
{
|
||||||
|
::new (static_cast<Base*>(this)) Base(m_result);
|
||||||
|
internal::call_assignment_no_alias(m_result, inv_xpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PlainObject m_result;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace internal
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // end namespace Eigen
|
||||||
|
|
||||||
|
#endif // EIGEN_INVERSE_H
|
@ -2,13 +2,14 @@
|
|||||||
// for linear algebra.
|
// for linear algebra.
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
// Copyright (C) 2008-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
||||||
|
// Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla
|
// 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
|
// 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/.
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#ifndef EIGEN_INVERSE_H
|
#ifndef EIGEN_INVERSE_IMPL_H
|
||||||
#define EIGEN_INVERSE_H
|
#define EIGEN_INVERSE_IMPL_H
|
||||||
|
|
||||||
namespace Eigen {
|
namespace Eigen {
|
||||||
|
|
||||||
@ -324,117 +325,9 @@ struct inverse_impl : public ReturnByValue<inverse_impl<MatrixType> >
|
|||||||
|
|
||||||
#ifdef EIGEN_TEST_EVALUATORS
|
#ifdef EIGEN_TEST_EVALUATORS
|
||||||
|
|
||||||
// TODO move the general declaration in Core, and rename this file DenseInverseImpl.h, or something like this...
|
|
||||||
|
|
||||||
template<typename XprType,typename StorageKind> class InverseImpl;
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
template<typename XprType>
|
// Specialization for "dense = dense_xpr.inverse()"
|
||||||
struct traits<Inverse<XprType> >
|
|
||||||
: traits<typename XprType::PlainObject>
|
|
||||||
{
|
|
||||||
typedef typename XprType::PlainObject PlainObject;
|
|
||||||
typedef traits<PlainObject> BaseTraits;
|
|
||||||
enum {
|
|
||||||
Flags = BaseTraits::Flags & RowMajorBit,
|
|
||||||
CoeffReadCost = Dynamic
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace internal
|
|
||||||
|
|
||||||
/** \class Inverse
|
|
||||||
* \ingroup LU_Module
|
|
||||||
*
|
|
||||||
* \brief Expression of the inverse of another expression
|
|
||||||
*
|
|
||||||
* \tparam XprType the type of the expression we are taking the inverse
|
|
||||||
*
|
|
||||||
* This class represents an abstract expression of A.inverse()
|
|
||||||
* and most of the time this is the only way it is used.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<typename XprType>
|
|
||||||
class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef typename XprType::Index Index;
|
|
||||||
typedef typename XprType::PlainObject PlainObject;
|
|
||||||
typedef typename internal::nested<XprType>::type XprTypeNested;
|
|
||||||
typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned;
|
|
||||||
|
|
||||||
Inverse(const XprType &xpr)
|
|
||||||
: m_xpr(xpr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); }
|
|
||||||
EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); }
|
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
XprTypeNested &m_xpr;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** \internal
|
|
||||||
* Specialization of the Inverse expression for dense expressions.
|
|
||||||
* Direct access to the coefficients are discared.
|
|
||||||
* FIXME this intermediate class is probably not needed anymore.
|
|
||||||
*/
|
|
||||||
template<typename XprType>
|
|
||||||
class InverseImpl<XprType,Dense>
|
|
||||||
: public MatrixBase<Inverse<XprType> >
|
|
||||||
{
|
|
||||||
typedef Inverse<XprType> Derived;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef MatrixBase<Derived> Base;
|
|
||||||
EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Scalar coeff(Index row, Index col) const;
|
|
||||||
Scalar coeff(Index i) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
/** \internal
|
|
||||||
* \brief Default evaluator for Inverse expression.
|
|
||||||
*
|
|
||||||
* This default evaluator for Inverse expression simply evaluate the inverse into a temporary
|
|
||||||
* by a call to internal::call_assignment_no_alias.
|
|
||||||
* Therefore, inverse implementers only have to specialize Assignment<Dst,Inverse<...>, ...> for
|
|
||||||
* there own nested expression.
|
|
||||||
*
|
|
||||||
* \sa class Inverse
|
|
||||||
*/
|
|
||||||
template<typename XprType>
|
|
||||||
struct evaluator<Inverse<XprType> >
|
|
||||||
: public evaluator<typename Inverse<XprType>::PlainObject>::type
|
|
||||||
{
|
|
||||||
typedef Inverse<XprType> InverseType;
|
|
||||||
typedef typename InverseType::PlainObject PlainObject;
|
|
||||||
typedef typename evaluator<PlainObject>::type Base;
|
|
||||||
|
|
||||||
typedef evaluator type;
|
|
||||||
typedef evaluator nestedType;
|
|
||||||
|
|
||||||
evaluator(const InverseType& inv_xpr)
|
|
||||||
: m_result(inv_xpr.rows(), inv_xpr.cols())
|
|
||||||
{
|
|
||||||
::new (static_cast<Base*>(this)) Base(m_result);
|
|
||||||
internal::call_assignment_no_alias(m_result, inv_xpr);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PlainObject m_result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Specialization for "dst = xpr.inverse()"
|
|
||||||
// NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
|
|
||||||
template<typename DstXprType, typename XprType, typename Scalar>
|
template<typename DstXprType, typename XprType, typename Scalar>
|
||||||
struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<Scalar>, Dense2Dense, Scalar>
|
struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<Scalar>, Dense2Dense, Scalar>
|
||||||
{
|
{
|
||||||
@ -569,4 +462,4 @@ inline void MatrixBase<Derived>::computeInverseWithCheck(
|
|||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
|
||||||
#endif // EIGEN_INVERSE_H
|
#endif // EIGEN_INVERSE_IMPL_H
|
Loading…
x
Reference in New Issue
Block a user