2011-03-23 11:54:00 +01:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
|
|
|
|
|
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
|
|
|
|
|
// Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
|
|
|
|
|
//
|
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef EIGEN_COREEVALUATORS_H
|
|
|
|
|
#define EIGEN_COREEVALUATORS_H
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct evaluator_impl {};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct evaluator
|
|
|
|
|
{
|
|
|
|
|
typedef evaluator_impl<T> type;
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-04 13:44:50 +01:00
|
|
|
// TODO: Think about const-correctness
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
template<typename T>
|
|
|
|
|
struct evaluator<const T>
|
|
|
|
|
{
|
|
|
|
|
typedef evaluator_impl<T> type;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- Transpose --------------------
|
2011-03-23 11:54:00 +01:00
|
|
|
|
|
|
|
|
template<typename ExpressionType>
|
|
|
|
|
struct evaluator_impl<Transpose<ExpressionType> >
|
|
|
|
|
{
|
|
|
|
|
typedef Transpose<ExpressionType> TransposeType;
|
|
|
|
|
evaluator_impl(const TransposeType& t) : m_argImpl(t.nestedExpression()) {}
|
|
|
|
|
|
|
|
|
|
typedef typename TransposeType::Index Index;
|
|
|
|
|
|
|
|
|
|
typename TransposeType::CoeffReturnType coeff(Index i, Index j) const
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeff(j, i);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename TransposeType::CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
typename TransposeType::Scalar& coeffRef(Index i, Index j)
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeffRef(j, i);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename TransposeType::Scalar& coeffRef(Index index)
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-28 21:29:47 +01:00
|
|
|
// TODO: Difference between PacketScalar and PacketReturnType?
|
2011-03-25 16:30:41 +00:00
|
|
|
template<int LoadMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
const typename ExpressionType::PacketScalar packet(Index row, Index col) const
|
2011-03-25 16:30:41 +00:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
return m_argImpl.template packet<LoadMode>(col, row);
|
2011-03-25 16:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-28 21:29:47 +01:00
|
|
|
template<int LoadMode>
|
|
|
|
|
const typename ExpressionType::PacketScalar packet(Index index) const
|
2011-03-27 13:49:15 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
return m_argImpl.template packet<LoadMode>(index);
|
2011-03-27 13:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
template<int StoreMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
void writePacket(Index row, Index col, const typename ExpressionType::PacketScalar& x)
|
2011-03-27 22:08:48 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
m_argImpl.template writePacket<StoreMode>(col, row, x);
|
2011-03-27 22:08:48 +01:00
|
|
|
}
|
2011-03-27 13:49:15 +01:00
|
|
|
|
|
|
|
|
template<int StoreMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
void writePacket(Index index, const typename ExpressionType::PacketScalar& x)
|
2011-03-27 13:49:15 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
m_argImpl.template writePacket<StoreMode>(index, x);
|
2011-03-27 13:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
protected:
|
|
|
|
|
typename evaluator<ExpressionType>::type m_argImpl;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- Matrix --------------------
|
2011-03-23 11:54:00 +01:00
|
|
|
|
|
|
|
|
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
|
|
|
|
struct evaluator_impl<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
|
|
|
|
|
{
|
|
|
|
|
typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> MatrixType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const MatrixType& m) : m_matrix(m) {}
|
|
|
|
|
|
|
|
|
|
typedef typename MatrixType::Index Index;
|
|
|
|
|
|
|
|
|
|
typename MatrixType::CoeffReturnType coeff(Index i, Index j) const
|
|
|
|
|
{
|
|
|
|
|
return m_matrix.coeff(i, j);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename MatrixType::CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_matrix.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
typename MatrixType::Scalar& coeffRef(Index i, Index j)
|
|
|
|
|
{
|
|
|
|
|
return m_matrix.const_cast_derived().coeffRef(i, j);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename MatrixType::Scalar& coeffRef(Index index)
|
|
|
|
|
{
|
|
|
|
|
return m_matrix.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 13:49:15 +01:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename MatrixType::PacketReturnType packet(Index row, Index col) const
|
|
|
|
|
{
|
|
|
|
|
return m_matrix.template packet<LoadMode>(row, col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
typename MatrixType::PacketReturnType packet(Index index) const
|
2011-03-27 13:49:15 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
// eigen_internal_assert(index >= 0 && index < size());
|
|
|
|
|
return m_matrix.template packet<LoadMode>(index);
|
2011-03-27 13:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
template<int StoreMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
void writePacket(Index row, Index col, const typename MatrixType::PacketScalar& x)
|
2011-03-25 16:30:41 +00:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
m_matrix.const_cast_derived().template writePacket<StoreMode>(row, col, x);
|
2011-03-25 16:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 13:49:15 +01:00
|
|
|
template<int StoreMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
void writePacket(Index index, const typename MatrixType::PacketScalar& x)
|
2011-03-27 13:49:15 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
// eigen_internal_assert(index >= 0 && index < size());
|
|
|
|
|
m_matrix.const_cast_derived().template writePacket<StoreMode>(index, x);
|
2011-03-27 13:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
protected:
|
|
|
|
|
const MatrixType &m_matrix;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- Array --------------------
|
|
|
|
|
|
|
|
|
|
// TODO: should be sharing code with Matrix case
|
2011-03-23 11:54:00 +01:00
|
|
|
|
|
|
|
|
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
|
|
|
|
struct evaluator_impl<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
|
|
|
|
|
{
|
|
|
|
|
typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const ArrayType& a) : m_array(a) {}
|
|
|
|
|
|
|
|
|
|
typedef typename ArrayType::Index Index;
|
|
|
|
|
|
|
|
|
|
typename ArrayType::CoeffReturnType coeff(Index i, Index j) const
|
|
|
|
|
{
|
|
|
|
|
return m_array.coeff(i, j);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-28 21:29:47 +01:00
|
|
|
typename ArrayType::CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_array.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
typename ArrayType::Scalar& coeffRef(Index i, Index j)
|
|
|
|
|
{
|
|
|
|
|
return m_array.const_cast_derived().coeffRef(i, j);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename ArrayType::Scalar& coeffRef(Index index)
|
|
|
|
|
{
|
|
|
|
|
return m_array.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 13:49:15 +01:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename ArrayType::PacketReturnType packet(Index row, Index col) const
|
|
|
|
|
{
|
|
|
|
|
return m_array.template packet<LoadMode>(row, col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
typename ArrayType::PacketReturnType packet(Index index) const
|
2011-03-27 13:49:15 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
// eigen_internal_assert(index >= 0 && index < size());
|
|
|
|
|
return m_array.template packet<LoadMode>(index);
|
2011-03-27 13:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
template<int StoreMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
void writePacket(Index row, Index col, const typename ArrayType::PacketScalar& x)
|
2011-03-25 16:30:41 +00:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
m_array.const_cast_derived().template writePacket<StoreMode>(row, col, x);
|
2011-03-25 16:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 13:49:15 +01:00
|
|
|
template<int StoreMode>
|
2011-03-28 21:29:47 +01:00
|
|
|
void writePacket(Index index, const typename ArrayType::PacketScalar& x)
|
2011-03-27 13:49:15 +01:00
|
|
|
{
|
2011-03-28 21:29:47 +01:00
|
|
|
// eigen_internal_assert(index >= 0 && index < size());
|
|
|
|
|
m_array.const_cast_derived().template writePacket<StoreMode>(index, x);
|
2011-03-27 13:49:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
protected:
|
|
|
|
|
const ArrayType &m_array;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- CwiseNullaryOp --------------------
|
2011-03-23 11:54:00 +01:00
|
|
|
|
|
|
|
|
template<typename NullaryOp, typename PlainObjectType>
|
|
|
|
|
struct evaluator_impl<CwiseNullaryOp<NullaryOp,PlainObjectType> >
|
|
|
|
|
{
|
|
|
|
|
typedef CwiseNullaryOp<NullaryOp,PlainObjectType> NullaryOpType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const NullaryOpType& n) : m_nullaryOp(n) {}
|
|
|
|
|
|
|
|
|
|
typedef typename NullaryOpType::Index Index;
|
|
|
|
|
|
|
|
|
|
typename NullaryOpType::CoeffReturnType coeff(Index i, Index j) const
|
|
|
|
|
{
|
|
|
|
|
return m_nullaryOp.coeff(i, j);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename NullaryOpType::CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_nullaryOp.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename NullaryOpType::PacketScalar packet(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_nullaryOp.template packet<LoadMode>(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
protected:
|
|
|
|
|
const NullaryOpType& m_nullaryOp;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- CwiseUnaryOp --------------------
|
2011-03-23 11:54:00 +01:00
|
|
|
|
|
|
|
|
template<typename UnaryOp, typename ArgType>
|
|
|
|
|
struct evaluator_impl<CwiseUnaryOp<UnaryOp, ArgType> >
|
|
|
|
|
{
|
|
|
|
|
typedef CwiseUnaryOp<UnaryOp, ArgType> UnaryOpType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const UnaryOpType& op) : m_unaryOp(op), m_argImpl(op.nestedExpression()) {}
|
|
|
|
|
|
|
|
|
|
typedef typename UnaryOpType::Index Index;
|
|
|
|
|
|
|
|
|
|
typename UnaryOpType::CoeffReturnType coeff(Index i, Index j) const
|
|
|
|
|
{
|
|
|
|
|
return m_unaryOp.functor()(m_argImpl.coeff(i, j));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename UnaryOpType::CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_unaryOp.functor()(m_argImpl.coeff(index));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename UnaryOpType::PacketScalar packet(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_unaryOp.functor().packetOp(m_argImpl.template packet<LoadMode>(index));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 13:49:15 +01:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename UnaryOpType::PacketScalar packet(Index row, Index col) const
|
|
|
|
|
{
|
|
|
|
|
return m_unaryOp.functor().packetOp(m_argImpl.template packet<LoadMode>(row, col));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
protected:
|
|
|
|
|
const UnaryOpType& m_unaryOp;
|
|
|
|
|
typename evaluator<ArgType>::type m_argImpl;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- CwiseBinaryOp --------------------
|
2011-03-23 11:54:00 +01:00
|
|
|
|
|
|
|
|
template<typename BinaryOp, typename Lhs, typename Rhs>
|
|
|
|
|
struct evaluator_impl<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
|
|
|
|
|
{
|
|
|
|
|
typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> BinaryOpType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const BinaryOpType& xpr) : m_binaryOp(xpr), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) {}
|
|
|
|
|
|
|
|
|
|
typedef typename BinaryOpType::Index Index;
|
|
|
|
|
|
|
|
|
|
typename BinaryOpType::CoeffReturnType coeff(Index i, Index j) const
|
|
|
|
|
{
|
2011-03-25 16:30:41 +00:00
|
|
|
return m_binaryOp.functor()(m_lhsImpl.coeff(i, j), m_rhsImpl.coeff(i, j));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
typename BinaryOpType::CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_binaryOp.functor()(m_lhsImpl.coeff(index), m_rhsImpl.coeff(index));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename BinaryOpType::PacketScalar packet(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_binaryOp.functor().packetOp(m_lhsImpl.template packet<LoadMode>(index),
|
|
|
|
|
m_rhsImpl.template packet<LoadMode>(index));
|
2011-03-23 11:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 22:08:48 +01:00
|
|
|
template<int LoadMode>
|
|
|
|
|
typename BinaryOpType::PacketScalar packet(Index row, Index col) const
|
|
|
|
|
{
|
|
|
|
|
return m_binaryOp.functor().packetOp(m_lhsImpl.template packet<LoadMode>(row, col),
|
|
|
|
|
m_rhsImpl.template packet<LoadMode>(row, col));
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
protected:
|
|
|
|
|
const BinaryOpType& m_binaryOp;
|
|
|
|
|
typename evaluator<Lhs>::type m_lhsImpl;
|
|
|
|
|
typename evaluator<Rhs>::type m_rhsImpl;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 16:30:41 +00:00
|
|
|
// -------------------- Product --------------------
|
2011-03-23 11:54:00 +01:00
|
|
|
|
2011-03-24 09:33:36 +01:00
|
|
|
template<typename Lhs, typename Rhs>
|
|
|
|
|
struct evaluator_impl<Product<Lhs,Rhs> > : public evaluator<typename Product<Lhs,Rhs>::PlainObject>::type
|
2011-03-23 11:54:00 +01:00
|
|
|
{
|
2011-03-24 09:33:36 +01:00
|
|
|
typedef Product<Lhs,Rhs> XprType;
|
2011-03-23 11:54:00 +01:00
|
|
|
typedef typename XprType::PlainObject PlainObject;
|
|
|
|
|
typedef typename evaluator<PlainObject>::type evaluator_base;
|
|
|
|
|
|
|
|
|
|
// enum {
|
|
|
|
|
// EvaluateLhs = ;
|
|
|
|
|
// EvaluateRhs = ;
|
|
|
|
|
// };
|
|
|
|
|
|
2011-03-24 09:33:36 +01:00
|
|
|
evaluator_impl(const XprType& product) : evaluator_base(m_result)
|
2011-03-23 11:54:00 +01:00
|
|
|
{
|
2011-03-24 09:33:36 +01:00
|
|
|
// here we process the left and right hand sides with a specialized evaluator
|
|
|
|
|
// perhaps this step should be done by the TreeOptimizer to get a canonical tree and reduce evaluator instanciations
|
|
|
|
|
// typename product_operand_evaluator<Lhs>::type m_lhsImpl(product.lhs());
|
|
|
|
|
// typename product_operand_evaluator<Rhs>::type m_rhsImpl(product.rhs());
|
|
|
|
|
|
|
|
|
|
// TODO do not rely on previous product mechanism !!
|
2011-03-23 11:54:00 +01:00
|
|
|
m_result.resize(product.rows(), product.cols());
|
2011-03-24 09:33:36 +01:00
|
|
|
m_result.noalias() = product.lhs() * product.rhs();
|
2011-03-23 11:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
PlainObject m_result;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-31 13:50:52 +01:00
|
|
|
// -------------------- Block --------------------
|
|
|
|
|
|
2011-04-04 13:44:50 +01:00
|
|
|
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
|
|
|
|
|
struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ false> >
|
2011-03-31 13:50:52 +01:00
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
typedef Block<XprType, BlockRows, BlockCols, InnerPanel, false> BlockType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const BlockType& block)
|
|
|
|
|
: m_argImpl(block.nestedExpression()),
|
|
|
|
|
m_startRow(block.startRow()),
|
|
|
|
|
m_startCol(block.startCol())
|
|
|
|
|
{ }
|
2011-03-31 13:50:52 +01:00
|
|
|
|
|
|
|
|
typedef typename BlockType::Index Index;
|
|
|
|
|
typedef typename BlockType::Scalar Scalar;
|
|
|
|
|
typedef typename BlockType::CoeffReturnType CoeffReturnType;
|
|
|
|
|
typedef typename BlockType::PacketScalar PacketScalar;
|
|
|
|
|
typedef typename BlockType::PacketReturnType PacketReturnType;
|
2011-04-04 13:44:50 +01:00
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
RowsAtCompileTime = BlockType::RowsAtCompileTime
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CoeffReturnType coeff(Index row, Index col) const
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeff(m_startRow + row, m_startCol + col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeff(m_startRow + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol + (RowsAtCompileTime == 1 ? index : 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Scalar& coeffRef(Index row, Index col)
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeffRef(m_startRow + row, m_startCol + col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Scalar& coeffRef(Index index)
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.coeffRef(m_startRow + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol + (RowsAtCompileTime == 1 ? index : 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
|
|
|
|
PacketReturnType packet(Index row, Index col) const
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.template packet<LoadMode>(m_startRow + row, m_startCol + col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
|
|
|
|
PacketReturnType packet(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.template packet<LoadMode>(m_startRow + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol + (RowsAtCompileTime == 1 ? index : 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int StoreMode>
|
|
|
|
|
void writePacket(Index row, Index col, const PacketScalar& x)
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.template writePacket<StoreMode>(m_startRow + row, m_startCol + col, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int StoreMode>
|
|
|
|
|
void writePacket(Index index, const PacketScalar& x)
|
|
|
|
|
{
|
|
|
|
|
return m_argImpl.template writePacket<StoreMode>(m_startRow + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol + (RowsAtCompileTime == 1 ? index : 0),
|
|
|
|
|
x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
typename evaluator<XprType>::type m_argImpl;
|
|
|
|
|
|
|
|
|
|
// TODO: Get rid of m_startRow, m_startCol if known at compile time
|
|
|
|
|
Index m_startRow;
|
|
|
|
|
Index m_startCol;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: This evaluator does not actually use the child evaluator;
|
|
|
|
|
// all action is via the data() as returned by the Block expression.
|
|
|
|
|
|
|
|
|
|
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
|
|
|
|
|
struct evaluator_impl<Block<XprType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ true> >
|
|
|
|
|
{
|
|
|
|
|
typedef Block<XprType, BlockRows, BlockCols, InnerPanel, true> BlockType;
|
|
|
|
|
typedef typename BlockType::PointerType PointerType;
|
|
|
|
|
typedef typename BlockType::Index Index;
|
|
|
|
|
typedef typename BlockType::Scalar Scalar;
|
|
|
|
|
typedef typename BlockType::CoeffReturnType CoeffReturnType;
|
|
|
|
|
typedef typename BlockType::PacketScalar PacketScalar;
|
|
|
|
|
typedef typename BlockType::PacketReturnType PacketReturnType;
|
|
|
|
|
|
|
|
|
|
evaluator_impl(const BlockType& block)
|
|
|
|
|
: m_argImpl(block.nestedExpression()),
|
|
|
|
|
m_data(const_cast<PointerType>(block.data())),
|
|
|
|
|
m_rowStride(block.rowStride()),
|
|
|
|
|
m_colStride(block.colStride())
|
|
|
|
|
{ }
|
2011-03-31 13:50:52 +01:00
|
|
|
|
2011-04-04 13:44:50 +01:00
|
|
|
enum {
|
|
|
|
|
RowsAtCompileTime = BlockType::RowsAtCompileTime
|
|
|
|
|
};
|
2011-03-31 13:50:52 +01:00
|
|
|
|
2011-04-04 13:44:50 +01:00
|
|
|
CoeffReturnType coeff(Index row, Index col) const
|
2011-03-31 13:50:52 +01:00
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
return m_data[col * m_colStride + row * m_rowStride];
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CoeffReturnType coeff(Index index) const
|
|
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
return coeff(RowsAtCompileTime == 1 ? 0 : index,
|
|
|
|
|
RowsAtCompileTime == 1 ? index : 0);
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-04 13:44:50 +01:00
|
|
|
Scalar& coeffRef(Index row, Index col)
|
2011-03-31 13:50:52 +01:00
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
return m_data[col * m_colStride + row * m_rowStride];
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Scalar& coeffRef(Index index)
|
|
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
return coeffRef(RowsAtCompileTime == 1 ? 0 : index,
|
|
|
|
|
RowsAtCompileTime == 1 ? index : 0);
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
|
|
|
|
PacketReturnType packet(Index row, Index col) const
|
|
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
PointerType ptr = m_data + row * m_rowStride + col * m_colStride;
|
|
|
|
|
return internal::ploadt<PacketScalar, LoadMode>(ptr);
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
|
|
|
|
PacketReturnType packet(Index index) const
|
|
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
return packet<LoadMode>(RowsAtCompileTime == 1 ? 0 : index,
|
|
|
|
|
RowsAtCompileTime == 1 ? index : 0);
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int StoreMode>
|
|
|
|
|
void writePacket(Index row, Index col, const PacketScalar& x)
|
|
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
PointerType ptr = m_data + row * m_rowStride + col * m_colStride;
|
|
|
|
|
return internal::pstoret<Scalar, PacketScalar, StoreMode>(ptr, x);
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int StoreMode>
|
|
|
|
|
void writePacket(Index index, const PacketScalar& x)
|
|
|
|
|
{
|
2011-04-04 13:44:50 +01:00
|
|
|
return writePacket<StoreMode>(RowsAtCompileTime == 1 ? 0 : index,
|
|
|
|
|
RowsAtCompileTime == 1 ? index : 0,
|
|
|
|
|
x);
|
2011-03-31 13:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2011-04-04 13:44:50 +01:00
|
|
|
typename evaluator<XprType>::type m_argImpl;
|
|
|
|
|
PointerType m_data;
|
|
|
|
|
int m_rowStride;
|
|
|
|
|
int m_colStride;
|
2011-03-31 13:50:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-03-23 11:54:00 +01:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
#endif // EIGEN_COREEVALUATORS_H
|