2007-10-12 05:15:25 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra. Eigen itself is part of the KDE project.
|
2007-09-05 10:42:15 +00:00
|
|
|
//
|
2008-01-07 09:34:21 +00:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
2007-09-05 10:42:15 +00:00
|
|
|
//
|
2008-02-28 15:44:45 +00:00
|
|
|
// 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.
|
2007-09-05 10:42:15 +00:00
|
|
|
//
|
2007-10-12 05:15:25 +00:00
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
2007-09-05 10:42:15 +00:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-02-28 15:44:45 +00:00
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
2007-09-05 10:42:15 +00:00
|
|
|
//
|
2008-02-28 15:44:45 +00:00
|
|
|
// 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/>.
|
2007-09-05 10:42:15 +00:00
|
|
|
|
2007-11-26 08:47:07 +00:00
|
|
|
#ifndef EIGEN_SCALARMULTIPLE_H
|
|
|
|
|
#define EIGEN_SCALARMULTIPLE_H
|
2007-09-05 10:42:15 +00:00
|
|
|
|
2008-01-07 09:34:21 +00:00
|
|
|
/** \class ScalarMultiple
|
|
|
|
|
*
|
|
|
|
|
* \brief Expression of the product of a matrix or vector by a scalar
|
|
|
|
|
*
|
|
|
|
|
* \param FactorTye the type of scalar by which to multiply
|
|
|
|
|
* \param MatrixType the type of the matrix or vector to multiply
|
|
|
|
|
*
|
|
|
|
|
* This class represents an expression of the product of a matrix or vector by a scalar.
|
|
|
|
|
* It is the return type of the operator* between a matrix or vector and a scalar, and most
|
|
|
|
|
* of the time this is the only way it is used.
|
|
|
|
|
*/
|
2007-12-26 08:30:21 +00:00
|
|
|
template<typename FactorType, typename MatrixType> class ScalarMultiple : NoOperatorEquals,
|
|
|
|
|
public MatrixBase<typename MatrixType::Scalar, ScalarMultiple<FactorType, MatrixType> >
|
2007-09-05 10:42:15 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef typename MatrixType::Scalar Scalar;
|
2007-10-15 05:56:21 +00:00
|
|
|
typedef typename MatrixType::Ref MatRef;
|
2008-01-15 13:55:47 +00:00
|
|
|
friend class MatrixBase<Scalar, ScalarMultiple>;
|
|
|
|
|
typedef MatrixBase<Scalar, ScalarMultiple> Base;
|
2007-09-05 10:42:15 +00:00
|
|
|
|
2007-12-26 08:30:21 +00:00
|
|
|
ScalarMultiple(const MatRef& matrix, FactorType factor)
|
|
|
|
|
: m_matrix(matrix), m_factor(factor) {}
|
2007-09-05 10:42:15 +00:00
|
|
|
|
2008-01-06 13:17:07 +00:00
|
|
|
private:
|
2008-01-10 20:45:35 +00:00
|
|
|
enum {
|
|
|
|
|
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
|
2008-01-13 19:55:23 +00:00
|
|
|
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
|
|
|
|
|
MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
|
|
|
|
|
MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
|
2008-01-10 20:45:35 +00:00
|
|
|
};
|
2008-01-06 16:35:21 +00:00
|
|
|
|
2007-10-13 14:19:23 +00:00
|
|
|
const ScalarMultiple& _ref() const { return *this; }
|
2007-12-11 14:57:42 +00:00
|
|
|
int _rows() const { return m_matrix.rows(); }
|
|
|
|
|
int _cols() const { return m_matrix.cols(); }
|
2007-09-26 14:06:14 +00:00
|
|
|
|
2007-12-17 07:25:11 +00:00
|
|
|
Scalar _coeff(int row, int col) const
|
2007-09-05 10:42:15 +00:00
|
|
|
{
|
2007-12-26 08:30:21 +00:00
|
|
|
return m_factor * m_matrix.coeff(row, col);
|
2007-09-05 10:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2007-09-26 14:06:14 +00:00
|
|
|
const MatRef m_matrix;
|
2007-12-26 08:30:21 +00:00
|
|
|
const FactorType m_factor;
|
2007-09-05 10:42:15 +00:00
|
|
|
};
|
|
|
|
|
|
2007-12-26 08:30:21 +00:00
|
|
|
#define EIGEN_MAKE_SCALAR_OPS(FactorType) \
|
2008-01-07 09:34:21 +00:00
|
|
|
/** \relates MatrixBase \sa class ScalarMultiple */ \
|
2007-09-27 07:42:12 +00:00
|
|
|
template<typename Scalar, typename Derived> \
|
2007-12-26 08:30:21 +00:00
|
|
|
const ScalarMultiple<FactorType, Derived> \
|
2007-12-12 17:48:20 +00:00
|
|
|
operator*(const MatrixBase<Scalar, Derived>& matrix, \
|
2007-12-26 08:30:21 +00:00
|
|
|
FactorType scalar) \
|
2007-09-27 07:42:12 +00:00
|
|
|
{ \
|
2007-12-26 08:30:21 +00:00
|
|
|
return ScalarMultiple<FactorType, Derived>(matrix.ref(), scalar); \
|
2007-09-27 07:42:12 +00:00
|
|
|
} \
|
|
|
|
|
\
|
2008-01-07 09:34:21 +00:00
|
|
|
/** \relates MatrixBase \sa class ScalarMultiple */ \
|
2007-09-27 07:42:12 +00:00
|
|
|
template<typename Scalar, typename Derived> \
|
2007-12-26 08:30:21 +00:00
|
|
|
const ScalarMultiple<FactorType, Derived> \
|
|
|
|
|
operator*(FactorType scalar, \
|
2007-12-12 17:48:20 +00:00
|
|
|
const MatrixBase<Scalar, Derived>& matrix) \
|
2007-09-27 07:42:12 +00:00
|
|
|
{ \
|
2007-12-26 08:30:21 +00:00
|
|
|
return ScalarMultiple<FactorType, Derived>(matrix.ref(), scalar); \
|
2007-09-27 07:42:12 +00:00
|
|
|
} \
|
|
|
|
|
\
|
2008-01-07 09:34:21 +00:00
|
|
|
/** \relates MatrixBase \sa class ScalarMultiple */ \
|
2007-09-27 07:42:12 +00:00
|
|
|
template<typename Scalar, typename Derived> \
|
2007-12-26 09:25:00 +00:00
|
|
|
const ScalarMultiple<typename NumTraits<FactorType>::FloatingPoint, Derived> \
|
2007-12-12 17:48:20 +00:00
|
|
|
operator/(const MatrixBase<Scalar, Derived>& matrix, \
|
2007-12-26 08:30:21 +00:00
|
|
|
FactorType scalar) \
|
2007-09-27 07:42:12 +00:00
|
|
|
{ \
|
2007-12-12 17:48:20 +00:00
|
|
|
assert(NumTraits<Scalar>::HasFloatingPoint); \
|
2007-12-26 09:25:00 +00:00
|
|
|
return matrix * (static_cast< \
|
|
|
|
|
typename NumTraits<FactorType>::FloatingPoint \
|
|
|
|
|
>(1) / scalar); \
|
2007-09-27 19:20:06 +00:00
|
|
|
} \
|
|
|
|
|
\
|
2008-01-07 09:34:21 +00:00
|
|
|
/** \sa class ScalarMultiple */ \
|
2007-09-27 19:20:06 +00:00
|
|
|
template<typename Scalar, typename Derived> \
|
|
|
|
|
Derived & \
|
2007-12-26 08:30:21 +00:00
|
|
|
MatrixBase<Scalar, Derived>::operator*=(const FactorType &other) \
|
2007-09-27 19:20:06 +00:00
|
|
|
{ \
|
2007-10-01 07:45:30 +00:00
|
|
|
return *this = *this * other; \
|
2007-09-27 19:20:06 +00:00
|
|
|
} \
|
|
|
|
|
\
|
2008-01-07 09:34:21 +00:00
|
|
|
/** \sa class ScalarMultiple */ \
|
2007-09-27 19:20:06 +00:00
|
|
|
template<typename Scalar, typename Derived> \
|
|
|
|
|
Derived & \
|
2007-12-26 08:30:21 +00:00
|
|
|
MatrixBase<Scalar, Derived>::operator/=(const FactorType &other) \
|
2007-09-27 19:20:06 +00:00
|
|
|
{ \
|
2007-10-01 07:45:30 +00:00
|
|
|
return *this = *this / other; \
|
2007-09-05 10:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-26 08:47:07 +00:00
|
|
|
EIGEN_MAKE_SCALAR_OPS(int)
|
|
|
|
|
EIGEN_MAKE_SCALAR_OPS(float)
|
|
|
|
|
EIGEN_MAKE_SCALAR_OPS(double)
|
|
|
|
|
EIGEN_MAKE_SCALAR_OPS(std::complex<float>)
|
|
|
|
|
EIGEN_MAKE_SCALAR_OPS(std::complex<double>)
|
2007-09-06 10:16:51 +00:00
|
|
|
|
2007-11-26 08:47:07 +00:00
|
|
|
#undef EIGEN_MAKE_SCALAR_OPS
|
2007-09-06 10:16:51 +00:00
|
|
|
|
2007-11-26 08:47:07 +00:00
|
|
|
#endif // EIGEN_SCALARMULTIPLE_H
|