Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- include/eigen/Eigen/src/CholmodSupport/CholmodSupport.h +682 -0
- include/eigen/Eigen/src/Core/ArithmeticSequence.h +406 -0
- include/eigen/Eigen/src/Core/Array.h +425 -0
- include/eigen/Eigen/src/Core/ArrayBase.h +226 -0
- include/eigen/Eigen/src/Core/ArrayWrapper.h +209 -0
- include/eigen/Eigen/src/Core/Assign.h +90 -0
- include/eigen/Eigen/src/Core/AssignEvaluator.h +1010 -0
- include/eigen/Eigen/src/Core/Assign_MKL.h +178 -0
- include/eigen/Eigen/src/Core/BandMatrix.h +353 -0
- include/eigen/Eigen/src/Core/Block.h +463 -0
- include/eigen/Eigen/src/Core/BooleanRedux.h +164 -0
- include/eigen/Eigen/src/Core/CommaInitializer.h +164 -0
- include/eigen/Eigen/src/Core/ConditionEstimator.h +175 -0
- include/eigen/Eigen/src/Core/CoreIterators.h +132 -0
- include/eigen/Eigen/src/Core/CwiseBinaryOp.h +183 -0
- include/eigen/Eigen/src/Core/CwiseNullaryOp.h +1001 -0
- include/eigen/Eigen/src/Core/CwiseTernaryOp.h +197 -0
- include/eigen/Eigen/src/Core/CwiseUnaryOp.h +103 -0
- include/eigen/Eigen/src/Core/CwiseUnaryView.h +132 -0
- include/eigen/Eigen/src/Core/DenseBase.h +701 -0
- include/eigen/Eigen/src/Core/DenseStorage.h +652 -0
- include/eigen/Eigen/src/Core/Diagonal.h +259 -0
- include/eigen/Eigen/src/Core/DiagonalMatrix.h +391 -0
- include/eigen/Eigen/src/Core/DiagonalProduct.h +28 -0
- include/eigen/Eigen/src/Core/Dot.h +313 -0
- include/eigen/Eigen/src/Core/EigenBase.h +160 -0
- include/eigen/Eigen/src/Core/ForceAlignedAccess.h +150 -0
- include/eigen/Eigen/src/Core/Fuzzy.h +155 -0
- include/eigen/Eigen/src/Core/GeneralProduct.h +465 -0
- include/eigen/Eigen/src/Core/GenericPacketMath.h +1040 -0
- include/eigen/Eigen/src/Core/GlobalFunctions.h +194 -0
- include/eigen/Eigen/src/Core/IO.h +258 -0
- include/eigen/Eigen/src/Core/IndexedView.h +247 -0
- include/eigen/Eigen/src/Core/Inverse.h +117 -0
- include/eigen/Eigen/src/Core/Map.h +171 -0
- include/eigen/Eigen/src/Core/MapBase.h +310 -0
- include/eigen/Eigen/src/Core/MathFunctions.h +2212 -0
- include/eigen/Eigen/src/Core/MathFunctionsImpl.h +200 -0
- include/eigen/Eigen/src/Core/Matrix.h +578 -0
- include/eigen/Eigen/src/Core/MatrixBase.h +541 -0
- include/eigen/Eigen/src/Core/NestByValue.h +85 -0
- include/eigen/Eigen/src/Core/NoAlias.h +109 -0
- include/eigen/Eigen/src/Core/NumTraits.h +351 -0
- include/eigen/Eigen/src/Core/PartialReduxEvaluator.h +237 -0
- include/eigen/Eigen/src/Core/PermutationMatrix.h +605 -0
- include/eigen/Eigen/src/Core/PlainObjectBase.h +1128 -0
- include/eigen/Eigen/src/Core/Product.h +191 -0
- include/eigen/Eigen/src/Core/ProductEvaluators.h +1179 -0
- include/eigen/Eigen/src/Core/Random.h +218 -0
- include/eigen/Eigen/src/Core/Redux.h +515 -0
include/eigen/Eigen/src/CholmodSupport/CholmodSupport.h
ADDED
|
@@ -0,0 +1,682 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_CHOLMODSUPPORT_H
|
| 11 |
+
#define EIGEN_CHOLMODSUPPORT_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
template<typename Scalar> struct cholmod_configure_matrix;
|
| 18 |
+
|
| 19 |
+
template<> struct cholmod_configure_matrix<double> {
|
| 20 |
+
template<typename CholmodType>
|
| 21 |
+
static void run(CholmodType& mat) {
|
| 22 |
+
mat.xtype = CHOLMOD_REAL;
|
| 23 |
+
mat.dtype = CHOLMOD_DOUBLE;
|
| 24 |
+
}
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
template<> struct cholmod_configure_matrix<std::complex<double> > {
|
| 28 |
+
template<typename CholmodType>
|
| 29 |
+
static void run(CholmodType& mat) {
|
| 30 |
+
mat.xtype = CHOLMOD_COMPLEX;
|
| 31 |
+
mat.dtype = CHOLMOD_DOUBLE;
|
| 32 |
+
}
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
// Other scalar types are not yet supported by Cholmod
|
| 36 |
+
// template<> struct cholmod_configure_matrix<float> {
|
| 37 |
+
// template<typename CholmodType>
|
| 38 |
+
// static void run(CholmodType& mat) {
|
| 39 |
+
// mat.xtype = CHOLMOD_REAL;
|
| 40 |
+
// mat.dtype = CHOLMOD_SINGLE;
|
| 41 |
+
// }
|
| 42 |
+
// };
|
| 43 |
+
//
|
| 44 |
+
// template<> struct cholmod_configure_matrix<std::complex<float> > {
|
| 45 |
+
// template<typename CholmodType>
|
| 46 |
+
// static void run(CholmodType& mat) {
|
| 47 |
+
// mat.xtype = CHOLMOD_COMPLEX;
|
| 48 |
+
// mat.dtype = CHOLMOD_SINGLE;
|
| 49 |
+
// }
|
| 50 |
+
// };
|
| 51 |
+
|
| 52 |
+
} // namespace internal
|
| 53 |
+
|
| 54 |
+
/** Wraps the Eigen sparse matrix \a mat into a Cholmod sparse matrix object.
|
| 55 |
+
* Note that the data are shared.
|
| 56 |
+
*/
|
| 57 |
+
template<typename _Scalar, int _Options, typename _StorageIndex>
|
| 58 |
+
cholmod_sparse viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_StorageIndex> > mat)
|
| 59 |
+
{
|
| 60 |
+
cholmod_sparse res;
|
| 61 |
+
res.nzmax = mat.nonZeros();
|
| 62 |
+
res.nrow = mat.rows();
|
| 63 |
+
res.ncol = mat.cols();
|
| 64 |
+
res.p = mat.outerIndexPtr();
|
| 65 |
+
res.i = mat.innerIndexPtr();
|
| 66 |
+
res.x = mat.valuePtr();
|
| 67 |
+
res.z = 0;
|
| 68 |
+
res.sorted = 1;
|
| 69 |
+
if(mat.isCompressed())
|
| 70 |
+
{
|
| 71 |
+
res.packed = 1;
|
| 72 |
+
res.nz = 0;
|
| 73 |
+
}
|
| 74 |
+
else
|
| 75 |
+
{
|
| 76 |
+
res.packed = 0;
|
| 77 |
+
res.nz = mat.innerNonZeroPtr();
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
res.dtype = 0;
|
| 81 |
+
res.stype = -1;
|
| 82 |
+
|
| 83 |
+
if (internal::is_same<_StorageIndex,int>::value)
|
| 84 |
+
{
|
| 85 |
+
res.itype = CHOLMOD_INT;
|
| 86 |
+
}
|
| 87 |
+
else if (internal::is_same<_StorageIndex,SuiteSparse_long>::value)
|
| 88 |
+
{
|
| 89 |
+
res.itype = CHOLMOD_LONG;
|
| 90 |
+
}
|
| 91 |
+
else
|
| 92 |
+
{
|
| 93 |
+
eigen_assert(false && "Index type not supported yet");
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// setup res.xtype
|
| 97 |
+
internal::cholmod_configure_matrix<_Scalar>::run(res);
|
| 98 |
+
|
| 99 |
+
res.stype = 0;
|
| 100 |
+
|
| 101 |
+
return res;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
template<typename _Scalar, int _Options, typename _Index>
|
| 105 |
+
const cholmod_sparse viewAsCholmod(const SparseMatrix<_Scalar,_Options,_Index>& mat)
|
| 106 |
+
{
|
| 107 |
+
cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_Index> >(mat.const_cast_derived()));
|
| 108 |
+
return res;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
template<typename _Scalar, int _Options, typename _Index>
|
| 112 |
+
const cholmod_sparse viewAsCholmod(const SparseVector<_Scalar,_Options,_Index>& mat)
|
| 113 |
+
{
|
| 114 |
+
cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_Index> >(mat.const_cast_derived()));
|
| 115 |
+
return res;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/** Returns a view of the Eigen sparse matrix \a mat as Cholmod sparse matrix.
|
| 119 |
+
* The data are not copied but shared. */
|
| 120 |
+
template<typename _Scalar, int _Options, typename _Index, unsigned int UpLo>
|
| 121 |
+
cholmod_sparse viewAsCholmod(const SparseSelfAdjointView<const SparseMatrix<_Scalar,_Options,_Index>, UpLo>& mat)
|
| 122 |
+
{
|
| 123 |
+
cholmod_sparse res = viewAsCholmod(Ref<SparseMatrix<_Scalar,_Options,_Index> >(mat.matrix().const_cast_derived()));
|
| 124 |
+
|
| 125 |
+
if(UpLo==Upper) res.stype = 1;
|
| 126 |
+
if(UpLo==Lower) res.stype = -1;
|
| 127 |
+
// swap stype for rowmajor matrices (only works for real matrices)
|
| 128 |
+
EIGEN_STATIC_ASSERT((_Options & RowMajorBit) == 0 || NumTraits<_Scalar>::IsComplex == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
|
| 129 |
+
if(_Options & RowMajorBit) res.stype *=-1;
|
| 130 |
+
|
| 131 |
+
return res;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/** Returns a view of the Eigen \b dense matrix \a mat as Cholmod dense matrix.
|
| 135 |
+
* The data are not copied but shared. */
|
| 136 |
+
template<typename Derived>
|
| 137 |
+
cholmod_dense viewAsCholmod(MatrixBase<Derived>& mat)
|
| 138 |
+
{
|
| 139 |
+
EIGEN_STATIC_ASSERT((internal::traits<Derived>::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
|
| 140 |
+
typedef typename Derived::Scalar Scalar;
|
| 141 |
+
|
| 142 |
+
cholmod_dense res;
|
| 143 |
+
res.nrow = mat.rows();
|
| 144 |
+
res.ncol = mat.cols();
|
| 145 |
+
res.nzmax = res.nrow * res.ncol;
|
| 146 |
+
res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride();
|
| 147 |
+
res.x = (void*)(mat.derived().data());
|
| 148 |
+
res.z = 0;
|
| 149 |
+
|
| 150 |
+
internal::cholmod_configure_matrix<Scalar>::run(res);
|
| 151 |
+
|
| 152 |
+
return res;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/** Returns a view of the Cholmod sparse matrix \a cm as an Eigen sparse matrix.
|
| 156 |
+
* The data are not copied but shared. */
|
| 157 |
+
template<typename Scalar, int Flags, typename StorageIndex>
|
| 158 |
+
MappedSparseMatrix<Scalar,Flags,StorageIndex> viewAsEigen(cholmod_sparse& cm)
|
| 159 |
+
{
|
| 160 |
+
return MappedSparseMatrix<Scalar,Flags,StorageIndex>
|
| 161 |
+
(cm.nrow, cm.ncol, static_cast<StorageIndex*>(cm.p)[cm.ncol],
|
| 162 |
+
static_cast<StorageIndex*>(cm.p), static_cast<StorageIndex*>(cm.i),static_cast<Scalar*>(cm.x) );
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
namespace internal {
|
| 166 |
+
|
| 167 |
+
// template specializations for int and long that call the correct cholmod method
|
| 168 |
+
|
| 169 |
+
#define EIGEN_CHOLMOD_SPECIALIZE0(ret, name) \
|
| 170 |
+
template<typename _StorageIndex> inline ret cm_ ## name (cholmod_common &Common) { return cholmod_ ## name (&Common); } \
|
| 171 |
+
template<> inline ret cm_ ## name<SuiteSparse_long> (cholmod_common &Common) { return cholmod_l_ ## name (&Common); }
|
| 172 |
+
|
| 173 |
+
#define EIGEN_CHOLMOD_SPECIALIZE1(ret, name, t1, a1) \
|
| 174 |
+
template<typename _StorageIndex> inline ret cm_ ## name (t1& a1, cholmod_common &Common) { return cholmod_ ## name (&a1, &Common); } \
|
| 175 |
+
template<> inline ret cm_ ## name<SuiteSparse_long> (t1& a1, cholmod_common &Common) { return cholmod_l_ ## name (&a1, &Common); }
|
| 176 |
+
|
| 177 |
+
EIGEN_CHOLMOD_SPECIALIZE0(int, start)
|
| 178 |
+
EIGEN_CHOLMOD_SPECIALIZE0(int, finish)
|
| 179 |
+
|
| 180 |
+
EIGEN_CHOLMOD_SPECIALIZE1(int, free_factor, cholmod_factor*, L)
|
| 181 |
+
EIGEN_CHOLMOD_SPECIALIZE1(int, free_dense, cholmod_dense*, X)
|
| 182 |
+
EIGEN_CHOLMOD_SPECIALIZE1(int, free_sparse, cholmod_sparse*, A)
|
| 183 |
+
|
| 184 |
+
EIGEN_CHOLMOD_SPECIALIZE1(cholmod_factor*, analyze, cholmod_sparse, A)
|
| 185 |
+
|
| 186 |
+
template<typename _StorageIndex> inline cholmod_dense* cm_solve (int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common &Common) { return cholmod_solve (sys, &L, &B, &Common); }
|
| 187 |
+
template<> inline cholmod_dense* cm_solve<SuiteSparse_long> (int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common &Common) { return cholmod_l_solve (sys, &L, &B, &Common); }
|
| 188 |
+
|
| 189 |
+
template<typename _StorageIndex> inline cholmod_sparse* cm_spsolve (int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common &Common) { return cholmod_spsolve (sys, &L, &B, &Common); }
|
| 190 |
+
template<> inline cholmod_sparse* cm_spsolve<SuiteSparse_long> (int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common &Common) { return cholmod_l_spsolve (sys, &L, &B, &Common); }
|
| 191 |
+
|
| 192 |
+
template<typename _StorageIndex>
|
| 193 |
+
inline int cm_factorize_p (cholmod_sparse* A, double beta[2], _StorageIndex* fset, std::size_t fsize, cholmod_factor* L, cholmod_common &Common) { return cholmod_factorize_p (A, beta, fset, fsize, L, &Common); }
|
| 194 |
+
template<>
|
| 195 |
+
inline int cm_factorize_p<SuiteSparse_long> (cholmod_sparse* A, double beta[2], SuiteSparse_long* fset, std::size_t fsize, cholmod_factor* L, cholmod_common &Common) { return cholmod_l_factorize_p (A, beta, fset, fsize, L, &Common); }
|
| 196 |
+
|
| 197 |
+
#undef EIGEN_CHOLMOD_SPECIALIZE0
|
| 198 |
+
#undef EIGEN_CHOLMOD_SPECIALIZE1
|
| 199 |
+
|
| 200 |
+
} // namespace internal
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
enum CholmodMode {
|
| 204 |
+
CholmodAuto, CholmodSimplicialLLt, CholmodSupernodalLLt, CholmodLDLt
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
/** \ingroup CholmodSupport_Module
|
| 209 |
+
* \class CholmodBase
|
| 210 |
+
* \brief The base class for the direct Cholesky factorization of Cholmod
|
| 211 |
+
* \sa class CholmodSupernodalLLT, class CholmodSimplicialLDLT, class CholmodSimplicialLLT
|
| 212 |
+
*/
|
| 213 |
+
template<typename _MatrixType, int _UpLo, typename Derived>
|
| 214 |
+
class CholmodBase : public SparseSolverBase<Derived>
|
| 215 |
+
{
|
| 216 |
+
protected:
|
| 217 |
+
typedef SparseSolverBase<Derived> Base;
|
| 218 |
+
using Base::derived;
|
| 219 |
+
using Base::m_isInitialized;
|
| 220 |
+
public:
|
| 221 |
+
typedef _MatrixType MatrixType;
|
| 222 |
+
enum { UpLo = _UpLo };
|
| 223 |
+
typedef typename MatrixType::Scalar Scalar;
|
| 224 |
+
typedef typename MatrixType::RealScalar RealScalar;
|
| 225 |
+
typedef MatrixType CholMatrixType;
|
| 226 |
+
typedef typename MatrixType::StorageIndex StorageIndex;
|
| 227 |
+
enum {
|
| 228 |
+
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
|
| 229 |
+
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
public:
|
| 233 |
+
|
| 234 |
+
CholmodBase()
|
| 235 |
+
: m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false)
|
| 236 |
+
{
|
| 237 |
+
EIGEN_STATIC_ASSERT((internal::is_same<double,RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY);
|
| 238 |
+
m_shiftOffset[0] = m_shiftOffset[1] = 0.0;
|
| 239 |
+
internal::cm_start<StorageIndex>(m_cholmod);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
explicit CholmodBase(const MatrixType& matrix)
|
| 243 |
+
: m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false)
|
| 244 |
+
{
|
| 245 |
+
EIGEN_STATIC_ASSERT((internal::is_same<double,RealScalar>::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY);
|
| 246 |
+
m_shiftOffset[0] = m_shiftOffset[1] = 0.0;
|
| 247 |
+
internal::cm_start<StorageIndex>(m_cholmod);
|
| 248 |
+
compute(matrix);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
~CholmodBase()
|
| 252 |
+
{
|
| 253 |
+
if(m_cholmodFactor)
|
| 254 |
+
internal::cm_free_factor<StorageIndex>(m_cholmodFactor, m_cholmod);
|
| 255 |
+
internal::cm_finish<StorageIndex>(m_cholmod);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
inline StorageIndex cols() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); }
|
| 259 |
+
inline StorageIndex rows() const { return internal::convert_index<StorageIndex, Index>(m_cholmodFactor->n); }
|
| 260 |
+
|
| 261 |
+
/** \brief Reports whether previous computation was successful.
|
| 262 |
+
*
|
| 263 |
+
* \returns \c Success if computation was successful,
|
| 264 |
+
* \c NumericalIssue if the matrix.appears to be negative.
|
| 265 |
+
*/
|
| 266 |
+
ComputationInfo info() const
|
| 267 |
+
{
|
| 268 |
+
eigen_assert(m_isInitialized && "Decomposition is not initialized.");
|
| 269 |
+
return m_info;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
/** Computes the sparse Cholesky decomposition of \a matrix */
|
| 273 |
+
Derived& compute(const MatrixType& matrix)
|
| 274 |
+
{
|
| 275 |
+
analyzePattern(matrix);
|
| 276 |
+
factorize(matrix);
|
| 277 |
+
return derived();
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
/** Performs a symbolic decomposition on the sparsity pattern of \a matrix.
|
| 281 |
+
*
|
| 282 |
+
* This function is particularly useful when solving for several problems having the same structure.
|
| 283 |
+
*
|
| 284 |
+
* \sa factorize()
|
| 285 |
+
*/
|
| 286 |
+
void analyzePattern(const MatrixType& matrix)
|
| 287 |
+
{
|
| 288 |
+
if(m_cholmodFactor)
|
| 289 |
+
{
|
| 290 |
+
internal::cm_free_factor<StorageIndex>(m_cholmodFactor, m_cholmod);
|
| 291 |
+
m_cholmodFactor = 0;
|
| 292 |
+
}
|
| 293 |
+
cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>());
|
| 294 |
+
m_cholmodFactor = internal::cm_analyze<StorageIndex>(A, m_cholmod);
|
| 295 |
+
|
| 296 |
+
this->m_isInitialized = true;
|
| 297 |
+
this->m_info = Success;
|
| 298 |
+
m_analysisIsOk = true;
|
| 299 |
+
m_factorizationIsOk = false;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
/** Performs a numeric decomposition of \a matrix
|
| 303 |
+
*
|
| 304 |
+
* The given matrix must have the same sparsity pattern as the matrix on which the symbolic decomposition has been performed.
|
| 305 |
+
*
|
| 306 |
+
* \sa analyzePattern()
|
| 307 |
+
*/
|
| 308 |
+
void factorize(const MatrixType& matrix)
|
| 309 |
+
{
|
| 310 |
+
eigen_assert(m_analysisIsOk && "You must first call analyzePattern()");
|
| 311 |
+
cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView<UpLo>());
|
| 312 |
+
internal::cm_factorize_p<StorageIndex>(&A, m_shiftOffset, 0, 0, m_cholmodFactor, m_cholmod);
|
| 313 |
+
|
| 314 |
+
// If the factorization failed, minor is the column at which it did. On success minor == n.
|
| 315 |
+
this->m_info = (m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue);
|
| 316 |
+
m_factorizationIsOk = true;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/** Returns a reference to the Cholmod's configuration structure to get a full control over the performed operations.
|
| 320 |
+
* See the Cholmod user guide for details. */
|
| 321 |
+
cholmod_common& cholmod() { return m_cholmod; }
|
| 322 |
+
|
| 323 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 324 |
+
/** \internal */
|
| 325 |
+
template<typename Rhs,typename Dest>
|
| 326 |
+
void _solve_impl(const MatrixBase<Rhs> &b, MatrixBase<Dest> &dest) const
|
| 327 |
+
{
|
| 328 |
+
eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
|
| 329 |
+
const Index size = m_cholmodFactor->n;
|
| 330 |
+
EIGEN_UNUSED_VARIABLE(size);
|
| 331 |
+
eigen_assert(size==b.rows());
|
| 332 |
+
|
| 333 |
+
// Cholmod needs column-major storage without inner-stride, which corresponds to the default behavior of Ref.
|
| 334 |
+
Ref<const Matrix<typename Rhs::Scalar,Dynamic,Dynamic,ColMajor> > b_ref(b.derived());
|
| 335 |
+
|
| 336 |
+
cholmod_dense b_cd = viewAsCholmod(b_ref);
|
| 337 |
+
cholmod_dense* x_cd = internal::cm_solve<StorageIndex>(CHOLMOD_A, *m_cholmodFactor, b_cd, m_cholmod);
|
| 338 |
+
if(!x_cd)
|
| 339 |
+
{
|
| 340 |
+
this->m_info = NumericalIssue;
|
| 341 |
+
return;
|
| 342 |
+
}
|
| 343 |
+
// TODO optimize this copy by swapping when possible (be careful with alignment, etc.)
|
| 344 |
+
// NOTE Actually, the copy can be avoided by calling cholmod_solve2 instead of cholmod_solve
|
| 345 |
+
dest = Matrix<Scalar,Dest::RowsAtCompileTime,Dest::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x),b.rows(),b.cols());
|
| 346 |
+
internal::cm_free_dense<StorageIndex>(x_cd, m_cholmod);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/** \internal */
|
| 350 |
+
template<typename RhsDerived, typename DestDerived>
|
| 351 |
+
void _solve_impl(const SparseMatrixBase<RhsDerived> &b, SparseMatrixBase<DestDerived> &dest) const
|
| 352 |
+
{
|
| 353 |
+
eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
|
| 354 |
+
const Index size = m_cholmodFactor->n;
|
| 355 |
+
EIGEN_UNUSED_VARIABLE(size);
|
| 356 |
+
eigen_assert(size==b.rows());
|
| 357 |
+
|
| 358 |
+
// note: cs stands for Cholmod Sparse
|
| 359 |
+
Ref<SparseMatrix<typename RhsDerived::Scalar,ColMajor,typename RhsDerived::StorageIndex> > b_ref(b.const_cast_derived());
|
| 360 |
+
cholmod_sparse b_cs = viewAsCholmod(b_ref);
|
| 361 |
+
cholmod_sparse* x_cs = internal::cm_spsolve<StorageIndex>(CHOLMOD_A, *m_cholmodFactor, b_cs, m_cholmod);
|
| 362 |
+
if(!x_cs)
|
| 363 |
+
{
|
| 364 |
+
this->m_info = NumericalIssue;
|
| 365 |
+
return;
|
| 366 |
+
}
|
| 367 |
+
// TODO optimize this copy by swapping when possible (be careful with alignment, etc.)
|
| 368 |
+
// NOTE cholmod_spsolve in fact just calls the dense solver for blocks of 4 columns at a time (similar to Eigen's sparse solver)
|
| 369 |
+
dest.derived() = viewAsEigen<typename DestDerived::Scalar,ColMajor,typename DestDerived::StorageIndex>(*x_cs);
|
| 370 |
+
internal::cm_free_sparse<StorageIndex>(x_cs, m_cholmod);
|
| 371 |
+
}
|
| 372 |
+
#endif // EIGEN_PARSED_BY_DOXYGEN
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
/** Sets the shift parameter that will be used to adjust the diagonal coefficients during the numerical factorization.
|
| 376 |
+
*
|
| 377 |
+
* During the numerical factorization, an offset term is added to the diagonal coefficients:\n
|
| 378 |
+
* \c d_ii = \a offset + \c d_ii
|
| 379 |
+
*
|
| 380 |
+
* The default is \a offset=0.
|
| 381 |
+
*
|
| 382 |
+
* \returns a reference to \c *this.
|
| 383 |
+
*/
|
| 384 |
+
Derived& setShift(const RealScalar& offset)
|
| 385 |
+
{
|
| 386 |
+
m_shiftOffset[0] = double(offset);
|
| 387 |
+
return derived();
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
/** \returns the determinant of the underlying matrix from the current factorization */
|
| 391 |
+
Scalar determinant() const
|
| 392 |
+
{
|
| 393 |
+
using std::exp;
|
| 394 |
+
return exp(logDeterminant());
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
/** \returns the log determinant of the underlying matrix from the current factorization */
|
| 398 |
+
Scalar logDeterminant() const
|
| 399 |
+
{
|
| 400 |
+
using std::log;
|
| 401 |
+
using numext::real;
|
| 402 |
+
eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()");
|
| 403 |
+
|
| 404 |
+
RealScalar logDet = 0;
|
| 405 |
+
Scalar *x = static_cast<Scalar*>(m_cholmodFactor->x);
|
| 406 |
+
if (m_cholmodFactor->is_super)
|
| 407 |
+
{
|
| 408 |
+
// Supernodal factorization stored as a packed list of dense column-major blocs,
|
| 409 |
+
// as described by the following structure:
|
| 410 |
+
|
| 411 |
+
// super[k] == index of the first column of the j-th super node
|
| 412 |
+
StorageIndex *super = static_cast<StorageIndex*>(m_cholmodFactor->super);
|
| 413 |
+
// pi[k] == offset to the description of row indices
|
| 414 |
+
StorageIndex *pi = static_cast<StorageIndex*>(m_cholmodFactor->pi);
|
| 415 |
+
// px[k] == offset to the respective dense block
|
| 416 |
+
StorageIndex *px = static_cast<StorageIndex*>(m_cholmodFactor->px);
|
| 417 |
+
|
| 418 |
+
Index nb_super_nodes = m_cholmodFactor->nsuper;
|
| 419 |
+
for (Index k=0; k < nb_super_nodes; ++k)
|
| 420 |
+
{
|
| 421 |
+
StorageIndex ncols = super[k + 1] - super[k];
|
| 422 |
+
StorageIndex nrows = pi[k + 1] - pi[k];
|
| 423 |
+
|
| 424 |
+
Map<const Array<Scalar,1,Dynamic>, 0, InnerStride<> > sk(x + px[k], ncols, InnerStride<>(nrows+1));
|
| 425 |
+
logDet += sk.real().log().sum();
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
else
|
| 429 |
+
{
|
| 430 |
+
// Simplicial factorization stored as standard CSC matrix.
|
| 431 |
+
StorageIndex *p = static_cast<StorageIndex*>(m_cholmodFactor->p);
|
| 432 |
+
Index size = m_cholmodFactor->n;
|
| 433 |
+
for (Index k=0; k<size; ++k)
|
| 434 |
+
logDet += log(real( x[p[k]] ));
|
| 435 |
+
}
|
| 436 |
+
if (m_cholmodFactor->is_ll)
|
| 437 |
+
logDet *= 2.0;
|
| 438 |
+
return logDet;
|
| 439 |
+
};
|
| 440 |
+
|
| 441 |
+
template<typename Stream>
|
| 442 |
+
void dumpMemory(Stream& /*s*/)
|
| 443 |
+
{}
|
| 444 |
+
|
| 445 |
+
protected:
|
| 446 |
+
mutable cholmod_common m_cholmod;
|
| 447 |
+
cholmod_factor* m_cholmodFactor;
|
| 448 |
+
double m_shiftOffset[2];
|
| 449 |
+
mutable ComputationInfo m_info;
|
| 450 |
+
int m_factorizationIsOk;
|
| 451 |
+
int m_analysisIsOk;
|
| 452 |
+
};
|
| 453 |
+
|
| 454 |
+
/** \ingroup CholmodSupport_Module
|
| 455 |
+
* \class CholmodSimplicialLLT
|
| 456 |
+
* \brief A simplicial direct Cholesky (LLT) factorization and solver based on Cholmod
|
| 457 |
+
*
|
| 458 |
+
* This class allows to solve for A.X = B sparse linear problems via a simplicial LL^T Cholesky factorization
|
| 459 |
+
* using the Cholmod library.
|
| 460 |
+
* This simplicial variant is equivalent to Eigen's built-in SimplicialLLT class. Therefore, it has little practical interest.
|
| 461 |
+
* The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices
|
| 462 |
+
* X and B can be either dense or sparse.
|
| 463 |
+
*
|
| 464 |
+
* \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<>
|
| 465 |
+
* \tparam _UpLo the triangular part that will be used for the computations. It can be Lower
|
| 466 |
+
* or Upper. Default is Lower.
|
| 467 |
+
*
|
| 468 |
+
* \implsparsesolverconcept
|
| 469 |
+
*
|
| 470 |
+
* This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed.
|
| 471 |
+
*
|
| 472 |
+
* \warning Only double precision real and complex scalar types are supported by Cholmod.
|
| 473 |
+
*
|
| 474 |
+
* \sa \ref TutorialSparseSolverConcept, class CholmodSupernodalLLT, class SimplicialLLT
|
| 475 |
+
*/
|
| 476 |
+
template<typename _MatrixType, int _UpLo = Lower>
|
| 477 |
+
class CholmodSimplicialLLT : public CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLLT<_MatrixType, _UpLo> >
|
| 478 |
+
{
|
| 479 |
+
typedef CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLLT> Base;
|
| 480 |
+
using Base::m_cholmod;
|
| 481 |
+
|
| 482 |
+
public:
|
| 483 |
+
|
| 484 |
+
typedef _MatrixType MatrixType;
|
| 485 |
+
|
| 486 |
+
CholmodSimplicialLLT() : Base() { init(); }
|
| 487 |
+
|
| 488 |
+
CholmodSimplicialLLT(const MatrixType& matrix) : Base()
|
| 489 |
+
{
|
| 490 |
+
init();
|
| 491 |
+
this->compute(matrix);
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
~CholmodSimplicialLLT() {}
|
| 495 |
+
protected:
|
| 496 |
+
void init()
|
| 497 |
+
{
|
| 498 |
+
m_cholmod.final_asis = 0;
|
| 499 |
+
m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
|
| 500 |
+
m_cholmod.final_ll = 1;
|
| 501 |
+
}
|
| 502 |
+
};
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
/** \ingroup CholmodSupport_Module
|
| 506 |
+
* \class CholmodSimplicialLDLT
|
| 507 |
+
* \brief A simplicial direct Cholesky (LDLT) factorization and solver based on Cholmod
|
| 508 |
+
*
|
| 509 |
+
* This class allows to solve for A.X = B sparse linear problems via a simplicial LDL^T Cholesky factorization
|
| 510 |
+
* using the Cholmod library.
|
| 511 |
+
* This simplicial variant is equivalent to Eigen's built-in SimplicialLDLT class. Therefore, it has little practical interest.
|
| 512 |
+
* The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices
|
| 513 |
+
* X and B can be either dense or sparse.
|
| 514 |
+
*
|
| 515 |
+
* \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<>
|
| 516 |
+
* \tparam _UpLo the triangular part that will be used for the computations. It can be Lower
|
| 517 |
+
* or Upper. Default is Lower.
|
| 518 |
+
*
|
| 519 |
+
* \implsparsesolverconcept
|
| 520 |
+
*
|
| 521 |
+
* This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed.
|
| 522 |
+
*
|
| 523 |
+
* \warning Only double precision real and complex scalar types are supported by Cholmod.
|
| 524 |
+
*
|
| 525 |
+
* \sa \ref TutorialSparseSolverConcept, class CholmodSupernodalLLT, class SimplicialLDLT
|
| 526 |
+
*/
|
| 527 |
+
template<typename _MatrixType, int _UpLo = Lower>
|
| 528 |
+
class CholmodSimplicialLDLT : public CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLDLT<_MatrixType, _UpLo> >
|
| 529 |
+
{
|
| 530 |
+
typedef CholmodBase<_MatrixType, _UpLo, CholmodSimplicialLDLT> Base;
|
| 531 |
+
using Base::m_cholmod;
|
| 532 |
+
|
| 533 |
+
public:
|
| 534 |
+
|
| 535 |
+
typedef _MatrixType MatrixType;
|
| 536 |
+
|
| 537 |
+
CholmodSimplicialLDLT() : Base() { init(); }
|
| 538 |
+
|
| 539 |
+
CholmodSimplicialLDLT(const MatrixType& matrix) : Base()
|
| 540 |
+
{
|
| 541 |
+
init();
|
| 542 |
+
this->compute(matrix);
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
~CholmodSimplicialLDLT() {}
|
| 546 |
+
protected:
|
| 547 |
+
void init()
|
| 548 |
+
{
|
| 549 |
+
m_cholmod.final_asis = 1;
|
| 550 |
+
m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
|
| 551 |
+
}
|
| 552 |
+
};
|
| 553 |
+
|
| 554 |
+
/** \ingroup CholmodSupport_Module
|
| 555 |
+
* \class CholmodSupernodalLLT
|
| 556 |
+
* \brief A supernodal Cholesky (LLT) factorization and solver based on Cholmod
|
| 557 |
+
*
|
| 558 |
+
* This class allows to solve for A.X = B sparse linear problems via a supernodal LL^T Cholesky factorization
|
| 559 |
+
* using the Cholmod library.
|
| 560 |
+
* This supernodal variant performs best on dense enough problems, e.g., 3D FEM, or very high order 2D FEM.
|
| 561 |
+
* The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices
|
| 562 |
+
* X and B can be either dense or sparse.
|
| 563 |
+
*
|
| 564 |
+
* \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<>
|
| 565 |
+
* \tparam _UpLo the triangular part that will be used for the computations. It can be Lower
|
| 566 |
+
* or Upper. Default is Lower.
|
| 567 |
+
*
|
| 568 |
+
* \implsparsesolverconcept
|
| 569 |
+
*
|
| 570 |
+
* This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed.
|
| 571 |
+
*
|
| 572 |
+
* \warning Only double precision real and complex scalar types are supported by Cholmod.
|
| 573 |
+
*
|
| 574 |
+
* \sa \ref TutorialSparseSolverConcept
|
| 575 |
+
*/
|
| 576 |
+
template<typename _MatrixType, int _UpLo = Lower>
|
| 577 |
+
class CholmodSupernodalLLT : public CholmodBase<_MatrixType, _UpLo, CholmodSupernodalLLT<_MatrixType, _UpLo> >
|
| 578 |
+
{
|
| 579 |
+
typedef CholmodBase<_MatrixType, _UpLo, CholmodSupernodalLLT> Base;
|
| 580 |
+
using Base::m_cholmod;
|
| 581 |
+
|
| 582 |
+
public:
|
| 583 |
+
|
| 584 |
+
typedef _MatrixType MatrixType;
|
| 585 |
+
|
| 586 |
+
CholmodSupernodalLLT() : Base() { init(); }
|
| 587 |
+
|
| 588 |
+
CholmodSupernodalLLT(const MatrixType& matrix) : Base()
|
| 589 |
+
{
|
| 590 |
+
init();
|
| 591 |
+
this->compute(matrix);
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
~CholmodSupernodalLLT() {}
|
| 595 |
+
protected:
|
| 596 |
+
void init()
|
| 597 |
+
{
|
| 598 |
+
m_cholmod.final_asis = 1;
|
| 599 |
+
m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
|
| 600 |
+
}
|
| 601 |
+
};
|
| 602 |
+
|
| 603 |
+
/** \ingroup CholmodSupport_Module
|
| 604 |
+
* \class CholmodDecomposition
|
| 605 |
+
* \brief A general Cholesky factorization and solver based on Cholmod
|
| 606 |
+
*
|
| 607 |
+
* This class allows to solve for A.X = B sparse linear problems via a LL^T or LDL^T Cholesky factorization
|
| 608 |
+
* using the Cholmod library. The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices
|
| 609 |
+
* X and B can be either dense or sparse.
|
| 610 |
+
*
|
| 611 |
+
* This variant permits to change the underlying Cholesky method at runtime.
|
| 612 |
+
* On the other hand, it does not provide access to the result of the factorization.
|
| 613 |
+
* The default is to let Cholmod automatically choose between a simplicial and supernodal factorization.
|
| 614 |
+
*
|
| 615 |
+
* \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<>
|
| 616 |
+
* \tparam _UpLo the triangular part that will be used for the computations. It can be Lower
|
| 617 |
+
* or Upper. Default is Lower.
|
| 618 |
+
*
|
| 619 |
+
* \implsparsesolverconcept
|
| 620 |
+
*
|
| 621 |
+
* This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non compressed.
|
| 622 |
+
*
|
| 623 |
+
* \warning Only double precision real and complex scalar types are supported by Cholmod.
|
| 624 |
+
*
|
| 625 |
+
* \sa \ref TutorialSparseSolverConcept
|
| 626 |
+
*/
|
| 627 |
+
template<typename _MatrixType, int _UpLo = Lower>
|
| 628 |
+
class CholmodDecomposition : public CholmodBase<_MatrixType, _UpLo, CholmodDecomposition<_MatrixType, _UpLo> >
|
| 629 |
+
{
|
| 630 |
+
typedef CholmodBase<_MatrixType, _UpLo, CholmodDecomposition> Base;
|
| 631 |
+
using Base::m_cholmod;
|
| 632 |
+
|
| 633 |
+
public:
|
| 634 |
+
|
| 635 |
+
typedef _MatrixType MatrixType;
|
| 636 |
+
|
| 637 |
+
CholmodDecomposition() : Base() { init(); }
|
| 638 |
+
|
| 639 |
+
CholmodDecomposition(const MatrixType& matrix) : Base()
|
| 640 |
+
{
|
| 641 |
+
init();
|
| 642 |
+
this->compute(matrix);
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
~CholmodDecomposition() {}
|
| 646 |
+
|
| 647 |
+
void setMode(CholmodMode mode)
|
| 648 |
+
{
|
| 649 |
+
switch(mode)
|
| 650 |
+
{
|
| 651 |
+
case CholmodAuto:
|
| 652 |
+
m_cholmod.final_asis = 1;
|
| 653 |
+
m_cholmod.supernodal = CHOLMOD_AUTO;
|
| 654 |
+
break;
|
| 655 |
+
case CholmodSimplicialLLt:
|
| 656 |
+
m_cholmod.final_asis = 0;
|
| 657 |
+
m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
|
| 658 |
+
m_cholmod.final_ll = 1;
|
| 659 |
+
break;
|
| 660 |
+
case CholmodSupernodalLLt:
|
| 661 |
+
m_cholmod.final_asis = 1;
|
| 662 |
+
m_cholmod.supernodal = CHOLMOD_SUPERNODAL;
|
| 663 |
+
break;
|
| 664 |
+
case CholmodLDLt:
|
| 665 |
+
m_cholmod.final_asis = 1;
|
| 666 |
+
m_cholmod.supernodal = CHOLMOD_SIMPLICIAL;
|
| 667 |
+
break;
|
| 668 |
+
default:
|
| 669 |
+
break;
|
| 670 |
+
}
|
| 671 |
+
}
|
| 672 |
+
protected:
|
| 673 |
+
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_ARITHMETIC_SEQUENCE_H
|
| 11 |
+
#define EIGEN_ARITHMETIC_SEQUENCE_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
#if (!EIGEN_HAS_CXX11) || !((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48)
|
| 18 |
+
template<typename T> struct aseq_negate {};
|
| 19 |
+
|
| 20 |
+
template<> struct aseq_negate<Index> {
|
| 21 |
+
typedef Index type;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
template<int N> struct aseq_negate<FixedInt<N> > {
|
| 25 |
+
typedef FixedInt<-N> type;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
// Compilation error in the following case:
|
| 29 |
+
template<> struct aseq_negate<FixedInt<DynamicIndex> > {};
|
| 30 |
+
|
| 31 |
+
template<typename FirstType,typename SizeType,typename IncrType,
|
| 32 |
+
bool FirstIsSymbolic=symbolic::is_symbolic<FirstType>::value,
|
| 33 |
+
bool SizeIsSymbolic =symbolic::is_symbolic<SizeType>::value>
|
| 34 |
+
struct aseq_reverse_first_type {
|
| 35 |
+
typedef Index type;
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 39 |
+
struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,true> {
|
| 40 |
+
typedef symbolic::AddExpr<FirstType,
|
| 41 |
+
symbolic::ProductExpr<symbolic::AddExpr<SizeType,symbolic::ValueExpr<FixedInt<-1> > >,
|
| 42 |
+
symbolic::ValueExpr<IncrType> >
|
| 43 |
+
> type;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
template<typename SizeType,typename IncrType,typename EnableIf = void>
|
| 47 |
+
struct aseq_reverse_first_type_aux {
|
| 48 |
+
typedef Index type;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
template<typename SizeType,typename IncrType>
|
| 52 |
+
struct aseq_reverse_first_type_aux<SizeType,IncrType,typename internal::enable_if<bool((SizeType::value+IncrType::value)|0x1)>::type> {
|
| 53 |
+
typedef FixedInt<(SizeType::value-1)*IncrType::value> type;
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 57 |
+
struct aseq_reverse_first_type<FirstType,SizeType,IncrType,true,false> {
|
| 58 |
+
typedef typename aseq_reverse_first_type_aux<SizeType,IncrType>::type Aux;
|
| 59 |
+
typedef symbolic::AddExpr<FirstType,symbolic::ValueExpr<Aux> > type;
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 63 |
+
struct aseq_reverse_first_type<FirstType,SizeType,IncrType,false,true> {
|
| 64 |
+
typedef symbolic::AddExpr<symbolic::ProductExpr<symbolic::AddExpr<SizeType,symbolic::ValueExpr<FixedInt<-1> > >,
|
| 65 |
+
symbolic::ValueExpr<IncrType> >,
|
| 66 |
+
symbolic::ValueExpr<> > type;
|
| 67 |
+
};
|
| 68 |
+
#endif
|
| 69 |
+
|
| 70 |
+
// Helper to cleanup the type of the increment:
|
| 71 |
+
template<typename T> struct cleanup_seq_incr {
|
| 72 |
+
typedef typename cleanup_index_type<T,DynamicIndex>::type type;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
//--------------------------------------------------------------------------------
|
| 78 |
+
// seq(first,last,incr) and seqN(first,size,incr)
|
| 79 |
+
//--------------------------------------------------------------------------------
|
| 80 |
+
|
| 81 |
+
template<typename FirstType=Index,typename SizeType=Index,typename IncrType=internal::FixedInt<1> >
|
| 82 |
+
class ArithmeticSequence;
|
| 83 |
+
|
| 84 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 85 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
|
| 86 |
+
typename internal::cleanup_index_type<SizeType>::type,
|
| 87 |
+
typename internal::cleanup_seq_incr<IncrType>::type >
|
| 88 |
+
seqN(FirstType first, SizeType size, IncrType incr);
|
| 89 |
+
|
| 90 |
+
/** \class ArithmeticSequence
|
| 91 |
+
* \ingroup Core_Module
|
| 92 |
+
*
|
| 93 |
+
* This class represents an arithmetic progression \f$ a_0, a_1, a_2, ..., a_{n-1}\f$ defined by
|
| 94 |
+
* its \em first value \f$ a_0 \f$, its \em size (aka length) \em n, and the \em increment (aka stride)
|
| 95 |
+
* that is equal to \f$ a_{i+1}-a_{i}\f$ for any \em i.
|
| 96 |
+
*
|
| 97 |
+
* It is internally used as the return type of the Eigen::seq and Eigen::seqN functions, and as the input arguments
|
| 98 |
+
* of DenseBase::operator()(const RowIndices&, const ColIndices&), and most of the time this is the
|
| 99 |
+
* only way it is used.
|
| 100 |
+
*
|
| 101 |
+
* \tparam FirstType type of the first element, usually an Index,
|
| 102 |
+
* but internally it can be a symbolic expression
|
| 103 |
+
* \tparam SizeType type representing the size of the sequence, usually an Index
|
| 104 |
+
* or a compile time integral constant. Internally, it can also be a symbolic expression
|
| 105 |
+
* \tparam IncrType type of the increment, can be a runtime Index, or a compile time integral constant (default is compile-time 1)
|
| 106 |
+
*
|
| 107 |
+
* \sa Eigen::seq, Eigen::seqN, DenseBase::operator()(const RowIndices&, const ColIndices&), class IndexedView
|
| 108 |
+
*/
|
| 109 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 110 |
+
class ArithmeticSequence
|
| 111 |
+
{
|
| 112 |
+
public:
|
| 113 |
+
ArithmeticSequence(FirstType first, SizeType size) : m_first(first), m_size(size) {}
|
| 114 |
+
ArithmeticSequence(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {}
|
| 115 |
+
|
| 116 |
+
enum {
|
| 117 |
+
SizeAtCompileTime = internal::get_fixed_value<SizeType>::value,
|
| 118 |
+
IncrAtCompileTime = internal::get_fixed_value<IncrType,DynamicIndex>::value
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
/** \returns the size, i.e., number of elements, of the sequence */
|
| 122 |
+
Index size() const { return m_size; }
|
| 123 |
+
|
| 124 |
+
/** \returns the first element \f$ a_0 \f$ in the sequence */
|
| 125 |
+
Index first() const { return m_first; }
|
| 126 |
+
|
| 127 |
+
/** \returns the value \f$ a_i \f$ at index \a i in the sequence. */
|
| 128 |
+
Index operator[](Index i) const { return m_first + i * m_incr; }
|
| 129 |
+
|
| 130 |
+
const FirstType& firstObject() const { return m_first; }
|
| 131 |
+
const SizeType& sizeObject() const { return m_size; }
|
| 132 |
+
const IncrType& incrObject() const { return m_incr; }
|
| 133 |
+
|
| 134 |
+
protected:
|
| 135 |
+
FirstType m_first;
|
| 136 |
+
SizeType m_size;
|
| 137 |
+
IncrType m_incr;
|
| 138 |
+
|
| 139 |
+
public:
|
| 140 |
+
|
| 141 |
+
#if EIGEN_HAS_CXX11 && ((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48)
|
| 142 |
+
auto reverse() const -> decltype(Eigen::seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr)) {
|
| 143 |
+
return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr);
|
| 144 |
+
}
|
| 145 |
+
#else
|
| 146 |
+
protected:
|
| 147 |
+
typedef typename internal::aseq_negate<IncrType>::type ReverseIncrType;
|
| 148 |
+
typedef typename internal::aseq_reverse_first_type<FirstType,SizeType,IncrType>::type ReverseFirstType;
|
| 149 |
+
public:
|
| 150 |
+
ArithmeticSequence<ReverseFirstType,SizeType,ReverseIncrType>
|
| 151 |
+
reverse() const {
|
| 152 |
+
return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr);
|
| 153 |
+
}
|
| 154 |
+
#endif
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
/** \returns an ArithmeticSequence starting at \a first, of length \a size, and increment \a incr
|
| 158 |
+
*
|
| 159 |
+
* \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */
|
| 160 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 161 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type >
|
| 162 |
+
seqN(FirstType first, SizeType size, IncrType incr) {
|
| 163 |
+
return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type,typename internal::cleanup_seq_incr<IncrType>::type>(first,size,incr);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/** \returns an ArithmeticSequence starting at \a first, of length \a size, and unit increment
|
| 167 |
+
*
|
| 168 |
+
* \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType) */
|
| 169 |
+
template<typename FirstType,typename SizeType>
|
| 170 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type >
|
| 171 |
+
seqN(FirstType first, SizeType size) {
|
| 172 |
+
return ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,typename internal::cleanup_index_type<SizeType>::type>(first,size);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
#if EIGEN_HAS_CXX11
|
| 177 |
+
|
| 178 |
+
/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and with positive (or negative) increment \a incr
|
| 179 |
+
*
|
| 180 |
+
* It is essentially an alias to:
|
| 181 |
+
* \code
|
| 182 |
+
* seqN(f, (l-f+incr)/incr, incr);
|
| 183 |
+
* \endcode
|
| 184 |
+
*
|
| 185 |
+
* \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType)
|
| 186 |
+
*/
|
| 187 |
+
template<typename FirstType,typename LastType>
|
| 188 |
+
auto seq(FirstType f, LastType l) -> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 189 |
+
( typename internal::cleanup_index_type<LastType>::type(l)
|
| 190 |
+
- typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())))
|
| 191 |
+
{
|
| 192 |
+
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 193 |
+
(typename internal::cleanup_index_type<LastType>::type(l)
|
| 194 |
+
-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and unit increment
|
| 198 |
+
*
|
| 199 |
+
* It is essentially an alias to:
|
| 200 |
+
* \code
|
| 201 |
+
* seqN(f,l-f+1);
|
| 202 |
+
* \endcode
|
| 203 |
+
*
|
| 204 |
+
* \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType)
|
| 205 |
+
*/
|
| 206 |
+
template<typename FirstType,typename LastType, typename IncrType>
|
| 207 |
+
auto seq(FirstType f, LastType l, IncrType incr)
|
| 208 |
+
-> decltype(seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 209 |
+
( typename internal::cleanup_index_type<LastType>::type(l)
|
| 210 |
+
- typename internal::cleanup_index_type<FirstType>::type(f)+typename internal::cleanup_seq_incr<IncrType>::type(incr)
|
| 211 |
+
) / typename internal::cleanup_seq_incr<IncrType>::type(incr),
|
| 212 |
+
typename internal::cleanup_seq_incr<IncrType>::type(incr)))
|
| 213 |
+
{
|
| 214 |
+
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
| 215 |
+
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 216 |
+
( typename internal::cleanup_index_type<LastType>::type(l)
|
| 217 |
+
-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr)) / CleanedIncrType(incr),
|
| 218 |
+
CleanedIncrType(incr));
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
#else // EIGEN_HAS_CXX11
|
| 222 |
+
|
| 223 |
+
template<typename FirstType,typename LastType>
|
| 224 |
+
typename internal::enable_if<!(symbolic::is_symbolic<FirstType>::value || symbolic::is_symbolic<LastType>::value),
|
| 225 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index> >::type
|
| 226 |
+
seq(FirstType f, LastType l)
|
| 227 |
+
{
|
| 228 |
+
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 229 |
+
Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>())));
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
template<typename FirstTypeDerived,typename LastType>
|
| 233 |
+
typename internal::enable_if<!symbolic::is_symbolic<LastType>::value,
|
| 234 |
+
ArithmeticSequence<FirstTypeDerived, symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,symbolic::ValueExpr<> >,
|
| 235 |
+
symbolic::ValueExpr<internal::FixedInt<1> > > > >::type
|
| 236 |
+
seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l)
|
| 237 |
+
{
|
| 238 |
+
return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+fix<1>()));
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
template<typename FirstType,typename LastTypeDerived>
|
| 242 |
+
typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value,
|
| 243 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
|
| 244 |
+
symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >,
|
| 245 |
+
symbolic::ValueExpr<internal::FixedInt<1> > > > >::type
|
| 246 |
+
seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l)
|
| 247 |
+
{
|
| 248 |
+
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),(l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+fix<1>()));
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
template<typename FirstTypeDerived,typename LastTypeDerived>
|
| 252 |
+
ArithmeticSequence<FirstTypeDerived,
|
| 253 |
+
symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::NegateExpr<FirstTypeDerived> >,symbolic::ValueExpr<internal::FixedInt<1> > > >
|
| 254 |
+
seq(const symbolic::BaseExpr<FirstTypeDerived> &f, const symbolic::BaseExpr<LastTypeDerived> &l)
|
| 255 |
+
{
|
| 256 |
+
return seqN(f.derived(),(l.derived()-f.derived()+fix<1>()));
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
template<typename FirstType,typename LastType, typename IncrType>
|
| 261 |
+
typename internal::enable_if<!(symbolic::is_symbolic<FirstType>::value || symbolic::is_symbolic<LastType>::value),
|
| 262 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,Index,typename internal::cleanup_seq_incr<IncrType>::type> >::type
|
| 263 |
+
seq(FirstType f, LastType l, IncrType incr)
|
| 264 |
+
{
|
| 265 |
+
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
| 266 |
+
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 267 |
+
Index((typename internal::cleanup_index_type<LastType>::type(l)-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr)), incr);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
template<typename FirstTypeDerived,typename LastType, typename IncrType>
|
| 271 |
+
typename internal::enable_if<!symbolic::is_symbolic<LastType>::value,
|
| 272 |
+
ArithmeticSequence<FirstTypeDerived,
|
| 273 |
+
symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<symbolic::NegateExpr<FirstTypeDerived>,
|
| 274 |
+
symbolic::ValueExpr<> >,
|
| 275 |
+
symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
|
| 276 |
+
symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
|
| 277 |
+
typename internal::cleanup_seq_incr<IncrType>::type> >::type
|
| 278 |
+
seq(const symbolic::BaseExpr<FirstTypeDerived> &f, LastType l, IncrType incr)
|
| 279 |
+
{
|
| 280 |
+
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
| 281 |
+
return seqN(f.derived(),(typename internal::cleanup_index_type<LastType>::type(l)-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
template<typename FirstType,typename LastTypeDerived, typename IncrType>
|
| 285 |
+
typename internal::enable_if<!symbolic::is_symbolic<FirstType>::value,
|
| 286 |
+
ArithmeticSequence<typename internal::cleanup_index_type<FirstType>::type,
|
| 287 |
+
symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,symbolic::ValueExpr<> >,
|
| 288 |
+
symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
|
| 289 |
+
symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
|
| 290 |
+
typename internal::cleanup_seq_incr<IncrType>::type> >::type
|
| 291 |
+
seq(FirstType f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr)
|
| 292 |
+
{
|
| 293 |
+
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
| 294 |
+
return seqN(typename internal::cleanup_index_type<FirstType>::type(f),
|
| 295 |
+
(l.derived()-typename internal::cleanup_index_type<FirstType>::type(f)+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
template<typename FirstTypeDerived,typename LastTypeDerived, typename IncrType>
|
| 299 |
+
ArithmeticSequence<FirstTypeDerived,
|
| 300 |
+
symbolic::QuotientExpr<symbolic::AddExpr<symbolic::AddExpr<LastTypeDerived,
|
| 301 |
+
symbolic::NegateExpr<FirstTypeDerived> >,
|
| 302 |
+
symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
|
| 303 |
+
symbolic::ValueExpr<typename internal::cleanup_seq_incr<IncrType>::type> >,
|
| 304 |
+
typename internal::cleanup_seq_incr<IncrType>::type>
|
| 305 |
+
seq(const symbolic::BaseExpr<FirstTypeDerived> &f, const symbolic::BaseExpr<LastTypeDerived> &l, IncrType incr)
|
| 306 |
+
{
|
| 307 |
+
typedef typename internal::cleanup_seq_incr<IncrType>::type CleanedIncrType;
|
| 308 |
+
return seqN(f.derived(),(l.derived()-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr);
|
| 309 |
+
}
|
| 310 |
+
#endif // EIGEN_HAS_CXX11
|
| 311 |
+
|
| 312 |
+
#if EIGEN_HAS_CXX11
|
| 313 |
+
/** \cpp11
|
| 314 |
+
* \returns a symbolic ArithmeticSequence representing the last \a size elements with a unit increment.
|
| 315 |
+
*
|
| 316 |
+
* \anchor indexing_lastN
|
| 317 |
+
*
|
| 318 |
+
* It is a shortcut for: \code seq(last+fix<1>-size, last) \endcode
|
| 319 |
+
*
|
| 320 |
+
* \sa lastN(SizeType,IncrType, seqN(FirstType,SizeType), seq(FirstType,LastType) */
|
| 321 |
+
template<typename SizeType>
|
| 322 |
+
auto lastN(SizeType size)
|
| 323 |
+
-> decltype(seqN(Eigen::last+fix<1>()-size, size))
|
| 324 |
+
{
|
| 325 |
+
return seqN(Eigen::last+fix<1>()-size, size);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
/** \cpp11
|
| 329 |
+
* \returns a symbolic ArithmeticSequence representing the last \a size elements with increment \a incr.
|
| 330 |
+
*
|
| 331 |
+
* \anchor indexing_lastN_with_incr
|
| 332 |
+
*
|
| 333 |
+
* It is a shortcut for: \code seqN(last-(size-fix<1>)*incr, size, incr) \endcode
|
| 334 |
+
*
|
| 335 |
+
* \sa lastN(SizeType), seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */
|
| 336 |
+
template<typename SizeType,typename IncrType>
|
| 337 |
+
auto lastN(SizeType size, IncrType incr)
|
| 338 |
+
-> decltype(seqN(Eigen::last-(size-fix<1>())*incr, size, incr))
|
| 339 |
+
{
|
| 340 |
+
return seqN(Eigen::last-(size-fix<1>())*incr, size, incr);
|
| 341 |
+
}
|
| 342 |
+
#endif
|
| 343 |
+
|
| 344 |
+
namespace internal {
|
| 345 |
+
|
| 346 |
+
// Convert a symbolic span into a usable one (i.e., remove last/end "keywords")
|
| 347 |
+
template<typename T>
|
| 348 |
+
struct make_size_type {
|
| 349 |
+
typedef typename internal::conditional<symbolic::is_symbolic<T>::value, Index, T>::type type;
|
| 350 |
+
};
|
| 351 |
+
|
| 352 |
+
template<typename FirstType,typename SizeType,typename IncrType,int XprSize>
|
| 353 |
+
struct IndexedViewCompatibleType<ArithmeticSequence<FirstType,SizeType,IncrType>, XprSize> {
|
| 354 |
+
typedef ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType> type;
|
| 355 |
+
};
|
| 356 |
+
|
| 357 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 358 |
+
ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType>
|
| 359 |
+
makeIndexedViewCompatible(const ArithmeticSequence<FirstType,SizeType,IncrType>& ids, Index size,SpecializedType) {
|
| 360 |
+
return ArithmeticSequence<Index,typename make_size_type<SizeType>::type,IncrType>(
|
| 361 |
+
eval_expr_given_size(ids.firstObject(),size),eval_expr_given_size(ids.sizeObject(),size),ids.incrObject());
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
template<typename FirstType,typename SizeType,typename IncrType>
|
| 365 |
+
struct get_compile_time_incr<ArithmeticSequence<FirstType,SizeType,IncrType> > {
|
| 366 |
+
enum { value = get_fixed_value<IncrType,DynamicIndex>::value };
|
| 367 |
+
};
|
| 368 |
+
|
| 369 |
+
} // end namespace internal
|
| 370 |
+
|
| 371 |
+
/** \namespace Eigen::indexing
|
| 372 |
+
* \ingroup Core_Module
|
| 373 |
+
*
|
| 374 |
+
* The sole purpose of this namespace is to be able to import all functions
|
| 375 |
+
* and symbols that are expected to be used within operator() for indexing
|
| 376 |
+
* and slicing. If you already imported the whole Eigen namespace:
|
| 377 |
+
* \code using namespace Eigen; \endcode
|
| 378 |
+
* then you are already all set. Otherwise, if you don't want/cannot import
|
| 379 |
+
* the whole Eigen namespace, the following line:
|
| 380 |
+
* \code using namespace Eigen::indexing; \endcode
|
| 381 |
+
* is equivalent to:
|
| 382 |
+
* \code
|
| 383 |
+
using Eigen::all;
|
| 384 |
+
using Eigen::seq;
|
| 385 |
+
using Eigen::seqN;
|
| 386 |
+
using Eigen::lastN; // c++11 only
|
| 387 |
+
using Eigen::last;
|
| 388 |
+
using Eigen::lastp1;
|
| 389 |
+
using Eigen::fix;
|
| 390 |
+
\endcode
|
| 391 |
+
*/
|
| 392 |
+
namespace indexing {
|
| 393 |
+
using Eigen::all;
|
| 394 |
+
using Eigen::seq;
|
| 395 |
+
using Eigen::seqN;
|
| 396 |
+
#if EIGEN_HAS_CXX11
|
| 397 |
+
using Eigen::lastN;
|
| 398 |
+
#endif
|
| 399 |
+
using Eigen::last;
|
| 400 |
+
using Eigen::lastp1;
|
| 401 |
+
using Eigen::fix;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
} // end namespace Eigen
|
| 405 |
+
|
| 406 |
+
#endif // EIGEN_ARITHMETIC_SEQUENCE_H
|
include/eigen/Eigen/src/Core/Array.h
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_ARRAY_H
|
| 11 |
+
#define EIGEN_ARRAY_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
| 17 |
+
struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
| 18 |
+
{
|
| 19 |
+
typedef ArrayXpr XprKind;
|
| 20 |
+
typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase;
|
| 21 |
+
};
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/** \class Array
|
| 25 |
+
* \ingroup Core_Module
|
| 26 |
+
*
|
| 27 |
+
* \brief General-purpose arrays with easy API for coefficient-wise operations
|
| 28 |
+
*
|
| 29 |
+
* The %Array class is very similar to the Matrix class. It provides
|
| 30 |
+
* general-purpose one- and two-dimensional arrays. The difference between the
|
| 31 |
+
* %Array and the %Matrix class is primarily in the API: the API for the
|
| 32 |
+
* %Array class provides easy access to coefficient-wise operations, while the
|
| 33 |
+
* API for the %Matrix class provides easy access to linear-algebra
|
| 34 |
+
* operations.
|
| 35 |
+
*
|
| 36 |
+
* See documentation of class Matrix for detailed information on the template parameters
|
| 37 |
+
* storage layout.
|
| 38 |
+
*
|
| 39 |
+
* This class can be extended with the help of the plugin mechanism described on the page
|
| 40 |
+
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAY_PLUGIN.
|
| 41 |
+
*
|
| 42 |
+
* \sa \blank \ref TutorialArrayClass, \ref TopicClassHierarchy
|
| 43 |
+
*/
|
| 44 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
| 45 |
+
class Array
|
| 46 |
+
: public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
| 47 |
+
{
|
| 48 |
+
public:
|
| 49 |
+
|
| 50 |
+
typedef PlainObjectBase<Array> Base;
|
| 51 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(Array)
|
| 52 |
+
|
| 53 |
+
enum { Options = _Options };
|
| 54 |
+
typedef typename Base::PlainObject PlainObject;
|
| 55 |
+
|
| 56 |
+
protected:
|
| 57 |
+
template <typename Derived, typename OtherDerived, bool IsVector>
|
| 58 |
+
friend struct internal::conservative_resize_like_impl;
|
| 59 |
+
|
| 60 |
+
using Base::m_storage;
|
| 61 |
+
|
| 62 |
+
public:
|
| 63 |
+
|
| 64 |
+
using Base::base;
|
| 65 |
+
using Base::coeff;
|
| 66 |
+
using Base::coeffRef;
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* The usage of
|
| 70 |
+
* using Base::operator=;
|
| 71 |
+
* fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
|
| 72 |
+
* the usage of 'using'. This should be done only for operator=.
|
| 73 |
+
*/
|
| 74 |
+
template<typename OtherDerived>
|
| 75 |
+
EIGEN_DEVICE_FUNC
|
| 76 |
+
EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
|
| 77 |
+
{
|
| 78 |
+
return Base::operator=(other);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/** Set all the entries to \a value.
|
| 82 |
+
* \sa DenseBase::setConstant(), DenseBase::fill()
|
| 83 |
+
*/
|
| 84 |
+
/* This overload is needed because the usage of
|
| 85 |
+
* using Base::operator=;
|
| 86 |
+
* fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
|
| 87 |
+
* the usage of 'using'. This should be done only for operator=.
|
| 88 |
+
*/
|
| 89 |
+
EIGEN_DEVICE_FUNC
|
| 90 |
+
EIGEN_STRONG_INLINE Array& operator=(const Scalar &value)
|
| 91 |
+
{
|
| 92 |
+
Base::setConstant(value);
|
| 93 |
+
return *this;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/** Copies the value of the expression \a other into \c *this with automatic resizing.
|
| 97 |
+
*
|
| 98 |
+
* *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
|
| 99 |
+
* it will be initialized.
|
| 100 |
+
*
|
| 101 |
+
* Note that copying a row-vector into a vector (and conversely) is allowed.
|
| 102 |
+
* The resizing, if any, is then done in the appropriate way so that row-vectors
|
| 103 |
+
* remain row-vectors and vectors remain vectors.
|
| 104 |
+
*/
|
| 105 |
+
template<typename OtherDerived>
|
| 106 |
+
EIGEN_DEVICE_FUNC
|
| 107 |
+
EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other)
|
| 108 |
+
{
|
| 109 |
+
return Base::_set(other);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/** This is a special case of the templated operator=. Its purpose is to
|
| 113 |
+
* prevent a default operator= from hiding the templated operator=.
|
| 114 |
+
*/
|
| 115 |
+
EIGEN_DEVICE_FUNC
|
| 116 |
+
EIGEN_STRONG_INLINE Array& operator=(const Array& other)
|
| 117 |
+
{
|
| 118 |
+
return Base::_set(other);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/** Default constructor.
|
| 122 |
+
*
|
| 123 |
+
* For fixed-size matrices, does nothing.
|
| 124 |
+
*
|
| 125 |
+
* For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
|
| 126 |
+
* is called a null matrix. This constructor is the unique way to create null matrices: resizing
|
| 127 |
+
* a matrix to 0 is not supported.
|
| 128 |
+
*
|
| 129 |
+
* \sa resize(Index,Index)
|
| 130 |
+
*/
|
| 131 |
+
EIGEN_DEVICE_FUNC
|
| 132 |
+
EIGEN_STRONG_INLINE Array() : Base()
|
| 133 |
+
{
|
| 134 |
+
Base::_check_template_params();
|
| 135 |
+
EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 139 |
+
// FIXME is it still needed ??
|
| 140 |
+
/** \internal */
|
| 141 |
+
EIGEN_DEVICE_FUNC
|
| 142 |
+
Array(internal::constructor_without_unaligned_array_assert)
|
| 143 |
+
: Base(internal::constructor_without_unaligned_array_assert())
|
| 144 |
+
{
|
| 145 |
+
Base::_check_template_params();
|
| 146 |
+
EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 147 |
+
}
|
| 148 |
+
#endif
|
| 149 |
+
|
| 150 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 151 |
+
EIGEN_DEVICE_FUNC
|
| 152 |
+
Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
|
| 153 |
+
: Base(std::move(other))
|
| 154 |
+
{
|
| 155 |
+
Base::_check_template_params();
|
| 156 |
+
}
|
| 157 |
+
EIGEN_DEVICE_FUNC
|
| 158 |
+
Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
|
| 159 |
+
{
|
| 160 |
+
Base::operator=(std::move(other));
|
| 161 |
+
return *this;
|
| 162 |
+
}
|
| 163 |
+
#endif
|
| 164 |
+
|
| 165 |
+
#if EIGEN_HAS_CXX11
|
| 166 |
+
/** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. \cpp11
|
| 167 |
+
*
|
| 168 |
+
* \only_for_vectors
|
| 169 |
+
*
|
| 170 |
+
* This constructor is for 1D array or vectors with more than 4 coefficients.
|
| 171 |
+
* There exists C++98 analogue constructors for fixed-size array/vector having 1, 2, 3, or 4 coefficients.
|
| 172 |
+
*
|
| 173 |
+
* \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this
|
| 174 |
+
* constructor must match the the fixed number of rows (resp. columns) of \c *this.
|
| 175 |
+
*
|
| 176 |
+
* Example: \include Array_variadic_ctor_cxx11.cpp
|
| 177 |
+
* Output: \verbinclude Array_variadic_ctor_cxx11.out
|
| 178 |
+
*
|
| 179 |
+
* \sa Array(const std::initializer_list<std::initializer_list<Scalar>>&)
|
| 180 |
+
* \sa Array(const Scalar&), Array(const Scalar&,const Scalar&)
|
| 181 |
+
*/
|
| 182 |
+
template <typename... ArgTypes>
|
| 183 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 184 |
+
Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 185 |
+
: Base(a0, a1, a2, a3, args...) {}
|
| 186 |
+
|
| 187 |
+
/** \brief Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11
|
| 188 |
+
*
|
| 189 |
+
* In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients:
|
| 190 |
+
*
|
| 191 |
+
* Example: \include Array_initializer_list_23_cxx11.cpp
|
| 192 |
+
* Output: \verbinclude Array_initializer_list_23_cxx11.out
|
| 193 |
+
*
|
| 194 |
+
* Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered.
|
| 195 |
+
*
|
| 196 |
+
* In the case of a compile-time column 1D array, implicit transposition from a single row is allowed.
|
| 197 |
+
* Therefore <code> Array<int,Dynamic,1>{{1,2,3,4,5}}</code> is legal and the more verbose syntax
|
| 198 |
+
* <code>Array<int,Dynamic,1>{{1},{2},{3},{4},{5}}</code> can be avoided:
|
| 199 |
+
*
|
| 200 |
+
* Example: \include Array_initializer_list_vector_cxx11.cpp
|
| 201 |
+
* Output: \verbinclude Array_initializer_list_vector_cxx11.out
|
| 202 |
+
*
|
| 203 |
+
* In the case of fixed-sized arrays, the initializer list sizes must exactly match the array sizes,
|
| 204 |
+
* and implicit transposition is allowed for compile-time 1D arrays only.
|
| 205 |
+
*
|
| 206 |
+
* \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 207 |
+
*/
|
| 208 |
+
EIGEN_DEVICE_FUNC
|
| 209 |
+
EIGEN_STRONG_INLINE Array(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
|
| 210 |
+
#endif // end EIGEN_HAS_CXX11
|
| 211 |
+
|
| 212 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 213 |
+
template<typename T>
|
| 214 |
+
EIGEN_DEVICE_FUNC
|
| 215 |
+
EIGEN_STRONG_INLINE explicit Array(const T& x)
|
| 216 |
+
{
|
| 217 |
+
Base::_check_template_params();
|
| 218 |
+
Base::template _init1<T>(x);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
template<typename T0, typename T1>
|
| 222 |
+
EIGEN_DEVICE_FUNC
|
| 223 |
+
EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1)
|
| 224 |
+
{
|
| 225 |
+
Base::_check_template_params();
|
| 226 |
+
this->template _init2<T0,T1>(val0, val1);
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
#else
|
| 230 |
+
/** \brief Constructs a fixed-sized array initialized with coefficients starting at \a data */
|
| 231 |
+
EIGEN_DEVICE_FUNC explicit Array(const Scalar *data);
|
| 232 |
+
/** Constructs a vector or row-vector with given dimension. \only_for_vectors
|
| 233 |
+
*
|
| 234 |
+
* Note that this is only useful for dynamic-size vectors. For fixed-size vectors,
|
| 235 |
+
* it is redundant to pass the dimension here, so it makes more sense to use the default
|
| 236 |
+
* constructor Array() instead.
|
| 237 |
+
*/
|
| 238 |
+
EIGEN_DEVICE_FUNC
|
| 239 |
+
EIGEN_STRONG_INLINE explicit Array(Index dim);
|
| 240 |
+
/** constructs an initialized 1x1 Array with the given coefficient
|
| 241 |
+
* \sa const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args */
|
| 242 |
+
Array(const Scalar& value);
|
| 243 |
+
/** constructs an uninitialized array with \a rows rows and \a cols columns.
|
| 244 |
+
*
|
| 245 |
+
* This is useful for dynamic-size arrays. For fixed-size arrays,
|
| 246 |
+
* it is redundant to pass these parameters, so one should use the default constructor
|
| 247 |
+
* Array() instead. */
|
| 248 |
+
Array(Index rows, Index cols);
|
| 249 |
+
/** constructs an initialized 2D vector with given coefficients
|
| 250 |
+
* \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) */
|
| 251 |
+
Array(const Scalar& val0, const Scalar& val1);
|
| 252 |
+
#endif // end EIGEN_PARSED_BY_DOXYGEN
|
| 253 |
+
|
| 254 |
+
/** constructs an initialized 3D vector with given coefficients
|
| 255 |
+
* \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 256 |
+
*/
|
| 257 |
+
EIGEN_DEVICE_FUNC
|
| 258 |
+
EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2)
|
| 259 |
+
{
|
| 260 |
+
Base::_check_template_params();
|
| 261 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
|
| 262 |
+
m_storage.data()[0] = val0;
|
| 263 |
+
m_storage.data()[1] = val1;
|
| 264 |
+
m_storage.data()[2] = val2;
|
| 265 |
+
}
|
| 266 |
+
/** constructs an initialized 4D vector with given coefficients
|
| 267 |
+
* \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 268 |
+
*/
|
| 269 |
+
EIGEN_DEVICE_FUNC
|
| 270 |
+
EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3)
|
| 271 |
+
{
|
| 272 |
+
Base::_check_template_params();
|
| 273 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
|
| 274 |
+
m_storage.data()[0] = val0;
|
| 275 |
+
m_storage.data()[1] = val1;
|
| 276 |
+
m_storage.data()[2] = val2;
|
| 277 |
+
m_storage.data()[3] = val3;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
/** Copy constructor */
|
| 281 |
+
EIGEN_DEVICE_FUNC
|
| 282 |
+
EIGEN_STRONG_INLINE Array(const Array& other)
|
| 283 |
+
: Base(other)
|
| 284 |
+
{ }
|
| 285 |
+
|
| 286 |
+
private:
|
| 287 |
+
struct PrivateType {};
|
| 288 |
+
public:
|
| 289 |
+
|
| 290 |
+
/** \sa MatrixBase::operator=(const EigenBase<OtherDerived>&) */
|
| 291 |
+
template<typename OtherDerived>
|
| 292 |
+
EIGEN_DEVICE_FUNC
|
| 293 |
+
EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other,
|
| 294 |
+
typename internal::enable_if<internal::is_convertible<typename OtherDerived::Scalar,Scalar>::value,
|
| 295 |
+
PrivateType>::type = PrivateType())
|
| 296 |
+
: Base(other.derived())
|
| 297 |
+
{ }
|
| 298 |
+
|
| 299 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 300 |
+
inline Index innerStride() const EIGEN_NOEXCEPT{ return 1; }
|
| 301 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 302 |
+
inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
|
| 303 |
+
|
| 304 |
+
#ifdef EIGEN_ARRAY_PLUGIN
|
| 305 |
+
#include EIGEN_ARRAY_PLUGIN
|
| 306 |
+
#endif
|
| 307 |
+
|
| 308 |
+
private:
|
| 309 |
+
|
| 310 |
+
template<typename MatrixType, typename OtherDerived, bool SwapPointers>
|
| 311 |
+
friend struct internal::matrix_swap_impl;
|
| 312 |
+
};
|
| 313 |
+
|
| 314 |
+
/** \defgroup arraytypedefs Global array typedefs
|
| 315 |
+
* \ingroup Core_Module
|
| 316 |
+
*
|
| 317 |
+
* %Eigen defines several typedef shortcuts for most common 1D and 2D array types.
|
| 318 |
+
*
|
| 319 |
+
* The general patterns are the following:
|
| 320 |
+
*
|
| 321 |
+
* \c ArrayRowsColsType where \c Rows and \c Cols can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size,
|
| 322 |
+
* and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd
|
| 323 |
+
* for complex double.
|
| 324 |
+
*
|
| 325 |
+
* For example, \c Array33d is a fixed-size 3x3 array type of doubles, and \c ArrayXXf is a dynamic-size matrix of floats.
|
| 326 |
+
*
|
| 327 |
+
* There are also \c ArraySizeType which are self-explanatory. For example, \c Array4cf is
|
| 328 |
+
* a fixed-size 1D array of 4 complex floats.
|
| 329 |
+
*
|
| 330 |
+
* With \cpp11, template alias are also defined for common sizes.
|
| 331 |
+
* They follow the same pattern as above except that the scalar type suffix is replaced by a
|
| 332 |
+
* template parameter, i.e.:
|
| 333 |
+
* - `ArrayRowsCols<Type>` where `Rows` and `Cols` can be \c 2,\c 3,\c 4, or \c X for fixed or dynamic size.
|
| 334 |
+
* - `ArraySize<Type>` where `Size` can be \c 2,\c 3,\c 4 or \c X for fixed or dynamic size 1D arrays.
|
| 335 |
+
*
|
| 336 |
+
* \sa class Array
|
| 337 |
+
*/
|
| 338 |
+
|
| 339 |
+
#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
|
| 340 |
+
/** \ingroup arraytypedefs */ \
|
| 341 |
+
typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
|
| 342 |
+
/** \ingroup arraytypedefs */ \
|
| 343 |
+
typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
|
| 344 |
+
|
| 345 |
+
#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
|
| 346 |
+
/** \ingroup arraytypedefs */ \
|
| 347 |
+
typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
|
| 348 |
+
/** \ingroup arraytypedefs */ \
|
| 349 |
+
typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
|
| 350 |
+
|
| 351 |
+
#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
|
| 352 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
|
| 353 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
|
| 354 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
|
| 355 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
|
| 356 |
+
EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
|
| 357 |
+
EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
|
| 358 |
+
EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
|
| 359 |
+
|
| 360 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i)
|
| 361 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f)
|
| 362 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d)
|
| 363 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
|
| 364 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
|
| 365 |
+
|
| 366 |
+
#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
|
| 367 |
+
#undef EIGEN_MAKE_ARRAY_TYPEDEFS
|
| 368 |
+
#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
|
| 369 |
+
|
| 370 |
+
#if EIGEN_HAS_CXX11
|
| 371 |
+
|
| 372 |
+
#define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \
|
| 373 |
+
/** \ingroup arraytypedefs */ \
|
| 374 |
+
/** \brief \cpp11 */ \
|
| 375 |
+
template <typename Type> \
|
| 376 |
+
using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \
|
| 377 |
+
/** \ingroup arraytypedefs */ \
|
| 378 |
+
/** \brief \cpp11 */ \
|
| 379 |
+
template <typename Type> \
|
| 380 |
+
using Array##SizeSuffix = Array<Type, Size, 1>;
|
| 381 |
+
|
| 382 |
+
#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \
|
| 383 |
+
/** \ingroup arraytypedefs */ \
|
| 384 |
+
/** \brief \cpp11 */ \
|
| 385 |
+
template <typename Type> \
|
| 386 |
+
using Array##Size##X = Array<Type, Size, Dynamic>; \
|
| 387 |
+
/** \ingroup arraytypedefs */ \
|
| 388 |
+
/** \brief \cpp11 */ \
|
| 389 |
+
template <typename Type> \
|
| 390 |
+
using Array##X##Size = Array<Type, Dynamic, Size>;
|
| 391 |
+
|
| 392 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2)
|
| 393 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3)
|
| 394 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4)
|
| 395 |
+
EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X)
|
| 396 |
+
EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2)
|
| 397 |
+
EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3)
|
| 398 |
+
EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4)
|
| 399 |
+
|
| 400 |
+
#undef EIGEN_MAKE_ARRAY_TYPEDEFS
|
| 401 |
+
#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
|
| 402 |
+
|
| 403 |
+
#endif // EIGEN_HAS_CXX11
|
| 404 |
+
|
| 405 |
+
#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
|
| 406 |
+
using Eigen::Matrix##SizeSuffix##TypeSuffix; \
|
| 407 |
+
using Eigen::Vector##SizeSuffix##TypeSuffix; \
|
| 408 |
+
using Eigen::RowVector##SizeSuffix##TypeSuffix;
|
| 409 |
+
|
| 410 |
+
#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
|
| 411 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
|
| 412 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
|
| 413 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
|
| 414 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
|
| 415 |
+
|
| 416 |
+
#define EIGEN_USING_ARRAY_TYPEDEFS \
|
| 417 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
|
| 418 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
|
| 419 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
|
| 420 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
|
| 421 |
+
EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
|
| 422 |
+
|
| 423 |
+
} // end namespace Eigen
|
| 424 |
+
|
| 425 |
+
#endif // EIGEN_ARRAY_H
|
include/eigen/Eigen/src/Core/ArrayBase.h
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_ARRAYBASE_H
|
| 11 |
+
#define EIGEN_ARRAYBASE_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
template<typename ExpressionType> class MatrixWrapper;
|
| 16 |
+
|
| 17 |
+
/** \class ArrayBase
|
| 18 |
+
* \ingroup Core_Module
|
| 19 |
+
*
|
| 20 |
+
* \brief Base class for all 1D and 2D array, and related expressions
|
| 21 |
+
*
|
| 22 |
+
* An array is similar to a dense vector or matrix. While matrices are mathematical
|
| 23 |
+
* objects with well defined linear algebra operators, an array is just a collection
|
| 24 |
+
* of scalar values arranged in a one or two dimensionnal fashion. As the main consequence,
|
| 25 |
+
* all operations applied to an array are performed coefficient wise. Furthermore,
|
| 26 |
+
* arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
|
| 27 |
+
* constructors allowing to easily write generic code working for both scalar values
|
| 28 |
+
* and arrays.
|
| 29 |
+
*
|
| 30 |
+
* This class is the base that is inherited by all array expression types.
|
| 31 |
+
*
|
| 32 |
+
* \tparam Derived is the derived type, e.g., an array or an expression type.
|
| 33 |
+
*
|
| 34 |
+
* This class can be extended with the help of the plugin mechanism described on the page
|
| 35 |
+
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
|
| 36 |
+
*
|
| 37 |
+
* \sa class MatrixBase, \ref TopicClassHierarchy
|
| 38 |
+
*/
|
| 39 |
+
template<typename Derived> class ArrayBase
|
| 40 |
+
: public DenseBase<Derived>
|
| 41 |
+
{
|
| 42 |
+
public:
|
| 43 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 44 |
+
/** The base class for a given storage type. */
|
| 45 |
+
typedef ArrayBase StorageBaseType;
|
| 46 |
+
|
| 47 |
+
typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
|
| 48 |
+
|
| 49 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 50 |
+
typedef typename internal::traits<Derived>::Scalar Scalar;
|
| 51 |
+
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
|
| 52 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 53 |
+
|
| 54 |
+
typedef DenseBase<Derived> Base;
|
| 55 |
+
using Base::RowsAtCompileTime;
|
| 56 |
+
using Base::ColsAtCompileTime;
|
| 57 |
+
using Base::SizeAtCompileTime;
|
| 58 |
+
using Base::MaxRowsAtCompileTime;
|
| 59 |
+
using Base::MaxColsAtCompileTime;
|
| 60 |
+
using Base::MaxSizeAtCompileTime;
|
| 61 |
+
using Base::IsVectorAtCompileTime;
|
| 62 |
+
using Base::Flags;
|
| 63 |
+
|
| 64 |
+
using Base::derived;
|
| 65 |
+
using Base::const_cast_derived;
|
| 66 |
+
using Base::rows;
|
| 67 |
+
using Base::cols;
|
| 68 |
+
using Base::size;
|
| 69 |
+
using Base::coeff;
|
| 70 |
+
using Base::coeffRef;
|
| 71 |
+
using Base::lazyAssign;
|
| 72 |
+
using Base::operator-;
|
| 73 |
+
using Base::operator=;
|
| 74 |
+
using Base::operator+=;
|
| 75 |
+
using Base::operator-=;
|
| 76 |
+
using Base::operator*=;
|
| 77 |
+
using Base::operator/=;
|
| 78 |
+
|
| 79 |
+
typedef typename Base::CoeffReturnType CoeffReturnType;
|
| 80 |
+
|
| 81 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 82 |
+
|
| 83 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 84 |
+
typedef typename Base::PlainObject PlainObject;
|
| 85 |
+
|
| 86 |
+
/** \internal Represents a matrix with all coefficients equal to one another*/
|
| 87 |
+
typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
|
| 88 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 89 |
+
|
| 90 |
+
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
|
| 91 |
+
#define EIGEN_DOC_UNARY_ADDONS(X,Y)
|
| 92 |
+
# include "../plugins/MatrixCwiseUnaryOps.h"
|
| 93 |
+
# include "../plugins/ArrayCwiseUnaryOps.h"
|
| 94 |
+
# include "../plugins/CommonCwiseBinaryOps.h"
|
| 95 |
+
# include "../plugins/MatrixCwiseBinaryOps.h"
|
| 96 |
+
# include "../plugins/ArrayCwiseBinaryOps.h"
|
| 97 |
+
# ifdef EIGEN_ARRAYBASE_PLUGIN
|
| 98 |
+
# include EIGEN_ARRAYBASE_PLUGIN
|
| 99 |
+
# endif
|
| 100 |
+
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
|
| 101 |
+
#undef EIGEN_DOC_UNARY_ADDONS
|
| 102 |
+
|
| 103 |
+
/** Special case of the template operator=, in order to prevent the compiler
|
| 104 |
+
* from generating a default operator= (issue hit with g++ 4.1)
|
| 105 |
+
*/
|
| 106 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 107 |
+
Derived& operator=(const ArrayBase& other)
|
| 108 |
+
{
|
| 109 |
+
internal::call_assignment(derived(), other.derived());
|
| 110 |
+
return derived();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/** Set all the entries to \a value.
|
| 114 |
+
* \sa DenseBase::setConstant(), DenseBase::fill() */
|
| 115 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 116 |
+
Derived& operator=(const Scalar &value)
|
| 117 |
+
{ Base::setConstant(value); return derived(); }
|
| 118 |
+
|
| 119 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 120 |
+
Derived& operator+=(const Scalar& scalar);
|
| 121 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 122 |
+
Derived& operator-=(const Scalar& scalar);
|
| 123 |
+
|
| 124 |
+
template<typename OtherDerived>
|
| 125 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 126 |
+
Derived& operator+=(const ArrayBase<OtherDerived>& other);
|
| 127 |
+
template<typename OtherDerived>
|
| 128 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 129 |
+
Derived& operator-=(const ArrayBase<OtherDerived>& other);
|
| 130 |
+
|
| 131 |
+
template<typename OtherDerived>
|
| 132 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 133 |
+
Derived& operator*=(const ArrayBase<OtherDerived>& other);
|
| 134 |
+
|
| 135 |
+
template<typename OtherDerived>
|
| 136 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 137 |
+
Derived& operator/=(const ArrayBase<OtherDerived>& other);
|
| 138 |
+
|
| 139 |
+
public:
|
| 140 |
+
EIGEN_DEVICE_FUNC
|
| 141 |
+
ArrayBase<Derived>& array() { return *this; }
|
| 142 |
+
EIGEN_DEVICE_FUNC
|
| 143 |
+
const ArrayBase<Derived>& array() const { return *this; }
|
| 144 |
+
|
| 145 |
+
/** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array
|
| 146 |
+
* \sa MatrixBase::array() */
|
| 147 |
+
EIGEN_DEVICE_FUNC
|
| 148 |
+
MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); }
|
| 149 |
+
EIGEN_DEVICE_FUNC
|
| 150 |
+
const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); }
|
| 151 |
+
|
| 152 |
+
// template<typename Dest>
|
| 153 |
+
// inline void evalTo(Dest& dst) const { dst = matrix(); }
|
| 154 |
+
|
| 155 |
+
protected:
|
| 156 |
+
EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
|
| 157 |
+
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)
|
| 158 |
+
|
| 159 |
+
private:
|
| 160 |
+
explicit ArrayBase(Index);
|
| 161 |
+
ArrayBase(Index,Index);
|
| 162 |
+
template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
|
| 163 |
+
protected:
|
| 164 |
+
// mixing arrays and matrices is not legal
|
| 165 |
+
template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
|
| 166 |
+
{EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
|
| 167 |
+
// mixing arrays and matrices is not legal
|
| 168 |
+
template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
|
| 169 |
+
{EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
/** replaces \c *this by \c *this - \a other.
|
| 173 |
+
*
|
| 174 |
+
* \returns a reference to \c *this
|
| 175 |
+
*/
|
| 176 |
+
template<typename Derived>
|
| 177 |
+
template<typename OtherDerived>
|
| 178 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
|
| 179 |
+
ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
|
| 180 |
+
{
|
| 181 |
+
call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 182 |
+
return derived();
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/** replaces \c *this by \c *this + \a other.
|
| 186 |
+
*
|
| 187 |
+
* \returns a reference to \c *this
|
| 188 |
+
*/
|
| 189 |
+
template<typename Derived>
|
| 190 |
+
template<typename OtherDerived>
|
| 191 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
|
| 192 |
+
ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
|
| 193 |
+
{
|
| 194 |
+
call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 195 |
+
return derived();
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/** replaces \c *this by \c *this * \a other coefficient wise.
|
| 199 |
+
*
|
| 200 |
+
* \returns a reference to \c *this
|
| 201 |
+
*/
|
| 202 |
+
template<typename Derived>
|
| 203 |
+
template<typename OtherDerived>
|
| 204 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
|
| 205 |
+
ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
|
| 206 |
+
{
|
| 207 |
+
call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 208 |
+
return derived();
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/** replaces \c *this by \c *this / \a other coefficient wise.
|
| 212 |
+
*
|
| 213 |
+
* \returns a reference to \c *this
|
| 214 |
+
*/
|
| 215 |
+
template<typename Derived>
|
| 216 |
+
template<typename OtherDerived>
|
| 217 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
|
| 218 |
+
ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
|
| 219 |
+
{
|
| 220 |
+
call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 221 |
+
return derived();
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
} // end namespace Eigen
|
| 225 |
+
|
| 226 |
+
#endif // EIGEN_ARRAYBASE_H
|
include/eigen/Eigen/src/Core/ArrayWrapper.h
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_ARRAYWRAPPER_H
|
| 11 |
+
#define EIGEN_ARRAYWRAPPER_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
/** \class ArrayWrapper
|
| 16 |
+
* \ingroup Core_Module
|
| 17 |
+
*
|
| 18 |
+
* \brief Expression of a mathematical vector or matrix as an array object
|
| 19 |
+
*
|
| 20 |
+
* This class is the return type of MatrixBase::array(), and most of the time
|
| 21 |
+
* this is the only way it is use.
|
| 22 |
+
*
|
| 23 |
+
* \sa MatrixBase::array(), class MatrixWrapper
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
namespace internal {
|
| 27 |
+
template<typename ExpressionType>
|
| 28 |
+
struct traits<ArrayWrapper<ExpressionType> >
|
| 29 |
+
: public traits<typename remove_all<typename ExpressionType::Nested>::type >
|
| 30 |
+
{
|
| 31 |
+
typedef ArrayXpr XprKind;
|
| 32 |
+
// Let's remove NestByRefBit
|
| 33 |
+
enum {
|
| 34 |
+
Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
|
| 35 |
+
LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
|
| 36 |
+
Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
|
| 37 |
+
};
|
| 38 |
+
};
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
template<typename ExpressionType>
|
| 42 |
+
class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
|
| 43 |
+
{
|
| 44 |
+
public:
|
| 45 |
+
typedef ArrayBase<ArrayWrapper> Base;
|
| 46 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
|
| 47 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
|
| 48 |
+
typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
|
| 49 |
+
|
| 50 |
+
typedef typename internal::conditional<
|
| 51 |
+
internal::is_lvalue<ExpressionType>::value,
|
| 52 |
+
Scalar,
|
| 53 |
+
const Scalar
|
| 54 |
+
>::type ScalarWithConstIfNotLvalue;
|
| 55 |
+
|
| 56 |
+
typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
|
| 57 |
+
|
| 58 |
+
using Base::coeffRef;
|
| 59 |
+
|
| 60 |
+
EIGEN_DEVICE_FUNC
|
| 61 |
+
explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
|
| 62 |
+
|
| 63 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 64 |
+
inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
|
| 65 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 66 |
+
inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
|
| 67 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 68 |
+
inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
|
| 69 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 70 |
+
inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
|
| 71 |
+
|
| 72 |
+
EIGEN_DEVICE_FUNC
|
| 73 |
+
inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
|
| 74 |
+
EIGEN_DEVICE_FUNC
|
| 75 |
+
inline const Scalar* data() const { return m_expression.data(); }
|
| 76 |
+
|
| 77 |
+
EIGEN_DEVICE_FUNC
|
| 78 |
+
inline const Scalar& coeffRef(Index rowId, Index colId) const
|
| 79 |
+
{
|
| 80 |
+
return m_expression.coeffRef(rowId, colId);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
EIGEN_DEVICE_FUNC
|
| 84 |
+
inline const Scalar& coeffRef(Index index) const
|
| 85 |
+
{
|
| 86 |
+
return m_expression.coeffRef(index);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
template<typename Dest>
|
| 90 |
+
EIGEN_DEVICE_FUNC
|
| 91 |
+
inline void evalTo(Dest& dst) const { dst = m_expression; }
|
| 92 |
+
|
| 93 |
+
EIGEN_DEVICE_FUNC
|
| 94 |
+
const typename internal::remove_all<NestedExpressionType>::type&
|
| 95 |
+
nestedExpression() const
|
| 96 |
+
{
|
| 97 |
+
return m_expression;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/** Forwards the resizing request to the nested expression
|
| 101 |
+
* \sa DenseBase::resize(Index) */
|
| 102 |
+
EIGEN_DEVICE_FUNC
|
| 103 |
+
void resize(Index newSize) { m_expression.resize(newSize); }
|
| 104 |
+
/** Forwards the resizing request to the nested expression
|
| 105 |
+
* \sa DenseBase::resize(Index,Index)*/
|
| 106 |
+
EIGEN_DEVICE_FUNC
|
| 107 |
+
void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
|
| 108 |
+
|
| 109 |
+
protected:
|
| 110 |
+
NestedExpressionType m_expression;
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
/** \class MatrixWrapper
|
| 114 |
+
* \ingroup Core_Module
|
| 115 |
+
*
|
| 116 |
+
* \brief Expression of an array as a mathematical vector or matrix
|
| 117 |
+
*
|
| 118 |
+
* This class is the return type of ArrayBase::matrix(), and most of the time
|
| 119 |
+
* this is the only way it is use.
|
| 120 |
+
*
|
| 121 |
+
* \sa MatrixBase::matrix(), class ArrayWrapper
|
| 122 |
+
*/
|
| 123 |
+
|
| 124 |
+
namespace internal {
|
| 125 |
+
template<typename ExpressionType>
|
| 126 |
+
struct traits<MatrixWrapper<ExpressionType> >
|
| 127 |
+
: public traits<typename remove_all<typename ExpressionType::Nested>::type >
|
| 128 |
+
{
|
| 129 |
+
typedef MatrixXpr XprKind;
|
| 130 |
+
// Let's remove NestByRefBit
|
| 131 |
+
enum {
|
| 132 |
+
Flags0 = traits<typename remove_all<typename ExpressionType::Nested>::type >::Flags,
|
| 133 |
+
LvalueBitFlag = is_lvalue<ExpressionType>::value ? LvalueBit : 0,
|
| 134 |
+
Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag
|
| 135 |
+
};
|
| 136 |
+
};
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
template<typename ExpressionType>
|
| 140 |
+
class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
|
| 141 |
+
{
|
| 142 |
+
public:
|
| 143 |
+
typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
|
| 144 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
|
| 145 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
|
| 146 |
+
typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
|
| 147 |
+
|
| 148 |
+
typedef typename internal::conditional<
|
| 149 |
+
internal::is_lvalue<ExpressionType>::value,
|
| 150 |
+
Scalar,
|
| 151 |
+
const Scalar
|
| 152 |
+
>::type ScalarWithConstIfNotLvalue;
|
| 153 |
+
|
| 154 |
+
typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
|
| 155 |
+
|
| 156 |
+
using Base::coeffRef;
|
| 157 |
+
|
| 158 |
+
EIGEN_DEVICE_FUNC
|
| 159 |
+
explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
|
| 160 |
+
|
| 161 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 162 |
+
inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
|
| 163 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 164 |
+
inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
|
| 165 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 166 |
+
inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
|
| 167 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 168 |
+
inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
|
| 169 |
+
|
| 170 |
+
EIGEN_DEVICE_FUNC
|
| 171 |
+
inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
|
| 172 |
+
EIGEN_DEVICE_FUNC
|
| 173 |
+
inline const Scalar* data() const { return m_expression.data(); }
|
| 174 |
+
|
| 175 |
+
EIGEN_DEVICE_FUNC
|
| 176 |
+
inline const Scalar& coeffRef(Index rowId, Index colId) const
|
| 177 |
+
{
|
| 178 |
+
return m_expression.derived().coeffRef(rowId, colId);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
EIGEN_DEVICE_FUNC
|
| 182 |
+
inline const Scalar& coeffRef(Index index) const
|
| 183 |
+
{
|
| 184 |
+
return m_expression.coeffRef(index);
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
EIGEN_DEVICE_FUNC
|
| 188 |
+
const typename internal::remove_all<NestedExpressionType>::type&
|
| 189 |
+
nestedExpression() const
|
| 190 |
+
{
|
| 191 |
+
return m_expression;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/** Forwards the resizing request to the nested expression
|
| 195 |
+
* \sa DenseBase::resize(Index) */
|
| 196 |
+
EIGEN_DEVICE_FUNC
|
| 197 |
+
void resize(Index newSize) { m_expression.resize(newSize); }
|
| 198 |
+
/** Forwards the resizing request to the nested expression
|
| 199 |
+
* \sa DenseBase::resize(Index,Index)*/
|
| 200 |
+
EIGEN_DEVICE_FUNC
|
| 201 |
+
void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
|
| 202 |
+
|
| 203 |
+
protected:
|
| 204 |
+
NestedExpressionType m_expression;
|
| 205 |
+
};
|
| 206 |
+
|
| 207 |
+
} // end namespace Eigen
|
| 208 |
+
|
| 209 |
+
#endif // EIGEN_ARRAYWRAPPER_H
|
include/eigen/Eigen/src/Core/Assign.h
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
|
| 5 |
+
// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 7 |
+
//
|
| 8 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 9 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 10 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 11 |
+
|
| 12 |
+
#ifndef EIGEN_ASSIGN_H
|
| 13 |
+
#define EIGEN_ASSIGN_H
|
| 14 |
+
|
| 15 |
+
namespace Eigen {
|
| 16 |
+
|
| 17 |
+
template<typename Derived>
|
| 18 |
+
template<typename OtherDerived>
|
| 19 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>
|
| 20 |
+
::lazyAssign(const DenseBase<OtherDerived>& other)
|
| 21 |
+
{
|
| 22 |
+
enum{
|
| 23 |
+
SameType = internal::is_same<typename Derived::Scalar,typename OtherDerived::Scalar>::value
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
EIGEN_STATIC_ASSERT_LVALUE(Derived)
|
| 27 |
+
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived)
|
| 28 |
+
EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
|
| 29 |
+
|
| 30 |
+
eigen_assert(rows() == other.rows() && cols() == other.cols());
|
| 31 |
+
internal::call_assignment_no_alias(derived(),other.derived());
|
| 32 |
+
|
| 33 |
+
return derived();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
template<typename Derived>
|
| 37 |
+
template<typename OtherDerived>
|
| 38 |
+
EIGEN_DEVICE_FUNC
|
| 39 |
+
EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
|
| 40 |
+
{
|
| 41 |
+
internal::call_assignment(derived(), other.derived());
|
| 42 |
+
return derived();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
template<typename Derived>
|
| 46 |
+
EIGEN_DEVICE_FUNC
|
| 47 |
+
EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase& other)
|
| 48 |
+
{
|
| 49 |
+
internal::call_assignment(derived(), other.derived());
|
| 50 |
+
return derived();
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
template<typename Derived>
|
| 54 |
+
EIGEN_DEVICE_FUNC
|
| 55 |
+
EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const MatrixBase& other)
|
| 56 |
+
{
|
| 57 |
+
internal::call_assignment(derived(), other.derived());
|
| 58 |
+
return derived();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
template<typename Derived>
|
| 62 |
+
template <typename OtherDerived>
|
| 63 |
+
EIGEN_DEVICE_FUNC
|
| 64 |
+
EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
|
| 65 |
+
{
|
| 66 |
+
internal::call_assignment(derived(), other.derived());
|
| 67 |
+
return derived();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
template<typename Derived>
|
| 71 |
+
template <typename OtherDerived>
|
| 72 |
+
EIGEN_DEVICE_FUNC
|
| 73 |
+
EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const EigenBase<OtherDerived>& other)
|
| 74 |
+
{
|
| 75 |
+
internal::call_assignment(derived(), other.derived());
|
| 76 |
+
return derived();
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
template<typename Derived>
|
| 80 |
+
template<typename OtherDerived>
|
| 81 |
+
EIGEN_DEVICE_FUNC
|
| 82 |
+
EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
|
| 83 |
+
{
|
| 84 |
+
other.derived().evalTo(derived());
|
| 85 |
+
return derived();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
} // end namespace Eigen
|
| 89 |
+
|
| 90 |
+
#endif // EIGEN_ASSIGN_H
|
include/eigen/Eigen/src/Core/AssignEvaluator.h
ADDED
|
@@ -0,0 +1,1010 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
// Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
|
| 7 |
+
//
|
| 8 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 9 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 10 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 11 |
+
|
| 12 |
+
#ifndef EIGEN_ASSIGN_EVALUATOR_H
|
| 13 |
+
#define EIGEN_ASSIGN_EVALUATOR_H
|
| 14 |
+
|
| 15 |
+
namespace Eigen {
|
| 16 |
+
|
| 17 |
+
// This implementation is based on Assign.h
|
| 18 |
+
|
| 19 |
+
namespace internal {
|
| 20 |
+
|
| 21 |
+
/***************************************************************************
|
| 22 |
+
* Part 1 : the logic deciding a strategy for traversal and unrolling *
|
| 23 |
+
***************************************************************************/
|
| 24 |
+
|
| 25 |
+
// copy_using_evaluator_traits is based on assign_traits
|
| 26 |
+
|
| 27 |
+
template <typename DstEvaluator, typename SrcEvaluator, typename AssignFunc, int MaxPacketSize = -1>
|
| 28 |
+
struct copy_using_evaluator_traits
|
| 29 |
+
{
|
| 30 |
+
typedef typename DstEvaluator::XprType Dst;
|
| 31 |
+
typedef typename Dst::Scalar DstScalar;
|
| 32 |
+
|
| 33 |
+
enum {
|
| 34 |
+
DstFlags = DstEvaluator::Flags,
|
| 35 |
+
SrcFlags = SrcEvaluator::Flags
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
public:
|
| 39 |
+
enum {
|
| 40 |
+
DstAlignment = DstEvaluator::Alignment,
|
| 41 |
+
SrcAlignment = SrcEvaluator::Alignment,
|
| 42 |
+
DstHasDirectAccess = (DstFlags & DirectAccessBit) == DirectAccessBit,
|
| 43 |
+
JointAlignment = EIGEN_PLAIN_ENUM_MIN(DstAlignment,SrcAlignment)
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
private:
|
| 47 |
+
enum {
|
| 48 |
+
InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime)
|
| 49 |
+
: int(DstFlags)&RowMajorBit ? int(Dst::ColsAtCompileTime)
|
| 50 |
+
: int(Dst::RowsAtCompileTime),
|
| 51 |
+
InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime)
|
| 52 |
+
: int(DstFlags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime)
|
| 53 |
+
: int(Dst::MaxRowsAtCompileTime),
|
| 54 |
+
RestrictedInnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(InnerSize,MaxPacketSize),
|
| 55 |
+
RestrictedLinearSize = EIGEN_SIZE_MIN_PREFER_FIXED(Dst::SizeAtCompileTime,MaxPacketSize),
|
| 56 |
+
OuterStride = int(outer_stride_at_compile_time<Dst>::ret),
|
| 57 |
+
MaxSizeAtCompileTime = Dst::SizeAtCompileTime
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
// TODO distinguish between linear traversal and inner-traversals
|
| 61 |
+
typedef typename find_best_packet<DstScalar,RestrictedLinearSize>::type LinearPacketType;
|
| 62 |
+
typedef typename find_best_packet<DstScalar,RestrictedInnerSize>::type InnerPacketType;
|
| 63 |
+
|
| 64 |
+
enum {
|
| 65 |
+
LinearPacketSize = unpacket_traits<LinearPacketType>::size,
|
| 66 |
+
InnerPacketSize = unpacket_traits<InnerPacketType>::size
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
public:
|
| 70 |
+
enum {
|
| 71 |
+
LinearRequiredAlignment = unpacket_traits<LinearPacketType>::alignment,
|
| 72 |
+
InnerRequiredAlignment = unpacket_traits<InnerPacketType>::alignment
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
private:
|
| 76 |
+
enum {
|
| 77 |
+
DstIsRowMajor = DstFlags&RowMajorBit,
|
| 78 |
+
SrcIsRowMajor = SrcFlags&RowMajorBit,
|
| 79 |
+
StorageOrdersAgree = (int(DstIsRowMajor) == int(SrcIsRowMajor)),
|
| 80 |
+
MightVectorize = bool(StorageOrdersAgree)
|
| 81 |
+
&& (int(DstFlags) & int(SrcFlags) & ActualPacketAccessBit)
|
| 82 |
+
&& bool(functor_traits<AssignFunc>::PacketAccess),
|
| 83 |
+
MayInnerVectorize = MightVectorize
|
| 84 |
+
&& int(InnerSize)!=Dynamic && int(InnerSize)%int(InnerPacketSize)==0
|
| 85 |
+
&& int(OuterStride)!=Dynamic && int(OuterStride)%int(InnerPacketSize)==0
|
| 86 |
+
&& (EIGEN_UNALIGNED_VECTORIZE || int(JointAlignment)>=int(InnerRequiredAlignment)),
|
| 87 |
+
MayLinearize = bool(StorageOrdersAgree) && (int(DstFlags) & int(SrcFlags) & LinearAccessBit),
|
| 88 |
+
MayLinearVectorize = bool(MightVectorize) && bool(MayLinearize) && bool(DstHasDirectAccess)
|
| 89 |
+
&& (EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment)) || MaxSizeAtCompileTime == Dynamic),
|
| 90 |
+
/* If the destination isn't aligned, we have to do runtime checks and we don't unroll,
|
| 91 |
+
so it's only good for large enough sizes. */
|
| 92 |
+
MaySliceVectorize = bool(MightVectorize) && bool(DstHasDirectAccess)
|
| 93 |
+
&& (int(InnerMaxSize)==Dynamic || int(InnerMaxSize)>=(EIGEN_UNALIGNED_VECTORIZE?InnerPacketSize:(3*InnerPacketSize)))
|
| 94 |
+
/* slice vectorization can be slow, so we only want it if the slices are big, which is
|
| 95 |
+
indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block
|
| 96 |
+
in a fixed-size matrix
|
| 97 |
+
However, with EIGEN_UNALIGNED_VECTORIZE and unrolling, slice vectorization is still worth it */
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
public:
|
| 101 |
+
enum {
|
| 102 |
+
Traversal = int(Dst::SizeAtCompileTime) == 0 ? int(AllAtOnceTraversal) // If compile-size is zero, traversing will fail at compile-time.
|
| 103 |
+
: (int(MayLinearVectorize) && (LinearPacketSize>InnerPacketSize)) ? int(LinearVectorizedTraversal)
|
| 104 |
+
: int(MayInnerVectorize) ? int(InnerVectorizedTraversal)
|
| 105 |
+
: int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
|
| 106 |
+
: int(MaySliceVectorize) ? int(SliceVectorizedTraversal)
|
| 107 |
+
: int(MayLinearize) ? int(LinearTraversal)
|
| 108 |
+
: int(DefaultTraversal),
|
| 109 |
+
Vectorized = int(Traversal) == InnerVectorizedTraversal
|
| 110 |
+
|| int(Traversal) == LinearVectorizedTraversal
|
| 111 |
+
|| int(Traversal) == SliceVectorizedTraversal
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
typedef typename conditional<int(Traversal)==LinearVectorizedTraversal, LinearPacketType, InnerPacketType>::type PacketType;
|
| 115 |
+
|
| 116 |
+
private:
|
| 117 |
+
enum {
|
| 118 |
+
ActualPacketSize = int(Traversal)==LinearVectorizedTraversal ? LinearPacketSize
|
| 119 |
+
: Vectorized ? InnerPacketSize
|
| 120 |
+
: 1,
|
| 121 |
+
UnrollingLimit = EIGEN_UNROLLING_LIMIT * ActualPacketSize,
|
| 122 |
+
MayUnrollCompletely = int(Dst::SizeAtCompileTime) != Dynamic
|
| 123 |
+
&& int(Dst::SizeAtCompileTime) * (int(DstEvaluator::CoeffReadCost)+int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit),
|
| 124 |
+
MayUnrollInner = int(InnerSize) != Dynamic
|
| 125 |
+
&& int(InnerSize) * (int(DstEvaluator::CoeffReadCost)+int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit)
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
public:
|
| 129 |
+
enum {
|
| 130 |
+
Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal))
|
| 131 |
+
? (
|
| 132 |
+
int(MayUnrollCompletely) ? int(CompleteUnrolling)
|
| 133 |
+
: int(MayUnrollInner) ? int(InnerUnrolling)
|
| 134 |
+
: int(NoUnrolling)
|
| 135 |
+
)
|
| 136 |
+
: int(Traversal) == int(LinearVectorizedTraversal)
|
| 137 |
+
? ( bool(MayUnrollCompletely) && ( EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment)))
|
| 138 |
+
? int(CompleteUnrolling)
|
| 139 |
+
: int(NoUnrolling) )
|
| 140 |
+
: int(Traversal) == int(LinearTraversal)
|
| 141 |
+
? ( bool(MayUnrollCompletely) ? int(CompleteUnrolling)
|
| 142 |
+
: int(NoUnrolling) )
|
| 143 |
+
#if EIGEN_UNALIGNED_VECTORIZE
|
| 144 |
+
: int(Traversal) == int(SliceVectorizedTraversal)
|
| 145 |
+
? ( bool(MayUnrollInner) ? int(InnerUnrolling)
|
| 146 |
+
: int(NoUnrolling) )
|
| 147 |
+
#endif
|
| 148 |
+
: int(NoUnrolling)
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
#ifdef EIGEN_DEBUG_ASSIGN
|
| 152 |
+
static void debug()
|
| 153 |
+
{
|
| 154 |
+
std::cerr << "DstXpr: " << typeid(typename DstEvaluator::XprType).name() << std::endl;
|
| 155 |
+
std::cerr << "SrcXpr: " << typeid(typename SrcEvaluator::XprType).name() << std::endl;
|
| 156 |
+
std::cerr.setf(std::ios::hex, std::ios::basefield);
|
| 157 |
+
std::cerr << "DstFlags" << " = " << DstFlags << " (" << demangle_flags(DstFlags) << " )" << std::endl;
|
| 158 |
+
std::cerr << "SrcFlags" << " = " << SrcFlags << " (" << demangle_flags(SrcFlags) << " )" << std::endl;
|
| 159 |
+
std::cerr.unsetf(std::ios::hex);
|
| 160 |
+
EIGEN_DEBUG_VAR(DstAlignment)
|
| 161 |
+
EIGEN_DEBUG_VAR(SrcAlignment)
|
| 162 |
+
EIGEN_DEBUG_VAR(LinearRequiredAlignment)
|
| 163 |
+
EIGEN_DEBUG_VAR(InnerRequiredAlignment)
|
| 164 |
+
EIGEN_DEBUG_VAR(JointAlignment)
|
| 165 |
+
EIGEN_DEBUG_VAR(InnerSize)
|
| 166 |
+
EIGEN_DEBUG_VAR(InnerMaxSize)
|
| 167 |
+
EIGEN_DEBUG_VAR(LinearPacketSize)
|
| 168 |
+
EIGEN_DEBUG_VAR(InnerPacketSize)
|
| 169 |
+
EIGEN_DEBUG_VAR(ActualPacketSize)
|
| 170 |
+
EIGEN_DEBUG_VAR(StorageOrdersAgree)
|
| 171 |
+
EIGEN_DEBUG_VAR(MightVectorize)
|
| 172 |
+
EIGEN_DEBUG_VAR(MayLinearize)
|
| 173 |
+
EIGEN_DEBUG_VAR(MayInnerVectorize)
|
| 174 |
+
EIGEN_DEBUG_VAR(MayLinearVectorize)
|
| 175 |
+
EIGEN_DEBUG_VAR(MaySliceVectorize)
|
| 176 |
+
std::cerr << "Traversal" << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl;
|
| 177 |
+
EIGEN_DEBUG_VAR(SrcEvaluator::CoeffReadCost)
|
| 178 |
+
EIGEN_DEBUG_VAR(DstEvaluator::CoeffReadCost)
|
| 179 |
+
EIGEN_DEBUG_VAR(Dst::SizeAtCompileTime)
|
| 180 |
+
EIGEN_DEBUG_VAR(UnrollingLimit)
|
| 181 |
+
EIGEN_DEBUG_VAR(MayUnrollCompletely)
|
| 182 |
+
EIGEN_DEBUG_VAR(MayUnrollInner)
|
| 183 |
+
std::cerr << "Unrolling" << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl;
|
| 184 |
+
std::cerr << std::endl;
|
| 185 |
+
}
|
| 186 |
+
#endif
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
/***************************************************************************
|
| 190 |
+
* Part 2 : meta-unrollers
|
| 191 |
+
***************************************************************************/
|
| 192 |
+
|
| 193 |
+
/************************
|
| 194 |
+
*** Default traversal ***
|
| 195 |
+
************************/
|
| 196 |
+
|
| 197 |
+
template<typename Kernel, int Index, int Stop>
|
| 198 |
+
struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling
|
| 199 |
+
{
|
| 200 |
+
// FIXME: this is not very clean, perhaps this information should be provided by the kernel?
|
| 201 |
+
typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
|
| 202 |
+
typedef typename DstEvaluatorType::XprType DstXprType;
|
| 203 |
+
|
| 204 |
+
enum {
|
| 205 |
+
outer = Index / DstXprType::InnerSizeAtCompileTime,
|
| 206 |
+
inner = Index % DstXprType::InnerSizeAtCompileTime
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 210 |
+
{
|
| 211 |
+
kernel.assignCoeffByOuterInner(outer, inner);
|
| 212 |
+
copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Index+1, Stop>::run(kernel);
|
| 213 |
+
}
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
template<typename Kernel, int Stop>
|
| 217 |
+
struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Stop, Stop>
|
| 218 |
+
{
|
| 219 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { }
|
| 220 |
+
};
|
| 221 |
+
|
| 222 |
+
template<typename Kernel, int Index_, int Stop>
|
| 223 |
+
struct copy_using_evaluator_DefaultTraversal_InnerUnrolling
|
| 224 |
+
{
|
| 225 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer)
|
| 226 |
+
{
|
| 227 |
+
kernel.assignCoeffByOuterInner(outer, Index_);
|
| 228 |
+
copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Index_+1, Stop>::run(kernel, outer);
|
| 229 |
+
}
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
template<typename Kernel, int Stop>
|
| 233 |
+
struct copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Stop, Stop>
|
| 234 |
+
{
|
| 235 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) { }
|
| 236 |
+
};
|
| 237 |
+
|
| 238 |
+
/***********************
|
| 239 |
+
*** Linear traversal ***
|
| 240 |
+
***********************/
|
| 241 |
+
|
| 242 |
+
template<typename Kernel, int Index, int Stop>
|
| 243 |
+
struct copy_using_evaluator_LinearTraversal_CompleteUnrolling
|
| 244 |
+
{
|
| 245 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel)
|
| 246 |
+
{
|
| 247 |
+
kernel.assignCoeff(Index);
|
| 248 |
+
copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Index+1, Stop>::run(kernel);
|
| 249 |
+
}
|
| 250 |
+
};
|
| 251 |
+
|
| 252 |
+
template<typename Kernel, int Stop>
|
| 253 |
+
struct copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Stop, Stop>
|
| 254 |
+
{
|
| 255 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { }
|
| 256 |
+
};
|
| 257 |
+
|
| 258 |
+
/**************************
|
| 259 |
+
*** Inner vectorization ***
|
| 260 |
+
**************************/
|
| 261 |
+
|
| 262 |
+
template<typename Kernel, int Index, int Stop>
|
| 263 |
+
struct copy_using_evaluator_innervec_CompleteUnrolling
|
| 264 |
+
{
|
| 265 |
+
// FIXME: this is not very clean, perhaps this information should be provided by the kernel?
|
| 266 |
+
typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
|
| 267 |
+
typedef typename DstEvaluatorType::XprType DstXprType;
|
| 268 |
+
typedef typename Kernel::PacketType PacketType;
|
| 269 |
+
|
| 270 |
+
enum {
|
| 271 |
+
outer = Index / DstXprType::InnerSizeAtCompileTime,
|
| 272 |
+
inner = Index % DstXprType::InnerSizeAtCompileTime,
|
| 273 |
+
SrcAlignment = Kernel::AssignmentTraits::SrcAlignment,
|
| 274 |
+
DstAlignment = Kernel::AssignmentTraits::DstAlignment
|
| 275 |
+
};
|
| 276 |
+
|
| 277 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 278 |
+
{
|
| 279 |
+
kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
|
| 280 |
+
enum { NextIndex = Index + unpacket_traits<PacketType>::size };
|
| 281 |
+
copy_using_evaluator_innervec_CompleteUnrolling<Kernel, NextIndex, Stop>::run(kernel);
|
| 282 |
+
}
|
| 283 |
+
};
|
| 284 |
+
|
| 285 |
+
template<typename Kernel, int Stop>
|
| 286 |
+
struct copy_using_evaluator_innervec_CompleteUnrolling<Kernel, Stop, Stop>
|
| 287 |
+
{
|
| 288 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { }
|
| 289 |
+
};
|
| 290 |
+
|
| 291 |
+
template<typename Kernel, int Index_, int Stop, int SrcAlignment, int DstAlignment>
|
| 292 |
+
struct copy_using_evaluator_innervec_InnerUnrolling
|
| 293 |
+
{
|
| 294 |
+
typedef typename Kernel::PacketType PacketType;
|
| 295 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer)
|
| 296 |
+
{
|
| 297 |
+
kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, Index_);
|
| 298 |
+
enum { NextIndex = Index_ + unpacket_traits<PacketType>::size };
|
| 299 |
+
copy_using_evaluator_innervec_InnerUnrolling<Kernel, NextIndex, Stop, SrcAlignment, DstAlignment>::run(kernel, outer);
|
| 300 |
+
}
|
| 301 |
+
};
|
| 302 |
+
|
| 303 |
+
template<typename Kernel, int Stop, int SrcAlignment, int DstAlignment>
|
| 304 |
+
struct copy_using_evaluator_innervec_InnerUnrolling<Kernel, Stop, Stop, SrcAlignment, DstAlignment>
|
| 305 |
+
{
|
| 306 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &, Index) { }
|
| 307 |
+
};
|
| 308 |
+
|
| 309 |
+
/***************************************************************************
|
| 310 |
+
* Part 3 : implementation of all cases
|
| 311 |
+
***************************************************************************/
|
| 312 |
+
|
| 313 |
+
// dense_assignment_loop is based on assign_impl
|
| 314 |
+
|
| 315 |
+
template<typename Kernel,
|
| 316 |
+
int Traversal = Kernel::AssignmentTraits::Traversal,
|
| 317 |
+
int Unrolling = Kernel::AssignmentTraits::Unrolling>
|
| 318 |
+
struct dense_assignment_loop;
|
| 319 |
+
|
| 320 |
+
/************************
|
| 321 |
+
***** Special Cases *****
|
| 322 |
+
************************/
|
| 323 |
+
|
| 324 |
+
// Zero-sized assignment is a no-op.
|
| 325 |
+
template<typename Kernel, int Unrolling>
|
| 326 |
+
struct dense_assignment_loop<Kernel, AllAtOnceTraversal, Unrolling>
|
| 327 |
+
{
|
| 328 |
+
EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel& /*kernel*/)
|
| 329 |
+
{
|
| 330 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 331 |
+
EIGEN_STATIC_ASSERT(int(DstXprType::SizeAtCompileTime) == 0,
|
| 332 |
+
EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT)
|
| 333 |
+
}
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
/************************
|
| 337 |
+
*** Default traversal ***
|
| 338 |
+
************************/
|
| 339 |
+
|
| 340 |
+
template<typename Kernel>
|
| 341 |
+
struct dense_assignment_loop<Kernel, DefaultTraversal, NoUnrolling>
|
| 342 |
+
{
|
| 343 |
+
EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel &kernel)
|
| 344 |
+
{
|
| 345 |
+
for(Index outer = 0; outer < kernel.outerSize(); ++outer) {
|
| 346 |
+
for(Index inner = 0; inner < kernel.innerSize(); ++inner) {
|
| 347 |
+
kernel.assignCoeffByOuterInner(outer, inner);
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
};
|
| 352 |
+
|
| 353 |
+
template<typename Kernel>
|
| 354 |
+
struct dense_assignment_loop<Kernel, DefaultTraversal, CompleteUnrolling>
|
| 355 |
+
{
|
| 356 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 357 |
+
{
|
| 358 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 359 |
+
copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
|
| 360 |
+
}
|
| 361 |
+
};
|
| 362 |
+
|
| 363 |
+
template<typename Kernel>
|
| 364 |
+
struct dense_assignment_loop<Kernel, DefaultTraversal, InnerUnrolling>
|
| 365 |
+
{
|
| 366 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 367 |
+
{
|
| 368 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 369 |
+
|
| 370 |
+
const Index outerSize = kernel.outerSize();
|
| 371 |
+
for(Index outer = 0; outer < outerSize; ++outer)
|
| 372 |
+
copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, 0, DstXprType::InnerSizeAtCompileTime>::run(kernel, outer);
|
| 373 |
+
}
|
| 374 |
+
};
|
| 375 |
+
|
| 376 |
+
/***************************
|
| 377 |
+
*** Linear vectorization ***
|
| 378 |
+
***************************/
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
// The goal of unaligned_dense_assignment_loop is simply to factorize the handling
|
| 382 |
+
// of the non vectorizable beginning and ending parts
|
| 383 |
+
|
| 384 |
+
template <bool IsAligned = false>
|
| 385 |
+
struct unaligned_dense_assignment_loop
|
| 386 |
+
{
|
| 387 |
+
// if IsAligned = true, then do nothing
|
| 388 |
+
template <typename Kernel>
|
| 389 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index, Index) {}
|
| 390 |
+
};
|
| 391 |
+
|
| 392 |
+
template <>
|
| 393 |
+
struct unaligned_dense_assignment_loop<false>
|
| 394 |
+
{
|
| 395 |
+
// MSVC must not inline this functions. If it does, it fails to optimize the
|
| 396 |
+
// packet access path.
|
| 397 |
+
// FIXME check which version exhibits this issue
|
| 398 |
+
#if EIGEN_COMP_MSVC
|
| 399 |
+
template <typename Kernel>
|
| 400 |
+
static EIGEN_DONT_INLINE void run(Kernel &kernel,
|
| 401 |
+
Index start,
|
| 402 |
+
Index end)
|
| 403 |
+
#else
|
| 404 |
+
template <typename Kernel>
|
| 405 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel,
|
| 406 |
+
Index start,
|
| 407 |
+
Index end)
|
| 408 |
+
#endif
|
| 409 |
+
{
|
| 410 |
+
for (Index index = start; index < end; ++index)
|
| 411 |
+
kernel.assignCoeff(index);
|
| 412 |
+
}
|
| 413 |
+
};
|
| 414 |
+
|
| 415 |
+
template<typename Kernel>
|
| 416 |
+
struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling>
|
| 417 |
+
{
|
| 418 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 419 |
+
{
|
| 420 |
+
const Index size = kernel.size();
|
| 421 |
+
typedef typename Kernel::Scalar Scalar;
|
| 422 |
+
typedef typename Kernel::PacketType PacketType;
|
| 423 |
+
enum {
|
| 424 |
+
requestedAlignment = Kernel::AssignmentTraits::LinearRequiredAlignment,
|
| 425 |
+
packetSize = unpacket_traits<PacketType>::size,
|
| 426 |
+
dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment)>=int(requestedAlignment),
|
| 427 |
+
dstAlignment = packet_traits<Scalar>::AlignedOnScalar ? int(requestedAlignment)
|
| 428 |
+
: int(Kernel::AssignmentTraits::DstAlignment),
|
| 429 |
+
srcAlignment = Kernel::AssignmentTraits::JointAlignment
|
| 430 |
+
};
|
| 431 |
+
const Index alignedStart = dstIsAligned ? 0 : internal::first_aligned<requestedAlignment>(kernel.dstDataPtr(), size);
|
| 432 |
+
const Index alignedEnd = alignedStart + ((size-alignedStart)/packetSize)*packetSize;
|
| 433 |
+
|
| 434 |
+
unaligned_dense_assignment_loop<dstIsAligned!=0>::run(kernel, 0, alignedStart);
|
| 435 |
+
|
| 436 |
+
for(Index index = alignedStart; index < alignedEnd; index += packetSize)
|
| 437 |
+
kernel.template assignPacket<dstAlignment, srcAlignment, PacketType>(index);
|
| 438 |
+
|
| 439 |
+
unaligned_dense_assignment_loop<>::run(kernel, alignedEnd, size);
|
| 440 |
+
}
|
| 441 |
+
};
|
| 442 |
+
|
| 443 |
+
template<typename Kernel>
|
| 444 |
+
struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, CompleteUnrolling>
|
| 445 |
+
{
|
| 446 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 447 |
+
{
|
| 448 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 449 |
+
typedef typename Kernel::PacketType PacketType;
|
| 450 |
+
|
| 451 |
+
enum { size = DstXprType::SizeAtCompileTime,
|
| 452 |
+
packetSize =unpacket_traits<PacketType>::size,
|
| 453 |
+
alignedSize = (int(size)/packetSize)*packetSize };
|
| 454 |
+
|
| 455 |
+
copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, alignedSize>::run(kernel);
|
| 456 |
+
copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, alignedSize, size>::run(kernel);
|
| 457 |
+
}
|
| 458 |
+
};
|
| 459 |
+
|
| 460 |
+
/**************************
|
| 461 |
+
*** Inner vectorization ***
|
| 462 |
+
**************************/
|
| 463 |
+
|
| 464 |
+
template<typename Kernel>
|
| 465 |
+
struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, NoUnrolling>
|
| 466 |
+
{
|
| 467 |
+
typedef typename Kernel::PacketType PacketType;
|
| 468 |
+
enum {
|
| 469 |
+
SrcAlignment = Kernel::AssignmentTraits::SrcAlignment,
|
| 470 |
+
DstAlignment = Kernel::AssignmentTraits::DstAlignment
|
| 471 |
+
};
|
| 472 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 473 |
+
{
|
| 474 |
+
const Index innerSize = kernel.innerSize();
|
| 475 |
+
const Index outerSize = kernel.outerSize();
|
| 476 |
+
const Index packetSize = unpacket_traits<PacketType>::size;
|
| 477 |
+
for(Index outer = 0; outer < outerSize; ++outer)
|
| 478 |
+
for(Index inner = 0; inner < innerSize; inner+=packetSize)
|
| 479 |
+
kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
|
| 480 |
+
}
|
| 481 |
+
};
|
| 482 |
+
|
| 483 |
+
template<typename Kernel>
|
| 484 |
+
struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, CompleteUnrolling>
|
| 485 |
+
{
|
| 486 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 487 |
+
{
|
| 488 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 489 |
+
copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
|
| 490 |
+
}
|
| 491 |
+
};
|
| 492 |
+
|
| 493 |
+
template<typename Kernel>
|
| 494 |
+
struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, InnerUnrolling>
|
| 495 |
+
{
|
| 496 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 497 |
+
{
|
| 498 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 499 |
+
typedef typename Kernel::AssignmentTraits Traits;
|
| 500 |
+
const Index outerSize = kernel.outerSize();
|
| 501 |
+
for(Index outer = 0; outer < outerSize; ++outer)
|
| 502 |
+
copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, DstXprType::InnerSizeAtCompileTime,
|
| 503 |
+
Traits::SrcAlignment, Traits::DstAlignment>::run(kernel, outer);
|
| 504 |
+
}
|
| 505 |
+
};
|
| 506 |
+
|
| 507 |
+
/***********************
|
| 508 |
+
*** Linear traversal ***
|
| 509 |
+
***********************/
|
| 510 |
+
|
| 511 |
+
template<typename Kernel>
|
| 512 |
+
struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling>
|
| 513 |
+
{
|
| 514 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 515 |
+
{
|
| 516 |
+
const Index size = kernel.size();
|
| 517 |
+
for(Index i = 0; i < size; ++i)
|
| 518 |
+
kernel.assignCoeff(i);
|
| 519 |
+
}
|
| 520 |
+
};
|
| 521 |
+
|
| 522 |
+
template<typename Kernel>
|
| 523 |
+
struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling>
|
| 524 |
+
{
|
| 525 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 526 |
+
{
|
| 527 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 528 |
+
copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
|
| 529 |
+
}
|
| 530 |
+
};
|
| 531 |
+
|
| 532 |
+
/**************************
|
| 533 |
+
*** Slice vectorization ***
|
| 534 |
+
***************************/
|
| 535 |
+
|
| 536 |
+
template<typename Kernel>
|
| 537 |
+
struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling>
|
| 538 |
+
{
|
| 539 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 540 |
+
{
|
| 541 |
+
typedef typename Kernel::Scalar Scalar;
|
| 542 |
+
typedef typename Kernel::PacketType PacketType;
|
| 543 |
+
enum {
|
| 544 |
+
packetSize = unpacket_traits<PacketType>::size,
|
| 545 |
+
requestedAlignment = int(Kernel::AssignmentTraits::InnerRequiredAlignment),
|
| 546 |
+
alignable = packet_traits<Scalar>::AlignedOnScalar || int(Kernel::AssignmentTraits::DstAlignment)>=sizeof(Scalar),
|
| 547 |
+
dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment)>=int(requestedAlignment),
|
| 548 |
+
dstAlignment = alignable ? int(requestedAlignment)
|
| 549 |
+
: int(Kernel::AssignmentTraits::DstAlignment)
|
| 550 |
+
};
|
| 551 |
+
const Scalar *dst_ptr = kernel.dstDataPtr();
|
| 552 |
+
if((!bool(dstIsAligned)) && (UIntPtr(dst_ptr) % sizeof(Scalar))>0)
|
| 553 |
+
{
|
| 554 |
+
// the pointer is not aligned-on scalar, so alignment is not possible
|
| 555 |
+
return dense_assignment_loop<Kernel,DefaultTraversal,NoUnrolling>::run(kernel);
|
| 556 |
+
}
|
| 557 |
+
const Index packetAlignedMask = packetSize - 1;
|
| 558 |
+
const Index innerSize = kernel.innerSize();
|
| 559 |
+
const Index outerSize = kernel.outerSize();
|
| 560 |
+
const Index alignedStep = alignable ? (packetSize - kernel.outerStride() % packetSize) & packetAlignedMask : 0;
|
| 561 |
+
Index alignedStart = ((!alignable) || bool(dstIsAligned)) ? 0 : internal::first_aligned<requestedAlignment>(dst_ptr, innerSize);
|
| 562 |
+
|
| 563 |
+
for(Index outer = 0; outer < outerSize; ++outer)
|
| 564 |
+
{
|
| 565 |
+
const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask);
|
| 566 |
+
// do the non-vectorizable part of the assignment
|
| 567 |
+
for(Index inner = 0; inner<alignedStart ; ++inner)
|
| 568 |
+
kernel.assignCoeffByOuterInner(outer, inner);
|
| 569 |
+
|
| 570 |
+
// do the vectorizable part of the assignment
|
| 571 |
+
for(Index inner = alignedStart; inner<alignedEnd; inner+=packetSize)
|
| 572 |
+
kernel.template assignPacketByOuterInner<dstAlignment, Unaligned, PacketType>(outer, inner);
|
| 573 |
+
|
| 574 |
+
// do the non-vectorizable part of the assignment
|
| 575 |
+
for(Index inner = alignedEnd; inner<innerSize ; ++inner)
|
| 576 |
+
kernel.assignCoeffByOuterInner(outer, inner);
|
| 577 |
+
|
| 578 |
+
alignedStart = numext::mini((alignedStart+alignedStep)%packetSize, innerSize);
|
| 579 |
+
}
|
| 580 |
+
}
|
| 581 |
+
};
|
| 582 |
+
|
| 583 |
+
#if EIGEN_UNALIGNED_VECTORIZE
|
| 584 |
+
template<typename Kernel>
|
| 585 |
+
struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, InnerUnrolling>
|
| 586 |
+
{
|
| 587 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel)
|
| 588 |
+
{
|
| 589 |
+
typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
|
| 590 |
+
typedef typename Kernel::PacketType PacketType;
|
| 591 |
+
|
| 592 |
+
enum { innerSize = DstXprType::InnerSizeAtCompileTime,
|
| 593 |
+
packetSize =unpacket_traits<PacketType>::size,
|
| 594 |
+
vectorizableSize = (int(innerSize) / int(packetSize)) * int(packetSize),
|
| 595 |
+
size = DstXprType::SizeAtCompileTime };
|
| 596 |
+
|
| 597 |
+
for(Index outer = 0; outer < kernel.outerSize(); ++outer)
|
| 598 |
+
{
|
| 599 |
+
copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, vectorizableSize, 0, 0>::run(kernel, outer);
|
| 600 |
+
copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, vectorizableSize, innerSize>::run(kernel, outer);
|
| 601 |
+
}
|
| 602 |
+
}
|
| 603 |
+
};
|
| 604 |
+
#endif
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
/***************************************************************************
|
| 608 |
+
* Part 4 : Generic dense assignment kernel
|
| 609 |
+
***************************************************************************/
|
| 610 |
+
|
| 611 |
+
// This class generalize the assignment of a coefficient (or packet) from one dense evaluator
|
| 612 |
+
// to another dense writable evaluator.
|
| 613 |
+
// It is parametrized by the two evaluators, and the actual assignment functor.
|
| 614 |
+
// This abstraction level permits to keep the evaluation loops as simple and as generic as possible.
|
| 615 |
+
// One can customize the assignment using this generic dense_assignment_kernel with different
|
| 616 |
+
// functors, or by completely overloading it, by-passing a functor.
|
| 617 |
+
template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version = Specialized>
|
| 618 |
+
class generic_dense_assignment_kernel
|
| 619 |
+
{
|
| 620 |
+
protected:
|
| 621 |
+
typedef typename DstEvaluatorTypeT::XprType DstXprType;
|
| 622 |
+
typedef typename SrcEvaluatorTypeT::XprType SrcXprType;
|
| 623 |
+
public:
|
| 624 |
+
|
| 625 |
+
typedef DstEvaluatorTypeT DstEvaluatorType;
|
| 626 |
+
typedef SrcEvaluatorTypeT SrcEvaluatorType;
|
| 627 |
+
typedef typename DstEvaluatorType::Scalar Scalar;
|
| 628 |
+
typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor> AssignmentTraits;
|
| 629 |
+
typedef typename AssignmentTraits::PacketType PacketType;
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 633 |
+
generic_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType& dstExpr)
|
| 634 |
+
: m_dst(dst), m_src(src), m_functor(func), m_dstExpr(dstExpr)
|
| 635 |
+
{
|
| 636 |
+
#ifdef EIGEN_DEBUG_ASSIGN
|
| 637 |
+
AssignmentTraits::debug();
|
| 638 |
+
#endif
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_dstExpr.size(); }
|
| 642 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const EIGEN_NOEXCEPT { return m_dstExpr.innerSize(); }
|
| 643 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const EIGEN_NOEXCEPT { return m_dstExpr.outerSize(); }
|
| 644 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_dstExpr.rows(); }
|
| 645 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_dstExpr.cols(); }
|
| 646 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT { return m_dstExpr.outerStride(); }
|
| 647 |
+
|
| 648 |
+
EIGEN_DEVICE_FUNC DstEvaluatorType& dstEvaluator() EIGEN_NOEXCEPT { return m_dst; }
|
| 649 |
+
EIGEN_DEVICE_FUNC const SrcEvaluatorType& srcEvaluator() const EIGEN_NOEXCEPT { return m_src; }
|
| 650 |
+
|
| 651 |
+
/// Assign src(row,col) to dst(row,col) through the assignment functor.
|
| 652 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col)
|
| 653 |
+
{
|
| 654 |
+
m_functor.assignCoeff(m_dst.coeffRef(row,col), m_src.coeff(row,col));
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
/// \sa assignCoeff(Index,Index)
|
| 658 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index)
|
| 659 |
+
{
|
| 660 |
+
m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index));
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
/// \sa assignCoeff(Index,Index)
|
| 664 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner)
|
| 665 |
+
{
|
| 666 |
+
Index row = rowIndexByOuterInner(outer, inner);
|
| 667 |
+
Index col = colIndexByOuterInner(outer, inner);
|
| 668 |
+
assignCoeff(row, col);
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
template<int StoreMode, int LoadMode, typename PacketType>
|
| 673 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index row, Index col)
|
| 674 |
+
{
|
| 675 |
+
m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(row,col), m_src.template packet<LoadMode,PacketType>(row,col));
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
template<int StoreMode, int LoadMode, typename PacketType>
|
| 679 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index index)
|
| 680 |
+
{
|
| 681 |
+
m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(index), m_src.template packet<LoadMode,PacketType>(index));
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
template<int StoreMode, int LoadMode, typename PacketType>
|
| 685 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner)
|
| 686 |
+
{
|
| 687 |
+
Index row = rowIndexByOuterInner(outer, inner);
|
| 688 |
+
Index col = colIndexByOuterInner(outer, inner);
|
| 689 |
+
assignPacket<StoreMode,LoadMode,PacketType>(row, col);
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner)
|
| 693 |
+
{
|
| 694 |
+
typedef typename DstEvaluatorType::ExpressionTraits Traits;
|
| 695 |
+
return int(Traits::RowsAtCompileTime) == 1 ? 0
|
| 696 |
+
: int(Traits::ColsAtCompileTime) == 1 ? inner
|
| 697 |
+
: int(DstEvaluatorType::Flags)&RowMajorBit ? outer
|
| 698 |
+
: inner;
|
| 699 |
+
}
|
| 700 |
+
|
| 701 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner)
|
| 702 |
+
{
|
| 703 |
+
typedef typename DstEvaluatorType::ExpressionTraits Traits;
|
| 704 |
+
return int(Traits::ColsAtCompileTime) == 1 ? 0
|
| 705 |
+
: int(Traits::RowsAtCompileTime) == 1 ? inner
|
| 706 |
+
: int(DstEvaluatorType::Flags)&RowMajorBit ? inner
|
| 707 |
+
: outer;
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
EIGEN_DEVICE_FUNC const Scalar* dstDataPtr() const
|
| 711 |
+
{
|
| 712 |
+
return m_dstExpr.data();
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
protected:
|
| 716 |
+
DstEvaluatorType& m_dst;
|
| 717 |
+
const SrcEvaluatorType& m_src;
|
| 718 |
+
const Functor &m_functor;
|
| 719 |
+
// TODO find a way to avoid the needs of the original expression
|
| 720 |
+
DstXprType& m_dstExpr;
|
| 721 |
+
};
|
| 722 |
+
|
| 723 |
+
// Special kernel used when computing small products whose operands have dynamic dimensions. It ensures that the
|
| 724 |
+
// PacketSize used is no larger than 4, thereby increasing the chance that vectorized instructions will be used
|
| 725 |
+
// when computing the product.
|
| 726 |
+
|
| 727 |
+
template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor>
|
| 728 |
+
class restricted_packet_dense_assignment_kernel : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn>
|
| 729 |
+
{
|
| 730 |
+
protected:
|
| 731 |
+
typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn> Base;
|
| 732 |
+
public:
|
| 733 |
+
typedef typename Base::Scalar Scalar;
|
| 734 |
+
typedef typename Base::DstXprType DstXprType;
|
| 735 |
+
typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, 4> AssignmentTraits;
|
| 736 |
+
typedef typename AssignmentTraits::PacketType PacketType;
|
| 737 |
+
|
| 738 |
+
EIGEN_DEVICE_FUNC restricted_packet_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr)
|
| 739 |
+
: Base(dst, src, func, dstExpr)
|
| 740 |
+
{
|
| 741 |
+
}
|
| 742 |
+
};
|
| 743 |
+
|
| 744 |
+
/***************************************************************************
|
| 745 |
+
* Part 5 : Entry point for dense rectangular assignment
|
| 746 |
+
***************************************************************************/
|
| 747 |
+
|
| 748 |
+
template<typename DstXprType,typename SrcXprType, typename Functor>
|
| 749 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 750 |
+
void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const Functor &/*func*/)
|
| 751 |
+
{
|
| 752 |
+
EIGEN_ONLY_USED_FOR_DEBUG(dst);
|
| 753 |
+
EIGEN_ONLY_USED_FOR_DEBUG(src);
|
| 754 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
template<typename DstXprType,typename SrcXprType, typename T1, typename T2>
|
| 758 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 759 |
+
void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const internal::assign_op<T1,T2> &/*func*/)
|
| 760 |
+
{
|
| 761 |
+
Index dstRows = src.rows();
|
| 762 |
+
Index dstCols = src.cols();
|
| 763 |
+
if(((dst.rows()!=dstRows) || (dst.cols()!=dstCols)))
|
| 764 |
+
dst.resize(dstRows, dstCols);
|
| 765 |
+
eigen_assert(dst.rows() == dstRows && dst.cols() == dstCols);
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
template<typename DstXprType, typename SrcXprType, typename Functor>
|
| 769 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func)
|
| 770 |
+
{
|
| 771 |
+
typedef evaluator<DstXprType> DstEvaluatorType;
|
| 772 |
+
typedef evaluator<SrcXprType> SrcEvaluatorType;
|
| 773 |
+
|
| 774 |
+
SrcEvaluatorType srcEvaluator(src);
|
| 775 |
+
|
| 776 |
+
// NOTE To properly handle A = (A*A.transpose())/s with A rectangular,
|
| 777 |
+
// we need to resize the destination after the source evaluator has been created.
|
| 778 |
+
resize_if_allowed(dst, src, func);
|
| 779 |
+
|
| 780 |
+
DstEvaluatorType dstEvaluator(dst);
|
| 781 |
+
|
| 782 |
+
typedef generic_dense_assignment_kernel<DstEvaluatorType,SrcEvaluatorType,Functor> Kernel;
|
| 783 |
+
Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
|
| 784 |
+
|
| 785 |
+
dense_assignment_loop<Kernel>::run(kernel);
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
// Specialization for filling the destination with a constant value.
|
| 789 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 790 |
+
template<typename DstXprType>
|
| 791 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<typename DstXprType::Scalar>, DstXprType>& src, const internal::assign_op<typename DstXprType::Scalar,typename DstXprType::Scalar>& func)
|
| 792 |
+
{
|
| 793 |
+
resize_if_allowed(dst, src, func);
|
| 794 |
+
std::fill_n(dst.data(), dst.size(), src.functor()());
|
| 795 |
+
}
|
| 796 |
+
#endif
|
| 797 |
+
|
| 798 |
+
template<typename DstXprType, typename SrcXprType>
|
| 799 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src)
|
| 800 |
+
{
|
| 801 |
+
call_dense_assignment_loop(dst, src, internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar>());
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
/***************************************************************************
|
| 805 |
+
* Part 6 : Generic assignment
|
| 806 |
+
***************************************************************************/
|
| 807 |
+
|
| 808 |
+
// Based on the respective shapes of the destination and source,
|
| 809 |
+
// the class AssignmentKind determine the kind of assignment mechanism.
|
| 810 |
+
// AssignmentKind must define a Kind typedef.
|
| 811 |
+
template<typename DstShape, typename SrcShape> struct AssignmentKind;
|
| 812 |
+
|
| 813 |
+
// Assignment kind defined in this file:
|
| 814 |
+
struct Dense2Dense {};
|
| 815 |
+
struct EigenBase2EigenBase {};
|
| 816 |
+
|
| 817 |
+
template<typename,typename> struct AssignmentKind { typedef EigenBase2EigenBase Kind; };
|
| 818 |
+
template<> struct AssignmentKind<DenseShape,DenseShape> { typedef Dense2Dense Kind; };
|
| 819 |
+
|
| 820 |
+
// This is the main assignment class
|
| 821 |
+
template< typename DstXprType, typename SrcXprType, typename Functor,
|
| 822 |
+
typename Kind = typename AssignmentKind< typename evaluator_traits<DstXprType>::Shape , typename evaluator_traits<SrcXprType>::Shape >::Kind,
|
| 823 |
+
typename EnableIf = void>
|
| 824 |
+
struct Assignment;
|
| 825 |
+
|
| 826 |
+
|
| 827 |
+
// The only purpose of this call_assignment() function is to deal with noalias() / "assume-aliasing" and automatic transposition.
|
| 828 |
+
// Indeed, I (Gael) think that this concept of "assume-aliasing" was a mistake, and it makes thing quite complicated.
|
| 829 |
+
// So this intermediate function removes everything related to "assume-aliasing" such that Assignment
|
| 830 |
+
// does not has to bother about these annoying details.
|
| 831 |
+
|
| 832 |
+
template<typename Dst, typename Src>
|
| 833 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 834 |
+
void call_assignment(Dst& dst, const Src& src)
|
| 835 |
+
{
|
| 836 |
+
call_assignment(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
|
| 837 |
+
}
|
| 838 |
+
template<typename Dst, typename Src>
|
| 839 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 840 |
+
void call_assignment(const Dst& dst, const Src& src)
|
| 841 |
+
{
|
| 842 |
+
call_assignment(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
|
| 843 |
+
}
|
| 844 |
+
|
| 845 |
+
// Deal with "assume-aliasing"
|
| 846 |
+
template<typename Dst, typename Src, typename Func>
|
| 847 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 848 |
+
void call_assignment(Dst& dst, const Src& src, const Func& func, typename enable_if< evaluator_assume_aliasing<Src>::value, void*>::type = 0)
|
| 849 |
+
{
|
| 850 |
+
typename plain_matrix_type<Src>::type tmp(src);
|
| 851 |
+
call_assignment_no_alias(dst, tmp, func);
|
| 852 |
+
}
|
| 853 |
+
|
| 854 |
+
template<typename Dst, typename Src, typename Func>
|
| 855 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 856 |
+
void call_assignment(Dst& dst, const Src& src, const Func& func, typename enable_if<!evaluator_assume_aliasing<Src>::value, void*>::type = 0)
|
| 857 |
+
{
|
| 858 |
+
call_assignment_no_alias(dst, src, func);
|
| 859 |
+
}
|
| 860 |
+
|
| 861 |
+
// by-pass "assume-aliasing"
|
| 862 |
+
// When there is no aliasing, we require that 'dst' has been properly resized
|
| 863 |
+
template<typename Dst, template <typename> class StorageBase, typename Src, typename Func>
|
| 864 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 865 |
+
void call_assignment(NoAlias<Dst,StorageBase>& dst, const Src& src, const Func& func)
|
| 866 |
+
{
|
| 867 |
+
call_assignment_no_alias(dst.expression(), src, func);
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
template<typename Dst, typename Src, typename Func>
|
| 872 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 873 |
+
void call_assignment_no_alias(Dst& dst, const Src& src, const Func& func)
|
| 874 |
+
{
|
| 875 |
+
enum {
|
| 876 |
+
NeedToTranspose = ( (int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1)
|
| 877 |
+
|| (int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1)
|
| 878 |
+
) && int(Dst::SizeAtCompileTime) != 1
|
| 879 |
+
};
|
| 880 |
+
|
| 881 |
+
typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst>::type ActualDstTypeCleaned;
|
| 882 |
+
typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst&>::type ActualDstType;
|
| 883 |
+
ActualDstType actualDst(dst);
|
| 884 |
+
|
| 885 |
+
// TODO check whether this is the right place to perform these checks:
|
| 886 |
+
EIGEN_STATIC_ASSERT_LVALUE(Dst)
|
| 887 |
+
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned,Src)
|
| 888 |
+
EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);
|
| 889 |
+
|
| 890 |
+
Assignment<ActualDstTypeCleaned,Src,Func>::run(actualDst, src, func);
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
template<typename Dst, typename Src, typename Func>
|
| 894 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 895 |
+
void call_restricted_packet_assignment_no_alias(Dst& dst, const Src& src, const Func& func)
|
| 896 |
+
{
|
| 897 |
+
typedef evaluator<Dst> DstEvaluatorType;
|
| 898 |
+
typedef evaluator<Src> SrcEvaluatorType;
|
| 899 |
+
typedef restricted_packet_dense_assignment_kernel<DstEvaluatorType,SrcEvaluatorType,Func> Kernel;
|
| 900 |
+
|
| 901 |
+
EIGEN_STATIC_ASSERT_LVALUE(Dst)
|
| 902 |
+
EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename Dst::Scalar,typename Src::Scalar);
|
| 903 |
+
|
| 904 |
+
SrcEvaluatorType srcEvaluator(src);
|
| 905 |
+
resize_if_allowed(dst, src, func);
|
| 906 |
+
|
| 907 |
+
DstEvaluatorType dstEvaluator(dst);
|
| 908 |
+
Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
|
| 909 |
+
|
| 910 |
+
dense_assignment_loop<Kernel>::run(kernel);
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
template<typename Dst, typename Src>
|
| 914 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 915 |
+
void call_assignment_no_alias(Dst& dst, const Src& src)
|
| 916 |
+
{
|
| 917 |
+
call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
template<typename Dst, typename Src, typename Func>
|
| 921 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 922 |
+
void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src, const Func& func)
|
| 923 |
+
{
|
| 924 |
+
// TODO check whether this is the right place to perform these checks:
|
| 925 |
+
EIGEN_STATIC_ASSERT_LVALUE(Dst)
|
| 926 |
+
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Dst,Src)
|
| 927 |
+
EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename Dst::Scalar,typename Src::Scalar);
|
| 928 |
+
|
| 929 |
+
Assignment<Dst,Src,Func>::run(dst, src, func);
|
| 930 |
+
}
|
| 931 |
+
template<typename Dst, typename Src>
|
| 932 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 933 |
+
void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src)
|
| 934 |
+
{
|
| 935 |
+
call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
// forward declaration
|
| 939 |
+
template<typename Dst, typename Src> void check_for_aliasing(const Dst &dst, const Src &src);
|
| 940 |
+
|
| 941 |
+
// Generic Dense to Dense assignment
|
| 942 |
+
// Note that the last template argument "Weak" is needed to make it possible to perform
|
| 943 |
+
// both partial specialization+SFINAE without ambiguous specialization
|
| 944 |
+
template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak>
|
| 945 |
+
struct Assignment<DstXprType, SrcXprType, Functor, Dense2Dense, Weak>
|
| 946 |
+
{
|
| 947 |
+
EIGEN_DEVICE_FUNC
|
| 948 |
+
static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
|
| 949 |
+
{
|
| 950 |
+
#ifndef EIGEN_NO_DEBUG
|
| 951 |
+
internal::check_for_aliasing(dst, src);
|
| 952 |
+
#endif
|
| 953 |
+
|
| 954 |
+
call_dense_assignment_loop(dst, src, func);
|
| 955 |
+
}
|
| 956 |
+
};
|
| 957 |
+
|
| 958 |
+
// Generic assignment through evalTo.
|
| 959 |
+
// TODO: not sure we have to keep that one, but it helps porting current code to new evaluator mechanism.
|
| 960 |
+
// Note that the last template argument "Weak" is needed to make it possible to perform
|
| 961 |
+
// both partial specialization+SFINAE without ambiguous specialization
|
| 962 |
+
template< typename DstXprType, typename SrcXprType, typename Functor, typename Weak>
|
| 963 |
+
struct Assignment<DstXprType, SrcXprType, Functor, EigenBase2EigenBase, Weak>
|
| 964 |
+
{
|
| 965 |
+
EIGEN_DEVICE_FUNC
|
| 966 |
+
static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
|
| 967 |
+
{
|
| 968 |
+
Index dstRows = src.rows();
|
| 969 |
+
Index dstCols = src.cols();
|
| 970 |
+
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
|
| 971 |
+
dst.resize(dstRows, dstCols);
|
| 972 |
+
|
| 973 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
| 974 |
+
src.evalTo(dst);
|
| 975 |
+
}
|
| 976 |
+
|
| 977 |
+
// NOTE The following two functions are templated to avoid their instantiation if not needed
|
| 978 |
+
// This is needed because some expressions supports evalTo only and/or have 'void' as scalar type.
|
| 979 |
+
template<typename SrcScalarType>
|
| 980 |
+
EIGEN_DEVICE_FUNC
|
| 981 |
+
static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,SrcScalarType> &/*func*/)
|
| 982 |
+
{
|
| 983 |
+
Index dstRows = src.rows();
|
| 984 |
+
Index dstCols = src.cols();
|
| 985 |
+
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
|
| 986 |
+
dst.resize(dstRows, dstCols);
|
| 987 |
+
|
| 988 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
| 989 |
+
src.addTo(dst);
|
| 990 |
+
}
|
| 991 |
+
|
| 992 |
+
template<typename SrcScalarType>
|
| 993 |
+
EIGEN_DEVICE_FUNC
|
| 994 |
+
static EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,SrcScalarType> &/*func*/)
|
| 995 |
+
{
|
| 996 |
+
Index dstRows = src.rows();
|
| 997 |
+
Index dstCols = src.cols();
|
| 998 |
+
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
|
| 999 |
+
dst.resize(dstRows, dstCols);
|
| 1000 |
+
|
| 1001 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
| 1002 |
+
src.subTo(dst);
|
| 1003 |
+
}
|
| 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2011, Intel Corporation. All rights reserved.
|
| 3 |
+
Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without modification,
|
| 6 |
+
are permitted provided that the following conditions are met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 9 |
+
list of conditions and the following disclaimer.
|
| 10 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
+
this list of conditions and the following disclaimer in the documentation
|
| 12 |
+
and/or other materials provided with the distribution.
|
| 13 |
+
* Neither the name of Intel Corporation nor the names of its contributors may
|
| 14 |
+
be used to endorse or promote products derived from this software without
|
| 15 |
+
specific prior written permission.
|
| 16 |
+
|
| 17 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 18 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 19 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 20 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 21 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 22 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 23 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 24 |
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 26 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
********************************************************************************
|
| 29 |
+
* Content : Eigen bindings to Intel(R) MKL
|
| 30 |
+
* MKL VML support for coefficient-wise unary Eigen expressions like a=b.sin()
|
| 31 |
+
********************************************************************************
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
#ifndef EIGEN_ASSIGN_VML_H
|
| 35 |
+
#define EIGEN_ASSIGN_VML_H
|
| 36 |
+
|
| 37 |
+
namespace Eigen {
|
| 38 |
+
|
| 39 |
+
namespace internal {
|
| 40 |
+
|
| 41 |
+
template<typename Dst, typename Src>
|
| 42 |
+
class vml_assign_traits
|
| 43 |
+
{
|
| 44 |
+
private:
|
| 45 |
+
enum {
|
| 46 |
+
DstHasDirectAccess = Dst::Flags & DirectAccessBit,
|
| 47 |
+
SrcHasDirectAccess = Src::Flags & DirectAccessBit,
|
| 48 |
+
StorageOrdersAgree = (int(Dst::IsRowMajor) == int(Src::IsRowMajor)),
|
| 49 |
+
InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime)
|
| 50 |
+
: int(Dst::Flags)&RowMajorBit ? int(Dst::ColsAtCompileTime)
|
| 51 |
+
: int(Dst::RowsAtCompileTime),
|
| 52 |
+
InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime)
|
| 53 |
+
: int(Dst::Flags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime)
|
| 54 |
+
: int(Dst::MaxRowsAtCompileTime),
|
| 55 |
+
MaxSizeAtCompileTime = Dst::SizeAtCompileTime,
|
| 56 |
+
|
| 57 |
+
MightEnableVml = StorageOrdersAgree && DstHasDirectAccess && SrcHasDirectAccess && Src::InnerStrideAtCompileTime==1 && Dst::InnerStrideAtCompileTime==1,
|
| 58 |
+
MightLinearize = MightEnableVml && (int(Dst::Flags) & int(Src::Flags) & LinearAccessBit),
|
| 59 |
+
VmlSize = MightLinearize ? MaxSizeAtCompileTime : InnerMaxSize,
|
| 60 |
+
LargeEnough = VmlSize==Dynamic || VmlSize>=EIGEN_MKL_VML_THRESHOLD
|
| 61 |
+
};
|
| 62 |
+
public:
|
| 63 |
+
enum {
|
| 64 |
+
EnableVml = MightEnableVml && LargeEnough,
|
| 65 |
+
Traversal = MightLinearize ? LinearTraversal : DefaultTraversal
|
| 66 |
+
};
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
#define EIGEN_PP_EXPAND(ARG) ARG
|
| 70 |
+
#if !defined (EIGEN_FAST_MATH) || (EIGEN_FAST_MATH != 1)
|
| 71 |
+
#define EIGEN_VMLMODE_EXPAND_xLA , VML_HA
|
| 72 |
+
#else
|
| 73 |
+
#define EIGEN_VMLMODE_EXPAND_xLA , VML_LA
|
| 74 |
+
#endif
|
| 75 |
+
|
| 76 |
+
#define EIGEN_VMLMODE_EXPAND_x_
|
| 77 |
+
|
| 78 |
+
#define EIGEN_VMLMODE_PREFIX_xLA vm
|
| 79 |
+
#define EIGEN_VMLMODE_PREFIX_x_ v
|
| 80 |
+
#define EIGEN_VMLMODE_PREFIX(VMLMODE) EIGEN_CAT(EIGEN_VMLMODE_PREFIX_x,VMLMODE)
|
| 81 |
+
|
| 82 |
+
#define EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \
|
| 83 |
+
template< typename DstXprType, typename SrcXprNested> \
|
| 84 |
+
struct Assignment<DstXprType, CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested>, assign_op<EIGENTYPE,EIGENTYPE>, \
|
| 85 |
+
Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \
|
| 86 |
+
typedef CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested> SrcXprType; \
|
| 87 |
+
static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \
|
| 88 |
+
resize_if_allowed(dst, src, func); \
|
| 89 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \
|
| 90 |
+
if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) { \
|
| 91 |
+
VMLOP(dst.size(), (const VMLTYPE*)src.nestedExpression().data(), \
|
| 92 |
+
(VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \
|
| 93 |
+
} else { \
|
| 94 |
+
const Index outerSize = dst.outerSize(); \
|
| 95 |
+
for(Index outer = 0; outer < outerSize; ++outer) { \
|
| 96 |
+
const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.nestedExpression().coeffRef(outer,0)) : \
|
| 97 |
+
&(src.nestedExpression().coeffRef(0, outer)); \
|
| 98 |
+
EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \
|
| 99 |
+
VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, \
|
| 100 |
+
(VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \
|
| 101 |
+
} \
|
| 102 |
+
} \
|
| 103 |
+
} \
|
| 104 |
+
}; \
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \
|
| 108 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),s##VMLOP), float, float, VMLMODE) \
|
| 109 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),d##VMLOP), double, double, VMLMODE)
|
| 110 |
+
|
| 111 |
+
#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) \
|
| 112 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),c##VMLOP), scomplex, MKL_Complex8, VMLMODE) \
|
| 113 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),z##VMLOP), dcomplex, MKL_Complex16, VMLMODE)
|
| 114 |
+
|
| 115 |
+
#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS(EIGENOP, VMLOP, VMLMODE) \
|
| 116 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \
|
| 117 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sin, Sin, LA)
|
| 121 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(asin, Asin, LA)
|
| 122 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sinh, Sinh, LA)
|
| 123 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cos, Cos, LA)
|
| 124 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(acos, Acos, LA)
|
| 125 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cosh, Cosh, LA)
|
| 126 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tan, Tan, LA)
|
| 127 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(atan, Atan, LA)
|
| 128 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tanh, Tanh, LA)
|
| 129 |
+
// EIGEN_MKL_VML_DECLARE_UNARY_CALLS(abs, Abs, _)
|
| 130 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(exp, Exp, LA)
|
| 131 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log, Ln, LA)
|
| 132 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log10, Log10, LA)
|
| 133 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sqrt, Sqrt, _)
|
| 134 |
+
|
| 135 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(square, Sqr, _)
|
| 136 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(arg, Arg, _)
|
| 137 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(round, Round, _)
|
| 138 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(floor, Floor, _)
|
| 139 |
+
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(ceil, Ceil, _)
|
| 140 |
+
|
| 141 |
+
#define EIGEN_MKL_VML_DECLARE_POW_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \
|
| 142 |
+
template< typename DstXprType, typename SrcXprNested, typename Plain> \
|
| 143 |
+
struct Assignment<DstXprType, CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \
|
| 144 |
+
const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> >, assign_op<EIGENTYPE,EIGENTYPE>, \
|
| 145 |
+
Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \
|
| 146 |
+
typedef CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \
|
| 147 |
+
const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> > SrcXprType; \
|
| 148 |
+
static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \
|
| 149 |
+
resize_if_allowed(dst, src, func); \
|
| 150 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \
|
| 151 |
+
VMLTYPE exponent = reinterpret_cast<const VMLTYPE&>(src.rhs().functor().m_other); \
|
| 152 |
+
if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) \
|
| 153 |
+
{ \
|
| 154 |
+
VMLOP( dst.size(), (const VMLTYPE*)src.lhs().data(), exponent, \
|
| 155 |
+
(VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \
|
| 156 |
+
} else { \
|
| 157 |
+
const Index outerSize = dst.outerSize(); \
|
| 158 |
+
for(Index outer = 0; outer < outerSize; ++outer) { \
|
| 159 |
+
const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.lhs().coeffRef(outer,0)) : \
|
| 160 |
+
&(src.lhs().coeffRef(0, outer)); \
|
| 161 |
+
EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \
|
| 162 |
+
VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, exponent, \
|
| 163 |
+
(VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \
|
| 164 |
+
} \
|
| 165 |
+
} \
|
| 166 |
+
} \
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmsPowx, float, float, LA)
|
| 170 |
+
EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmdPowx, double, double, LA)
|
| 171 |
+
EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmcPowx, scomplex, MKL_Complex8, LA)
|
| 172 |
+
EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmzPowx, dcomplex, MKL_Complex16, LA)
|
| 173 |
+
|
| 174 |
+
} // end namespace internal
|
| 175 |
+
|
| 176 |
+
} // end namespace Eigen
|
| 177 |
+
|
| 178 |
+
#endif // EIGEN_ASSIGN_VML_H
|
include/eigen/Eigen/src/Core/BandMatrix.h
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_BANDMATRIX_H
|
| 11 |
+
#define EIGEN_BANDMATRIX_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
template<typename Derived>
|
| 18 |
+
class BandMatrixBase : public EigenBase<Derived>
|
| 19 |
+
{
|
| 20 |
+
public:
|
| 21 |
+
|
| 22 |
+
enum {
|
| 23 |
+
Flags = internal::traits<Derived>::Flags,
|
| 24 |
+
CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
|
| 25 |
+
RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
|
| 26 |
+
ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
|
| 27 |
+
MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
|
| 28 |
+
MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
|
| 29 |
+
Supers = internal::traits<Derived>::Supers,
|
| 30 |
+
Subs = internal::traits<Derived>::Subs,
|
| 31 |
+
Options = internal::traits<Derived>::Options
|
| 32 |
+
};
|
| 33 |
+
typedef typename internal::traits<Derived>::Scalar Scalar;
|
| 34 |
+
typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> DenseMatrixType;
|
| 35 |
+
typedef typename DenseMatrixType::StorageIndex StorageIndex;
|
| 36 |
+
typedef typename internal::traits<Derived>::CoefficientsType CoefficientsType;
|
| 37 |
+
typedef EigenBase<Derived> Base;
|
| 38 |
+
|
| 39 |
+
protected:
|
| 40 |
+
enum {
|
| 41 |
+
DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic))
|
| 42 |
+
? 1 + Supers + Subs
|
| 43 |
+
: Dynamic,
|
| 44 |
+
SizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime)
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
public:
|
| 48 |
+
|
| 49 |
+
using Base::derived;
|
| 50 |
+
using Base::rows;
|
| 51 |
+
using Base::cols;
|
| 52 |
+
|
| 53 |
+
/** \returns the number of super diagonals */
|
| 54 |
+
inline Index supers() const { return derived().supers(); }
|
| 55 |
+
|
| 56 |
+
/** \returns the number of sub diagonals */
|
| 57 |
+
inline Index subs() const { return derived().subs(); }
|
| 58 |
+
|
| 59 |
+
/** \returns an expression of the underlying coefficient matrix */
|
| 60 |
+
inline const CoefficientsType& coeffs() const { return derived().coeffs(); }
|
| 61 |
+
|
| 62 |
+
/** \returns an expression of the underlying coefficient matrix */
|
| 63 |
+
inline CoefficientsType& coeffs() { return derived().coeffs(); }
|
| 64 |
+
|
| 65 |
+
/** \returns a vector expression of the \a i -th column,
|
| 66 |
+
* only the meaningful part is returned.
|
| 67 |
+
* \warning the internal storage must be column major. */
|
| 68 |
+
inline Block<CoefficientsType,Dynamic,1> col(Index i)
|
| 69 |
+
{
|
| 70 |
+
EIGEN_STATIC_ASSERT((int(Options) & int(RowMajor)) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
|
| 71 |
+
Index start = 0;
|
| 72 |
+
Index len = coeffs().rows();
|
| 73 |
+
if (i<=supers())
|
| 74 |
+
{
|
| 75 |
+
start = supers()-i;
|
| 76 |
+
len = (std::min)(rows(),std::max<Index>(0,coeffs().rows() - (supers()-i)));
|
| 77 |
+
}
|
| 78 |
+
else if (i>=rows()-subs())
|
| 79 |
+
len = std::max<Index>(0,coeffs().rows() - (i + 1 - rows() + subs()));
|
| 80 |
+
return Block<CoefficientsType,Dynamic,1>(coeffs(), start, i, len, 1);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/** \returns a vector expression of the main diagonal */
|
| 84 |
+
inline Block<CoefficientsType,1,SizeAtCompileTime> diagonal()
|
| 85 |
+
{ return Block<CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); }
|
| 86 |
+
|
| 87 |
+
/** \returns a vector expression of the main diagonal (const version) */
|
| 88 |
+
inline const Block<const CoefficientsType,1,SizeAtCompileTime> diagonal() const
|
| 89 |
+
{ return Block<const CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(std::min)(rows(),cols())); }
|
| 90 |
+
|
| 91 |
+
template<int Index> struct DiagonalIntReturnType {
|
| 92 |
+
enum {
|
| 93 |
+
ReturnOpposite = (int(Options) & int(SelfAdjoint)) && (((Index) > 0 && Supers == 0) || ((Index) < 0 && Subs == 0)),
|
| 94 |
+
Conjugate = ReturnOpposite && NumTraits<Scalar>::IsComplex,
|
| 95 |
+
ActualIndex = ReturnOpposite ? -Index : Index,
|
| 96 |
+
DiagonalSize = (RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic)
|
| 97 |
+
? Dynamic
|
| 98 |
+
: (ActualIndex<0
|
| 99 |
+
? EIGEN_SIZE_MIN_PREFER_DYNAMIC(ColsAtCompileTime, RowsAtCompileTime + ActualIndex)
|
| 100 |
+
: EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime, ColsAtCompileTime - ActualIndex))
|
| 101 |
+
};
|
| 102 |
+
typedef Block<CoefficientsType,1, DiagonalSize> BuildType;
|
| 103 |
+
typedef typename internal::conditional<Conjugate,
|
| 104 |
+
CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>,BuildType >,
|
| 105 |
+
BuildType>::type Type;
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
/** \returns a vector expression of the \a N -th sub or super diagonal */
|
| 109 |
+
template<int N> inline typename DiagonalIntReturnType<N>::Type diagonal()
|
| 110 |
+
{
|
| 111 |
+
return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N));
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/** \returns a vector expression of the \a N -th sub or super diagonal */
|
| 115 |
+
template<int N> inline const typename DiagonalIntReturnType<N>::Type diagonal() const
|
| 116 |
+
{
|
| 117 |
+
return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (std::max)(0,N), 1, diagonalLength(N));
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/** \returns a vector expression of the \a i -th sub or super diagonal */
|
| 121 |
+
inline Block<CoefficientsType,1,Dynamic> diagonal(Index i)
|
| 122 |
+
{
|
| 123 |
+
eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
|
| 124 |
+
return Block<CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i));
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/** \returns a vector expression of the \a i -th sub or super diagonal */
|
| 128 |
+
inline const Block<const CoefficientsType,1,Dynamic> diagonal(Index i) const
|
| 129 |
+
{
|
| 130 |
+
eigen_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
|
| 131 |
+
return Block<const CoefficientsType,1,Dynamic>(coeffs(), supers()-i, std::max<Index>(0,i), 1, diagonalLength(i));
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
template<typename Dest> inline void evalTo(Dest& dst) const
|
| 135 |
+
{
|
| 136 |
+
dst.resize(rows(),cols());
|
| 137 |
+
dst.setZero();
|
| 138 |
+
dst.diagonal() = diagonal();
|
| 139 |
+
for (Index i=1; i<=supers();++i)
|
| 140 |
+
dst.diagonal(i) = diagonal(i);
|
| 141 |
+
for (Index i=1; i<=subs();++i)
|
| 142 |
+
dst.diagonal(-i) = diagonal(-i);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
DenseMatrixType toDenseMatrix() const
|
| 146 |
+
{
|
| 147 |
+
DenseMatrixType res(rows(),cols());
|
| 148 |
+
evalTo(res);
|
| 149 |
+
return res;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
protected:
|
| 153 |
+
|
| 154 |
+
inline Index diagonalLength(Index i) const
|
| 155 |
+
{ return i<0 ? (std::min)(cols(),rows()+i) : (std::min)(rows(),cols()-i); }
|
| 156 |
+
};
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* \class BandMatrix
|
| 160 |
+
* \ingroup Core_Module
|
| 161 |
+
*
|
| 162 |
+
* \brief Represents a rectangular matrix with a banded storage
|
| 163 |
+
*
|
| 164 |
+
* \tparam _Scalar Numeric type, i.e. float, double, int
|
| 165 |
+
* \tparam _Rows Number of rows, or \b Dynamic
|
| 166 |
+
* \tparam _Cols Number of columns, or \b Dynamic
|
| 167 |
+
* \tparam _Supers Number of super diagonal
|
| 168 |
+
* \tparam _Subs Number of sub diagonal
|
| 169 |
+
* \tparam _Options A combination of either \b #RowMajor or \b #ColMajor, and of \b #SelfAdjoint
|
| 170 |
+
* The former controls \ref TopicStorageOrders "storage order", and defaults to
|
| 171 |
+
* column-major. The latter controls whether the matrix represents a selfadjoint
|
| 172 |
+
* matrix in which case either Supers of Subs have to be null.
|
| 173 |
+
*
|
| 174 |
+
* \sa class TridiagonalMatrix
|
| 175 |
+
*/
|
| 176 |
+
|
| 177 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options>
|
| 178 |
+
struct traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 179 |
+
{
|
| 180 |
+
typedef _Scalar Scalar;
|
| 181 |
+
typedef Dense StorageKind;
|
| 182 |
+
typedef Eigen::Index StorageIndex;
|
| 183 |
+
enum {
|
| 184 |
+
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
| 185 |
+
RowsAtCompileTime = _Rows,
|
| 186 |
+
ColsAtCompileTime = _Cols,
|
| 187 |
+
MaxRowsAtCompileTime = _Rows,
|
| 188 |
+
MaxColsAtCompileTime = _Cols,
|
| 189 |
+
Flags = LvalueBit,
|
| 190 |
+
Supers = _Supers,
|
| 191 |
+
Subs = _Subs,
|
| 192 |
+
Options = _Options,
|
| 193 |
+
DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic
|
| 194 |
+
};
|
| 195 |
+
typedef Matrix<Scalar, DataRowsAtCompileTime, ColsAtCompileTime, int(Options) & int(RowMajor) ? RowMajor : ColMajor> CoefficientsType;
|
| 196 |
+
};
|
| 197 |
+
|
| 198 |
+
template<typename _Scalar, int Rows, int Cols, int Supers, int Subs, int Options>
|
| 199 |
+
class BandMatrix : public BandMatrixBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
|
| 200 |
+
{
|
| 201 |
+
public:
|
| 202 |
+
|
| 203 |
+
typedef typename internal::traits<BandMatrix>::Scalar Scalar;
|
| 204 |
+
typedef typename internal::traits<BandMatrix>::StorageIndex StorageIndex;
|
| 205 |
+
typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType;
|
| 206 |
+
|
| 207 |
+
explicit inline BandMatrix(Index rows=Rows, Index cols=Cols, Index supers=Supers, Index subs=Subs)
|
| 208 |
+
: m_coeffs(1+supers+subs,cols),
|
| 209 |
+
m_rows(rows), m_supers(supers), m_subs(subs)
|
| 210 |
+
{
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/** \returns the number of columns */
|
| 214 |
+
inline EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); }
|
| 215 |
+
|
| 216 |
+
/** \returns the number of rows */
|
| 217 |
+
inline EIGEN_CONSTEXPR Index cols() const { return m_coeffs.cols(); }
|
| 218 |
+
|
| 219 |
+
/** \returns the number of super diagonals */
|
| 220 |
+
inline EIGEN_CONSTEXPR Index supers() const { return m_supers.value(); }
|
| 221 |
+
|
| 222 |
+
/** \returns the number of sub diagonals */
|
| 223 |
+
inline EIGEN_CONSTEXPR Index subs() const { return m_subs.value(); }
|
| 224 |
+
|
| 225 |
+
inline const CoefficientsType& coeffs() const { return m_coeffs; }
|
| 226 |
+
inline CoefficientsType& coeffs() { return m_coeffs; }
|
| 227 |
+
|
| 228 |
+
protected:
|
| 229 |
+
|
| 230 |
+
CoefficientsType m_coeffs;
|
| 231 |
+
internal::variable_if_dynamic<Index, Rows> m_rows;
|
| 232 |
+
internal::variable_if_dynamic<Index, Supers> m_supers;
|
| 233 |
+
internal::variable_if_dynamic<Index, Subs> m_subs;
|
| 234 |
+
};
|
| 235 |
+
|
| 236 |
+
template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
|
| 237 |
+
class BandMatrixWrapper;
|
| 238 |
+
|
| 239 |
+
template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
|
| 240 |
+
struct traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 241 |
+
{
|
| 242 |
+
typedef typename _CoefficientsType::Scalar Scalar;
|
| 243 |
+
typedef typename _CoefficientsType::StorageKind StorageKind;
|
| 244 |
+
typedef typename _CoefficientsType::StorageIndex StorageIndex;
|
| 245 |
+
enum {
|
| 246 |
+
CoeffReadCost = internal::traits<_CoefficientsType>::CoeffReadCost,
|
| 247 |
+
RowsAtCompileTime = _Rows,
|
| 248 |
+
ColsAtCompileTime = _Cols,
|
| 249 |
+
MaxRowsAtCompileTime = _Rows,
|
| 250 |
+
MaxColsAtCompileTime = _Cols,
|
| 251 |
+
Flags = LvalueBit,
|
| 252 |
+
Supers = _Supers,
|
| 253 |
+
Subs = _Subs,
|
| 254 |
+
Options = _Options,
|
| 255 |
+
DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic)) ? 1 + Supers + Subs : Dynamic
|
| 256 |
+
};
|
| 257 |
+
typedef _CoefficientsType CoefficientsType;
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
|
| 261 |
+
class BandMatrixWrapper : public BandMatrixBase<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 262 |
+
{
|
| 263 |
+
public:
|
| 264 |
+
|
| 265 |
+
typedef typename internal::traits<BandMatrixWrapper>::Scalar Scalar;
|
| 266 |
+
typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType;
|
| 267 |
+
typedef typename internal::traits<BandMatrixWrapper>::StorageIndex StorageIndex;
|
| 268 |
+
|
| 269 |
+
explicit inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows=_Rows, Index cols=_Cols, Index supers=_Supers, Index subs=_Subs)
|
| 270 |
+
: m_coeffs(coeffs),
|
| 271 |
+
m_rows(rows), m_supers(supers), m_subs(subs)
|
| 272 |
+
{
|
| 273 |
+
EIGEN_UNUSED_VARIABLE(cols);
|
| 274 |
+
//internal::assert(coeffs.cols()==cols() && (supers()+subs()+1)==coeffs.rows());
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
/** \returns the number of columns */
|
| 278 |
+
inline EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); }
|
| 279 |
+
|
| 280 |
+
/** \returns the number of rows */
|
| 281 |
+
inline EIGEN_CONSTEXPR Index cols() const { return m_coeffs.cols(); }
|
| 282 |
+
|
| 283 |
+
/** \returns the number of super diagonals */
|
| 284 |
+
inline EIGEN_CONSTEXPR Index supers() const { return m_supers.value(); }
|
| 285 |
+
|
| 286 |
+
/** \returns the number of sub diagonals */
|
| 287 |
+
inline EIGEN_CONSTEXPR Index subs() const { return m_subs.value(); }
|
| 288 |
+
|
| 289 |
+
inline const CoefficientsType& coeffs() const { return m_coeffs; }
|
| 290 |
+
|
| 291 |
+
protected:
|
| 292 |
+
|
| 293 |
+
const CoefficientsType& m_coeffs;
|
| 294 |
+
internal::variable_if_dynamic<Index, _Rows> m_rows;
|
| 295 |
+
internal::variable_if_dynamic<Index, _Supers> m_supers;
|
| 296 |
+
internal::variable_if_dynamic<Index, _Subs> m_subs;
|
| 297 |
+
};
|
| 298 |
+
|
| 299 |
+
/**
|
| 300 |
+
* \class TridiagonalMatrix
|
| 301 |
+
* \ingroup Core_Module
|
| 302 |
+
*
|
| 303 |
+
* \brief Represents a tridiagonal matrix with a compact banded storage
|
| 304 |
+
*
|
| 305 |
+
* \tparam Scalar Numeric type, i.e. float, double, int
|
| 306 |
+
* \tparam Size Number of rows and cols, or \b Dynamic
|
| 307 |
+
* \tparam Options Can be 0 or \b SelfAdjoint
|
| 308 |
+
*
|
| 309 |
+
* \sa class BandMatrix
|
| 310 |
+
*/
|
| 311 |
+
template<typename Scalar, int Size, int Options>
|
| 312 |
+
class TridiagonalMatrix : public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor>
|
| 313 |
+
{
|
| 314 |
+
typedef BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> Base;
|
| 315 |
+
typedef typename Base::StorageIndex StorageIndex;
|
| 316 |
+
public:
|
| 317 |
+
explicit TridiagonalMatrix(Index size = Size) : Base(size,size,Options&SelfAdjoint?0:1,1) {}
|
| 318 |
+
|
| 319 |
+
inline typename Base::template DiagonalIntReturnType<1>::Type super()
|
| 320 |
+
{ return Base::template diagonal<1>(); }
|
| 321 |
+
inline const typename Base::template DiagonalIntReturnType<1>::Type super() const
|
| 322 |
+
{ return Base::template diagonal<1>(); }
|
| 323 |
+
inline typename Base::template DiagonalIntReturnType<-1>::Type sub()
|
| 324 |
+
{ return Base::template diagonal<-1>(); }
|
| 325 |
+
inline const typename Base::template DiagonalIntReturnType<-1>::Type sub() const
|
| 326 |
+
{ return Base::template diagonal<-1>(); }
|
| 327 |
+
protected:
|
| 328 |
+
};
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
struct BandShape {};
|
| 332 |
+
|
| 333 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options>
|
| 334 |
+
struct evaluator_traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 335 |
+
: public evaluator_traits_base<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 336 |
+
{
|
| 337 |
+
typedef BandShape Shape;
|
| 338 |
+
};
|
| 339 |
+
|
| 340 |
+
template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options>
|
| 341 |
+
struct evaluator_traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 342 |
+
: public evaluator_traits_base<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> >
|
| 343 |
+
{
|
| 344 |
+
typedef BandShape Shape;
|
| 345 |
+
};
|
| 346 |
+
|
| 347 |
+
template<> struct AssignmentKind<DenseShape,BandShape> { typedef EigenBase2EigenBase Kind; };
|
| 348 |
+
|
| 349 |
+
} // end namespace internal
|
| 350 |
+
|
| 351 |
+
} // end namespace Eigen
|
| 352 |
+
|
| 353 |
+
#endif // EIGEN_BANDMATRIX_H
|
include/eigen/Eigen/src/Core/Block.h
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_BLOCK_H
|
| 12 |
+
#define EIGEN_BLOCK_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
|
| 18 |
+
struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType>
|
| 19 |
+
{
|
| 20 |
+
typedef typename traits<XprType>::Scalar Scalar;
|
| 21 |
+
typedef typename traits<XprType>::StorageKind StorageKind;
|
| 22 |
+
typedef typename traits<XprType>::XprKind XprKind;
|
| 23 |
+
typedef typename ref_selector<XprType>::type XprTypeNested;
|
| 24 |
+
typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
|
| 25 |
+
enum{
|
| 26 |
+
MatrixRows = traits<XprType>::RowsAtCompileTime,
|
| 27 |
+
MatrixCols = traits<XprType>::ColsAtCompileTime,
|
| 28 |
+
RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
|
| 29 |
+
ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
|
| 30 |
+
MaxRowsAtCompileTime = BlockRows==0 ? 0
|
| 31 |
+
: RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
|
| 32 |
+
: int(traits<XprType>::MaxRowsAtCompileTime),
|
| 33 |
+
MaxColsAtCompileTime = BlockCols==0 ? 0
|
| 34 |
+
: ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
|
| 35 |
+
: int(traits<XprType>::MaxColsAtCompileTime),
|
| 36 |
+
|
| 37 |
+
XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
|
| 38 |
+
IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
|
| 39 |
+
: (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
|
| 40 |
+
: XprTypeIsRowMajor,
|
| 41 |
+
HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
|
| 42 |
+
InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
|
| 43 |
+
InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
|
| 44 |
+
? int(inner_stride_at_compile_time<XprType>::ret)
|
| 45 |
+
: int(outer_stride_at_compile_time<XprType>::ret),
|
| 46 |
+
OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
|
| 47 |
+
? int(outer_stride_at_compile_time<XprType>::ret)
|
| 48 |
+
: int(inner_stride_at_compile_time<XprType>::ret),
|
| 49 |
+
|
| 50 |
+
// FIXME, this traits is rather specialized for dense object and it needs to be cleaned further
|
| 51 |
+
FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
|
| 52 |
+
FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
|
| 53 |
+
Flags = (traits<XprType>::Flags & (DirectAccessBit | (InnerPanel?CompressedAccessBit:0))) | FlagsLvalueBit | FlagsRowMajorBit,
|
| 54 |
+
// FIXME DirectAccessBit should not be handled by expressions
|
| 55 |
+
//
|
| 56 |
+
// Alignment is needed by MapBase's assertions
|
| 57 |
+
// We can sefely set it to false here. Internal alignment errors will be detected by an eigen_internal_assert in the respective evaluator
|
| 58 |
+
Alignment = 0
|
| 59 |
+
};
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false,
|
| 63 |
+
bool HasDirectAccess = internal::has_direct_access<XprType>::ret> class BlockImpl_dense;
|
| 64 |
+
|
| 65 |
+
} // end namespace internal
|
| 66 |
+
|
| 67 |
+
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, typename StorageKind> class BlockImpl;
|
| 68 |
+
|
| 69 |
+
/** \class Block
|
| 70 |
+
* \ingroup Core_Module
|
| 71 |
+
*
|
| 72 |
+
* \brief Expression of a fixed-size or dynamic-size block
|
| 73 |
+
*
|
| 74 |
+
* \tparam XprType the type of the expression in which we are taking a block
|
| 75 |
+
* \tparam BlockRows the number of rows of the block we are taking at compile time (optional)
|
| 76 |
+
* \tparam BlockCols the number of columns of the block we are taking at compile time (optional)
|
| 77 |
+
* \tparam InnerPanel is true, if the block maps to a set of rows of a row major matrix or
|
| 78 |
+
* to set of columns of a column major matrix (optional). The parameter allows to determine
|
| 79 |
+
* at compile time whether aligned access is possible on the block expression.
|
| 80 |
+
*
|
| 81 |
+
* This class represents an expression of either a fixed-size or dynamic-size block. It is the return
|
| 82 |
+
* type of DenseBase::block(Index,Index,Index,Index) and DenseBase::block<int,int>(Index,Index) and
|
| 83 |
+
* most of the time this is the only way it is used.
|
| 84 |
+
*
|
| 85 |
+
* However, if you want to directly maniputate block expressions,
|
| 86 |
+
* for instance if you want to write a function returning such an expression, you
|
| 87 |
+
* will need to use this class.
|
| 88 |
+
*
|
| 89 |
+
* Here is an example illustrating the dynamic case:
|
| 90 |
+
* \include class_Block.cpp
|
| 91 |
+
* Output: \verbinclude class_Block.out
|
| 92 |
+
*
|
| 93 |
+
* \note Even though this expression has dynamic size, in the case where \a XprType
|
| 94 |
+
* has fixed size, this expression inherits a fixed maximal size which means that evaluating
|
| 95 |
+
* it does not cause a dynamic memory allocation.
|
| 96 |
+
*
|
| 97 |
+
* Here is an example illustrating the fixed-size case:
|
| 98 |
+
* \include class_FixedBlock.cpp
|
| 99 |
+
* Output: \verbinclude class_FixedBlock.out
|
| 100 |
+
*
|
| 101 |
+
* \sa DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock
|
| 102 |
+
*/
|
| 103 |
+
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> class Block
|
| 104 |
+
: public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
|
| 105 |
+
{
|
| 106 |
+
typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl;
|
| 107 |
+
public:
|
| 108 |
+
//typedef typename Impl::Base Base;
|
| 109 |
+
typedef Impl Base;
|
| 110 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(Block)
|
| 111 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
|
| 112 |
+
|
| 113 |
+
typedef typename internal::remove_all<XprType>::type NestedExpression;
|
| 114 |
+
|
| 115 |
+
/** Column or Row constructor
|
| 116 |
+
*/
|
| 117 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 118 |
+
Block(XprType& xpr, Index i) : Impl(xpr,i)
|
| 119 |
+
{
|
| 120 |
+
eigen_assert( (i>=0) && (
|
| 121 |
+
((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
|
| 122 |
+
||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/** Fixed-size constructor
|
| 126 |
+
*/
|
| 127 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 128 |
+
Block(XprType& xpr, Index startRow, Index startCol)
|
| 129 |
+
: Impl(xpr, startRow, startCol)
|
| 130 |
+
{
|
| 131 |
+
EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
|
| 132 |
+
eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows()
|
| 133 |
+
&& startCol >= 0 && BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/** Dynamic-size constructor
|
| 137 |
+
*/
|
| 138 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 139 |
+
Block(XprType& xpr,
|
| 140 |
+
Index startRow, Index startCol,
|
| 141 |
+
Index blockRows, Index blockCols)
|
| 142 |
+
: Impl(xpr, startRow, startCol, blockRows, blockCols)
|
| 143 |
+
{
|
| 144 |
+
eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
|
| 145 |
+
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
|
| 146 |
+
eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows
|
| 147 |
+
&& startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols);
|
| 148 |
+
}
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
// The generic default implementation for dense block simplu forward to the internal::BlockImpl_dense
|
| 152 |
+
// that must be specialized for direct and non-direct access...
|
| 153 |
+
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
|
| 154 |
+
class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
|
| 155 |
+
: public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
|
| 156 |
+
{
|
| 157 |
+
typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> Impl;
|
| 158 |
+
typedef typename XprType::StorageIndex StorageIndex;
|
| 159 |
+
public:
|
| 160 |
+
typedef Impl Base;
|
| 161 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
|
| 162 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index i) : Impl(xpr,i) {}
|
| 163 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol) : Impl(xpr, startRow, startCol) {}
|
| 164 |
+
EIGEN_DEVICE_FUNC
|
| 165 |
+
EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
|
| 166 |
+
: Impl(xpr, startRow, startCol, blockRows, blockCols) {}
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
namespace internal {
|
| 170 |
+
|
| 171 |
+
/** \internal Internal implementation of dense Blocks in the general case. */
|
| 172 |
+
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool HasDirectAccess> class BlockImpl_dense
|
| 173 |
+
: public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type
|
| 174 |
+
{
|
| 175 |
+
typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
|
| 176 |
+
typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
|
| 177 |
+
public:
|
| 178 |
+
|
| 179 |
+
typedef typename internal::dense_xpr_base<BlockType>::type Base;
|
| 180 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
|
| 181 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
|
| 182 |
+
|
| 183 |
+
// class InnerIterator; // FIXME apparently never used
|
| 184 |
+
|
| 185 |
+
/** Column or Row constructor
|
| 186 |
+
*/
|
| 187 |
+
EIGEN_DEVICE_FUNC
|
| 188 |
+
inline BlockImpl_dense(XprType& xpr, Index i)
|
| 189 |
+
: m_xpr(xpr),
|
| 190 |
+
// It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime,
|
| 191 |
+
// and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1,
|
| 192 |
+
// all other cases are invalid.
|
| 193 |
+
// The case a 1x1 matrix seems ambiguous, but the result is the same anyway.
|
| 194 |
+
m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
|
| 195 |
+
m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
|
| 196 |
+
m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
|
| 197 |
+
m_blockCols(BlockCols==1 ? 1 : xpr.cols())
|
| 198 |
+
{}
|
| 199 |
+
|
| 200 |
+
/** Fixed-size constructor
|
| 201 |
+
*/
|
| 202 |
+
EIGEN_DEVICE_FUNC
|
| 203 |
+
inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
|
| 204 |
+
: m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
|
| 205 |
+
m_blockRows(BlockRows), m_blockCols(BlockCols)
|
| 206 |
+
{}
|
| 207 |
+
|
| 208 |
+
/** Dynamic-size constructor
|
| 209 |
+
*/
|
| 210 |
+
EIGEN_DEVICE_FUNC
|
| 211 |
+
inline BlockImpl_dense(XprType& xpr,
|
| 212 |
+
Index startRow, Index startCol,
|
| 213 |
+
Index blockRows, Index blockCols)
|
| 214 |
+
: m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
|
| 215 |
+
m_blockRows(blockRows), m_blockCols(blockCols)
|
| 216 |
+
{}
|
| 217 |
+
|
| 218 |
+
EIGEN_DEVICE_FUNC inline Index rows() const { return m_blockRows.value(); }
|
| 219 |
+
EIGEN_DEVICE_FUNC inline Index cols() const { return m_blockCols.value(); }
|
| 220 |
+
|
| 221 |
+
EIGEN_DEVICE_FUNC
|
| 222 |
+
inline Scalar& coeffRef(Index rowId, Index colId)
|
| 223 |
+
{
|
| 224 |
+
EIGEN_STATIC_ASSERT_LVALUE(XprType)
|
| 225 |
+
return m_xpr.coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
EIGEN_DEVICE_FUNC
|
| 229 |
+
inline const Scalar& coeffRef(Index rowId, Index colId) const
|
| 230 |
+
{
|
| 231 |
+
return m_xpr.derived().coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
EIGEN_DEVICE_FUNC
|
| 235 |
+
EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const
|
| 236 |
+
{
|
| 237 |
+
return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value());
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
EIGEN_DEVICE_FUNC
|
| 241 |
+
inline Scalar& coeffRef(Index index)
|
| 242 |
+
{
|
| 243 |
+
EIGEN_STATIC_ASSERT_LVALUE(XprType)
|
| 244 |
+
return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
| 245 |
+
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
EIGEN_DEVICE_FUNC
|
| 249 |
+
inline const Scalar& coeffRef(Index index) const
|
| 250 |
+
{
|
| 251 |
+
return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
| 252 |
+
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
EIGEN_DEVICE_FUNC
|
| 256 |
+
inline const CoeffReturnType coeff(Index index) const
|
| 257 |
+
{
|
| 258 |
+
return m_xpr.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
| 259 |
+
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
template<int LoadMode>
|
| 263 |
+
EIGEN_DEVICE_FUNC inline PacketScalar packet(Index rowId, Index colId) const
|
| 264 |
+
{
|
| 265 |
+
return m_xpr.template packet<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value());
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
template<int LoadMode>
|
| 269 |
+
EIGEN_DEVICE_FUNC inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
|
| 270 |
+
{
|
| 271 |
+
m_xpr.template writePacket<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value(), val);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
template<int LoadMode>
|
| 275 |
+
EIGEN_DEVICE_FUNC inline PacketScalar packet(Index index) const
|
| 276 |
+
{
|
| 277 |
+
return m_xpr.template packet<Unaligned>
|
| 278 |
+
(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
| 279 |
+
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
template<int LoadMode>
|
| 283 |
+
EIGEN_DEVICE_FUNC inline void writePacket(Index index, const PacketScalar& val)
|
| 284 |
+
{
|
| 285 |
+
m_xpr.template writePacket<Unaligned>
|
| 286 |
+
(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
| 287 |
+
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 291 |
+
/** \sa MapBase::data() */
|
| 292 |
+
EIGEN_DEVICE_FUNC inline const Scalar* data() const;
|
| 293 |
+
EIGEN_DEVICE_FUNC inline Index innerStride() const;
|
| 294 |
+
EIGEN_DEVICE_FUNC inline Index outerStride() const;
|
| 295 |
+
#endif
|
| 296 |
+
|
| 297 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 298 |
+
const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const
|
| 299 |
+
{
|
| 300 |
+
return m_xpr;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 304 |
+
XprType& nestedExpression() { return m_xpr; }
|
| 305 |
+
|
| 306 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 307 |
+
StorageIndex startRow() const EIGEN_NOEXCEPT
|
| 308 |
+
{
|
| 309 |
+
return m_startRow.value();
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 313 |
+
StorageIndex startCol() const EIGEN_NOEXCEPT
|
| 314 |
+
{
|
| 315 |
+
return m_startCol.value();
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
protected:
|
| 319 |
+
|
| 320 |
+
XprTypeNested m_xpr;
|
| 321 |
+
const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
|
| 322 |
+
const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
|
| 323 |
+
const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows;
|
| 324 |
+
const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols;
|
| 325 |
+
};
|
| 326 |
+
|
| 327 |
+
/** \internal Internal implementation of dense Blocks in the direct access case.*/
|
| 328 |
+
template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
|
| 329 |
+
class BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true>
|
| 330 |
+
: public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> >
|
| 331 |
+
{
|
| 332 |
+
typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
|
| 333 |
+
typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
|
| 334 |
+
enum {
|
| 335 |
+
XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0
|
| 336 |
+
};
|
| 337 |
+
|
| 338 |
+
/** \internal Returns base+offset (unless base is null, in which case returns null).
|
| 339 |
+
* Adding an offset to nullptr is undefined behavior, so we must avoid it.
|
| 340 |
+
*/
|
| 341 |
+
template <typename Scalar>
|
| 342 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE
|
| 343 |
+
static Scalar* add_to_nullable_pointer(Scalar* base, Index offset)
|
| 344 |
+
{
|
| 345 |
+
return base != NULL ? base+offset : NULL;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
public:
|
| 349 |
+
|
| 350 |
+
typedef MapBase<BlockType> Base;
|
| 351 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
|
| 352 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
|
| 353 |
+
|
| 354 |
+
/** Column or Row constructor
|
| 355 |
+
*/
|
| 356 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 357 |
+
BlockImpl_dense(XprType& xpr, Index i)
|
| 358 |
+
: Base((BlockRows == 0 || BlockCols == 0) ? NULL : add_to_nullable_pointer(xpr.data(),
|
| 359 |
+
i * ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor))
|
| 360 |
+
|| ((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && ( XprTypeIsRowMajor)) ? xpr.innerStride() : xpr.outerStride())),
|
| 361 |
+
BlockRows==1 ? 1 : xpr.rows(),
|
| 362 |
+
BlockCols==1 ? 1 : xpr.cols()),
|
| 363 |
+
m_xpr(xpr),
|
| 364 |
+
m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
|
| 365 |
+
m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)
|
| 366 |
+
{
|
| 367 |
+
init();
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
/** Fixed-size constructor
|
| 371 |
+
*/
|
| 372 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 373 |
+
BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
|
| 374 |
+
: Base((BlockRows == 0 || BlockCols == 0) ? NULL : add_to_nullable_pointer(xpr.data(),
|
| 375 |
+
xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol))),
|
| 376 |
+
m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
|
| 377 |
+
{
|
| 378 |
+
init();
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
/** Dynamic-size constructor
|
| 382 |
+
*/
|
| 383 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 384 |
+
BlockImpl_dense(XprType& xpr,
|
| 385 |
+
Index startRow, Index startCol,
|
| 386 |
+
Index blockRows, Index blockCols)
|
| 387 |
+
: Base((blockRows == 0 || blockCols == 0) ? NULL : add_to_nullable_pointer(xpr.data(),
|
| 388 |
+
xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol)),
|
| 389 |
+
blockRows, blockCols),
|
| 390 |
+
m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
|
| 391 |
+
{
|
| 392 |
+
init();
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 396 |
+
const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const EIGEN_NOEXCEPT
|
| 397 |
+
{
|
| 398 |
+
return m_xpr;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 402 |
+
XprType& nestedExpression() { return m_xpr; }
|
| 403 |
+
|
| 404 |
+
/** \sa MapBase::innerStride() */
|
| 405 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 406 |
+
Index innerStride() const EIGEN_NOEXCEPT
|
| 407 |
+
{
|
| 408 |
+
return internal::traits<BlockType>::HasSameStorageOrderAsXprType
|
| 409 |
+
? m_xpr.innerStride()
|
| 410 |
+
: m_xpr.outerStride();
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
/** \sa MapBase::outerStride() */
|
| 414 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 415 |
+
Index outerStride() const EIGEN_NOEXCEPT
|
| 416 |
+
{
|
| 417 |
+
return internal::traits<BlockType>::HasSameStorageOrderAsXprType
|
| 418 |
+
? m_xpr.outerStride()
|
| 419 |
+
: m_xpr.innerStride();
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 423 |
+
StorageIndex startRow() const EIGEN_NOEXCEPT { return m_startRow.value(); }
|
| 424 |
+
|
| 425 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 426 |
+
StorageIndex startCol() const EIGEN_NOEXCEPT { return m_startCol.value(); }
|
| 427 |
+
|
| 428 |
+
#ifndef __SUNPRO_CC
|
| 429 |
+
// FIXME sunstudio is not friendly with the above friend...
|
| 430 |
+
// META-FIXME there is no 'friend' keyword around here. Is this obsolete?
|
| 431 |
+
protected:
|
| 432 |
+
#endif
|
| 433 |
+
|
| 434 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 435 |
+
/** \internal used by allowAligned() */
|
| 436 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 437 |
+
BlockImpl_dense(XprType& xpr, const Scalar* data, Index blockRows, Index blockCols)
|
| 438 |
+
: Base(data, blockRows, blockCols), m_xpr(xpr)
|
| 439 |
+
{
|
| 440 |
+
init();
|
| 441 |
+
}
|
| 442 |
+
#endif
|
| 443 |
+
|
| 444 |
+
protected:
|
| 445 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 446 |
+
void init()
|
| 447 |
+
{
|
| 448 |
+
m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType
|
| 449 |
+
? m_xpr.outerStride()
|
| 450 |
+
: m_xpr.innerStride();
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
XprTypeNested m_xpr;
|
| 454 |
+
const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
|
| 455 |
+
const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
|
| 456 |
+
Index m_outerStride;
|
| 457 |
+
};
|
| 458 |
+
|
| 459 |
+
} // end namespace internal
|
| 460 |
+
|
| 461 |
+
} // end namespace Eigen
|
| 462 |
+
|
| 463 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_ALLANDANY_H
|
| 11 |
+
#define EIGEN_ALLANDANY_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
template<typename Derived, int UnrollCount, int InnerSize>
|
| 18 |
+
struct all_unroller
|
| 19 |
+
{
|
| 20 |
+
enum {
|
| 21 |
+
IsRowMajor = (int(Derived::Flags) & int(RowMajor)),
|
| 22 |
+
i = (UnrollCount-1) / InnerSize,
|
| 23 |
+
j = (UnrollCount-1) % InnerSize
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
|
| 27 |
+
{
|
| 28 |
+
return all_unroller<Derived, UnrollCount-1, InnerSize>::run(mat) && mat.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i);
|
| 29 |
+
}
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
template<typename Derived, int InnerSize>
|
| 33 |
+
struct all_unroller<Derived, 0, InnerSize>
|
| 34 |
+
{
|
| 35 |
+
EIGEN_DEVICE_FUNC static inline bool run(const Derived &/*mat*/) { return true; }
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
template<typename Derived, int InnerSize>
|
| 39 |
+
struct all_unroller<Derived, Dynamic, InnerSize>
|
| 40 |
+
{
|
| 41 |
+
EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
template<typename Derived, int UnrollCount, int InnerSize>
|
| 45 |
+
struct any_unroller
|
| 46 |
+
{
|
| 47 |
+
enum {
|
| 48 |
+
IsRowMajor = (int(Derived::Flags) & int(RowMajor)),
|
| 49 |
+
i = (UnrollCount-1) / InnerSize,
|
| 50 |
+
j = (UnrollCount-1) % InnerSize
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
|
| 54 |
+
{
|
| 55 |
+
return any_unroller<Derived, UnrollCount-1, InnerSize>::run(mat) || mat.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i);
|
| 56 |
+
}
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
template<typename Derived, int InnerSize>
|
| 60 |
+
struct any_unroller<Derived, 0, InnerSize>
|
| 61 |
+
{
|
| 62 |
+
EIGEN_DEVICE_FUNC static inline bool run(const Derived & /*mat*/) { return false; }
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
template<typename Derived, int InnerSize>
|
| 66 |
+
struct any_unroller<Derived, Dynamic, InnerSize>
|
| 67 |
+
{
|
| 68 |
+
EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
} // end namespace internal
|
| 72 |
+
|
| 73 |
+
/** \returns true if all coefficients are true
|
| 74 |
+
*
|
| 75 |
+
* Example: \include MatrixBase_all.cpp
|
| 76 |
+
* Output: \verbinclude MatrixBase_all.out
|
| 77 |
+
*
|
| 78 |
+
* \sa any(), Cwise::operator<()
|
| 79 |
+
*/
|
| 80 |
+
template<typename Derived>
|
| 81 |
+
EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const
|
| 82 |
+
{
|
| 83 |
+
typedef internal::evaluator<Derived> Evaluator;
|
| 84 |
+
enum {
|
| 85 |
+
unroll = SizeAtCompileTime != Dynamic
|
| 86 |
+
&& SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
|
| 87 |
+
};
|
| 88 |
+
Evaluator evaluator(derived());
|
| 89 |
+
if(unroll)
|
| 90 |
+
return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, InnerSizeAtCompileTime>::run(evaluator);
|
| 91 |
+
else
|
| 92 |
+
{
|
| 93 |
+
for(Index i = 0; i < derived().outerSize(); ++i)
|
| 94 |
+
for(Index j = 0; j < derived().innerSize(); ++j)
|
| 95 |
+
if (!evaluator.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i)) return false;
|
| 96 |
+
return true;
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/** \returns true if at least one coefficient is true
|
| 101 |
+
*
|
| 102 |
+
* \sa all()
|
| 103 |
+
*/
|
| 104 |
+
template<typename Derived>
|
| 105 |
+
EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const
|
| 106 |
+
{
|
| 107 |
+
typedef internal::evaluator<Derived> Evaluator;
|
| 108 |
+
enum {
|
| 109 |
+
unroll = SizeAtCompileTime != Dynamic
|
| 110 |
+
&& SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
|
| 111 |
+
};
|
| 112 |
+
Evaluator evaluator(derived());
|
| 113 |
+
if(unroll)
|
| 114 |
+
return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, InnerSizeAtCompileTime>::run(evaluator);
|
| 115 |
+
else
|
| 116 |
+
{
|
| 117 |
+
for(Index i = 0; i < derived().outerSize(); ++i)
|
| 118 |
+
for(Index j = 0; j < derived().innerSize(); ++j)
|
| 119 |
+
if (evaluator.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i)) return true;
|
| 120 |
+
return false;
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/** \returns the number of coefficients which evaluate to true
|
| 125 |
+
*
|
| 126 |
+
* \sa all(), any()
|
| 127 |
+
*/
|
| 128 |
+
template<typename Derived>
|
| 129 |
+
EIGEN_DEVICE_FUNC inline Eigen::Index DenseBase<Derived>::count() const
|
| 130 |
+
{
|
| 131 |
+
return derived().template cast<bool>().template cast<Index>().sum();
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/** \returns true is \c *this contains at least one Not A Number (NaN).
|
| 135 |
+
*
|
| 136 |
+
* \sa allFinite()
|
| 137 |
+
*/
|
| 138 |
+
template<typename Derived>
|
| 139 |
+
inline bool DenseBase<Derived>::hasNaN() const
|
| 140 |
+
{
|
| 141 |
+
#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
|
| 142 |
+
return derived().array().isNaN().any();
|
| 143 |
+
#else
|
| 144 |
+
return !((derived().array()==derived().array()).all());
|
| 145 |
+
#endif
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values.
|
| 149 |
+
*
|
| 150 |
+
* \sa hasNaN()
|
| 151 |
+
*/
|
| 152 |
+
template<typename Derived>
|
| 153 |
+
inline bool DenseBase<Derived>::allFinite() const
|
| 154 |
+
{
|
| 155 |
+
#if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
|
| 156 |
+
return derived().array().isFinite().all();
|
| 157 |
+
#else
|
| 158 |
+
return !((derived()-derived()).hasNaN());
|
| 159 |
+
#endif
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
} // end namespace Eigen
|
| 163 |
+
|
| 164 |
+
#endif // EIGEN_ALLANDANY_H
|
include/eigen/Eigen/src/Core/CommaInitializer.h
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_COMMAINITIALIZER_H
|
| 12 |
+
#define EIGEN_COMMAINITIALIZER_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
/** \class CommaInitializer
|
| 17 |
+
* \ingroup Core_Module
|
| 18 |
+
*
|
| 19 |
+
* \brief Helper class used by the comma initializer operator
|
| 20 |
+
*
|
| 21 |
+
* This class is internally used to implement the comma initializer feature. It is
|
| 22 |
+
* the return type of MatrixBase::operator<<, and most of the time this is the only
|
| 23 |
+
* way it is used.
|
| 24 |
+
*
|
| 25 |
+
* \sa \blank \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished()
|
| 26 |
+
*/
|
| 27 |
+
template<typename XprType>
|
| 28 |
+
struct CommaInitializer
|
| 29 |
+
{
|
| 30 |
+
typedef typename XprType::Scalar Scalar;
|
| 31 |
+
|
| 32 |
+
EIGEN_DEVICE_FUNC
|
| 33 |
+
inline CommaInitializer(XprType& xpr, const Scalar& s)
|
| 34 |
+
: m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
|
| 35 |
+
{
|
| 36 |
+
eigen_assert(m_xpr.rows() > 0 && m_xpr.cols() > 0
|
| 37 |
+
&& "Cannot comma-initialize a 0x0 matrix (operator<<)");
|
| 38 |
+
m_xpr.coeffRef(0,0) = s;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
template<typename OtherDerived>
|
| 42 |
+
EIGEN_DEVICE_FUNC
|
| 43 |
+
inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
|
| 44 |
+
: m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
|
| 45 |
+
{
|
| 46 |
+
eigen_assert(m_xpr.rows() >= other.rows() && m_xpr.cols() >= other.cols()
|
| 47 |
+
&& "Cannot comma-initialize a 0x0 matrix (operator<<)");
|
| 48 |
+
m_xpr.block(0, 0, other.rows(), other.cols()) = other;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/* Copy/Move constructor which transfers ownership. This is crucial in
|
| 52 |
+
* absence of return value optimization to avoid assertions during destruction. */
|
| 53 |
+
// FIXME in C++11 mode this could be replaced by a proper RValue constructor
|
| 54 |
+
EIGEN_DEVICE_FUNC
|
| 55 |
+
inline CommaInitializer(const CommaInitializer& o)
|
| 56 |
+
: m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) {
|
| 57 |
+
// Mark original object as finished. In absence of R-value references we need to const_cast:
|
| 58 |
+
const_cast<CommaInitializer&>(o).m_row = m_xpr.rows();
|
| 59 |
+
const_cast<CommaInitializer&>(o).m_col = m_xpr.cols();
|
| 60 |
+
const_cast<CommaInitializer&>(o).m_currentBlockRows = 0;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/* inserts a scalar value in the target matrix */
|
| 64 |
+
EIGEN_DEVICE_FUNC
|
| 65 |
+
CommaInitializer& operator,(const Scalar& s)
|
| 66 |
+
{
|
| 67 |
+
if (m_col==m_xpr.cols())
|
| 68 |
+
{
|
| 69 |
+
m_row+=m_currentBlockRows;
|
| 70 |
+
m_col = 0;
|
| 71 |
+
m_currentBlockRows = 1;
|
| 72 |
+
eigen_assert(m_row<m_xpr.rows()
|
| 73 |
+
&& "Too many rows passed to comma initializer (operator<<)");
|
| 74 |
+
}
|
| 75 |
+
eigen_assert(m_col<m_xpr.cols()
|
| 76 |
+
&& "Too many coefficients passed to comma initializer (operator<<)");
|
| 77 |
+
eigen_assert(m_currentBlockRows==1);
|
| 78 |
+
m_xpr.coeffRef(m_row, m_col++) = s;
|
| 79 |
+
return *this;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/* inserts a matrix expression in the target matrix */
|
| 83 |
+
template<typename OtherDerived>
|
| 84 |
+
EIGEN_DEVICE_FUNC
|
| 85 |
+
CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
|
| 86 |
+
{
|
| 87 |
+
if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows))
|
| 88 |
+
{
|
| 89 |
+
m_row+=m_currentBlockRows;
|
| 90 |
+
m_col = 0;
|
| 91 |
+
m_currentBlockRows = other.rows();
|
| 92 |
+
eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows()
|
| 93 |
+
&& "Too many rows passed to comma initializer (operator<<)");
|
| 94 |
+
}
|
| 95 |
+
eigen_assert((m_col + other.cols() <= m_xpr.cols())
|
| 96 |
+
&& "Too many coefficients passed to comma initializer (operator<<)");
|
| 97 |
+
eigen_assert(m_currentBlockRows==other.rows());
|
| 98 |
+
m_xpr.template block<OtherDerived::RowsAtCompileTime, OtherDerived::ColsAtCompileTime>
|
| 99 |
+
(m_row, m_col, other.rows(), other.cols()) = other;
|
| 100 |
+
m_col += other.cols();
|
| 101 |
+
return *this;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
EIGEN_DEVICE_FUNC
|
| 105 |
+
inline ~CommaInitializer()
|
| 106 |
+
#if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS
|
| 107 |
+
EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception)
|
| 108 |
+
#endif
|
| 109 |
+
{
|
| 110 |
+
finished();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/** \returns the built matrix once all its coefficients have been set.
|
| 114 |
+
* Calling finished is 100% optional. Its purpose is to write expressions
|
| 115 |
+
* like this:
|
| 116 |
+
* \code
|
| 117 |
+
* quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished());
|
| 118 |
+
* \endcode
|
| 119 |
+
*/
|
| 120 |
+
EIGEN_DEVICE_FUNC
|
| 121 |
+
inline XprType& finished() {
|
| 122 |
+
eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0)
|
| 123 |
+
&& m_col == m_xpr.cols()
|
| 124 |
+
&& "Too few coefficients passed to comma initializer (operator<<)");
|
| 125 |
+
return m_xpr;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
XprType& m_xpr; // target expression
|
| 129 |
+
Index m_row; // current row id
|
| 130 |
+
Index m_col; // current col id
|
| 131 |
+
Index m_currentBlockRows; // current block height
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
/** \anchor MatrixBaseCommaInitRef
|
| 135 |
+
* Convenient operator to set the coefficients of a matrix.
|
| 136 |
+
*
|
| 137 |
+
* The coefficients must be provided in a row major order and exactly match
|
| 138 |
+
* the size of the matrix. Otherwise an assertion is raised.
|
| 139 |
+
*
|
| 140 |
+
* Example: \include MatrixBase_set.cpp
|
| 141 |
+
* Output: \verbinclude MatrixBase_set.out
|
| 142 |
+
*
|
| 143 |
+
* \note According the c++ standard, the argument expressions of this comma initializer are evaluated in arbitrary order.
|
| 144 |
+
*
|
| 145 |
+
* \sa CommaInitializer::finished(), class CommaInitializer
|
| 146 |
+
*/
|
| 147 |
+
template<typename Derived>
|
| 148 |
+
EIGEN_DEVICE_FUNC inline CommaInitializer<Derived> DenseBase<Derived>::operator<< (const Scalar& s)
|
| 149 |
+
{
|
| 150 |
+
return CommaInitializer<Derived>(*static_cast<Derived*>(this), s);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/** \sa operator<<(const Scalar&) */
|
| 154 |
+
template<typename Derived>
|
| 155 |
+
template<typename OtherDerived>
|
| 156 |
+
EIGEN_DEVICE_FUNC inline CommaInitializer<Derived>
|
| 157 |
+
DenseBase<Derived>::operator<<(const DenseBase<OtherDerived>& other)
|
| 158 |
+
{
|
| 159 |
+
return CommaInitializer<Derived>(*static_cast<Derived *>(this), other);
|
| 160 |
+
}
|
| 161 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com)
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_CONDITIONESTIMATOR_H
|
| 11 |
+
#define EIGEN_CONDITIONESTIMATOR_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
template <typename Vector, typename RealVector, bool IsComplex>
|
| 18 |
+
struct rcond_compute_sign {
|
| 19 |
+
static inline Vector run(const Vector& v) {
|
| 20 |
+
const RealVector v_abs = v.cwiseAbs();
|
| 21 |
+
return (v_abs.array() == static_cast<typename Vector::RealScalar>(0))
|
| 22 |
+
.select(Vector::Ones(v.size()), v.cwiseQuotient(v_abs));
|
| 23 |
+
}
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
// Partial specialization to avoid elementwise division for real vectors.
|
| 27 |
+
template <typename Vector>
|
| 28 |
+
struct rcond_compute_sign<Vector, Vector, false> {
|
| 29 |
+
static inline Vector run(const Vector& v) {
|
| 30 |
+
return (v.array() < static_cast<typename Vector::RealScalar>(0))
|
| 31 |
+
.select(-Vector::Ones(v.size()), Vector::Ones(v.size()));
|
| 32 |
+
}
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* \returns an estimate of ||inv(matrix)||_1 given a decomposition of
|
| 37 |
+
* \a matrix that implements .solve() and .adjoint().solve() methods.
|
| 38 |
+
*
|
| 39 |
+
* This function implements Algorithms 4.1 and 5.1 from
|
| 40 |
+
* http://www.maths.manchester.ac.uk/~higham/narep/narep135.pdf
|
| 41 |
+
* which also forms the basis for the condition number estimators in
|
| 42 |
+
* LAPACK. Since at most 10 calls to the solve method of dec are
|
| 43 |
+
* performed, the total cost is O(dims^2), as opposed to O(dims^3)
|
| 44 |
+
* needed to compute the inverse matrix explicitly.
|
| 45 |
+
*
|
| 46 |
+
* The most common usage is in estimating the condition number
|
| 47 |
+
* ||matrix||_1 * ||inv(matrix)||_1. The first term ||matrix||_1 can be
|
| 48 |
+
* computed directly in O(n^2) operations.
|
| 49 |
+
*
|
| 50 |
+
* Supports the following decompositions: FullPivLU, PartialPivLU, LDLT, and
|
| 51 |
+
* LLT.
|
| 52 |
+
*
|
| 53 |
+
* \sa FullPivLU, PartialPivLU, LDLT, LLT.
|
| 54 |
+
*/
|
| 55 |
+
template <typename Decomposition>
|
| 56 |
+
typename Decomposition::RealScalar rcond_invmatrix_L1_norm_estimate(const Decomposition& dec)
|
| 57 |
+
{
|
| 58 |
+
typedef typename Decomposition::MatrixType MatrixType;
|
| 59 |
+
typedef typename Decomposition::Scalar Scalar;
|
| 60 |
+
typedef typename Decomposition::RealScalar RealScalar;
|
| 61 |
+
typedef typename internal::plain_col_type<MatrixType>::type Vector;
|
| 62 |
+
typedef typename internal::plain_col_type<MatrixType, RealScalar>::type RealVector;
|
| 63 |
+
const bool is_complex = (NumTraits<Scalar>::IsComplex != 0);
|
| 64 |
+
|
| 65 |
+
eigen_assert(dec.rows() == dec.cols());
|
| 66 |
+
const Index n = dec.rows();
|
| 67 |
+
if (n == 0)
|
| 68 |
+
return 0;
|
| 69 |
+
|
| 70 |
+
// Disable Index to float conversion warning
|
| 71 |
+
#ifdef __INTEL_COMPILER
|
| 72 |
+
#pragma warning push
|
| 73 |
+
#pragma warning ( disable : 2259 )
|
| 74 |
+
#endif
|
| 75 |
+
Vector v = dec.solve(Vector::Ones(n) / Scalar(n));
|
| 76 |
+
#ifdef __INTEL_COMPILER
|
| 77 |
+
#pragma warning pop
|
| 78 |
+
#endif
|
| 79 |
+
|
| 80 |
+
// lower_bound is a lower bound on
|
| 81 |
+
// ||inv(matrix)||_1 = sup_v ||inv(matrix) v||_1 / ||v||_1
|
| 82 |
+
// and is the objective maximized by the ("super-") gradient ascent
|
| 83 |
+
// algorithm below.
|
| 84 |
+
RealScalar lower_bound = v.template lpNorm<1>();
|
| 85 |
+
if (n == 1)
|
| 86 |
+
return lower_bound;
|
| 87 |
+
|
| 88 |
+
// Gradient ascent algorithm follows: We know that the optimum is achieved at
|
| 89 |
+
// one of the simplices v = e_i, so in each iteration we follow a
|
| 90 |
+
// super-gradient to move towards the optimal one.
|
| 91 |
+
RealScalar old_lower_bound = lower_bound;
|
| 92 |
+
Vector sign_vector(n);
|
| 93 |
+
Vector old_sign_vector;
|
| 94 |
+
Index v_max_abs_index = -1;
|
| 95 |
+
Index old_v_max_abs_index = v_max_abs_index;
|
| 96 |
+
for (int k = 0; k < 4; ++k)
|
| 97 |
+
{
|
| 98 |
+
sign_vector = internal::rcond_compute_sign<Vector, RealVector, is_complex>::run(v);
|
| 99 |
+
if (k > 0 && !is_complex && sign_vector == old_sign_vector) {
|
| 100 |
+
// Break if the solution stagnated.
|
| 101 |
+
break;
|
| 102 |
+
}
|
| 103 |
+
// v_max_abs_index = argmax |real( inv(matrix)^T * sign_vector )|
|
| 104 |
+
v = dec.adjoint().solve(sign_vector);
|
| 105 |
+
v.real().cwiseAbs().maxCoeff(&v_max_abs_index);
|
| 106 |
+
if (v_max_abs_index == old_v_max_abs_index) {
|
| 107 |
+
// Break if the solution stagnated.
|
| 108 |
+
break;
|
| 109 |
+
}
|
| 110 |
+
// Move to the new simplex e_j, where j = v_max_abs_index.
|
| 111 |
+
v = dec.solve(Vector::Unit(n, v_max_abs_index)); // v = inv(matrix) * e_j.
|
| 112 |
+
lower_bound = v.template lpNorm<1>();
|
| 113 |
+
if (lower_bound <= old_lower_bound) {
|
| 114 |
+
// Break if the gradient step did not increase the lower_bound.
|
| 115 |
+
break;
|
| 116 |
+
}
|
| 117 |
+
if (!is_complex) {
|
| 118 |
+
old_sign_vector = sign_vector;
|
| 119 |
+
}
|
| 120 |
+
old_v_max_abs_index = v_max_abs_index;
|
| 121 |
+
old_lower_bound = lower_bound;
|
| 122 |
+
}
|
| 123 |
+
// The following calculates an independent estimate of ||matrix||_1 by
|
| 124 |
+
// multiplying matrix by a vector with entries of slowly increasing
|
| 125 |
+
// magnitude and alternating sign:
|
| 126 |
+
// v_i = (-1)^{i} (1 + (i / (dim-1))), i = 0,...,dim-1.
|
| 127 |
+
// This improvement to Hager's algorithm above is due to Higham. It was
|
| 128 |
+
// added to make the algorithm more robust in certain corner cases where
|
| 129 |
+
// large elements in the matrix might otherwise escape detection due to
|
| 130 |
+
// exact cancellation (especially when op and op_adjoint correspond to a
|
| 131 |
+
// sequence of backsubstitutions and permutations), which could cause
|
| 132 |
+
// Hager's algorithm to vastly underestimate ||matrix||_1.
|
| 133 |
+
Scalar alternating_sign(RealScalar(1));
|
| 134 |
+
for (Index i = 0; i < n; ++i) {
|
| 135 |
+
// The static_cast is needed when Scalar is a complex and RealScalar implements expression templates
|
| 136 |
+
v[i] = alternating_sign * static_cast<RealScalar>(RealScalar(1) + (RealScalar(i) / (RealScalar(n - 1))));
|
| 137 |
+
alternating_sign = -alternating_sign;
|
| 138 |
+
}
|
| 139 |
+
v = dec.solve(v);
|
| 140 |
+
const RealScalar alternate_lower_bound = (2 * v.template lpNorm<1>()) / (3 * RealScalar(n));
|
| 141 |
+
return numext::maxi(lower_bound, alternate_lower_bound);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/** \brief Reciprocal condition number estimator.
|
| 145 |
+
*
|
| 146 |
+
* Computing a decomposition of a dense matrix takes O(n^3) operations, while
|
| 147 |
+
* this method estimates the condition number quickly and reliably in O(n^2)
|
| 148 |
+
* operations.
|
| 149 |
+
*
|
| 150 |
+
* \returns an estimate of the reciprocal condition number
|
| 151 |
+
* (1 / (||matrix||_1 * ||inv(matrix)||_1)) of matrix, given ||matrix||_1 and
|
| 152 |
+
* its decomposition. Supports the following decompositions: FullPivLU,
|
| 153 |
+
* PartialPivLU, LDLT, and LLT.
|
| 154 |
+
*
|
| 155 |
+
* \sa FullPivLU, PartialPivLU, LDLT, LLT.
|
| 156 |
+
*/
|
| 157 |
+
template <typename Decomposition>
|
| 158 |
+
typename Decomposition::RealScalar
|
| 159 |
+
rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, const Decomposition& dec)
|
| 160 |
+
{
|
| 161 |
+
typedef typename Decomposition::RealScalar RealScalar;
|
| 162 |
+
eigen_assert(dec.rows() == dec.cols());
|
| 163 |
+
if (dec.rows() == 0) return NumTraits<RealScalar>::infinity();
|
| 164 |
+
if (matrix_norm == RealScalar(0)) return RealScalar(0);
|
| 165 |
+
if (dec.rows() == 1) return RealScalar(1);
|
| 166 |
+
const RealScalar inverse_matrix_norm = rcond_invmatrix_L1_norm_estimate(dec);
|
| 167 |
+
return (inverse_matrix_norm == RealScalar(0) ? RealScalar(0)
|
| 168 |
+
: (RealScalar(1) / inverse_matrix_norm) / matrix_norm);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
} // namespace internal
|
| 172 |
+
|
| 173 |
+
} // namespace Eigen
|
| 174 |
+
|
| 175 |
+
#endif
|
include/eigen/Eigen/src/Core/CoreIterators.h
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_COREITERATORS_H
|
| 11 |
+
#define EIGEN_COREITERATORS_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
/* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
namespace internal {
|
| 19 |
+
|
| 20 |
+
template<typename XprType, typename EvaluatorKind>
|
| 21 |
+
class inner_iterator_selector;
|
| 22 |
+
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/** \class InnerIterator
|
| 26 |
+
* \brief An InnerIterator allows to loop over the element of any matrix expression.
|
| 27 |
+
*
|
| 28 |
+
* \warning To be used with care because an evaluator is constructed every time an InnerIterator iterator is constructed.
|
| 29 |
+
*
|
| 30 |
+
* TODO: add a usage example
|
| 31 |
+
*/
|
| 32 |
+
template<typename XprType>
|
| 33 |
+
class InnerIterator
|
| 34 |
+
{
|
| 35 |
+
protected:
|
| 36 |
+
typedef internal::inner_iterator_selector<XprType, typename internal::evaluator_traits<XprType>::Kind> IteratorType;
|
| 37 |
+
typedef internal::evaluator<XprType> EvaluatorType;
|
| 38 |
+
typedef typename internal::traits<XprType>::Scalar Scalar;
|
| 39 |
+
public:
|
| 40 |
+
/** Construct an iterator over the \a outerId -th row or column of \a xpr */
|
| 41 |
+
InnerIterator(const XprType &xpr, const Index &outerId)
|
| 42 |
+
: m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize())
|
| 43 |
+
{}
|
| 44 |
+
|
| 45 |
+
/// \returns the value of the current coefficient.
|
| 46 |
+
EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
|
| 47 |
+
/** Increment the iterator \c *this to the next non-zero coefficient.
|
| 48 |
+
* Explicit zeros are not skipped over. To skip explicit zeros, see class SparseView
|
| 49 |
+
*/
|
| 50 |
+
EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; }
|
| 51 |
+
EIGEN_STRONG_INLINE InnerIterator& operator+=(Index i) { m_iter.operator+=(i); return *this; }
|
| 52 |
+
EIGEN_STRONG_INLINE InnerIterator operator+(Index i)
|
| 53 |
+
{ InnerIterator result(*this); result+=i; return result; }
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
/// \returns the column or row index of the current coefficient.
|
| 57 |
+
EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
|
| 58 |
+
/// \returns the row index of the current coefficient.
|
| 59 |
+
EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
|
| 60 |
+
/// \returns the column index of the current coefficient.
|
| 61 |
+
EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
|
| 62 |
+
/// \returns \c true if the iterator \c *this still references a valid coefficient.
|
| 63 |
+
EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
|
| 64 |
+
|
| 65 |
+
protected:
|
| 66 |
+
EvaluatorType m_eval;
|
| 67 |
+
IteratorType m_iter;
|
| 68 |
+
private:
|
| 69 |
+
// If you get here, then you're not using the right InnerIterator type, e.g.:
|
| 70 |
+
// SparseMatrix<double,RowMajor> A;
|
| 71 |
+
// SparseMatrix<double>::InnerIterator it(A,0);
|
| 72 |
+
template<typename T> InnerIterator(const EigenBase<T>&,Index outer);
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
namespace internal {
|
| 76 |
+
|
| 77 |
+
// Generic inner iterator implementation for dense objects
|
| 78 |
+
template<typename XprType>
|
| 79 |
+
class inner_iterator_selector<XprType, IndexBased>
|
| 80 |
+
{
|
| 81 |
+
protected:
|
| 82 |
+
typedef evaluator<XprType> EvaluatorType;
|
| 83 |
+
typedef typename traits<XprType>::Scalar Scalar;
|
| 84 |
+
enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit };
|
| 85 |
+
|
| 86 |
+
public:
|
| 87 |
+
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize)
|
| 88 |
+
: m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize)
|
| 89 |
+
{}
|
| 90 |
+
|
| 91 |
+
EIGEN_STRONG_INLINE Scalar value() const
|
| 92 |
+
{
|
| 93 |
+
return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner)
|
| 94 |
+
: m_eval.coeff(m_inner, m_outer);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
EIGEN_STRONG_INLINE inner_iterator_selector& operator++() { m_inner++; return *this; }
|
| 98 |
+
|
| 99 |
+
EIGEN_STRONG_INLINE Index index() const { return m_inner; }
|
| 100 |
+
inline Index row() const { return IsRowMajor ? m_outer : index(); }
|
| 101 |
+
inline Index col() const { return IsRowMajor ? index() : m_outer; }
|
| 102 |
+
|
| 103 |
+
EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
|
| 104 |
+
|
| 105 |
+
protected:
|
| 106 |
+
const EvaluatorType& m_eval;
|
| 107 |
+
Index m_inner;
|
| 108 |
+
const Index m_outer;
|
| 109 |
+
const Index m_end;
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
// For iterator-based evaluator, inner-iterator is already implemented as
|
| 113 |
+
// evaluator<>::InnerIterator
|
| 114 |
+
template<typename XprType>
|
| 115 |
+
class inner_iterator_selector<XprType, IteratorBased>
|
| 116 |
+
: public evaluator<XprType>::InnerIterator
|
| 117 |
+
{
|
| 118 |
+
protected:
|
| 119 |
+
typedef typename evaluator<XprType>::InnerIterator Base;
|
| 120 |
+
typedef evaluator<XprType> EvaluatorType;
|
| 121 |
+
|
| 122 |
+
public:
|
| 123 |
+
EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &/*innerSize*/)
|
| 124 |
+
: Base(eval, outerId)
|
| 125 |
+
{}
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
} // end namespace internal
|
| 129 |
+
|
| 130 |
+
} // end namespace Eigen
|
| 131 |
+
|
| 132 |
+
#endif // EIGEN_COREITERATORS_H
|
include/eigen/Eigen/src/Core/CwiseBinaryOp.h
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
//
|
| 4 |
+
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_CWISE_BINARY_OP_H
|
| 12 |
+
#define EIGEN_CWISE_BINARY_OP_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
template<typename BinaryOp, typename Lhs, typename Rhs>
|
| 18 |
+
struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
|
| 19 |
+
{
|
| 20 |
+
// we must not inherit from traits<Lhs> since it has
|
| 21 |
+
// the potential to cause problems with MSVC
|
| 22 |
+
typedef typename remove_all<Lhs>::type Ancestor;
|
| 23 |
+
typedef typename traits<Ancestor>::XprKind XprKind;
|
| 24 |
+
enum {
|
| 25 |
+
RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
|
| 26 |
+
ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
|
| 27 |
+
MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
|
| 28 |
+
MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
// even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor),
|
| 32 |
+
// we still want to handle the case when the result type is different.
|
| 33 |
+
typedef typename result_of<
|
| 34 |
+
BinaryOp(
|
| 35 |
+
const typename Lhs::Scalar&,
|
| 36 |
+
const typename Rhs::Scalar&
|
| 37 |
+
)
|
| 38 |
+
>::type Scalar;
|
| 39 |
+
typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
|
| 40 |
+
typename traits<Rhs>::StorageKind,
|
| 41 |
+
BinaryOp>::ret StorageKind;
|
| 42 |
+
typedef typename promote_index_type<typename traits<Lhs>::StorageIndex,
|
| 43 |
+
typename traits<Rhs>::StorageIndex>::type StorageIndex;
|
| 44 |
+
typedef typename Lhs::Nested LhsNested;
|
| 45 |
+
typedef typename Rhs::Nested RhsNested;
|
| 46 |
+
typedef typename remove_reference<LhsNested>::type _LhsNested;
|
| 47 |
+
typedef typename remove_reference<RhsNested>::type _RhsNested;
|
| 48 |
+
enum {
|
| 49 |
+
Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,typename traits<Rhs>::StorageKind,_LhsNested::Flags & RowMajorBit,_RhsNested::Flags & RowMajorBit>::value
|
| 50 |
+
};
|
| 51 |
+
};
|
| 52 |
+
} // end namespace internal
|
| 53 |
+
|
| 54 |
+
template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
|
| 55 |
+
class CwiseBinaryOpImpl;
|
| 56 |
+
|
| 57 |
+
/** \class CwiseBinaryOp
|
| 58 |
+
* \ingroup Core_Module
|
| 59 |
+
*
|
| 60 |
+
* \brief Generic expression where a coefficient-wise binary operator is applied to two expressions
|
| 61 |
+
*
|
| 62 |
+
* \tparam BinaryOp template functor implementing the operator
|
| 63 |
+
* \tparam LhsType the type of the left-hand side
|
| 64 |
+
* \tparam RhsType the type of the right-hand side
|
| 65 |
+
*
|
| 66 |
+
* This class represents an expression where a coefficient-wise binary operator is applied to two expressions.
|
| 67 |
+
* It is the return type of binary operators, by which we mean only those binary operators where
|
| 68 |
+
* both the left-hand side and the right-hand side are Eigen expressions.
|
| 69 |
+
* For example, the return type of matrix1+matrix2 is a CwiseBinaryOp.
|
| 70 |
+
*
|
| 71 |
+
* Most of the time, this is the only way that it is used, so you typically don't have to name
|
| 72 |
+
* CwiseBinaryOp types explicitly.
|
| 73 |
+
*
|
| 74 |
+
* \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp
|
| 75 |
+
*/
|
| 76 |
+
template<typename BinaryOp, typename LhsType, typename RhsType>
|
| 77 |
+
class CwiseBinaryOp :
|
| 78 |
+
public CwiseBinaryOpImpl<
|
| 79 |
+
BinaryOp, LhsType, RhsType,
|
| 80 |
+
typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
|
| 81 |
+
typename internal::traits<RhsType>::StorageKind,
|
| 82 |
+
BinaryOp>::ret>,
|
| 83 |
+
internal::no_assignment_operator
|
| 84 |
+
{
|
| 85 |
+
public:
|
| 86 |
+
|
| 87 |
+
typedef typename internal::remove_all<BinaryOp>::type Functor;
|
| 88 |
+
typedef typename internal::remove_all<LhsType>::type Lhs;
|
| 89 |
+
typedef typename internal::remove_all<RhsType>::type Rhs;
|
| 90 |
+
|
| 91 |
+
typedef typename CwiseBinaryOpImpl<
|
| 92 |
+
BinaryOp, LhsType, RhsType,
|
| 93 |
+
typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
|
| 94 |
+
typename internal::traits<Rhs>::StorageKind,
|
| 95 |
+
BinaryOp>::ret>::Base Base;
|
| 96 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
|
| 97 |
+
|
| 98 |
+
typedef typename internal::ref_selector<LhsType>::type LhsNested;
|
| 99 |
+
typedef typename internal::ref_selector<RhsType>::type RhsNested;
|
| 100 |
+
typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
|
| 101 |
+
typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
|
| 102 |
+
|
| 103 |
+
#if EIGEN_COMP_MSVC && EIGEN_HAS_CXX11
|
| 104 |
+
//Required for Visual Studio or the Copy constructor will probably not get inlined!
|
| 105 |
+
EIGEN_STRONG_INLINE
|
| 106 |
+
CwiseBinaryOp(const CwiseBinaryOp<BinaryOp,LhsType,RhsType>&) = default;
|
| 107 |
+
#endif
|
| 108 |
+
|
| 109 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 110 |
+
CwiseBinaryOp(const Lhs& aLhs, const Rhs& aRhs, const BinaryOp& func = BinaryOp())
|
| 111 |
+
: m_lhs(aLhs), m_rhs(aRhs), m_functor(func)
|
| 112 |
+
{
|
| 113 |
+
EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
|
| 114 |
+
// require the sizes to match
|
| 115 |
+
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
|
| 116 |
+
eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 120 |
+
Index rows() const EIGEN_NOEXCEPT {
|
| 121 |
+
// return the fixed size type if available to enable compile time optimizations
|
| 122 |
+
return internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime==Dynamic ? m_rhs.rows() : m_lhs.rows();
|
| 123 |
+
}
|
| 124 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 125 |
+
Index cols() const EIGEN_NOEXCEPT {
|
| 126 |
+
// return the fixed size type if available to enable compile time optimizations
|
| 127 |
+
return internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic ? m_rhs.cols() : m_lhs.cols();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/** \returns the left hand side nested expression */
|
| 131 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 132 |
+
const _LhsNested& lhs() const { return m_lhs; }
|
| 133 |
+
/** \returns the right hand side nested expression */
|
| 134 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 135 |
+
const _RhsNested& rhs() const { return m_rhs; }
|
| 136 |
+
/** \returns the functor representing the binary operation */
|
| 137 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 138 |
+
const BinaryOp& functor() const { return m_functor; }
|
| 139 |
+
|
| 140 |
+
protected:
|
| 141 |
+
LhsNested m_lhs;
|
| 142 |
+
RhsNested m_rhs;
|
| 143 |
+
const BinaryOp m_functor;
|
| 144 |
+
};
|
| 145 |
+
|
| 146 |
+
// Generic API dispatcher
|
| 147 |
+
template<typename BinaryOp, typename Lhs, typename Rhs, typename StorageKind>
|
| 148 |
+
class CwiseBinaryOpImpl
|
| 149 |
+
: public internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
|
| 150 |
+
{
|
| 151 |
+
public:
|
| 152 |
+
typedef typename internal::generic_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type Base;
|
| 153 |
+
};
|
| 154 |
+
|
| 155 |
+
/** replaces \c *this by \c *this - \a other.
|
| 156 |
+
*
|
| 157 |
+
* \returns a reference to \c *this
|
| 158 |
+
*/
|
| 159 |
+
template<typename Derived>
|
| 160 |
+
template<typename OtherDerived>
|
| 161 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
|
| 162 |
+
MatrixBase<Derived>::operator-=(const MatrixBase<OtherDerived> &other)
|
| 163 |
+
{
|
| 164 |
+
call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 165 |
+
return derived();
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/** replaces \c *this by \c *this + \a other.
|
| 169 |
+
*
|
| 170 |
+
* \returns a reference to \c *this
|
| 171 |
+
*/
|
| 172 |
+
template<typename Derived>
|
| 173 |
+
template<typename OtherDerived>
|
| 174 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
|
| 175 |
+
MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
|
| 176 |
+
{
|
| 177 |
+
call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename Ot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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_CWISE_NULLARY_OP_H
|
| 11 |
+
#define EIGEN_CWISE_NULLARY_OP_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
template<typename NullaryOp, typename PlainObjectType>
|
| 17 |
+
struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
|
| 18 |
+
{
|
| 19 |
+
enum {
|
| 20 |
+
Flags = traits<PlainObjectType>::Flags & RowMajorBit
|
| 21 |
+
};
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
} // namespace internal
|
| 25 |
+
|
| 26 |
+
/** \class CwiseNullaryOp
|
| 27 |
+
* \ingroup Core_Module
|
| 28 |
+
*
|
| 29 |
+
* \brief Generic expression of a matrix where all coefficients are defined by a functor
|
| 30 |
+
*
|
| 31 |
+
* \tparam NullaryOp template functor implementing the operator
|
| 32 |
+
* \tparam PlainObjectType the underlying plain matrix/array type
|
| 33 |
+
*
|
| 34 |
+
* This class represents an expression of a generic nullary operator.
|
| 35 |
+
* It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() methods,
|
| 36 |
+
* and most of the time this is the only way it is used.
|
| 37 |
+
*
|
| 38 |
+
* However, if you want to write a function returning such an expression, you
|
| 39 |
+
* will need to use this class.
|
| 40 |
+
*
|
| 41 |
+
* The functor NullaryOp must expose one of the following method:
|
| 42 |
+
<table class="manual">
|
| 43 |
+
<tr ><td>\c operator()() </td><td>if the procedural generation does not depend on the coefficient entries (e.g., random numbers)</td></tr>
|
| 44 |
+
<tr class="alt"><td>\c operator()(Index i)</td><td>if the procedural generation makes sense for vectors only and that it depends on the coefficient index \c i (e.g., linspace) </td></tr>
|
| 45 |
+
<tr ><td>\c operator()(Index i,Index j)</td><td>if the procedural generation depends on the matrix coordinates \c i, \c j (e.g., to generate a checkerboard with 0 and 1)</td></tr>
|
| 46 |
+
</table>
|
| 47 |
+
* It is also possible to expose the last two operators if the generation makes sense for matrices but can be optimized for vectors.
|
| 48 |
+
*
|
| 49 |
+
* See DenseBase::NullaryExpr(Index,const CustomNullaryOp&) for an example binding
|
| 50 |
+
* C++11 random number generators.
|
| 51 |
+
*
|
| 52 |
+
* A nullary expression can also be used to implement custom sophisticated matrix manipulations
|
| 53 |
+
* that cannot be covered by the existing set of natively supported matrix manipulations.
|
| 54 |
+
* See this \ref TopicCustomizing_NullaryExpr "page" for some examples and additional explanations
|
| 55 |
+
* on the behavior of CwiseNullaryOp.
|
| 56 |
+
*
|
| 57 |
+
* \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr
|
| 58 |
+
*/
|
| 59 |
+
template<typename NullaryOp, typename PlainObjectType>
|
| 60 |
+
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
|
| 61 |
+
{
|
| 62 |
+
public:
|
| 63 |
+
|
| 64 |
+
typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
|
| 65 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
|
| 66 |
+
|
| 67 |
+
EIGEN_DEVICE_FUNC
|
| 68 |
+
CwiseNullaryOp(Index rows, Index cols, const NullaryOp& func = NullaryOp())
|
| 69 |
+
: m_rows(rows), m_cols(cols), m_functor(func)
|
| 70 |
+
{
|
| 71 |
+
eigen_assert(rows >= 0
|
| 72 |
+
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
|
| 73 |
+
&& cols >= 0
|
| 74 |
+
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 78 |
+
Index rows() const { return m_rows.value(); }
|
| 79 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 80 |
+
Index cols() const { return m_cols.value(); }
|
| 81 |
+
|
| 82 |
+
/** \returns the functor representing the nullary operation */
|
| 83 |
+
EIGEN_DEVICE_FUNC
|
| 84 |
+
const NullaryOp& functor() const { return m_functor; }
|
| 85 |
+
|
| 86 |
+
protected:
|
| 87 |
+
const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
|
| 88 |
+
const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
|
| 89 |
+
const NullaryOp m_functor;
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
/** \returns an expression of a matrix defined by a custom functor \a func
|
| 94 |
+
*
|
| 95 |
+
* The parameters \a rows and \a cols are the number of rows and of columns of
|
| 96 |
+
* the returned matrix. Must be compatible with this MatrixBase type.
|
| 97 |
+
*
|
| 98 |
+
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
|
| 99 |
+
* it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
|
| 100 |
+
* instead.
|
| 101 |
+
*
|
| 102 |
+
* The template parameter \a CustomNullaryOp is the type of the functor.
|
| 103 |
+
*
|
| 104 |
+
* \sa class CwiseNullaryOp
|
| 105 |
+
*/
|
| 106 |
+
template<typename Derived>
|
| 107 |
+
template<typename CustomNullaryOp>
|
| 108 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 109 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 110 |
+
const CwiseNullaryOp<CustomNullaryOp,typename DenseBase<Derived>::PlainObject>
|
| 111 |
+
#else
|
| 112 |
+
const CwiseNullaryOp<CustomNullaryOp,PlainObject>
|
| 113 |
+
#endif
|
| 114 |
+
DenseBase<Derived>::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func)
|
| 115 |
+
{
|
| 116 |
+
return CwiseNullaryOp<CustomNullaryOp, PlainObject>(rows, cols, func);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/** \returns an expression of a matrix defined by a custom functor \a func
|
| 120 |
+
*
|
| 121 |
+
* The parameter \a size is the size of the returned vector.
|
| 122 |
+
* Must be compatible with this MatrixBase type.
|
| 123 |
+
*
|
| 124 |
+
* \only_for_vectors
|
| 125 |
+
*
|
| 126 |
+
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
|
| 127 |
+
* it is redundant to pass \a size as argument, so Zero() should be used
|
| 128 |
+
* instead.
|
| 129 |
+
*
|
| 130 |
+
* The template parameter \a CustomNullaryOp is the type of the functor.
|
| 131 |
+
*
|
| 132 |
+
* Here is an example with C++11 random generators: \include random_cpp11.cpp
|
| 133 |
+
* Output: \verbinclude random_cpp11.out
|
| 134 |
+
*
|
| 135 |
+
* \sa class CwiseNullaryOp
|
| 136 |
+
*/
|
| 137 |
+
template<typename Derived>
|
| 138 |
+
template<typename CustomNullaryOp>
|
| 139 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 140 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 141 |
+
const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
|
| 142 |
+
#else
|
| 143 |
+
const CwiseNullaryOp<CustomNullaryOp, PlainObject>
|
| 144 |
+
#endif
|
| 145 |
+
DenseBase<Derived>::NullaryExpr(Index size, const CustomNullaryOp& func)
|
| 146 |
+
{
|
| 147 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 148 |
+
if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, PlainObject>(1, size, func);
|
| 149 |
+
else return CwiseNullaryOp<CustomNullaryOp, PlainObject>(size, 1, func);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/** \returns an expression of a matrix defined by a custom functor \a func
|
| 153 |
+
*
|
| 154 |
+
* This variant is only for fixed-size DenseBase types. For dynamic-size types, you
|
| 155 |
+
* need to use the variants taking size arguments.
|
| 156 |
+
*
|
| 157 |
+
* The template parameter \a CustomNullaryOp is the type of the functor.
|
| 158 |
+
*
|
| 159 |
+
* \sa class CwiseNullaryOp
|
| 160 |
+
*/
|
| 161 |
+
template<typename Derived>
|
| 162 |
+
template<typename CustomNullaryOp>
|
| 163 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 164 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 165 |
+
const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
|
| 166 |
+
#else
|
| 167 |
+
const CwiseNullaryOp<CustomNullaryOp, PlainObject>
|
| 168 |
+
#endif
|
| 169 |
+
DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
|
| 170 |
+
{
|
| 171 |
+
return CwiseNullaryOp<CustomNullaryOp, PlainObject>(RowsAtCompileTime, ColsAtCompileTime, func);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/** \returns an expression of a constant matrix of value \a value
|
| 175 |
+
*
|
| 176 |
+
* The parameters \a rows and \a cols are the number of rows and of columns of
|
| 177 |
+
* the returned matrix. Must be compatible with this DenseBase type.
|
| 178 |
+
*
|
| 179 |
+
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
|
| 180 |
+
* it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
|
| 181 |
+
* instead.
|
| 182 |
+
*
|
| 183 |
+
* The template parameter \a CustomNullaryOp is the type of the functor.
|
| 184 |
+
*
|
| 185 |
+
* \sa class CwiseNullaryOp
|
| 186 |
+
*/
|
| 187 |
+
template<typename Derived>
|
| 188 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 189 |
+
DenseBase<Derived>::Constant(Index rows, Index cols, const Scalar& value)
|
| 190 |
+
{
|
| 191 |
+
return DenseBase<Derived>::NullaryExpr(rows, cols, internal::scalar_constant_op<Scalar>(value));
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/** \returns an expression of a constant matrix of value \a value
|
| 195 |
+
*
|
| 196 |
+
* The parameter \a size is the size of the returned vector.
|
| 197 |
+
* Must be compatible with this DenseBase type.
|
| 198 |
+
*
|
| 199 |
+
* \only_for_vectors
|
| 200 |
+
*
|
| 201 |
+
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
|
| 202 |
+
* it is redundant to pass \a size as argument, so Zero() should be used
|
| 203 |
+
* instead.
|
| 204 |
+
*
|
| 205 |
+
* The template parameter \a CustomNullaryOp is the type of the functor.
|
| 206 |
+
*
|
| 207 |
+
* \sa class CwiseNullaryOp
|
| 208 |
+
*/
|
| 209 |
+
template<typename Derived>
|
| 210 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 211 |
+
DenseBase<Derived>::Constant(Index size, const Scalar& value)
|
| 212 |
+
{
|
| 213 |
+
return DenseBase<Derived>::NullaryExpr(size, internal::scalar_constant_op<Scalar>(value));
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/** \returns an expression of a constant matrix of value \a value
|
| 217 |
+
*
|
| 218 |
+
* This variant is only for fixed-size DenseBase types. For dynamic-size types, you
|
| 219 |
+
* need to use the variants taking size arguments.
|
| 220 |
+
*
|
| 221 |
+
* The template parameter \a CustomNullaryOp is the type of the functor.
|
| 222 |
+
*
|
| 223 |
+
* \sa class CwiseNullaryOp
|
| 224 |
+
*/
|
| 225 |
+
template<typename Derived>
|
| 226 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 227 |
+
DenseBase<Derived>::Constant(const Scalar& value)
|
| 228 |
+
{
|
| 229 |
+
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
|
| 230 |
+
return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value));
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(Index,const Scalar&,const Scalar&)
|
| 234 |
+
*
|
| 235 |
+
* \only_for_vectors
|
| 236 |
+
*
|
| 237 |
+
* Example: \include DenseBase_LinSpaced_seq_deprecated.cpp
|
| 238 |
+
* Output: \verbinclude DenseBase_LinSpaced_seq_deprecated.out
|
| 239 |
+
*
|
| 240 |
+
* \sa LinSpaced(Index,const Scalar&, const Scalar&), setLinSpaced(Index,const Scalar&,const Scalar&)
|
| 241 |
+
*/
|
| 242 |
+
template<typename Derived>
|
| 243 |
+
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
|
| 244 |
+
DenseBase<Derived>::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high)
|
| 245 |
+
{
|
| 246 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 247 |
+
return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar>(low,high,size));
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(const Scalar&,const Scalar&)
|
| 251 |
+
*
|
| 252 |
+
* \sa LinSpaced(const Scalar&, const Scalar&)
|
| 253 |
+
*/
|
| 254 |
+
template<typename Derived>
|
| 255 |
+
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
|
| 256 |
+
DenseBase<Derived>::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high)
|
| 257 |
+
{
|
| 258 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 259 |
+
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
|
| 260 |
+
return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime));
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
/**
|
| 264 |
+
* \brief Sets a linearly spaced vector.
|
| 265 |
+
*
|
| 266 |
+
* The function generates 'size' equally spaced values in the closed interval [low,high].
|
| 267 |
+
* When size is set to 1, a vector of length 1 containing 'high' is returned.
|
| 268 |
+
*
|
| 269 |
+
* \only_for_vectors
|
| 270 |
+
*
|
| 271 |
+
* Example: \include DenseBase_LinSpaced.cpp
|
| 272 |
+
* Output: \verbinclude DenseBase_LinSpaced.out
|
| 273 |
+
*
|
| 274 |
+
* For integer scalar types, an even spacing is possible if and only if the length of the range,
|
| 275 |
+
* i.e., \c high-low is a scalar multiple of \c size-1, or if \c size is a scalar multiple of the
|
| 276 |
+
* number of values \c high-low+1 (meaning each value can be repeated the same number of time).
|
| 277 |
+
* If one of these two considions is not satisfied, then \c high is lowered to the largest value
|
| 278 |
+
* satisfying one of this constraint.
|
| 279 |
+
* Here are some examples:
|
| 280 |
+
*
|
| 281 |
+
* Example: \include DenseBase_LinSpacedInt.cpp
|
| 282 |
+
* Output: \verbinclude DenseBase_LinSpacedInt.out
|
| 283 |
+
*
|
| 284 |
+
* \sa setLinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp
|
| 285 |
+
*/
|
| 286 |
+
template<typename Derived>
|
| 287 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
|
| 288 |
+
DenseBase<Derived>::LinSpaced(Index size, const Scalar& low, const Scalar& high)
|
| 289 |
+
{
|
| 290 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 291 |
+
return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar>(low,high,size));
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/**
|
| 295 |
+
* \copydoc DenseBase::LinSpaced(Index, const DenseBase::Scalar&, const DenseBase::Scalar&)
|
| 296 |
+
* Special version for fixed size types which does not require the size parameter.
|
| 297 |
+
*/
|
| 298 |
+
template<typename Derived>
|
| 299 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
|
| 300 |
+
DenseBase<Derived>::LinSpaced(const Scalar& low, const Scalar& high)
|
| 301 |
+
{
|
| 302 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 303 |
+
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
|
| 304 |
+
return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime));
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/** \returns true if all coefficients in this matrix are approximately equal to \a val, to within precision \a prec */
|
| 308 |
+
template<typename Derived>
|
| 309 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApproxToConstant
|
| 310 |
+
(const Scalar& val, const RealScalar& prec) const
|
| 311 |
+
{
|
| 312 |
+
typename internal::nested_eval<Derived,1>::type self(derived());
|
| 313 |
+
for(Index j = 0; j < cols(); ++j)
|
| 314 |
+
for(Index i = 0; i < rows(); ++i)
|
| 315 |
+
if(!internal::isApprox(self.coeff(i, j), val, prec))
|
| 316 |
+
return false;
|
| 317 |
+
return true;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
/** This is just an alias for isApproxToConstant().
|
| 321 |
+
*
|
| 322 |
+
* \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */
|
| 323 |
+
template<typename Derived>
|
| 324 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isConstant
|
| 325 |
+
(const Scalar& val, const RealScalar& prec) const
|
| 326 |
+
{
|
| 327 |
+
return isApproxToConstant(val, prec);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
/** Alias for setConstant(): sets all coefficients in this expression to \a val.
|
| 331 |
+
*
|
| 332 |
+
* \sa setConstant(), Constant(), class CwiseNullaryOp
|
| 333 |
+
*/
|
| 334 |
+
template<typename Derived>
|
| 335 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void DenseBase<Derived>::fill(const Scalar& val)
|
| 336 |
+
{
|
| 337 |
+
setConstant(val);
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
/** Sets all coefficients in this expression to value \a val.
|
| 341 |
+
*
|
| 342 |
+
* \sa fill(), setConstant(Index,const Scalar&), setConstant(Index,Index,const Scalar&), setZero(), setOnes(), Constant(), class CwiseNullaryOp, setZero(), setOnes()
|
| 343 |
+
*/
|
| 344 |
+
template<typename Derived>
|
| 345 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& val)
|
| 346 |
+
{
|
| 347 |
+
return derived() = Constant(rows(), cols(), val);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
/** Resizes to the given \a size, and sets all coefficients in this expression to the given value \a val.
|
| 351 |
+
*
|
| 352 |
+
* \only_for_vectors
|
| 353 |
+
*
|
| 354 |
+
* Example: \include Matrix_setConstant_int.cpp
|
| 355 |
+
* Output: \verbinclude Matrix_setConstant_int.out
|
| 356 |
+
*
|
| 357 |
+
* \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
|
| 358 |
+
*/
|
| 359 |
+
template<typename Derived>
|
| 360 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 361 |
+
PlainObjectBase<Derived>::setConstant(Index size, const Scalar& val)
|
| 362 |
+
{
|
| 363 |
+
resize(size);
|
| 364 |
+
return setConstant(val);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
/** Resizes to the given size, and sets all coefficients in this expression to the given value \a val.
|
| 368 |
+
*
|
| 369 |
+
* \param rows the new number of rows
|
| 370 |
+
* \param cols the new number of columns
|
| 371 |
+
* \param val the value to which all coefficients are set
|
| 372 |
+
*
|
| 373 |
+
* Example: \include Matrix_setConstant_int_int.cpp
|
| 374 |
+
* Output: \verbinclude Matrix_setConstant_int_int.out
|
| 375 |
+
*
|
| 376 |
+
* \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
|
| 377 |
+
*/
|
| 378 |
+
template<typename Derived>
|
| 379 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 380 |
+
PlainObjectBase<Derived>::setConstant(Index rows, Index cols, const Scalar& val)
|
| 381 |
+
{
|
| 382 |
+
resize(rows, cols);
|
| 383 |
+
return setConstant(val);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
/** Resizes to the given size, changing only the number of columns, and sets all
|
| 387 |
+
* coefficients in this expression to the given value \a val. For the parameter
|
| 388 |
+
* of type NoChange_t, just pass the special value \c NoChange.
|
| 389 |
+
*
|
| 390 |
+
* \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
|
| 391 |
+
*/
|
| 392 |
+
template<typename Derived>
|
| 393 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 394 |
+
PlainObjectBase<Derived>::setConstant(NoChange_t, Index cols, const Scalar& val)
|
| 395 |
+
{
|
| 396 |
+
return setConstant(rows(), cols, val);
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
/** Resizes to the given size, changing only the number of rows, and sets all
|
| 400 |
+
* coefficients in this expression to the given value \a val. For the parameter
|
| 401 |
+
* of type NoChange_t, just pass the special value \c NoChange.
|
| 402 |
+
*
|
| 403 |
+
* \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
|
| 404 |
+
*/
|
| 405 |
+
template<typename Derived>
|
| 406 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 407 |
+
PlainObjectBase<Derived>::setConstant(Index rows, NoChange_t, const Scalar& val)
|
| 408 |
+
{
|
| 409 |
+
return setConstant(rows, cols(), val);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
/**
|
| 414 |
+
* \brief Sets a linearly spaced vector.
|
| 415 |
+
*
|
| 416 |
+
* The function generates 'size' equally spaced values in the closed interval [low,high].
|
| 417 |
+
* When size is set to 1, a vector of length 1 containing 'high' is returned.
|
| 418 |
+
*
|
| 419 |
+
* \only_for_vectors
|
| 420 |
+
*
|
| 421 |
+
* Example: \include DenseBase_setLinSpaced.cpp
|
| 422 |
+
* Output: \verbinclude DenseBase_setLinSpaced.out
|
| 423 |
+
*
|
| 424 |
+
* For integer scalar types, do not miss the explanations on the definition
|
| 425 |
+
* of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink.
|
| 426 |
+
*
|
| 427 |
+
* \sa LinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp
|
| 428 |
+
*/
|
| 429 |
+
template<typename Derived>
|
| 430 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(Index newSize, const Scalar& low, const Scalar& high)
|
| 431 |
+
{
|
| 432 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 433 |
+
return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize));
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
/**
|
| 437 |
+
* \brief Sets a linearly spaced vector.
|
| 438 |
+
*
|
| 439 |
+
* The function fills \c *this with equally spaced values in the closed interval [low,high].
|
| 440 |
+
* When size is set to 1, a vector of length 1 containing 'high' is returned.
|
| 441 |
+
*
|
| 442 |
+
* \only_for_vectors
|
| 443 |
+
*
|
| 444 |
+
* For integer scalar types, do not miss the explanations on the definition
|
| 445 |
+
* of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink.
|
| 446 |
+
*
|
| 447 |
+
* \sa LinSpaced(Index,const Scalar&,const Scalar&), setLinSpaced(Index, const Scalar&, const Scalar&), CwiseNullaryOp
|
| 448 |
+
*/
|
| 449 |
+
template<typename Derived>
|
| 450 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(const Scalar& low, const Scalar& high)
|
| 451 |
+
{
|
| 452 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 453 |
+
return setLinSpaced(size(), low, high);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
// zero:
|
| 457 |
+
|
| 458 |
+
/** \returns an expression of a zero matrix.
|
| 459 |
+
*
|
| 460 |
+
* The parameters \a rows and \a cols are the number of rows and of columns of
|
| 461 |
+
* the returned matrix. Must be compatible with this MatrixBase type.
|
| 462 |
+
*
|
| 463 |
+
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
|
| 464 |
+
* it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
|
| 465 |
+
* instead.
|
| 466 |
+
*
|
| 467 |
+
* Example: \include MatrixBase_zero_int_int.cpp
|
| 468 |
+
* Output: \verbinclude MatrixBase_zero_int_int.out
|
| 469 |
+
*
|
| 470 |
+
* \sa Zero(), Zero(Index)
|
| 471 |
+
*/
|
| 472 |
+
template<typename Derived>
|
| 473 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 474 |
+
DenseBase<Derived>::Zero(Index rows, Index cols)
|
| 475 |
+
{
|
| 476 |
+
return Constant(rows, cols, Scalar(0));
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
/** \returns an expression of a zero vector.
|
| 480 |
+
*
|
| 481 |
+
* The parameter \a size is the size of the returned vector.
|
| 482 |
+
* Must be compatible with this MatrixBase type.
|
| 483 |
+
*
|
| 484 |
+
* \only_for_vectors
|
| 485 |
+
*
|
| 486 |
+
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
|
| 487 |
+
* it is redundant to pass \a size as argument, so Zero() should be used
|
| 488 |
+
* instead.
|
| 489 |
+
*
|
| 490 |
+
* Example: \include MatrixBase_zero_int.cpp
|
| 491 |
+
* Output: \verbinclude MatrixBase_zero_int.out
|
| 492 |
+
*
|
| 493 |
+
* \sa Zero(), Zero(Index,Index)
|
| 494 |
+
*/
|
| 495 |
+
template<typename Derived>
|
| 496 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 497 |
+
DenseBase<Derived>::Zero(Index size)
|
| 498 |
+
{
|
| 499 |
+
return Constant(size, Scalar(0));
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
/** \returns an expression of a fixed-size zero matrix or vector.
|
| 503 |
+
*
|
| 504 |
+
* This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
|
| 505 |
+
* need to use the variants taking size arguments.
|
| 506 |
+
*
|
| 507 |
+
* Example: \include MatrixBase_zero.cpp
|
| 508 |
+
* Output: \verbinclude MatrixBase_zero.out
|
| 509 |
+
*
|
| 510 |
+
* \sa Zero(Index), Zero(Index,Index)
|
| 511 |
+
*/
|
| 512 |
+
template<typename Derived>
|
| 513 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 514 |
+
DenseBase<Derived>::Zero()
|
| 515 |
+
{
|
| 516 |
+
return Constant(Scalar(0));
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
/** \returns true if *this is approximately equal to the zero matrix,
|
| 520 |
+
* within the precision given by \a prec.
|
| 521 |
+
*
|
| 522 |
+
* Example: \include MatrixBase_isZero.cpp
|
| 523 |
+
* Output: \verbinclude MatrixBase_isZero.out
|
| 524 |
+
*
|
| 525 |
+
* \sa class CwiseNullaryOp, Zero()
|
| 526 |
+
*/
|
| 527 |
+
template<typename Derived>
|
| 528 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isZero(const RealScalar& prec) const
|
| 529 |
+
{
|
| 530 |
+
typename internal::nested_eval<Derived,1>::type self(derived());
|
| 531 |
+
for(Index j = 0; j < cols(); ++j)
|
| 532 |
+
for(Index i = 0; i < rows(); ++i)
|
| 533 |
+
if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<Scalar>(1), prec))
|
| 534 |
+
return false;
|
| 535 |
+
return true;
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
/** Sets all coefficients in this expression to zero.
|
| 539 |
+
*
|
| 540 |
+
* Example: \include MatrixBase_setZero.cpp
|
| 541 |
+
* Output: \verbinclude MatrixBase_setZero.out
|
| 542 |
+
*
|
| 543 |
+
* \sa class CwiseNullaryOp, Zero()
|
| 544 |
+
*/
|
| 545 |
+
template<typename Derived>
|
| 546 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setZero()
|
| 547 |
+
{
|
| 548 |
+
return setConstant(Scalar(0));
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
/** Resizes to the given \a size, and sets all coefficients in this expression to zero.
|
| 552 |
+
*
|
| 553 |
+
* \only_for_vectors
|
| 554 |
+
*
|
| 555 |
+
* Example: \include Matrix_setZero_int.cpp
|
| 556 |
+
* Output: \verbinclude Matrix_setZero_int.out
|
| 557 |
+
*
|
| 558 |
+
* \sa DenseBase::setZero(), setZero(Index,Index), class CwiseNullaryOp, DenseBase::Zero()
|
| 559 |
+
*/
|
| 560 |
+
template<typename Derived>
|
| 561 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 562 |
+
PlainObjectBase<Derived>::setZero(Index newSize)
|
| 563 |
+
{
|
| 564 |
+
resize(newSize);
|
| 565 |
+
return setConstant(Scalar(0));
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
/** Resizes to the given size, and sets all coefficients in this expression to zero.
|
| 569 |
+
*
|
| 570 |
+
* \param rows the new number of rows
|
| 571 |
+
* \param cols the new number of columns
|
| 572 |
+
*
|
| 573 |
+
* Example: \include Matrix_setZero_int_int.cpp
|
| 574 |
+
* Output: \verbinclude Matrix_setZero_int_int.out
|
| 575 |
+
*
|
| 576 |
+
* \sa DenseBase::setZero(), setZero(Index), class CwiseNullaryOp, DenseBase::Zero()
|
| 577 |
+
*/
|
| 578 |
+
template<typename Derived>
|
| 579 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 580 |
+
PlainObjectBase<Derived>::setZero(Index rows, Index cols)
|
| 581 |
+
{
|
| 582 |
+
resize(rows, cols);
|
| 583 |
+
return setConstant(Scalar(0));
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
/** Resizes to the given size, changing only the number of columns, and sets all
|
| 587 |
+
* coefficients in this expression to zero. For the parameter of type NoChange_t,
|
| 588 |
+
* just pass the special value \c NoChange.
|
| 589 |
+
*
|
| 590 |
+
* \sa DenseBase::setZero(), setZero(Index), setZero(Index, Index), setZero(Index, NoChange_t), class CwiseNullaryOp, DenseBase::Zero()
|
| 591 |
+
*/
|
| 592 |
+
template<typename Derived>
|
| 593 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 594 |
+
PlainObjectBase<Derived>::setZero(NoChange_t, Index cols)
|
| 595 |
+
{
|
| 596 |
+
return setZero(rows(), cols);
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
/** Resizes to the given size, changing only the number of rows, and sets all
|
| 600 |
+
* coefficients in this expression to zero. For the parameter of type NoChange_t,
|
| 601 |
+
* just pass the special value \c NoChange.
|
| 602 |
+
*
|
| 603 |
+
* \sa DenseBase::setZero(), setZero(Index), setZero(Index, Index), setZero(NoChange_t, Index), class CwiseNullaryOp, DenseBase::Zero()
|
| 604 |
+
*/
|
| 605 |
+
template<typename Derived>
|
| 606 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 607 |
+
PlainObjectBase<Derived>::setZero(Index rows, NoChange_t)
|
| 608 |
+
{
|
| 609 |
+
return setZero(rows, cols());
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
// ones:
|
| 613 |
+
|
| 614 |
+
/** \returns an expression of a matrix where all coefficients equal one.
|
| 615 |
+
*
|
| 616 |
+
* The parameters \a rows and \a cols are the number of rows and of columns of
|
| 617 |
+
* the returned matrix. Must be compatible with this MatrixBase type.
|
| 618 |
+
*
|
| 619 |
+
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
|
| 620 |
+
* it is redundant to pass \a rows and \a cols as arguments, so Ones() should be used
|
| 621 |
+
* instead.
|
| 622 |
+
*
|
| 623 |
+
* Example: \include MatrixBase_ones_int_int.cpp
|
| 624 |
+
* Output: \verbinclude MatrixBase_ones_int_int.out
|
| 625 |
+
*
|
| 626 |
+
* \sa Ones(), Ones(Index), isOnes(), class Ones
|
| 627 |
+
*/
|
| 628 |
+
template<typename Derived>
|
| 629 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 630 |
+
DenseBase<Derived>::Ones(Index rows, Index cols)
|
| 631 |
+
{
|
| 632 |
+
return Constant(rows, cols, Scalar(1));
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
/** \returns an expression of a vector where all coefficients equal one.
|
| 636 |
+
*
|
| 637 |
+
* The parameter \a newSize is the size of the returned vector.
|
| 638 |
+
* Must be compatible with this MatrixBase type.
|
| 639 |
+
*
|
| 640 |
+
* \only_for_vectors
|
| 641 |
+
*
|
| 642 |
+
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
|
| 643 |
+
* it is redundant to pass \a size as argument, so Ones() should be used
|
| 644 |
+
* instead.
|
| 645 |
+
*
|
| 646 |
+
* Example: \include MatrixBase_ones_int.cpp
|
| 647 |
+
* Output: \verbinclude MatrixBase_ones_int.out
|
| 648 |
+
*
|
| 649 |
+
* \sa Ones(), Ones(Index,Index), isOnes(), class Ones
|
| 650 |
+
*/
|
| 651 |
+
template<typename Derived>
|
| 652 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 653 |
+
DenseBase<Derived>::Ones(Index newSize)
|
| 654 |
+
{
|
| 655 |
+
return Constant(newSize, Scalar(1));
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
/** \returns an expression of a fixed-size matrix or vector where all coefficients equal one.
|
| 659 |
+
*
|
| 660 |
+
* This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
|
| 661 |
+
* need to use the variants taking size arguments.
|
| 662 |
+
*
|
| 663 |
+
* Example: \include MatrixBase_ones.cpp
|
| 664 |
+
* Output: \verbinclude MatrixBase_ones.out
|
| 665 |
+
*
|
| 666 |
+
* \sa Ones(Index), Ones(Index,Index), isOnes(), class Ones
|
| 667 |
+
*/
|
| 668 |
+
template<typename Derived>
|
| 669 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
|
| 670 |
+
DenseBase<Derived>::Ones()
|
| 671 |
+
{
|
| 672 |
+
return Constant(Scalar(1));
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
/** \returns true if *this is approximately equal to the matrix where all coefficients
|
| 676 |
+
* are equal to 1, within the precision given by \a prec.
|
| 677 |
+
*
|
| 678 |
+
* Example: \include MatrixBase_isOnes.cpp
|
| 679 |
+
* Output: \verbinclude MatrixBase_isOnes.out
|
| 680 |
+
*
|
| 681 |
+
* \sa class CwiseNullaryOp, Ones()
|
| 682 |
+
*/
|
| 683 |
+
template<typename Derived>
|
| 684 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isOnes
|
| 685 |
+
(const RealScalar& prec) const
|
| 686 |
+
{
|
| 687 |
+
return isApproxToConstant(Scalar(1), prec);
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
/** Sets all coefficients in this expression to one.
|
| 691 |
+
*
|
| 692 |
+
* Example: \include MatrixBase_setOnes.cpp
|
| 693 |
+
* Output: \verbinclude MatrixBase_setOnes.out
|
| 694 |
+
*
|
| 695 |
+
* \sa class CwiseNullaryOp, Ones()
|
| 696 |
+
*/
|
| 697 |
+
template<typename Derived>
|
| 698 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setOnes()
|
| 699 |
+
{
|
| 700 |
+
return setConstant(Scalar(1));
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
/** Resizes to the given \a newSize, and sets all coefficients in this expression to one.
|
| 704 |
+
*
|
| 705 |
+
* \only_for_vectors
|
| 706 |
+
*
|
| 707 |
+
* Example: \include Matrix_setOnes_int.cpp
|
| 708 |
+
* Output: \verbinclude Matrix_setOnes_int.out
|
| 709 |
+
*
|
| 710 |
+
* \sa MatrixBase::setOnes(), setOnes(Index,Index), class CwiseNullaryOp, MatrixBase::Ones()
|
| 711 |
+
*/
|
| 712 |
+
template<typename Derived>
|
| 713 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 714 |
+
PlainObjectBase<Derived>::setOnes(Index newSize)
|
| 715 |
+
{
|
| 716 |
+
resize(newSize);
|
| 717 |
+
return setConstant(Scalar(1));
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
/** Resizes to the given size, and sets all coefficients in this expression to one.
|
| 721 |
+
*
|
| 722 |
+
* \param rows the new number of rows
|
| 723 |
+
* \param cols the new number of columns
|
| 724 |
+
*
|
| 725 |
+
* Example: \include Matrix_setOnes_int_int.cpp
|
| 726 |
+
* Output: \verbinclude Matrix_setOnes_int_int.out
|
| 727 |
+
*
|
| 728 |
+
* \sa MatrixBase::setOnes(), setOnes(Index), class CwiseNullaryOp, MatrixBase::Ones()
|
| 729 |
+
*/
|
| 730 |
+
template<typename Derived>
|
| 731 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 732 |
+
PlainObjectBase<Derived>::setOnes(Index rows, Index cols)
|
| 733 |
+
{
|
| 734 |
+
resize(rows, cols);
|
| 735 |
+
return setConstant(Scalar(1));
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
/** Resizes to the given size, changing only the number of rows, and sets all
|
| 739 |
+
* coefficients in this expression to one. For the parameter of type NoChange_t,
|
| 740 |
+
* just pass the special value \c NoChange.
|
| 741 |
+
*
|
| 742 |
+
* \sa MatrixBase::setOnes(), setOnes(Index), setOnes(Index, Index), setOnes(NoChange_t, Index), class CwiseNullaryOp, MatrixBase::Ones()
|
| 743 |
+
*/
|
| 744 |
+
template<typename Derived>
|
| 745 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 746 |
+
PlainObjectBase<Derived>::setOnes(Index rows, NoChange_t)
|
| 747 |
+
{
|
| 748 |
+
return setOnes(rows, cols());
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
/** Resizes to the given size, changing only the number of columns, and sets all
|
| 752 |
+
* coefficients in this expression to one. For the parameter of type NoChange_t,
|
| 753 |
+
* just pass the special value \c NoChange.
|
| 754 |
+
*
|
| 755 |
+
* \sa MatrixBase::setOnes(), setOnes(Index), setOnes(Index, Index), setOnes(Index, NoChange_t) class CwiseNullaryOp, MatrixBase::Ones()
|
| 756 |
+
*/
|
| 757 |
+
template<typename Derived>
|
| 758 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
|
| 759 |
+
PlainObjectBase<Derived>::setOnes(NoChange_t, Index cols)
|
| 760 |
+
{
|
| 761 |
+
return setOnes(rows(), cols);
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
// Identity:
|
| 765 |
+
|
| 766 |
+
/** \returns an expression of the identity matrix (not necessarily square).
|
| 767 |
+
*
|
| 768 |
+
* The parameters \a rows and \a cols are the number of rows and of columns of
|
| 769 |
+
* the returned matrix. Must be compatible with this MatrixBase type.
|
| 770 |
+
*
|
| 771 |
+
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
|
| 772 |
+
* it is redundant to pass \a rows and \a cols as arguments, so Identity() should be used
|
| 773 |
+
* instead.
|
| 774 |
+
*
|
| 775 |
+
* Example: \include MatrixBase_identity_int_int.cpp
|
| 776 |
+
* Output: \verbinclude MatrixBase_identity_int_int.out
|
| 777 |
+
*
|
| 778 |
+
* \sa Identity(), setIdentity(), isIdentity()
|
| 779 |
+
*/
|
| 780 |
+
template<typename Derived>
|
| 781 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
|
| 782 |
+
MatrixBase<Derived>::Identity(Index rows, Index cols)
|
| 783 |
+
{
|
| 784 |
+
return DenseBase<Derived>::NullaryExpr(rows, cols, internal::scalar_identity_op<Scalar>());
|
| 785 |
+
}
|
| 786 |
+
|
| 787 |
+
/** \returns an expression of the identity matrix (not necessarily square).
|
| 788 |
+
*
|
| 789 |
+
* This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
|
| 790 |
+
* need to use the variant taking size arguments.
|
| 791 |
+
*
|
| 792 |
+
* Example: \include MatrixBase_identity.cpp
|
| 793 |
+
* Output: \verbinclude MatrixBase_identity.out
|
| 794 |
+
*
|
| 795 |
+
* \sa Identity(Index,Index), setIdentity(), isIdentity()
|
| 796 |
+
*/
|
| 797 |
+
template<typename Derived>
|
| 798 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
|
| 799 |
+
MatrixBase<Derived>::Identity()
|
| 800 |
+
{
|
| 801 |
+
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
|
| 802 |
+
return MatrixBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op<Scalar>());
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
/** \returns true if *this is approximately equal to the identity matrix
|
| 806 |
+
* (not necessarily square),
|
| 807 |
+
* within the precision given by \a prec.
|
| 808 |
+
*
|
| 809 |
+
* Example: \include MatrixBase_isIdentity.cpp
|
| 810 |
+
* Output: \verbinclude MatrixBase_isIdentity.out
|
| 811 |
+
*
|
| 812 |
+
* \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), setIdentity()
|
| 813 |
+
*/
|
| 814 |
+
template<typename Derived>
|
| 815 |
+
bool MatrixBase<Derived>::isIdentity
|
| 816 |
+
(const RealScalar& prec) const
|
| 817 |
+
{
|
| 818 |
+
typename internal::nested_eval<Derived,1>::type self(derived());
|
| 819 |
+
for(Index j = 0; j < cols(); ++j)
|
| 820 |
+
{
|
| 821 |
+
for(Index i = 0; i < rows(); ++i)
|
| 822 |
+
{
|
| 823 |
+
if(i == j)
|
| 824 |
+
{
|
| 825 |
+
if(!internal::isApprox(self.coeff(i, j), static_cast<Scalar>(1), prec))
|
| 826 |
+
return false;
|
| 827 |
+
}
|
| 828 |
+
else
|
| 829 |
+
{
|
| 830 |
+
if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<RealScalar>(1), prec))
|
| 831 |
+
return false;
|
| 832 |
+
}
|
| 833 |
+
}
|
| 834 |
+
}
|
| 835 |
+
return true;
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
namespace internal {
|
| 839 |
+
|
| 840 |
+
template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
|
| 841 |
+
struct setIdentity_impl
|
| 842 |
+
{
|
| 843 |
+
EIGEN_DEVICE_FUNC
|
| 844 |
+
static EIGEN_STRONG_INLINE Derived& run(Derived& m)
|
| 845 |
+
{
|
| 846 |
+
return m = Derived::Identity(m.rows(), m.cols());
|
| 847 |
+
}
|
| 848 |
+
};
|
| 849 |
+
|
| 850 |
+
template<typename Derived>
|
| 851 |
+
struct setIdentity_impl<Derived, true>
|
| 852 |
+
{
|
| 853 |
+
EIGEN_DEVICE_FUNC
|
| 854 |
+
static EIGEN_STRONG_INLINE Derived& run(Derived& m)
|
| 855 |
+
{
|
| 856 |
+
m.setZero();
|
| 857 |
+
const Index size = numext::mini(m.rows(), m.cols());
|
| 858 |
+
for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1);
|
| 859 |
+
return m;
|
| 860 |
+
}
|
| 861 |
+
};
|
| 862 |
+
|
| 863 |
+
} // end namespace internal
|
| 864 |
+
|
| 865 |
+
/** Writes the identity expression (not necessarily square) into *this.
|
| 866 |
+
*
|
| 867 |
+
* Example: \include MatrixBase_setIdentity.cpp
|
| 868 |
+
* Output: \verbinclude MatrixBase_setIdentity.out
|
| 869 |
+
*
|
| 870 |
+
* \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), isIdentity()
|
| 871 |
+
*/
|
| 872 |
+
template<typename Derived>
|
| 873 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity()
|
| 874 |
+
{
|
| 875 |
+
return internal::setIdentity_impl<Derived>::run(derived());
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
/** \brief Resizes to the given size, and writes the identity expression (not necessarily square) into *this.
|
| 879 |
+
*
|
| 880 |
+
* \param rows the new number of rows
|
| 881 |
+
* \param cols the new number of columns
|
| 882 |
+
*
|
| 883 |
+
* Example: \include Matrix_setIdentity_int_int.cpp
|
| 884 |
+
* Output: \verbinclude Matrix_setIdentity_int_int.out
|
| 885 |
+
*
|
| 886 |
+
* \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Identity()
|
| 887 |
+
*/
|
| 888 |
+
template<typename Derived>
|
| 889 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity(Index rows, Index cols)
|
| 890 |
+
{
|
| 891 |
+
derived().resize(rows, cols);
|
| 892 |
+
return setIdentity();
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
/** \returns an expression of the i-th unit (basis) vector.
|
| 896 |
+
*
|
| 897 |
+
* \only_for_vectors
|
| 898 |
+
*
|
| 899 |
+
* \sa MatrixBase::Unit(Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
|
| 900 |
+
*/
|
| 901 |
+
template<typename Derived>
|
| 902 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index newSize, Index i)
|
| 903 |
+
{
|
| 904 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 905 |
+
return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
/** \returns an expression of the i-th unit (basis) vector.
|
| 909 |
+
*
|
| 910 |
+
* \only_for_vectors
|
| 911 |
+
*
|
| 912 |
+
* This variant is for fixed-size vector only.
|
| 913 |
+
*
|
| 914 |
+
* \sa MatrixBase::Unit(Index,Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
|
| 915 |
+
*/
|
| 916 |
+
template<typename Derived>
|
| 917 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index i)
|
| 918 |
+
{
|
| 919 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 920 |
+
return BasisReturnType(SquareMatrixType::Identity(),i);
|
| 921 |
+
}
|
| 922 |
+
|
| 923 |
+
/** \returns an expression of the X axis unit vector (1{,0}^*)
|
| 924 |
+
*
|
| 925 |
+
* \only_for_vectors
|
| 926 |
+
*
|
| 927 |
+
* \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
|
| 928 |
+
*/
|
| 929 |
+
template<typename Derived>
|
| 930 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitX()
|
| 931 |
+
{ return Derived::Unit(0); }
|
| 932 |
+
|
| 933 |
+
/** \returns an expression of the Y axis unit vector (0,1{,0}^*)
|
| 934 |
+
*
|
| 935 |
+
* \only_for_vectors
|
| 936 |
+
*
|
| 937 |
+
* \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
|
| 938 |
+
*/
|
| 939 |
+
template<typename Derived>
|
| 940 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitY()
|
| 941 |
+
{ return Derived::Unit(1); }
|
| 942 |
+
|
| 943 |
+
/** \returns an expression of the Z axis unit vector (0,0,1{,0}^*)
|
| 944 |
+
*
|
| 945 |
+
* \only_for_vectors
|
| 946 |
+
*
|
| 947 |
+
* \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
|
| 948 |
+
*/
|
| 949 |
+
template<typename Derived>
|
| 950 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitZ()
|
| 951 |
+
{ return Derived::Unit(2); }
|
| 952 |
+
|
| 953 |
+
/** \returns an expression of the W axis unit vector (0,0,0,1)
|
| 954 |
+
*
|
| 955 |
+
* \only_for_vectors
|
| 956 |
+
*
|
| 957 |
+
* \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
|
| 958 |
+
*/
|
| 959 |
+
template<typename Derived>
|
| 960 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitW()
|
| 961 |
+
{ return Derived::Unit(3); }
|
| 962 |
+
|
| 963 |
+
/** \brief Set the coefficients of \c *this to the i-th unit (basis) vector
|
| 964 |
+
*
|
| 965 |
+
* \param i index of the unique coefficient to be set to 1
|
| 966 |
+
*
|
| 967 |
+
* \only_for_vectors
|
| 968 |
+
*
|
| 969 |
+
* \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index)
|
| 970 |
+
*/
|
| 971 |
+
template<typename Derived>
|
| 972 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setUnit(Index i)
|
| 973 |
+
{
|
| 974 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
|
| 975 |
+
eigen_assert(i<size());
|
| 976 |
+
derived().setZero();
|
| 977 |
+
derived().coeffRef(i) = Scalar(1);
|
| 978 |
+
return derived();
|
| 979 |
+
}
|
| 980 |
+
|
| 981 |
+
/** \brief Resizes to the given \a newSize, and writes the i-th unit (basis) vector into *this.
|
| 982 |
+
*
|
| 983 |
+
* \param newSize the new size of the vector
|
| 984 |
+
* \param i index of the unique coefficient to be set to 1
|
| 985 |
+
*
|
| 986 |
+
* \only_for_vectors
|
| 987 |
+
*
|
| 988 |
+
* \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index)
|
| 989 |
+
*/
|
| 990 |
+
template<typename Derived>
|
| 991 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setUnit(Index newSize, Index i)
|
| 992 |
+
{
|
| 993 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
|
| 994 |
+
eigen_assert(i<newSize);
|
| 995 |
+
derived().resize(newSize);
|
| 996 |
+
return setUnit(i);
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
} // end namespace Eigen
|
| 1000 |
+
|
| 1001 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
|
| 7 |
+
//
|
| 8 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 9 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 10 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 11 |
+
|
| 12 |
+
#ifndef EIGEN_CWISE_TERNARY_OP_H
|
| 13 |
+
#define EIGEN_CWISE_TERNARY_OP_H
|
| 14 |
+
|
| 15 |
+
namespace Eigen {
|
| 16 |
+
|
| 17 |
+
namespace internal {
|
| 18 |
+
template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3>
|
| 19 |
+
struct traits<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > {
|
| 20 |
+
// we must not inherit from traits<Arg1> since it has
|
| 21 |
+
// the potential to cause problems with MSVC
|
| 22 |
+
typedef typename remove_all<Arg1>::type Ancestor;
|
| 23 |
+
typedef typename traits<Ancestor>::XprKind XprKind;
|
| 24 |
+
enum {
|
| 25 |
+
RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
|
| 26 |
+
ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
|
| 27 |
+
MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
|
| 28 |
+
MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
// even though we require Arg1, Arg2, and Arg3 to have the same scalar type
|
| 32 |
+
// (see CwiseTernaryOp constructor),
|
| 33 |
+
// we still want to handle the case when the result type is different.
|
| 34 |
+
typedef typename result_of<TernaryOp(
|
| 35 |
+
const typename Arg1::Scalar&, const typename Arg2::Scalar&,
|
| 36 |
+
const typename Arg3::Scalar&)>::type Scalar;
|
| 37 |
+
|
| 38 |
+
typedef typename internal::traits<Arg1>::StorageKind StorageKind;
|
| 39 |
+
typedef typename internal::traits<Arg1>::StorageIndex StorageIndex;
|
| 40 |
+
|
| 41 |
+
typedef typename Arg1::Nested Arg1Nested;
|
| 42 |
+
typedef typename Arg2::Nested Arg2Nested;
|
| 43 |
+
typedef typename Arg3::Nested Arg3Nested;
|
| 44 |
+
typedef typename remove_reference<Arg1Nested>::type _Arg1Nested;
|
| 45 |
+
typedef typename remove_reference<Arg2Nested>::type _Arg2Nested;
|
| 46 |
+
typedef typename remove_reference<Arg3Nested>::type _Arg3Nested;
|
| 47 |
+
enum { Flags = _Arg1Nested::Flags & RowMajorBit };
|
| 48 |
+
};
|
| 49 |
+
} // end namespace internal
|
| 50 |
+
|
| 51 |
+
template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3,
|
| 52 |
+
typename StorageKind>
|
| 53 |
+
class CwiseTernaryOpImpl;
|
| 54 |
+
|
| 55 |
+
/** \class CwiseTernaryOp
|
| 56 |
+
* \ingroup Core_Module
|
| 57 |
+
*
|
| 58 |
+
* \brief Generic expression where a coefficient-wise ternary operator is
|
| 59 |
+
* applied to two expressions
|
| 60 |
+
*
|
| 61 |
+
* \tparam TernaryOp template functor implementing the operator
|
| 62 |
+
* \tparam Arg1Type the type of the first argument
|
| 63 |
+
* \tparam Arg2Type the type of the second argument
|
| 64 |
+
* \tparam Arg3Type the type of the third argument
|
| 65 |
+
*
|
| 66 |
+
* This class represents an expression where a coefficient-wise ternary
|
| 67 |
+
* operator is applied to three expressions.
|
| 68 |
+
* It is the return type of ternary operators, by which we mean only those
|
| 69 |
+
* ternary operators where
|
| 70 |
+
* all three arguments are Eigen expressions.
|
| 71 |
+
* For example, the return type of betainc(matrix1, matrix2, matrix3) is a
|
| 72 |
+
* CwiseTernaryOp.
|
| 73 |
+
*
|
| 74 |
+
* Most of the time, this is the only way that it is used, so you typically
|
| 75 |
+
* don't have to name
|
| 76 |
+
* CwiseTernaryOp types explicitly.
|
| 77 |
+
*
|
| 78 |
+
* \sa MatrixBase::ternaryExpr(const MatrixBase<Argument2> &, const
|
| 79 |
+
* MatrixBase<Argument3> &, const CustomTernaryOp &) const, class CwiseBinaryOp,
|
| 80 |
+
* class CwiseUnaryOp, class CwiseNullaryOp
|
| 81 |
+
*/
|
| 82 |
+
template <typename TernaryOp, typename Arg1Type, typename Arg2Type,
|
| 83 |
+
typename Arg3Type>
|
| 84 |
+
class CwiseTernaryOp : public CwiseTernaryOpImpl<
|
| 85 |
+
TernaryOp, Arg1Type, Arg2Type, Arg3Type,
|
| 86 |
+
typename internal::traits<Arg1Type>::StorageKind>,
|
| 87 |
+
internal::no_assignment_operator
|
| 88 |
+
{
|
| 89 |
+
public:
|
| 90 |
+
typedef typename internal::remove_all<Arg1Type>::type Arg1;
|
| 91 |
+
typedef typename internal::remove_all<Arg2Type>::type Arg2;
|
| 92 |
+
typedef typename internal::remove_all<Arg3Type>::type Arg3;
|
| 93 |
+
|
| 94 |
+
typedef typename CwiseTernaryOpImpl<
|
| 95 |
+
TernaryOp, Arg1Type, Arg2Type, Arg3Type,
|
| 96 |
+
typename internal::traits<Arg1Type>::StorageKind>::Base Base;
|
| 97 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseTernaryOp)
|
| 98 |
+
|
| 99 |
+
typedef typename internal::ref_selector<Arg1Type>::type Arg1Nested;
|
| 100 |
+
typedef typename internal::ref_selector<Arg2Type>::type Arg2Nested;
|
| 101 |
+
typedef typename internal::ref_selector<Arg3Type>::type Arg3Nested;
|
| 102 |
+
typedef typename internal::remove_reference<Arg1Nested>::type _Arg1Nested;
|
| 103 |
+
typedef typename internal::remove_reference<Arg2Nested>::type _Arg2Nested;
|
| 104 |
+
typedef typename internal::remove_reference<Arg3Nested>::type _Arg3Nested;
|
| 105 |
+
|
| 106 |
+
EIGEN_DEVICE_FUNC
|
| 107 |
+
EIGEN_STRONG_INLINE CwiseTernaryOp(const Arg1& a1, const Arg2& a2,
|
| 108 |
+
const Arg3& a3,
|
| 109 |
+
const TernaryOp& func = TernaryOp())
|
| 110 |
+
: m_arg1(a1), m_arg2(a2), m_arg3(a3), m_functor(func) {
|
| 111 |
+
// require the sizes to match
|
| 112 |
+
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg2)
|
| 113 |
+
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg3)
|
| 114 |
+
|
| 115 |
+
// The index types should match
|
| 116 |
+
EIGEN_STATIC_ASSERT((internal::is_same<
|
| 117 |
+
typename internal::traits<Arg1Type>::StorageKind,
|
| 118 |
+
typename internal::traits<Arg2Type>::StorageKind>::value),
|
| 119 |
+
STORAGE_KIND_MUST_MATCH)
|
| 120 |
+
EIGEN_STATIC_ASSERT((internal::is_same<
|
| 121 |
+
typename internal::traits<Arg1Type>::StorageKind,
|
| 122 |
+
typename internal::traits<Arg3Type>::StorageKind>::value),
|
| 123 |
+
STORAGE_KIND_MUST_MATCH)
|
| 124 |
+
|
| 125 |
+
eigen_assert(a1.rows() == a2.rows() && a1.cols() == a2.cols() &&
|
| 126 |
+
a1.rows() == a3.rows() && a1.cols() == a3.cols());
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
EIGEN_DEVICE_FUNC
|
| 130 |
+
EIGEN_STRONG_INLINE Index rows() const {
|
| 131 |
+
// return the fixed size type if available to enable compile time
|
| 132 |
+
// optimizations
|
| 133 |
+
if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
|
| 134 |
+
RowsAtCompileTime == Dynamic &&
|
| 135 |
+
internal::traits<typename internal::remove_all<Arg2Nested>::type>::
|
| 136 |
+
RowsAtCompileTime == Dynamic)
|
| 137 |
+
return m_arg3.rows();
|
| 138 |
+
else if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
|
| 139 |
+
RowsAtCompileTime == Dynamic &&
|
| 140 |
+
internal::traits<typename internal::remove_all<Arg3Nested>::type>::
|
| 141 |
+
RowsAtCompileTime == Dynamic)
|
| 142 |
+
return m_arg2.rows();
|
| 143 |
+
else
|
| 144 |
+
return m_arg1.rows();
|
| 145 |
+
}
|
| 146 |
+
EIGEN_DEVICE_FUNC
|
| 147 |
+
EIGEN_STRONG_INLINE Index cols() const {
|
| 148 |
+
// return the fixed size type if available to enable compile time
|
| 149 |
+
// optimizations
|
| 150 |
+
if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
|
| 151 |
+
ColsAtCompileTime == Dynamic &&
|
| 152 |
+
internal::traits<typename internal::remove_all<Arg2Nested>::type>::
|
| 153 |
+
ColsAtCompileTime == Dynamic)
|
| 154 |
+
return m_arg3.cols();
|
| 155 |
+
else if (internal::traits<typename internal::remove_all<Arg1Nested>::type>::
|
| 156 |
+
ColsAtCompileTime == Dynamic &&
|
| 157 |
+
internal::traits<typename internal::remove_all<Arg3Nested>::type>::
|
| 158 |
+
ColsAtCompileTime == Dynamic)
|
| 159 |
+
return m_arg2.cols();
|
| 160 |
+
else
|
| 161 |
+
return m_arg1.cols();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/** \returns the first argument nested expression */
|
| 165 |
+
EIGEN_DEVICE_FUNC
|
| 166 |
+
const _Arg1Nested& arg1() const { return m_arg1; }
|
| 167 |
+
/** \returns the first argument nested expression */
|
| 168 |
+
EIGEN_DEVICE_FUNC
|
| 169 |
+
const _Arg2Nested& arg2() const { return m_arg2; }
|
| 170 |
+
/** \returns the third argument nested expression */
|
| 171 |
+
EIGEN_DEVICE_FUNC
|
| 172 |
+
const _Arg3Nested& arg3() const { return m_arg3; }
|
| 173 |
+
/** \returns the functor representing the ternary operation */
|
| 174 |
+
EIGEN_DEVICE_FUNC
|
| 175 |
+
const TernaryOp& functor() const { return m_functor; }
|
| 176 |
+
|
| 177 |
+
protected:
|
| 178 |
+
Arg1Nested m_arg1;
|
| 179 |
+
Arg2Nested m_arg2;
|
| 180 |
+
Arg3Nested m_arg3;
|
| 181 |
+
const TernaryOp m_functor;
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
// Generic API dispatcher
|
| 185 |
+
template <typename TernaryOp, typename Arg1, typename Arg2, typename Arg3,
|
| 186 |
+
typename StorageKind>
|
| 187 |
+
class CwiseTernaryOpImpl
|
| 188 |
+
: public internal::generic_xpr_base<
|
| 189 |
+
CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type {
|
| 190 |
+
public:
|
| 191 |
+
typedef typename internal::generic_xpr_base<
|
| 192 |
+
CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >::type Base;
|
| 193 |
+
};
|
| 194 |
+
|
| 195 |
+
} // end namespace Eigen
|
| 196 |
+
|
| 197 |
+
#endif // EIGEN_CWISE_TERNARY_OP_H
|
include/eigen/Eigen/src/Core/CwiseUnaryOp.h
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_CWISE_UNARY_OP_H
|
| 12 |
+
#define EIGEN_CWISE_UNARY_OP_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
template<typename UnaryOp, typename XprType>
|
| 18 |
+
struct traits<CwiseUnaryOp<UnaryOp, XprType> >
|
| 19 |
+
: traits<XprType>
|
| 20 |
+
{
|
| 21 |
+
typedef typename result_of<
|
| 22 |
+
UnaryOp(const typename XprType::Scalar&)
|
| 23 |
+
>::type Scalar;
|
| 24 |
+
typedef typename XprType::Nested XprTypeNested;
|
| 25 |
+
typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
|
| 26 |
+
enum {
|
| 27 |
+
Flags = _XprTypeNested::Flags & RowMajorBit
|
| 28 |
+
};
|
| 29 |
+
};
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
template<typename UnaryOp, typename XprType, typename StorageKind>
|
| 33 |
+
class CwiseUnaryOpImpl;
|
| 34 |
+
|
| 35 |
+
/** \class CwiseUnaryOp
|
| 36 |
+
* \ingroup Core_Module
|
| 37 |
+
*
|
| 38 |
+
* \brief Generic expression where a coefficient-wise unary operator is applied to an expression
|
| 39 |
+
*
|
| 40 |
+
* \tparam UnaryOp template functor implementing the operator
|
| 41 |
+
* \tparam XprType the type of the expression to which we are applying the unary operator
|
| 42 |
+
*
|
| 43 |
+
* This class represents an expression where a unary operator is applied to an expression.
|
| 44 |
+
* It is the return type of all operations taking exactly 1 input expression, regardless of the
|
| 45 |
+
* presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix
|
| 46 |
+
* is considered unary, because only the right-hand side is an expression, and its
|
| 47 |
+
* return type is a specialization of CwiseUnaryOp.
|
| 48 |
+
*
|
| 49 |
+
* Most of the time, this is the only way that it is used, so you typically don't have to name
|
| 50 |
+
* CwiseUnaryOp types explicitly.
|
| 51 |
+
*
|
| 52 |
+
* \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp
|
| 53 |
+
*/
|
| 54 |
+
template<typename UnaryOp, typename XprType>
|
| 55 |
+
class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator
|
| 56 |
+
{
|
| 57 |
+
public:
|
| 58 |
+
|
| 59 |
+
typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
|
| 60 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
|
| 61 |
+
typedef typename internal::ref_selector<XprType>::type XprTypeNested;
|
| 62 |
+
typedef typename internal::remove_all<XprType>::type NestedExpression;
|
| 63 |
+
|
| 64 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 65 |
+
explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
|
| 66 |
+
: m_xpr(xpr), m_functor(func) {}
|
| 67 |
+
|
| 68 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 69 |
+
Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
|
| 70 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 71 |
+
Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
|
| 72 |
+
|
| 73 |
+
/** \returns the functor representing the unary operation */
|
| 74 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 75 |
+
const UnaryOp& functor() const { return m_functor; }
|
| 76 |
+
|
| 77 |
+
/** \returns the nested expression */
|
| 78 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 79 |
+
const typename internal::remove_all<XprTypeNested>::type&
|
| 80 |
+
nestedExpression() const { return m_xpr; }
|
| 81 |
+
|
| 82 |
+
/** \returns the nested expression */
|
| 83 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 84 |
+
typename internal::remove_all<XprTypeNested>::type&
|
| 85 |
+
nestedExpression() { return m_xpr; }
|
| 86 |
+
|
| 87 |
+
protected:
|
| 88 |
+
XprTypeNested m_xpr;
|
| 89 |
+
const UnaryOp m_functor;
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
// Generic API dispatcher
|
| 93 |
+
template<typename UnaryOp, typename XprType, typename StorageKind>
|
| 94 |
+
class CwiseUnaryOpImpl
|
| 95 |
+
: public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
|
| 96 |
+
{
|
| 97 |
+
public:
|
| 98 |
+
typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
} // end namespace Eigen
|
| 102 |
+
|
| 103 |
+
#endif // EIGEN_CWISE_UNARY_OP_H
|
include/eigen/Eigen/src/Core/CwiseUnaryView.h
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_CWISE_UNARY_VIEW_H
|
| 11 |
+
#define EIGEN_CWISE_UNARY_VIEW_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
template<typename ViewOp, typename MatrixType>
|
| 17 |
+
struct traits<CwiseUnaryView<ViewOp, MatrixType> >
|
| 18 |
+
: traits<MatrixType>
|
| 19 |
+
{
|
| 20 |
+
typedef typename result_of<
|
| 21 |
+
ViewOp(const typename traits<MatrixType>::Scalar&)
|
| 22 |
+
>::type Scalar;
|
| 23 |
+
typedef typename MatrixType::Nested MatrixTypeNested;
|
| 24 |
+
typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
|
| 25 |
+
enum {
|
| 26 |
+
FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
|
| 27 |
+
Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
|
| 28 |
+
MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
|
| 29 |
+
// need to cast the sizeof's from size_t to int explicitly, otherwise:
|
| 30 |
+
// "error: no integral type can represent all of the enumerator values
|
| 31 |
+
InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
|
| 32 |
+
? int(Dynamic)
|
| 33 |
+
: int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
|
| 34 |
+
OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
|
| 35 |
+
? int(Dynamic)
|
| 36 |
+
: outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
|
| 37 |
+
};
|
| 38 |
+
};
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
template<typename ViewOp, typename MatrixType, typename StorageKind>
|
| 42 |
+
class CwiseUnaryViewImpl;
|
| 43 |
+
|
| 44 |
+
/** \class CwiseUnaryView
|
| 45 |
+
* \ingroup Core_Module
|
| 46 |
+
*
|
| 47 |
+
* \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector
|
| 48 |
+
*
|
| 49 |
+
* \tparam ViewOp template functor implementing the view
|
| 50 |
+
* \tparam MatrixType the type of the matrix we are applying the unary operator
|
| 51 |
+
*
|
| 52 |
+
* This class represents a lvalue expression of a generic unary view operator of a matrix or a vector.
|
| 53 |
+
* It is the return type of real() and imag(), and most of the time this is the only way it is used.
|
| 54 |
+
*
|
| 55 |
+
* \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp
|
| 56 |
+
*/
|
| 57 |
+
template<typename ViewOp, typename MatrixType>
|
| 58 |
+
class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
|
| 59 |
+
{
|
| 60 |
+
public:
|
| 61 |
+
|
| 62 |
+
typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
|
| 63 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
|
| 64 |
+
typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
|
| 65 |
+
typedef typename internal::remove_all<MatrixType>::type NestedExpression;
|
| 66 |
+
|
| 67 |
+
explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
|
| 68 |
+
: m_matrix(mat), m_functor(func) {}
|
| 69 |
+
|
| 70 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
|
| 71 |
+
|
| 72 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 73 |
+
Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
|
| 74 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 75 |
+
Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
|
| 76 |
+
|
| 77 |
+
/** \returns the functor representing unary operation */
|
| 78 |
+
EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; }
|
| 79 |
+
|
| 80 |
+
/** \returns the nested expression */
|
| 81 |
+
EIGEN_DEVICE_FUNC const typename internal::remove_all<MatrixTypeNested>::type&
|
| 82 |
+
nestedExpression() const { return m_matrix; }
|
| 83 |
+
|
| 84 |
+
/** \returns the nested expression */
|
| 85 |
+
EIGEN_DEVICE_FUNC typename internal::remove_reference<MatrixTypeNested>::type&
|
| 86 |
+
nestedExpression() { return m_matrix; }
|
| 87 |
+
|
| 88 |
+
protected:
|
| 89 |
+
MatrixTypeNested m_matrix;
|
| 90 |
+
ViewOp m_functor;
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
// Generic API dispatcher
|
| 94 |
+
template<typename ViewOp, typename XprType, typename StorageKind>
|
| 95 |
+
class CwiseUnaryViewImpl
|
| 96 |
+
: public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
|
| 97 |
+
{
|
| 98 |
+
public:
|
| 99 |
+
typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
template<typename ViewOp, typename MatrixType>
|
| 103 |
+
class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
|
| 104 |
+
: public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
|
| 105 |
+
{
|
| 106 |
+
public:
|
| 107 |
+
|
| 108 |
+
typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
|
| 109 |
+
typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
|
| 110 |
+
|
| 111 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
|
| 112 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
|
| 113 |
+
|
| 114 |
+
EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
|
| 115 |
+
EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
|
| 116 |
+
|
| 117 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const
|
| 118 |
+
{
|
| 119 |
+
return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const
|
| 123 |
+
{
|
| 124 |
+
return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
|
| 125 |
+
}
|
| 126 |
+
protected:
|
| 127 |
+
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
} // end namespace Eigen
|
| 131 |
+
|
| 132 |
+
#endif // EIGEN_CWISE_UNARY_VIEW_H
|
include/eigen/Eigen/src/Core/DenseBase.h
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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acob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_DENSEBASE_H
|
| 12 |
+
#define EIGEN_DENSEBASE_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
|
| 18 |
+
// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
|
| 19 |
+
// This dummy function simply aims at checking that at compile time.
|
| 20 |
+
static inline void check_DenseIndex_is_signed() {
|
| 21 |
+
EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
} // end namespace internal
|
| 25 |
+
|
| 26 |
+
/** \class DenseBase
|
| 27 |
+
* \ingroup Core_Module
|
| 28 |
+
*
|
| 29 |
+
* \brief Base class for all dense matrices, vectors, and arrays
|
| 30 |
+
*
|
| 31 |
+
* This class is the base that is inherited by all dense objects (matrix, vector, arrays,
|
| 32 |
+
* and related expression types). The common Eigen API for dense objects is contained in this class.
|
| 33 |
+
*
|
| 34 |
+
* \tparam Derived is the derived type, e.g., a matrix type or an expression.
|
| 35 |
+
*
|
| 36 |
+
* This class can be extended with the help of the plugin mechanism described on the page
|
| 37 |
+
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_DENSEBASE_PLUGIN.
|
| 38 |
+
*
|
| 39 |
+
* \sa \blank \ref TopicClassHierarchy
|
| 40 |
+
*/
|
| 41 |
+
template<typename Derived> class DenseBase
|
| 42 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 43 |
+
: public DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value>
|
| 44 |
+
#else
|
| 45 |
+
: public DenseCoeffsBase<Derived,DirectWriteAccessors>
|
| 46 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 47 |
+
{
|
| 48 |
+
public:
|
| 49 |
+
|
| 50 |
+
/** Inner iterator type to iterate over the coefficients of a row or column.
|
| 51 |
+
* \sa class InnerIterator
|
| 52 |
+
*/
|
| 53 |
+
typedef Eigen::InnerIterator<Derived> InnerIterator;
|
| 54 |
+
|
| 55 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* \brief The type used to store indices
|
| 59 |
+
* \details This typedef is relevant for types that store multiple indices such as
|
| 60 |
+
* PermutationMatrix or Transpositions, otherwise it defaults to Eigen::Index
|
| 61 |
+
* \sa \blank \ref TopicPreprocessorDirectives, Eigen::Index, SparseMatrixBase.
|
| 62 |
+
*/
|
| 63 |
+
typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
|
| 64 |
+
|
| 65 |
+
/** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc. */
|
| 66 |
+
typedef typename internal::traits<Derived>::Scalar Scalar;
|
| 67 |
+
|
| 68 |
+
/** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex<float>, etc.
|
| 69 |
+
*
|
| 70 |
+
* It is an alias for the Scalar type */
|
| 71 |
+
typedef Scalar value_type;
|
| 72 |
+
|
| 73 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 74 |
+
typedef DenseCoeffsBase<Derived, internal::accessors_level<Derived>::value> Base;
|
| 75 |
+
|
| 76 |
+
using Base::derived;
|
| 77 |
+
using Base::const_cast_derived;
|
| 78 |
+
using Base::rows;
|
| 79 |
+
using Base::cols;
|
| 80 |
+
using Base::size;
|
| 81 |
+
using Base::rowIndexByOuterInner;
|
| 82 |
+
using Base::colIndexByOuterInner;
|
| 83 |
+
using Base::coeff;
|
| 84 |
+
using Base::coeffByOuterInner;
|
| 85 |
+
using Base::operator();
|
| 86 |
+
using Base::operator[];
|
| 87 |
+
using Base::x;
|
| 88 |
+
using Base::y;
|
| 89 |
+
using Base::z;
|
| 90 |
+
using Base::w;
|
| 91 |
+
using Base::stride;
|
| 92 |
+
using Base::innerStride;
|
| 93 |
+
using Base::outerStride;
|
| 94 |
+
using Base::rowStride;
|
| 95 |
+
using Base::colStride;
|
| 96 |
+
typedef typename Base::CoeffReturnType CoeffReturnType;
|
| 97 |
+
|
| 98 |
+
enum {
|
| 99 |
+
|
| 100 |
+
RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
|
| 101 |
+
/**< The number of rows at compile-time. This is just a copy of the value provided
|
| 102 |
+
* by the \a Derived type. If a value is not known at compile-time,
|
| 103 |
+
* it is set to the \a Dynamic constant.
|
| 104 |
+
* \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
|
| 105 |
+
|
| 106 |
+
ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
|
| 107 |
+
/**< The number of columns at compile-time. This is just a copy of the value provided
|
| 108 |
+
* by the \a Derived type. If a value is not known at compile-time,
|
| 109 |
+
* it is set to the \a Dynamic constant.
|
| 110 |
+
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
SizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
|
| 114 |
+
internal::traits<Derived>::ColsAtCompileTime>::ret),
|
| 115 |
+
/**< This is equal to the number of coefficients, i.e. the number of
|
| 116 |
+
* rows times the number of columns, or to \a Dynamic if this is not
|
| 117 |
+
* known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
|
| 118 |
+
|
| 119 |
+
MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
|
| 120 |
+
/**< This value is equal to the maximum possible number of rows that this expression
|
| 121 |
+
* might have. If this expression might have an arbitrarily high number of rows,
|
| 122 |
+
* this value is set to \a Dynamic.
|
| 123 |
+
*
|
| 124 |
+
* This value is useful to know when evaluating an expression, in order to determine
|
| 125 |
+
* whether it is possible to avoid doing a dynamic memory allocation.
|
| 126 |
+
*
|
| 127 |
+
* \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime
|
| 128 |
+
*/
|
| 129 |
+
|
| 130 |
+
MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
|
| 131 |
+
/**< This value is equal to the maximum possible number of columns that this expression
|
| 132 |
+
* might have. If this expression might have an arbitrarily high number of columns,
|
| 133 |
+
* this value is set to \a Dynamic.
|
| 134 |
+
*
|
| 135 |
+
* This value is useful to know when evaluating an expression, in order to determine
|
| 136 |
+
* whether it is possible to avoid doing a dynamic memory allocation.
|
| 137 |
+
*
|
| 138 |
+
* \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
|
| 139 |
+
*/
|
| 140 |
+
|
| 141 |
+
MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
|
| 142 |
+
internal::traits<Derived>::MaxColsAtCompileTime>::ret),
|
| 143 |
+
/**< This value is equal to the maximum possible number of coefficients that this expression
|
| 144 |
+
* might have. If this expression might have an arbitrarily high number of coefficients,
|
| 145 |
+
* this value is set to \a Dynamic.
|
| 146 |
+
*
|
| 147 |
+
* This value is useful to know when evaluating an expression, in order to determine
|
| 148 |
+
* whether it is possible to avoid doing a dynamic memory allocation.
|
| 149 |
+
*
|
| 150 |
+
* \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
|
| 151 |
+
*/
|
| 152 |
+
|
| 153 |
+
IsVectorAtCompileTime = internal::traits<Derived>::RowsAtCompileTime == 1
|
| 154 |
+
|| internal::traits<Derived>::ColsAtCompileTime == 1,
|
| 155 |
+
/**< This is set to true if either the number of rows or the number of
|
| 156 |
+
* columns is known at compile-time to be equal to 1. Indeed, in that case,
|
| 157 |
+
* we are dealing with a column-vector (if there is only one column) or with
|
| 158 |
+
* a row-vector (if there is only one row). */
|
| 159 |
+
|
| 160 |
+
NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2,
|
| 161 |
+
/**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors,
|
| 162 |
+
* and 2 for matrices.
|
| 163 |
+
*/
|
| 164 |
+
|
| 165 |
+
Flags = internal::traits<Derived>::Flags,
|
| 166 |
+
/**< This stores expression \ref flags flags which may or may not be inherited by new expressions
|
| 167 |
+
* constructed from this one. See the \ref flags "list of flags".
|
| 168 |
+
*/
|
| 169 |
+
|
| 170 |
+
IsRowMajor = int(Flags) & RowMajorBit, /**< True if this expression has row-major storage order. */
|
| 171 |
+
|
| 172 |
+
InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
|
| 173 |
+
: int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
|
| 174 |
+
|
| 175 |
+
InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
|
| 176 |
+
OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
|
| 177 |
+
};
|
| 178 |
+
|
| 179 |
+
typedef typename internal::find_best_packet<Scalar,SizeAtCompileTime>::type PacketScalar;
|
| 180 |
+
|
| 181 |
+
enum { IsPlainObjectBase = 0 };
|
| 182 |
+
|
| 183 |
+
/** The plain matrix type corresponding to this expression.
|
| 184 |
+
* \sa PlainObject */
|
| 185 |
+
typedef Matrix<typename internal::traits<Derived>::Scalar,
|
| 186 |
+
internal::traits<Derived>::RowsAtCompileTime,
|
| 187 |
+
internal::traits<Derived>::ColsAtCompileTime,
|
| 188 |
+
AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
|
| 189 |
+
internal::traits<Derived>::MaxRowsAtCompileTime,
|
| 190 |
+
internal::traits<Derived>::MaxColsAtCompileTime
|
| 191 |
+
> PlainMatrix;
|
| 192 |
+
|
| 193 |
+
/** The plain array type corresponding to this expression.
|
| 194 |
+
* \sa PlainObject */
|
| 195 |
+
typedef Array<typename internal::traits<Derived>::Scalar,
|
| 196 |
+
internal::traits<Derived>::RowsAtCompileTime,
|
| 197 |
+
internal::traits<Derived>::ColsAtCompileTime,
|
| 198 |
+
AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
|
| 199 |
+
internal::traits<Derived>::MaxRowsAtCompileTime,
|
| 200 |
+
internal::traits<Derived>::MaxColsAtCompileTime
|
| 201 |
+
> PlainArray;
|
| 202 |
+
|
| 203 |
+
/** \brief The plain matrix or array type corresponding to this expression.
|
| 204 |
+
*
|
| 205 |
+
* This is not necessarily exactly the return type of eval(). In the case of plain matrices,
|
| 206 |
+
* the return type of eval() is a const reference to a matrix, not a matrix! It is however guaranteed
|
| 207 |
+
* that the return type of eval() is either PlainObject or const PlainObject&.
|
| 208 |
+
*/
|
| 209 |
+
typedef typename internal::conditional<internal::is_same<typename internal::traits<Derived>::XprKind,MatrixXpr >::value,
|
| 210 |
+
PlainMatrix, PlainArray>::type PlainObject;
|
| 211 |
+
|
| 212 |
+
/** \returns the number of nonzero coefficients which is in practice the number
|
| 213 |
+
* of stored coefficients. */
|
| 214 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 215 |
+
inline Index nonZeros() const { return size(); }
|
| 216 |
+
|
| 217 |
+
/** \returns the outer size.
|
| 218 |
+
*
|
| 219 |
+
* \note For a vector, this returns just 1. For a matrix (non-vector), this is the major dimension
|
| 220 |
+
* with respect to the \ref TopicStorageOrders "storage order", i.e., the number of columns for a
|
| 221 |
+
* column-major matrix, and the number of rows for a row-major matrix. */
|
| 222 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 223 |
+
Index outerSize() const
|
| 224 |
+
{
|
| 225 |
+
return IsVectorAtCompileTime ? 1
|
| 226 |
+
: int(IsRowMajor) ? this->rows() : this->cols();
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/** \returns the inner size.
|
| 230 |
+
*
|
| 231 |
+
* \note For a vector, this is just the size. For a matrix (non-vector), this is the minor dimension
|
| 232 |
+
* with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a
|
| 233 |
+
* column-major matrix, and the number of columns for a row-major matrix. */
|
| 234 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 235 |
+
Index innerSize() const
|
| 236 |
+
{
|
| 237 |
+
return IsVectorAtCompileTime ? this->size()
|
| 238 |
+
: int(IsRowMajor) ? this->cols() : this->rows();
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
|
| 242 |
+
* Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
|
| 243 |
+
* nothing else.
|
| 244 |
+
*/
|
| 245 |
+
EIGEN_DEVICE_FUNC
|
| 246 |
+
void resize(Index newSize)
|
| 247 |
+
{
|
| 248 |
+
EIGEN_ONLY_USED_FOR_DEBUG(newSize);
|
| 249 |
+
eigen_assert(newSize == this->size()
|
| 250 |
+
&& "DenseBase::resize() does not actually allow to resize.");
|
| 251 |
+
}
|
| 252 |
+
/** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are
|
| 253 |
+
* Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and does
|
| 254 |
+
* nothing else.
|
| 255 |
+
*/
|
| 256 |
+
EIGEN_DEVICE_FUNC
|
| 257 |
+
void resize(Index rows, Index cols)
|
| 258 |
+
{
|
| 259 |
+
EIGEN_ONLY_USED_FOR_DEBUG(rows);
|
| 260 |
+
EIGEN_ONLY_USED_FOR_DEBUG(cols);
|
| 261 |
+
eigen_assert(rows == this->rows() && cols == this->cols()
|
| 262 |
+
&& "DenseBase::resize() does not actually allow to resize.");
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 266 |
+
/** \internal Represents a matrix with all coefficients equal to one another*/
|
| 267 |
+
typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
|
| 268 |
+
/** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */
|
| 269 |
+
EIGEN_DEPRECATED typedef CwiseNullaryOp<internal::linspaced_op<Scalar>,PlainObject> SequentialLinSpacedReturnType;
|
| 270 |
+
/** \internal Represents a vector with linearly spaced coefficients that allows random access. */
|
| 271 |
+
typedef CwiseNullaryOp<internal::linspaced_op<Scalar>,PlainObject> RandomAccessLinSpacedReturnType;
|
| 272 |
+
/** \internal the return type of MatrixBase::eigenvalues() */
|
| 273 |
+
typedef Matrix<typename NumTraits<typename internal::traits<Derived>::Scalar>::Real, internal::traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
|
| 274 |
+
|
| 275 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 276 |
+
|
| 277 |
+
/** Copies \a other into *this. \returns a reference to *this. */
|
| 278 |
+
template<typename OtherDerived>
|
| 279 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 280 |
+
Derived& operator=(const DenseBase<OtherDerived>& other);
|
| 281 |
+
|
| 282 |
+
/** Special case of the template operator=, in order to prevent the compiler
|
| 283 |
+
* from generating a default operator= (issue hit with g++ 4.1)
|
| 284 |
+
*/
|
| 285 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 286 |
+
Derived& operator=(const DenseBase& other);
|
| 287 |
+
|
| 288 |
+
template<typename OtherDerived>
|
| 289 |
+
EIGEN_DEVICE_FUNC
|
| 290 |
+
Derived& operator=(const EigenBase<OtherDerived> &other);
|
| 291 |
+
|
| 292 |
+
template<typename OtherDerived>
|
| 293 |
+
EIGEN_DEVICE_FUNC
|
| 294 |
+
Derived& operator+=(const EigenBase<OtherDerived> &other);
|
| 295 |
+
|
| 296 |
+
template<typename OtherDerived>
|
| 297 |
+
EIGEN_DEVICE_FUNC
|
| 298 |
+
Derived& operator-=(const EigenBase<OtherDerived> &other);
|
| 299 |
+
|
| 300 |
+
template<typename OtherDerived>
|
| 301 |
+
EIGEN_DEVICE_FUNC
|
| 302 |
+
Derived& operator=(const ReturnByValue<OtherDerived>& func);
|
| 303 |
+
|
| 304 |
+
/** \internal
|
| 305 |
+
* Copies \a other into *this without evaluating other. \returns a reference to *this. */
|
| 306 |
+
template<typename OtherDerived>
|
| 307 |
+
/** \deprecated */
|
| 308 |
+
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC
|
| 309 |
+
Derived& lazyAssign(const DenseBase<OtherDerived>& other);
|
| 310 |
+
|
| 311 |
+
EIGEN_DEVICE_FUNC
|
| 312 |
+
CommaInitializer<Derived> operator<< (const Scalar& s);
|
| 313 |
+
|
| 314 |
+
template<unsigned int Added,unsigned int Removed>
|
| 315 |
+
/** \deprecated it now returns \c *this */
|
| 316 |
+
EIGEN_DEPRECATED
|
| 317 |
+
const Derived& flagged() const
|
| 318 |
+
{ return derived(); }
|
| 319 |
+
|
| 320 |
+
template<typename OtherDerived>
|
| 321 |
+
EIGEN_DEVICE_FUNC
|
| 322 |
+
CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
|
| 323 |
+
|
| 324 |
+
typedef Transpose<Derived> TransposeReturnType;
|
| 325 |
+
EIGEN_DEVICE_FUNC
|
| 326 |
+
TransposeReturnType transpose();
|
| 327 |
+
typedef Transpose<const Derived> ConstTransposeReturnType;
|
| 328 |
+
EIGEN_DEVICE_FUNC
|
| 329 |
+
const ConstTransposeReturnType transpose() const;
|
| 330 |
+
EIGEN_DEVICE_FUNC
|
| 331 |
+
void transposeInPlace();
|
| 332 |
+
|
| 333 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType
|
| 334 |
+
Constant(Index rows, Index cols, const Scalar& value);
|
| 335 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType
|
| 336 |
+
Constant(Index size, const Scalar& value);
|
| 337 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType
|
| 338 |
+
Constant(const Scalar& value);
|
| 339 |
+
|
| 340 |
+
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
|
| 341 |
+
LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
|
| 342 |
+
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
|
| 343 |
+
LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
|
| 344 |
+
|
| 345 |
+
EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
|
| 346 |
+
LinSpaced(Index size, const Scalar& low, const Scalar& high);
|
| 347 |
+
EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType
|
| 348 |
+
LinSpaced(const Scalar& low, const Scalar& high);
|
| 349 |
+
|
| 350 |
+
template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
|
| 351 |
+
static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
|
| 352 |
+
NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
|
| 353 |
+
template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
|
| 354 |
+
static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
|
| 355 |
+
NullaryExpr(Index size, const CustomNullaryOp& func);
|
| 356 |
+
template<typename CustomNullaryOp> EIGEN_DEVICE_FUNC
|
| 357 |
+
static const CwiseNullaryOp<CustomNullaryOp, PlainObject>
|
| 358 |
+
NullaryExpr(const CustomNullaryOp& func);
|
| 359 |
+
|
| 360 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols);
|
| 361 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size);
|
| 362 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType Zero();
|
| 363 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols);
|
| 364 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size);
|
| 365 |
+
EIGEN_DEVICE_FUNC static const ConstantReturnType Ones();
|
| 366 |
+
|
| 367 |
+
EIGEN_DEVICE_FUNC void fill(const Scalar& value);
|
| 368 |
+
EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value);
|
| 369 |
+
EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
|
| 370 |
+
EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high);
|
| 371 |
+
EIGEN_DEVICE_FUNC Derived& setZero();
|
| 372 |
+
EIGEN_DEVICE_FUNC Derived& setOnes();
|
| 373 |
+
EIGEN_DEVICE_FUNC Derived& setRandom();
|
| 374 |
+
|
| 375 |
+
template<typename OtherDerived> EIGEN_DEVICE_FUNC
|
| 376 |
+
bool isApprox(const DenseBase<OtherDerived>& other,
|
| 377 |
+
const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 378 |
+
EIGEN_DEVICE_FUNC
|
| 379 |
+
bool isMuchSmallerThan(const RealScalar& other,
|
| 380 |
+
const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 381 |
+
template<typename OtherDerived> EIGEN_DEVICE_FUNC
|
| 382 |
+
bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
|
| 383 |
+
const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 384 |
+
|
| 385 |
+
EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 386 |
+
EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 387 |
+
EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 388 |
+
EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 389 |
+
|
| 390 |
+
inline bool hasNaN() const;
|
| 391 |
+
inline bool allFinite() const;
|
| 392 |
+
|
| 393 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 394 |
+
Derived& operator*=(const Scalar& other);
|
| 395 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 396 |
+
Derived& operator/=(const Scalar& other);
|
| 397 |
+
|
| 398 |
+
typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType;
|
| 399 |
+
/** \returns the matrix or vector obtained by evaluating this expression.
|
| 400 |
+
*
|
| 401 |
+
* Notice that in the case of a plain matrix or vector (not an expression) this function just returns
|
| 402 |
+
* a const reference, in order to avoid a useless copy.
|
| 403 |
+
*
|
| 404 |
+
* \warning Be careful with eval() and the auto C++ keyword, as detailed in this \link TopicPitfalls_auto_keyword page \endlink.
|
| 405 |
+
*/
|
| 406 |
+
EIGEN_DEVICE_FUNC
|
| 407 |
+
EIGEN_STRONG_INLINE EvalReturnType eval() const
|
| 408 |
+
{
|
| 409 |
+
// Even though MSVC does not honor strong inlining when the return type
|
| 410 |
+
// is a dynamic matrix, we desperately need strong inlining for fixed
|
| 411 |
+
// size types on MSVC.
|
| 412 |
+
return typename internal::eval<Derived>::type(derived());
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/** swaps *this with the expression \a other.
|
| 416 |
+
*
|
| 417 |
+
*/
|
| 418 |
+
template<typename OtherDerived>
|
| 419 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 420 |
+
void swap(const DenseBase<OtherDerived>& other)
|
| 421 |
+
{
|
| 422 |
+
EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY);
|
| 423 |
+
eigen_assert(rows()==other.rows() && cols()==other.cols());
|
| 424 |
+
call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/** swaps *this with the matrix or array \a other.
|
| 428 |
+
*
|
| 429 |
+
*/
|
| 430 |
+
template<typename OtherDerived>
|
| 431 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 432 |
+
void swap(PlainObjectBase<OtherDerived>& other)
|
| 433 |
+
{
|
| 434 |
+
eigen_assert(rows()==other.rows() && cols()==other.cols());
|
| 435 |
+
call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
EIGEN_DEVICE_FUNC inline const NestByValue<Derived> nestByValue() const;
|
| 439 |
+
EIGEN_DEVICE_FUNC inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
|
| 440 |
+
EIGEN_DEVICE_FUNC inline ForceAlignedAccess<Derived> forceAlignedAccess();
|
| 441 |
+
template<bool Enable> EIGEN_DEVICE_FUNC
|
| 442 |
+
inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
|
| 443 |
+
template<bool Enable> EIGEN_DEVICE_FUNC
|
| 444 |
+
inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
|
| 445 |
+
|
| 446 |
+
EIGEN_DEVICE_FUNC Scalar sum() const;
|
| 447 |
+
EIGEN_DEVICE_FUNC Scalar mean() const;
|
| 448 |
+
EIGEN_DEVICE_FUNC Scalar trace() const;
|
| 449 |
+
|
| 450 |
+
EIGEN_DEVICE_FUNC Scalar prod() const;
|
| 451 |
+
|
| 452 |
+
template<int NaNPropagation>
|
| 453 |
+
EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const;
|
| 454 |
+
template<int NaNPropagation>
|
| 455 |
+
EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const;
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
// By default, the fastest version with undefined NaN propagation semantics is
|
| 459 |
+
// used.
|
| 460 |
+
// TODO(rmlarsen): Replace with default template argument when we move to
|
| 461 |
+
// c++11 or beyond.
|
| 462 |
+
EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar minCoeff() const {
|
| 463 |
+
return minCoeff<PropagateFast>();
|
| 464 |
+
}
|
| 465 |
+
EIGEN_DEVICE_FUNC inline typename internal::traits<Derived>::Scalar maxCoeff() const {
|
| 466 |
+
return maxCoeff<PropagateFast>();
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
template<int NaNPropagation, typename IndexType>
|
| 470 |
+
EIGEN_DEVICE_FUNC
|
| 471 |
+
typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
|
| 472 |
+
template<int NaNPropagation, typename IndexType>
|
| 473 |
+
EIGEN_DEVICE_FUNC
|
| 474 |
+
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
|
| 475 |
+
template<int NaNPropagation, typename IndexType>
|
| 476 |
+
EIGEN_DEVICE_FUNC
|
| 477 |
+
typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
|
| 478 |
+
template<int NaNPropagation, typename IndexType>
|
| 479 |
+
EIGEN_DEVICE_FUNC
|
| 480 |
+
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
|
| 481 |
+
|
| 482 |
+
// TODO(rmlarsen): Replace these methods with a default template argument.
|
| 483 |
+
template<typename IndexType>
|
| 484 |
+
EIGEN_DEVICE_FUNC inline
|
| 485 |
+
typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const {
|
| 486 |
+
return minCoeff<PropagateFast>(row, col);
|
| 487 |
+
}
|
| 488 |
+
template<typename IndexType>
|
| 489 |
+
EIGEN_DEVICE_FUNC inline
|
| 490 |
+
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const {
|
| 491 |
+
return maxCoeff<PropagateFast>(row, col);
|
| 492 |
+
}
|
| 493 |
+
template<typename IndexType>
|
| 494 |
+
EIGEN_DEVICE_FUNC inline
|
| 495 |
+
typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const {
|
| 496 |
+
return minCoeff<PropagateFast>(index);
|
| 497 |
+
}
|
| 498 |
+
template<typename IndexType>
|
| 499 |
+
EIGEN_DEVICE_FUNC inline
|
| 500 |
+
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const {
|
| 501 |
+
return maxCoeff<PropagateFast>(index);
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
template<typename BinaryOp>
|
| 505 |
+
EIGEN_DEVICE_FUNC
|
| 506 |
+
Scalar redux(const BinaryOp& func) const;
|
| 507 |
+
|
| 508 |
+
template<typename Visitor>
|
| 509 |
+
EIGEN_DEVICE_FUNC
|
| 510 |
+
void visit(Visitor& func) const;
|
| 511 |
+
|
| 512 |
+
/** \returns a WithFormat proxy object allowing to print a matrix the with given
|
| 513 |
+
* format \a fmt.
|
| 514 |
+
*
|
| 515 |
+
* See class IOFormat for some examples.
|
| 516 |
+
*
|
| 517 |
+
* \sa class IOFormat, class WithFormat
|
| 518 |
+
*/
|
| 519 |
+
inline const WithFormat<Derived> format(const IOFormat& fmt) const
|
| 520 |
+
{
|
| 521 |
+
return WithFormat<Derived>(derived(), fmt);
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
/** \returns the unique coefficient of a 1x1 expression */
|
| 525 |
+
EIGEN_DEVICE_FUNC
|
| 526 |
+
CoeffReturnType value() const
|
| 527 |
+
{
|
| 528 |
+
EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
|
| 529 |
+
eigen_assert(this->rows() == 1 && this->cols() == 1);
|
| 530 |
+
return derived().coeff(0,0);
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
EIGEN_DEVICE_FUNC bool all() const;
|
| 534 |
+
EIGEN_DEVICE_FUNC bool any() const;
|
| 535 |
+
EIGEN_DEVICE_FUNC Index count() const;
|
| 536 |
+
|
| 537 |
+
typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType;
|
| 538 |
+
typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType;
|
| 539 |
+
typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType;
|
| 540 |
+
typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType;
|
| 541 |
+
|
| 542 |
+
/** \returns a VectorwiseOp wrapper of *this for broadcasting and partial reductions
|
| 543 |
+
*
|
| 544 |
+
* Example: \include MatrixBase_rowwise.cpp
|
| 545 |
+
* Output: \verbinclude MatrixBase_rowwise.out
|
| 546 |
+
*
|
| 547 |
+
* \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
|
| 548 |
+
*/
|
| 549 |
+
//Code moved here due to a CUDA compiler bug
|
| 550 |
+
EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const {
|
| 551 |
+
return ConstRowwiseReturnType(derived());
|
| 552 |
+
}
|
| 553 |
+
EIGEN_DEVICE_FUNC RowwiseReturnType rowwise();
|
| 554 |
+
|
| 555 |
+
/** \returns a VectorwiseOp wrapper of *this broadcasting and partial reductions
|
| 556 |
+
*
|
| 557 |
+
* Example: \include MatrixBase_colwise.cpp
|
| 558 |
+
* Output: \verbinclude MatrixBase_colwise.out
|
| 559 |
+
*
|
| 560 |
+
* \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting
|
| 561 |
+
*/
|
| 562 |
+
EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const {
|
| 563 |
+
return ConstColwiseReturnType(derived());
|
| 564 |
+
}
|
| 565 |
+
EIGEN_DEVICE_FUNC ColwiseReturnType colwise();
|
| 566 |
+
|
| 567 |
+
typedef CwiseNullaryOp<internal::scalar_random_op<Scalar>,PlainObject> RandomReturnType;
|
| 568 |
+
static const RandomReturnType Random(Index rows, Index cols);
|
| 569 |
+
static const RandomReturnType Random(Index size);
|
| 570 |
+
static const RandomReturnType Random();
|
| 571 |
+
|
| 572 |
+
template<typename ThenDerived,typename ElseDerived>
|
| 573 |
+
inline EIGEN_DEVICE_FUNC const Select<Derived,ThenDerived,ElseDerived>
|
| 574 |
+
select(const DenseBase<ThenDerived>& thenMatrix,
|
| 575 |
+
const DenseBase<ElseDerived>& elseMatrix) const;
|
| 576 |
+
|
| 577 |
+
template<typename ThenDerived>
|
| 578 |
+
inline EIGEN_DEVICE_FUNC const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
|
| 579 |
+
select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const;
|
| 580 |
+
|
| 581 |
+
template<typename ElseDerived>
|
| 582 |
+
inline EIGEN_DEVICE_FUNC const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
|
| 583 |
+
select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
|
| 584 |
+
|
| 585 |
+
template<int p> RealScalar lpNorm() const;
|
| 586 |
+
|
| 587 |
+
template<int RowFactor, int ColFactor>
|
| 588 |
+
EIGEN_DEVICE_FUNC
|
| 589 |
+
const Replicate<Derived,RowFactor,ColFactor> replicate() const;
|
| 590 |
+
/**
|
| 591 |
+
* \return an expression of the replication of \c *this
|
| 592 |
+
*
|
| 593 |
+
* Example: \include MatrixBase_replicate_int_int.cpp
|
| 594 |
+
* Output: \verbinclude MatrixBase_replicate_int_int.out
|
| 595 |
+
*
|
| 596 |
+
* \sa VectorwiseOp::replicate(), DenseBase::replicate<int,int>(), class Replicate
|
| 597 |
+
*/
|
| 598 |
+
//Code moved here due to a CUDA compiler bug
|
| 599 |
+
EIGEN_DEVICE_FUNC
|
| 600 |
+
const Replicate<Derived, Dynamic, Dynamic> replicate(Index rowFactor, Index colFactor) const
|
| 601 |
+
{
|
| 602 |
+
return Replicate<Derived, Dynamic, Dynamic>(derived(), rowFactor, colFactor);
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
typedef Reverse<Derived, BothDirections> ReverseReturnType;
|
| 606 |
+
typedef const Reverse<const Derived, BothDirections> ConstReverseReturnType;
|
| 607 |
+
EIGEN_DEVICE_FUNC ReverseReturnType reverse();
|
| 608 |
+
/** This is the const version of reverse(). */
|
| 609 |
+
//Code moved here due to a CUDA compiler bug
|
| 610 |
+
EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const
|
| 611 |
+
{
|
| 612 |
+
return ConstReverseReturnType(derived());
|
| 613 |
+
}
|
| 614 |
+
EIGEN_DEVICE_FUNC void reverseInPlace();
|
| 615 |
+
|
| 616 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 617 |
+
/** STL-like <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">RandomAccessIterator</a>
|
| 618 |
+
* iterator type as returned by the begin() and end() methods.
|
| 619 |
+
*/
|
| 620 |
+
typedef random_access_iterator_type iterator;
|
| 621 |
+
/** This is the const version of iterator (aka read-only) */
|
| 622 |
+
typedef random_access_iterator_type const_iterator;
|
| 623 |
+
#else
|
| 624 |
+
typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit,
|
| 625 |
+
internal::pointer_based_stl_iterator<Derived>,
|
| 626 |
+
internal::generic_randaccess_stl_iterator<Derived>
|
| 627 |
+
>::type iterator_type;
|
| 628 |
+
|
| 629 |
+
typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit,
|
| 630 |
+
internal::pointer_based_stl_iterator<const Derived>,
|
| 631 |
+
internal::generic_randaccess_stl_iterator<const Derived>
|
| 632 |
+
>::type const_iterator_type;
|
| 633 |
+
|
| 634 |
+
// Stl-style iterators are supported only for vectors.
|
| 635 |
+
|
| 636 |
+
typedef typename internal::conditional< IsVectorAtCompileTime,
|
| 637 |
+
iterator_type,
|
| 638 |
+
void
|
| 639 |
+
>::type iterator;
|
| 640 |
+
|
| 641 |
+
typedef typename internal::conditional< IsVectorAtCompileTime,
|
| 642 |
+
const_iterator_type,
|
| 643 |
+
void
|
| 644 |
+
>::type const_iterator;
|
| 645 |
+
#endif
|
| 646 |
+
|
| 647 |
+
inline iterator begin();
|
| 648 |
+
inline const_iterator begin() const;
|
| 649 |
+
inline const_iterator cbegin() const;
|
| 650 |
+
inline iterator end();
|
| 651 |
+
inline const_iterator end() const;
|
| 652 |
+
inline const_iterator cend() const;
|
| 653 |
+
|
| 654 |
+
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
|
| 655 |
+
#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
|
| 656 |
+
#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
|
| 657 |
+
#define EIGEN_DOC_UNARY_ADDONS(X,Y)
|
| 658 |
+
# include "../plugins/CommonCwiseUnaryOps.h"
|
| 659 |
+
# include "../plugins/BlockMethods.h"
|
| 660 |
+
# include "../plugins/IndexedViewMethods.h"
|
| 661 |
+
# include "../plugins/ReshapedMethods.h"
|
| 662 |
+
# ifdef EIGEN_DENSEBASE_PLUGIN
|
| 663 |
+
# include EIGEN_DENSEBASE_PLUGIN
|
| 664 |
+
# endif
|
| 665 |
+
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
|
| 666 |
+
#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
|
| 667 |
+
#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
|
| 668 |
+
#undef EIGEN_DOC_UNARY_ADDONS
|
| 669 |
+
|
| 670 |
+
// disable the use of evalTo for dense objects with a nice compilation error
|
| 671 |
+
template<typename Dest>
|
| 672 |
+
EIGEN_DEVICE_FUNC
|
| 673 |
+
inline void evalTo(Dest& ) const
|
| 674 |
+
{
|
| 675 |
+
EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
protected:
|
| 679 |
+
EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase)
|
| 680 |
+
/** Default constructor. Do nothing. */
|
| 681 |
+
EIGEN_DEVICE_FUNC DenseBase()
|
| 682 |
+
{
|
| 683 |
+
/* Just checks for self-consistency of the flags.
|
| 684 |
+
* Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down
|
| 685 |
+
*/
|
| 686 |
+
#ifdef EIGEN_INTERNAL_DEBUGGING
|
| 687 |
+
EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
|
| 688 |
+
&& EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
|
| 689 |
+
INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
|
| 690 |
+
#endif
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
private:
|
| 694 |
+
EIGEN_DEVICE_FUNC explicit DenseBase(int);
|
| 695 |
+
EIGEN_DEVICE_FUNC DenseBase(int,int);
|
| 696 |
+
template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase<OtherDerived>&);
|
| 697 |
+
};
|
| 698 |
+
|
| 699 |
+
} // end namespace Eigen
|
| 700 |
+
|
| 701 |
+
#endif // EIGEN_DENSEBASE_H
|
include/eigen/Eigen/src/Core/DenseStorage.h
ADDED
|
@@ -0,0 +1,652 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
// Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
|
| 7 |
+
//
|
| 8 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 9 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 10 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 11 |
+
|
| 12 |
+
#ifndef EIGEN_MATRIXSTORAGE_H
|
| 13 |
+
#define EIGEN_MATRIXSTORAGE_H
|
| 14 |
+
|
| 15 |
+
#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
| 16 |
+
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) X; EIGEN_DENSE_STORAGE_CTOR_PLUGIN;
|
| 17 |
+
#else
|
| 18 |
+
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
namespace Eigen {
|
| 22 |
+
|
| 23 |
+
namespace internal {
|
| 24 |
+
|
| 25 |
+
struct constructor_without_unaligned_array_assert {};
|
| 26 |
+
|
| 27 |
+
template<typename T, int Size>
|
| 28 |
+
EIGEN_DEVICE_FUNC
|
| 29 |
+
void check_static_allocation_size()
|
| 30 |
+
{
|
| 31 |
+
// if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit
|
| 32 |
+
#if EIGEN_STACK_ALLOCATION_LIMIT
|
| 33 |
+
EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG);
|
| 34 |
+
#endif
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/** \internal
|
| 38 |
+
* Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned:
|
| 39 |
+
* to 16 bytes boundary if the total size is a multiple of 16 bytes.
|
| 40 |
+
*/
|
| 41 |
+
template <typename T, int Size, int MatrixOrArrayOptions,
|
| 42 |
+
int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
|
| 43 |
+
: compute_default_alignment<T,Size>::value >
|
| 44 |
+
struct plain_array
|
| 45 |
+
{
|
| 46 |
+
T array[Size];
|
| 47 |
+
|
| 48 |
+
EIGEN_DEVICE_FUNC
|
| 49 |
+
plain_array()
|
| 50 |
+
{
|
| 51 |
+
check_static_allocation_size<T,Size>();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
EIGEN_DEVICE_FUNC
|
| 55 |
+
plain_array(constructor_without_unaligned_array_assert)
|
| 56 |
+
{
|
| 57 |
+
check_static_allocation_size<T,Size>();
|
| 58 |
+
}
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT)
|
| 62 |
+
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask)
|
| 63 |
+
#elif EIGEN_GNUC_AT_LEAST(4,7)
|
| 64 |
+
// GCC 4.7 is too aggressive in its optimizations and remove the alignment test based on the fact the array is declared to be aligned.
|
| 65 |
+
// See this bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900
|
| 66 |
+
// Hiding the origin of the array pointer behind a function argument seems to do the trick even if the function is inlined:
|
| 67 |
+
template<typename PtrType>
|
| 68 |
+
EIGEN_ALWAYS_INLINE PtrType eigen_unaligned_array_assert_workaround_gcc47(PtrType array) { return array; }
|
| 69 |
+
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
|
| 70 |
+
eigen_assert((internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (sizemask)) == 0 \
|
| 71 |
+
&& "this assertion is explained here: " \
|
| 72 |
+
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
| 73 |
+
" **** READ THIS WEB PAGE !!! ****");
|
| 74 |
+
#else
|
| 75 |
+
#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \
|
| 76 |
+
eigen_assert((internal::UIntPtr(array) & (sizemask)) == 0 \
|
| 77 |
+
&& "this assertion is explained here: " \
|
| 78 |
+
"http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \
|
| 79 |
+
" **** READ THIS WEB PAGE !!! ****");
|
| 80 |
+
#endif
|
| 81 |
+
|
| 82 |
+
template <typename T, int Size, int MatrixOrArrayOptions>
|
| 83 |
+
struct plain_array<T, Size, MatrixOrArrayOptions, 8>
|
| 84 |
+
{
|
| 85 |
+
EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size];
|
| 86 |
+
|
| 87 |
+
EIGEN_DEVICE_FUNC
|
| 88 |
+
plain_array()
|
| 89 |
+
{
|
| 90 |
+
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7);
|
| 91 |
+
check_static_allocation_size<T,Size>();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
EIGEN_DEVICE_FUNC
|
| 95 |
+
plain_array(constructor_without_unaligned_array_assert)
|
| 96 |
+
{
|
| 97 |
+
check_static_allocation_size<T,Size>();
|
| 98 |
+
}
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
template <typename T, int Size, int MatrixOrArrayOptions>
|
| 102 |
+
struct plain_array<T, Size, MatrixOrArrayOptions, 16>
|
| 103 |
+
{
|
| 104 |
+
EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size];
|
| 105 |
+
|
| 106 |
+
EIGEN_DEVICE_FUNC
|
| 107 |
+
plain_array()
|
| 108 |
+
{
|
| 109 |
+
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15);
|
| 110 |
+
check_static_allocation_size<T,Size>();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
EIGEN_DEVICE_FUNC
|
| 114 |
+
plain_array(constructor_without_unaligned_array_assert)
|
| 115 |
+
{
|
| 116 |
+
check_static_allocation_size<T,Size>();
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
template <typename T, int Size, int MatrixOrArrayOptions>
|
| 121 |
+
struct plain_array<T, Size, MatrixOrArrayOptions, 32>
|
| 122 |
+
{
|
| 123 |
+
EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size];
|
| 124 |
+
|
| 125 |
+
EIGEN_DEVICE_FUNC
|
| 126 |
+
plain_array()
|
| 127 |
+
{
|
| 128 |
+
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31);
|
| 129 |
+
check_static_allocation_size<T,Size>();
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
EIGEN_DEVICE_FUNC
|
| 133 |
+
plain_array(constructor_without_unaligned_array_assert)
|
| 134 |
+
{
|
| 135 |
+
check_static_allocation_size<T,Size>();
|
| 136 |
+
}
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
template <typename T, int Size, int MatrixOrArrayOptions>
|
| 140 |
+
struct plain_array<T, Size, MatrixOrArrayOptions, 64>
|
| 141 |
+
{
|
| 142 |
+
EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size];
|
| 143 |
+
|
| 144 |
+
EIGEN_DEVICE_FUNC
|
| 145 |
+
plain_array()
|
| 146 |
+
{
|
| 147 |
+
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63);
|
| 148 |
+
check_static_allocation_size<T,Size>();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
EIGEN_DEVICE_FUNC
|
| 152 |
+
plain_array(constructor_without_unaligned_array_assert)
|
| 153 |
+
{
|
| 154 |
+
check_static_allocation_size<T,Size>();
|
| 155 |
+
}
|
| 156 |
+
};
|
| 157 |
+
|
| 158 |
+
template <typename T, int MatrixOrArrayOptions, int Alignment>
|
| 159 |
+
struct plain_array<T, 0, MatrixOrArrayOptions, Alignment>
|
| 160 |
+
{
|
| 161 |
+
T array[1];
|
| 162 |
+
EIGEN_DEVICE_FUNC plain_array() {}
|
| 163 |
+
EIGEN_DEVICE_FUNC plain_array(constructor_without_unaligned_array_assert) {}
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
struct plain_array_helper {
|
| 167 |
+
template<typename T, int Size, int MatrixOrArrayOptions, int Alignment>
|
| 168 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 169 |
+
static void copy(const plain_array<T, Size, MatrixOrArrayOptions, Alignment>& src, const Eigen::Index size,
|
| 170 |
+
plain_array<T, Size, MatrixOrArrayOptions, Alignment>& dst) {
|
| 171 |
+
smart_copy(src.array, src.array + size, dst.array);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
template<typename T, int Size, int MatrixOrArrayOptions, int Alignment>
|
| 175 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 176 |
+
static void swap(plain_array<T, Size, MatrixOrArrayOptions, Alignment>& a, const Eigen::Index a_size,
|
| 177 |
+
plain_array<T, Size, MatrixOrArrayOptions, Alignment>& b, const Eigen::Index b_size) {
|
| 178 |
+
if (a_size < b_size) {
|
| 179 |
+
std::swap_ranges(b.array, b.array + a_size, a.array);
|
| 180 |
+
smart_move(b.array + a_size, b.array + b_size, a.array + a_size);
|
| 181 |
+
} else if (a_size > b_size) {
|
| 182 |
+
std::swap_ranges(a.array, a.array + b_size, b.array);
|
| 183 |
+
smart_move(a.array + b_size, a.array + a_size, b.array + b_size);
|
| 184 |
+
} else {
|
| 185 |
+
std::swap_ranges(a.array, a.array + a_size, b.array);
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
};
|
| 189 |
+
|
| 190 |
+
} // end namespace internal
|
| 191 |
+
|
| 192 |
+
/** \internal
|
| 193 |
+
*
|
| 194 |
+
* \class DenseStorage
|
| 195 |
+
* \ingroup Core_Module
|
| 196 |
+
*
|
| 197 |
+
* \brief Stores the data of a matrix
|
| 198 |
+
*
|
| 199 |
+
* This class stores the data of fixed-size, dynamic-size or mixed matrices
|
| 200 |
+
* in a way as compact as possible.
|
| 201 |
+
*
|
| 202 |
+
* \sa Matrix
|
| 203 |
+
*/
|
| 204 |
+
template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage;
|
| 205 |
+
|
| 206 |
+
// purely fixed-size matrix
|
| 207 |
+
template<typename T, int Size, int _Rows, int _Cols, int _Options> class DenseStorage
|
| 208 |
+
{
|
| 209 |
+
internal::plain_array<T,Size,_Options> m_data;
|
| 210 |
+
public:
|
| 211 |
+
EIGEN_DEVICE_FUNC DenseStorage() {
|
| 212 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
|
| 213 |
+
}
|
| 214 |
+
EIGEN_DEVICE_FUNC
|
| 215 |
+
explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
|
| 216 |
+
: m_data(internal::constructor_without_unaligned_array_assert()) {}
|
| 217 |
+
#if !EIGEN_HAS_CXX11 || defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN)
|
| 218 |
+
EIGEN_DEVICE_FUNC
|
| 219 |
+
DenseStorage(const DenseStorage& other) : m_data(other.m_data) {
|
| 220 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)
|
| 221 |
+
}
|
| 222 |
+
#else
|
| 223 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) = default;
|
| 224 |
+
#endif
|
| 225 |
+
#if !EIGEN_HAS_CXX11
|
| 226 |
+
EIGEN_DEVICE_FUNC
|
| 227 |
+
DenseStorage& operator=(const DenseStorage& other)
|
| 228 |
+
{
|
| 229 |
+
if (this != &other) m_data = other.m_data;
|
| 230 |
+
return *this;
|
| 231 |
+
}
|
| 232 |
+
#else
|
| 233 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) = default;
|
| 234 |
+
#endif
|
| 235 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 236 |
+
#if !EIGEN_HAS_CXX11
|
| 237 |
+
EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 238 |
+
: m_data(std::move(other.m_data))
|
| 239 |
+
{
|
| 240 |
+
}
|
| 241 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 242 |
+
{
|
| 243 |
+
if (this != &other)
|
| 244 |
+
m_data = std::move(other.m_data);
|
| 245 |
+
return *this;
|
| 246 |
+
}
|
| 247 |
+
#else
|
| 248 |
+
EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&&) = default;
|
| 249 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&&) = default;
|
| 250 |
+
#endif
|
| 251 |
+
#endif
|
| 252 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) {
|
| 253 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 254 |
+
eigen_internal_assert(size==rows*cols && rows==_Rows && cols==_Cols);
|
| 255 |
+
EIGEN_UNUSED_VARIABLE(size);
|
| 256 |
+
EIGEN_UNUSED_VARIABLE(rows);
|
| 257 |
+
EIGEN_UNUSED_VARIABLE(cols);
|
| 258 |
+
}
|
| 259 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
|
| 260 |
+
numext::swap(m_data, other.m_data);
|
| 261 |
+
}
|
| 262 |
+
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return _Rows;}
|
| 263 |
+
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return _Cols;}
|
| 264 |
+
EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {}
|
| 265 |
+
EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {}
|
| 266 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
|
| 267 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
// null matrix
|
| 271 |
+
template<typename T, int _Rows, int _Cols, int _Options> class DenseStorage<T, 0, _Rows, _Cols, _Options>
|
| 272 |
+
{
|
| 273 |
+
public:
|
| 274 |
+
EIGEN_DEVICE_FUNC DenseStorage() {}
|
| 275 |
+
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) {}
|
| 276 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage&) {}
|
| 277 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage&) { return *this; }
|
| 278 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index,Index,Index) {}
|
| 279 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& ) {}
|
| 280 |
+
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return _Rows;}
|
| 281 |
+
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT {return _Cols;}
|
| 282 |
+
EIGEN_DEVICE_FUNC void conservativeResize(Index,Index,Index) {}
|
| 283 |
+
EIGEN_DEVICE_FUNC void resize(Index,Index,Index) {}
|
| 284 |
+
EIGEN_DEVICE_FUNC const T *data() const { return 0; }
|
| 285 |
+
EIGEN_DEVICE_FUNC T *data() { return 0; }
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
// more specializations for null matrices; these are necessary to resolve ambiguities
|
| 289 |
+
template<typename T, int _Options> class DenseStorage<T, 0, Dynamic, Dynamic, _Options>
|
| 290 |
+
: public DenseStorage<T, 0, 0, 0, _Options> { };
|
| 291 |
+
|
| 292 |
+
template<typename T, int _Rows, int _Options> class DenseStorage<T, 0, _Rows, Dynamic, _Options>
|
| 293 |
+
: public DenseStorage<T, 0, 0, 0, _Options> { };
|
| 294 |
+
|
| 295 |
+
template<typename T, int _Cols, int _Options> class DenseStorage<T, 0, Dynamic, _Cols, _Options>
|
| 296 |
+
: public DenseStorage<T, 0, 0, 0, _Options> { };
|
| 297 |
+
|
| 298 |
+
// dynamic-size matrix with fixed-size storage
|
| 299 |
+
template<typename T, int Size, int _Options> class DenseStorage<T, Size, Dynamic, Dynamic, _Options>
|
| 300 |
+
{
|
| 301 |
+
internal::plain_array<T,Size,_Options> m_data;
|
| 302 |
+
Index m_rows;
|
| 303 |
+
Index m_cols;
|
| 304 |
+
public:
|
| 305 |
+
EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {}
|
| 306 |
+
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
|
| 307 |
+
: m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {}
|
| 308 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
|
| 309 |
+
: m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows), m_cols(other.m_cols)
|
| 310 |
+
{
|
| 311 |
+
internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
|
| 312 |
+
}
|
| 313 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
|
| 314 |
+
{
|
| 315 |
+
if (this != &other)
|
| 316 |
+
{
|
| 317 |
+
m_rows = other.m_rows;
|
| 318 |
+
m_cols = other.m_cols;
|
| 319 |
+
internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data);
|
| 320 |
+
}
|
| 321 |
+
return *this;
|
| 322 |
+
}
|
| 323 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {}
|
| 324 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
|
| 325 |
+
{
|
| 326 |
+
internal::plain_array_helper::swap(m_data, m_rows * m_cols, other.m_data, other.m_rows * other.m_cols);
|
| 327 |
+
numext::swap(m_rows,other.m_rows);
|
| 328 |
+
numext::swap(m_cols,other.m_cols);
|
| 329 |
+
}
|
| 330 |
+
EIGEN_DEVICE_FUNC Index rows() const {return m_rows;}
|
| 331 |
+
EIGEN_DEVICE_FUNC Index cols() const {return m_cols;}
|
| 332 |
+
EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; }
|
| 333 |
+
EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) { m_rows = rows; m_cols = cols; }
|
| 334 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
|
| 335 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
|
| 336 |
+
};
|
| 337 |
+
|
| 338 |
+
// dynamic-size matrix with fixed-size storage and fixed width
|
| 339 |
+
template<typename T, int Size, int _Cols, int _Options> class DenseStorage<T, Size, Dynamic, _Cols, _Options>
|
| 340 |
+
{
|
| 341 |
+
internal::plain_array<T,Size,_Options> m_data;
|
| 342 |
+
Index m_rows;
|
| 343 |
+
public:
|
| 344 |
+
EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {}
|
| 345 |
+
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
|
| 346 |
+
: m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {}
|
| 347 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
|
| 348 |
+
: m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows)
|
| 349 |
+
{
|
| 350 |
+
internal::plain_array_helper::copy(other.m_data, m_rows * _Cols, m_data);
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
|
| 354 |
+
{
|
| 355 |
+
if (this != &other)
|
| 356 |
+
{
|
| 357 |
+
m_rows = other.m_rows;
|
| 358 |
+
internal::plain_array_helper::copy(other.m_data, m_rows * _Cols, m_data);
|
| 359 |
+
}
|
| 360 |
+
return *this;
|
| 361 |
+
}
|
| 362 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) {}
|
| 363 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
|
| 364 |
+
{
|
| 365 |
+
internal::plain_array_helper::swap(m_data, m_rows * _Cols, other.m_data, other.m_rows * _Cols);
|
| 366 |
+
numext::swap(m_rows, other.m_rows);
|
| 367 |
+
}
|
| 368 |
+
EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
|
| 369 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols(void) const EIGEN_NOEXCEPT {return _Cols;}
|
| 370 |
+
EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index) { m_rows = rows; }
|
| 371 |
+
EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index) { m_rows = rows; }
|
| 372 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
|
| 373 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
|
| 374 |
+
};
|
| 375 |
+
|
| 376 |
+
// dynamic-size matrix with fixed-size storage and fixed height
|
| 377 |
+
template<typename T, int Size, int _Rows, int _Options> class DenseStorage<T, Size, _Rows, Dynamic, _Options>
|
| 378 |
+
{
|
| 379 |
+
internal::plain_array<T,Size,_Options> m_data;
|
| 380 |
+
Index m_cols;
|
| 381 |
+
public:
|
| 382 |
+
EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {}
|
| 383 |
+
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
|
| 384 |
+
: m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {}
|
| 385 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
|
| 386 |
+
: m_data(internal::constructor_without_unaligned_array_assert()), m_cols(other.m_cols)
|
| 387 |
+
{
|
| 388 |
+
internal::plain_array_helper::copy(other.m_data, _Rows * m_cols, m_data);
|
| 389 |
+
}
|
| 390 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
|
| 391 |
+
{
|
| 392 |
+
if (this != &other)
|
| 393 |
+
{
|
| 394 |
+
m_cols = other.m_cols;
|
| 395 |
+
internal::plain_array_helper::copy(other.m_data, _Rows * m_cols, m_data);
|
| 396 |
+
}
|
| 397 |
+
return *this;
|
| 398 |
+
}
|
| 399 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {}
|
| 400 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
|
| 401 |
+
internal::plain_array_helper::swap(m_data, _Rows * m_cols, other.m_data, _Rows * other.m_cols);
|
| 402 |
+
numext::swap(m_cols, other.m_cols);
|
| 403 |
+
}
|
| 404 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows(void) const EIGEN_NOEXCEPT {return _Rows;}
|
| 405 |
+
EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
|
| 406 |
+
EIGEN_DEVICE_FUNC void conservativeResize(Index, Index, Index cols) { m_cols = cols; }
|
| 407 |
+
EIGEN_DEVICE_FUNC void resize(Index, Index, Index cols) { m_cols = cols; }
|
| 408 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data.array; }
|
| 409 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data.array; }
|
| 410 |
+
};
|
| 411 |
+
|
| 412 |
+
// purely dynamic matrix.
|
| 413 |
+
template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynamic, _Options>
|
| 414 |
+
{
|
| 415 |
+
T *m_data;
|
| 416 |
+
Index m_rows;
|
| 417 |
+
Index m_cols;
|
| 418 |
+
public:
|
| 419 |
+
EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0), m_cols(0) {}
|
| 420 |
+
EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert)
|
| 421 |
+
: m_data(0), m_rows(0), m_cols(0) {}
|
| 422 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols)
|
| 423 |
+
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
|
| 424 |
+
{
|
| 425 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 426 |
+
eigen_internal_assert(size==rows*cols && rows>=0 && cols >=0);
|
| 427 |
+
}
|
| 428 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
|
| 429 |
+
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*other.m_cols))
|
| 430 |
+
, m_rows(other.m_rows)
|
| 431 |
+
, m_cols(other.m_cols)
|
| 432 |
+
{
|
| 433 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*m_cols)
|
| 434 |
+
internal::smart_copy(other.m_data, other.m_data+other.m_rows*other.m_cols, m_data);
|
| 435 |
+
}
|
| 436 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
|
| 437 |
+
{
|
| 438 |
+
if (this != &other)
|
| 439 |
+
{
|
| 440 |
+
DenseStorage tmp(other);
|
| 441 |
+
this->swap(tmp);
|
| 442 |
+
}
|
| 443 |
+
return *this;
|
| 444 |
+
}
|
| 445 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 446 |
+
EIGEN_DEVICE_FUNC
|
| 447 |
+
DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 448 |
+
: m_data(std::move(other.m_data))
|
| 449 |
+
, m_rows(std::move(other.m_rows))
|
| 450 |
+
, m_cols(std::move(other.m_cols))
|
| 451 |
+
{
|
| 452 |
+
other.m_data = nullptr;
|
| 453 |
+
other.m_rows = 0;
|
| 454 |
+
other.m_cols = 0;
|
| 455 |
+
}
|
| 456 |
+
EIGEN_DEVICE_FUNC
|
| 457 |
+
DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 458 |
+
{
|
| 459 |
+
numext::swap(m_data, other.m_data);
|
| 460 |
+
numext::swap(m_rows, other.m_rows);
|
| 461 |
+
numext::swap(m_cols, other.m_cols);
|
| 462 |
+
return *this;
|
| 463 |
+
}
|
| 464 |
+
#endif
|
| 465 |
+
EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
|
| 466 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other)
|
| 467 |
+
{
|
| 468 |
+
numext::swap(m_data,other.m_data);
|
| 469 |
+
numext::swap(m_rows,other.m_rows);
|
| 470 |
+
numext::swap(m_cols,other.m_cols);
|
| 471 |
+
}
|
| 472 |
+
EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
|
| 473 |
+
EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
|
| 474 |
+
void conservativeResize(Index size, Index rows, Index cols)
|
| 475 |
+
{
|
| 476 |
+
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
|
| 477 |
+
m_rows = rows;
|
| 478 |
+
m_cols = cols;
|
| 479 |
+
}
|
| 480 |
+
EIGEN_DEVICE_FUNC void resize(Index size, Index rows, Index cols)
|
| 481 |
+
{
|
| 482 |
+
if(size != m_rows*m_cols)
|
| 483 |
+
{
|
| 484 |
+
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
|
| 485 |
+
if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
|
| 486 |
+
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
| 487 |
+
else
|
| 488 |
+
m_data = 0;
|
| 489 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 490 |
+
}
|
| 491 |
+
m_rows = rows;
|
| 492 |
+
m_cols = cols;
|
| 493 |
+
}
|
| 494 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
|
| 495 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data; }
|
| 496 |
+
};
|
| 497 |
+
|
| 498 |
+
// matrix with dynamic width and fixed height (so that matrix has dynamic size).
|
| 499 |
+
template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Rows, Dynamic, _Options>
|
| 500 |
+
{
|
| 501 |
+
T *m_data;
|
| 502 |
+
Index m_cols;
|
| 503 |
+
public:
|
| 504 |
+
EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_cols(0) {}
|
| 505 |
+
explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
|
| 506 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
|
| 507 |
+
{
|
| 508 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 509 |
+
eigen_internal_assert(size==rows*cols && rows==_Rows && cols >=0);
|
| 510 |
+
EIGEN_UNUSED_VARIABLE(rows);
|
| 511 |
+
}
|
| 512 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
|
| 513 |
+
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(_Rows*other.m_cols))
|
| 514 |
+
, m_cols(other.m_cols)
|
| 515 |
+
{
|
| 516 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_cols*_Rows)
|
| 517 |
+
internal::smart_copy(other.m_data, other.m_data+_Rows*m_cols, m_data);
|
| 518 |
+
}
|
| 519 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
|
| 520 |
+
{
|
| 521 |
+
if (this != &other)
|
| 522 |
+
{
|
| 523 |
+
DenseStorage tmp(other);
|
| 524 |
+
this->swap(tmp);
|
| 525 |
+
}
|
| 526 |
+
return *this;
|
| 527 |
+
}
|
| 528 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 529 |
+
EIGEN_DEVICE_FUNC
|
| 530 |
+
DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 531 |
+
: m_data(std::move(other.m_data))
|
| 532 |
+
, m_cols(std::move(other.m_cols))
|
| 533 |
+
{
|
| 534 |
+
other.m_data = nullptr;
|
| 535 |
+
other.m_cols = 0;
|
| 536 |
+
}
|
| 537 |
+
EIGEN_DEVICE_FUNC
|
| 538 |
+
DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 539 |
+
{
|
| 540 |
+
numext::swap(m_data, other.m_data);
|
| 541 |
+
numext::swap(m_cols, other.m_cols);
|
| 542 |
+
return *this;
|
| 543 |
+
}
|
| 544 |
+
#endif
|
| 545 |
+
EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
|
| 546 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
|
| 547 |
+
numext::swap(m_data,other.m_data);
|
| 548 |
+
numext::swap(m_cols,other.m_cols);
|
| 549 |
+
}
|
| 550 |
+
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT {return _Rows;}
|
| 551 |
+
EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT {return m_cols;}
|
| 552 |
+
EIGEN_DEVICE_FUNC void conservativeResize(Index size, Index, Index cols)
|
| 553 |
+
{
|
| 554 |
+
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
|
| 555 |
+
m_cols = cols;
|
| 556 |
+
}
|
| 557 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index, Index cols)
|
| 558 |
+
{
|
| 559 |
+
if(size != _Rows*m_cols)
|
| 560 |
+
{
|
| 561 |
+
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
|
| 562 |
+
if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
|
| 563 |
+
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
| 564 |
+
else
|
| 565 |
+
m_data = 0;
|
| 566 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 567 |
+
}
|
| 568 |
+
m_cols = cols;
|
| 569 |
+
}
|
| 570 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
|
| 571 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data; }
|
| 572 |
+
};
|
| 573 |
+
|
| 574 |
+
// matrix with dynamic height and fixed width (so that matrix has dynamic size).
|
| 575 |
+
template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dynamic, _Cols, _Options>
|
| 576 |
+
{
|
| 577 |
+
T *m_data;
|
| 578 |
+
Index m_rows;
|
| 579 |
+
public:
|
| 580 |
+
EIGEN_DEVICE_FUNC DenseStorage() : m_data(0), m_rows(0) {}
|
| 581 |
+
explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
|
| 582 |
+
EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
|
| 583 |
+
{
|
| 584 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 585 |
+
eigen_internal_assert(size==rows*cols && rows>=0 && cols == _Cols);
|
| 586 |
+
EIGEN_UNUSED_VARIABLE(cols);
|
| 587 |
+
}
|
| 588 |
+
EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other)
|
| 589 |
+
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(other.m_rows*_Cols))
|
| 590 |
+
, m_rows(other.m_rows)
|
| 591 |
+
{
|
| 592 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows*_Cols)
|
| 593 |
+
internal::smart_copy(other.m_data, other.m_data+other.m_rows*_Cols, m_data);
|
| 594 |
+
}
|
| 595 |
+
EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other)
|
| 596 |
+
{
|
| 597 |
+
if (this != &other)
|
| 598 |
+
{
|
| 599 |
+
DenseStorage tmp(other);
|
| 600 |
+
this->swap(tmp);
|
| 601 |
+
}
|
| 602 |
+
return *this;
|
| 603 |
+
}
|
| 604 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 605 |
+
EIGEN_DEVICE_FUNC
|
| 606 |
+
DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 607 |
+
: m_data(std::move(other.m_data))
|
| 608 |
+
, m_rows(std::move(other.m_rows))
|
| 609 |
+
{
|
| 610 |
+
other.m_data = nullptr;
|
| 611 |
+
other.m_rows = 0;
|
| 612 |
+
}
|
| 613 |
+
EIGEN_DEVICE_FUNC
|
| 614 |
+
DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT
|
| 615 |
+
{
|
| 616 |
+
numext::swap(m_data, other.m_data);
|
| 617 |
+
numext::swap(m_rows, other.m_rows);
|
| 618 |
+
return *this;
|
| 619 |
+
}
|
| 620 |
+
#endif
|
| 621 |
+
EIGEN_DEVICE_FUNC ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
|
| 622 |
+
EIGEN_DEVICE_FUNC void swap(DenseStorage& other) {
|
| 623 |
+
numext::swap(m_data,other.m_data);
|
| 624 |
+
numext::swap(m_rows,other.m_rows);
|
| 625 |
+
}
|
| 626 |
+
EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT {return m_rows;}
|
| 627 |
+
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) {return _Cols;}
|
| 628 |
+
void conservativeResize(Index size, Index rows, Index)
|
| 629 |
+
{
|
| 630 |
+
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
|
| 631 |
+
m_rows = rows;
|
| 632 |
+
}
|
| 633 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index rows, Index)
|
| 634 |
+
{
|
| 635 |
+
if(size != m_rows*_Cols)
|
| 636 |
+
{
|
| 637 |
+
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
|
| 638 |
+
if (size>0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative
|
| 639 |
+
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
| 640 |
+
else
|
| 641 |
+
m_data = 0;
|
| 642 |
+
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
|
| 643 |
+
}
|
| 644 |
+
m_rows = rows;
|
| 645 |
+
}
|
| 646 |
+
EIGEN_DEVICE_FUNC const T *data() const { return m_data; }
|
| 647 |
+
EIGEN_DEVICE_FUNC T *data() { return m_data; }
|
| 648 |
+
};
|
| 649 |
+
|
| 650 |
+
} // end namespace Eigen
|
| 651 |
+
|
| 652 |
+
#endif // EIGEN_MATRIX_H
|
include/eigen/Eigen/src/Core/Diagonal.h
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_DIAGONAL_H
|
| 12 |
+
#define EIGEN_DIAGONAL_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
/** \class Diagonal
|
| 17 |
+
* \ingroup Core_Module
|
| 18 |
+
*
|
| 19 |
+
* \brief Expression of a diagonal/subdiagonal/superdiagonal in a matrix
|
| 20 |
+
*
|
| 21 |
+
* \param MatrixType the type of the object in which we are taking a sub/main/super diagonal
|
| 22 |
+
* \param DiagIndex the index of the sub/super diagonal. The default is 0 and it means the main diagonal.
|
| 23 |
+
* A positive value means a superdiagonal, a negative value means a subdiagonal.
|
| 24 |
+
* You can also use DynamicIndex so the index can be set at runtime.
|
| 25 |
+
*
|
| 26 |
+
* The matrix is not required to be square.
|
| 27 |
+
*
|
| 28 |
+
* This class represents an expression of the main diagonal, or any sub/super diagonal
|
| 29 |
+
* of a square matrix. It is the return type of MatrixBase::diagonal() and MatrixBase::diagonal(Index) and most of the
|
| 30 |
+
* time this is the only way it is used.
|
| 31 |
+
*
|
| 32 |
+
* \sa MatrixBase::diagonal(), MatrixBase::diagonal(Index)
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
namespace internal {
|
| 36 |
+
template<typename MatrixType, int DiagIndex>
|
| 37 |
+
struct traits<Diagonal<MatrixType,DiagIndex> >
|
| 38 |
+
: traits<MatrixType>
|
| 39 |
+
{
|
| 40 |
+
typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
|
| 41 |
+
typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
|
| 42 |
+
typedef typename MatrixType::StorageKind StorageKind;
|
| 43 |
+
enum {
|
| 44 |
+
RowsAtCompileTime = (int(DiagIndex) == DynamicIndex || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic
|
| 45 |
+
: (EIGEN_PLAIN_ENUM_MIN(MatrixType::RowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
|
| 46 |
+
MatrixType::ColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
|
| 47 |
+
ColsAtCompileTime = 1,
|
| 48 |
+
MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
|
| 49 |
+
: DiagIndex == DynamicIndex ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime,
|
| 50 |
+
MatrixType::MaxColsAtCompileTime)
|
| 51 |
+
: (EIGEN_PLAIN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
|
| 52 |
+
MatrixType::MaxColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
|
| 53 |
+
MaxColsAtCompileTime = 1,
|
| 54 |
+
MaskLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
|
| 55 |
+
Flags = (unsigned int)_MatrixTypeNested::Flags & (RowMajorBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, // FIXME DirectAccessBit should not be handled by expressions
|
| 56 |
+
MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
|
| 57 |
+
InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
|
| 58 |
+
OuterStrideAtCompileTime = 0
|
| 59 |
+
};
|
| 60 |
+
};
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
template<typename MatrixType, int _DiagIndex> class Diagonal
|
| 64 |
+
: public internal::dense_xpr_base< Diagonal<MatrixType,_DiagIndex> >::type
|
| 65 |
+
{
|
| 66 |
+
public:
|
| 67 |
+
|
| 68 |
+
enum { DiagIndex = _DiagIndex };
|
| 69 |
+
typedef typename internal::dense_xpr_base<Diagonal>::type Base;
|
| 70 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
|
| 71 |
+
|
| 72 |
+
EIGEN_DEVICE_FUNC
|
| 73 |
+
explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) : m_matrix(matrix), m_index(a_index)
|
| 74 |
+
{
|
| 75 |
+
eigen_assert( a_index <= m_matrix.cols() && -a_index <= m_matrix.rows() );
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
|
| 79 |
+
|
| 80 |
+
EIGEN_DEVICE_FUNC
|
| 81 |
+
inline Index rows() const
|
| 82 |
+
{
|
| 83 |
+
return m_index.value()<0 ? numext::mini<Index>(m_matrix.cols(),m_matrix.rows()+m_index.value())
|
| 84 |
+
: numext::mini<Index>(m_matrix.rows(),m_matrix.cols()-m_index.value());
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 88 |
+
inline Index cols() const EIGEN_NOEXCEPT { return 1; }
|
| 89 |
+
|
| 90 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 91 |
+
inline Index innerStride() const EIGEN_NOEXCEPT {
|
| 92 |
+
return m_matrix.outerStride() + 1;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 96 |
+
inline Index outerStride() const EIGEN_NOEXCEPT { return 0; }
|
| 97 |
+
|
| 98 |
+
typedef typename internal::conditional<
|
| 99 |
+
internal::is_lvalue<MatrixType>::value,
|
| 100 |
+
Scalar,
|
| 101 |
+
const Scalar
|
| 102 |
+
>::type ScalarWithConstIfNotLvalue;
|
| 103 |
+
|
| 104 |
+
EIGEN_DEVICE_FUNC
|
| 105 |
+
inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
|
| 106 |
+
EIGEN_DEVICE_FUNC
|
| 107 |
+
inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); }
|
| 108 |
+
|
| 109 |
+
EIGEN_DEVICE_FUNC
|
| 110 |
+
inline Scalar& coeffRef(Index row, Index)
|
| 111 |
+
{
|
| 112 |
+
EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
|
| 113 |
+
return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
EIGEN_DEVICE_FUNC
|
| 117 |
+
inline const Scalar& coeffRef(Index row, Index) const
|
| 118 |
+
{
|
| 119 |
+
return m_matrix.coeffRef(row+rowOffset(), row+colOffset());
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
EIGEN_DEVICE_FUNC
|
| 123 |
+
inline CoeffReturnType coeff(Index row, Index) const
|
| 124 |
+
{
|
| 125 |
+
return m_matrix.coeff(row+rowOffset(), row+colOffset());
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
EIGEN_DEVICE_FUNC
|
| 129 |
+
inline Scalar& coeffRef(Index idx)
|
| 130 |
+
{
|
| 131 |
+
EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
|
| 132 |
+
return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
EIGEN_DEVICE_FUNC
|
| 136 |
+
inline const Scalar& coeffRef(Index idx) const
|
| 137 |
+
{
|
| 138 |
+
return m_matrix.coeffRef(idx+rowOffset(), idx+colOffset());
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
EIGEN_DEVICE_FUNC
|
| 142 |
+
inline CoeffReturnType coeff(Index idx) const
|
| 143 |
+
{
|
| 144 |
+
return m_matrix.coeff(idx+rowOffset(), idx+colOffset());
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
EIGEN_DEVICE_FUNC
|
| 148 |
+
inline const typename internal::remove_all<typename MatrixType::Nested>::type&
|
| 149 |
+
nestedExpression() const
|
| 150 |
+
{
|
| 151 |
+
return m_matrix;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
EIGEN_DEVICE_FUNC
|
| 155 |
+
inline Index index() const
|
| 156 |
+
{
|
| 157 |
+
return m_index.value();
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
protected:
|
| 161 |
+
typename internal::ref_selector<MatrixType>::non_const_type m_matrix;
|
| 162 |
+
const internal::variable_if_dynamicindex<Index, DiagIndex> m_index;
|
| 163 |
+
|
| 164 |
+
private:
|
| 165 |
+
// some compilers may fail to optimize std::max etc in case of compile-time constants...
|
| 166 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 167 |
+
Index absDiagIndex() const EIGEN_NOEXCEPT { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
|
| 168 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 169 |
+
Index rowOffset() const EIGEN_NOEXCEPT { return m_index.value()>0 ? 0 : -m_index.value(); }
|
| 170 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 171 |
+
Index colOffset() const EIGEN_NOEXCEPT { return m_index.value()>0 ? m_index.value() : 0; }
|
| 172 |
+
// trigger a compile-time error if someone try to call packet
|
| 173 |
+
template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
|
| 174 |
+
template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
/** \returns an expression of the main diagonal of the matrix \c *this
|
| 178 |
+
*
|
| 179 |
+
* \c *this is not required to be square.
|
| 180 |
+
*
|
| 181 |
+
* Example: \include MatrixBase_diagonal.cpp
|
| 182 |
+
* Output: \verbinclude MatrixBase_diagonal.out
|
| 183 |
+
*
|
| 184 |
+
* \sa class Diagonal */
|
| 185 |
+
template<typename Derived>
|
| 186 |
+
EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::DiagonalReturnType
|
| 187 |
+
MatrixBase<Derived>::diagonal()
|
| 188 |
+
{
|
| 189 |
+
return DiagonalReturnType(derived());
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/** This is the const version of diagonal(). */
|
| 193 |
+
template<typename Derived>
|
| 194 |
+
EIGEN_DEVICE_FUNC inline
|
| 195 |
+
const typename MatrixBase<Derived>::ConstDiagonalReturnType
|
| 196 |
+
MatrixBase<Derived>::diagonal() const
|
| 197 |
+
{
|
| 198 |
+
return ConstDiagonalReturnType(derived());
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this
|
| 202 |
+
*
|
| 203 |
+
* \c *this is not required to be square.
|
| 204 |
+
*
|
| 205 |
+
* The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0
|
| 206 |
+
* and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal.
|
| 207 |
+
*
|
| 208 |
+
* Example: \include MatrixBase_diagonal_int.cpp
|
| 209 |
+
* Output: \verbinclude MatrixBase_diagonal_int.out
|
| 210 |
+
*
|
| 211 |
+
* \sa MatrixBase::diagonal(), class Diagonal */
|
| 212 |
+
template<typename Derived>
|
| 213 |
+
EIGEN_DEVICE_FUNC inline Diagonal<Derived, DynamicIndex>
|
| 214 |
+
MatrixBase<Derived>::diagonal(Index index)
|
| 215 |
+
{
|
| 216 |
+
return Diagonal<Derived, DynamicIndex>(derived(), index);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/** This is the const version of diagonal(Index). */
|
| 220 |
+
template<typename Derived>
|
| 221 |
+
EIGEN_DEVICE_FUNC inline const Diagonal<const Derived, DynamicIndex>
|
| 222 |
+
MatrixBase<Derived>::diagonal(Index index) const
|
| 223 |
+
{
|
| 224 |
+
return Diagonal<const Derived, DynamicIndex>(derived(), index);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this
|
| 228 |
+
*
|
| 229 |
+
* \c *this is not required to be square.
|
| 230 |
+
*
|
| 231 |
+
* The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0
|
| 232 |
+
* and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal.
|
| 233 |
+
*
|
| 234 |
+
* Example: \include MatrixBase_diagonal_template_int.cpp
|
| 235 |
+
* Output: \verbinclude MatrixBase_diagonal_template_int.out
|
| 236 |
+
*
|
| 237 |
+
* \sa MatrixBase::diagonal(), class Diagonal */
|
| 238 |
+
template<typename Derived>
|
| 239 |
+
template<int Index_>
|
| 240 |
+
EIGEN_DEVICE_FUNC
|
| 241 |
+
inline Diagonal<Derived, Index_>
|
| 242 |
+
MatrixBase<Derived>::diagonal()
|
| 243 |
+
{
|
| 244 |
+
return Diagonal<Derived, Index_>(derived());
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
/** This is the const version of diagonal<int>(). */
|
| 248 |
+
template<typename Derived>
|
| 249 |
+
template<int Index_>
|
| 250 |
+
EIGEN_DEVICE_FUNC
|
| 251 |
+
inline const Diagonal<const Derived, Index_>
|
| 252 |
+
MatrixBase<Derived>::diagonal() const
|
| 253 |
+
{
|
| 254 |
+
return Diagonal<const Derived, Index_>(derived());
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
} // end namespace Eigen
|
| 258 |
+
|
| 259 |
+
#endif // EIGEN_DIAGONAL_H
|
include/eigen/Eigen/src/Core/DiagonalMatrix.h
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_DIAGONALMATRIX_H
|
| 12 |
+
#define EIGEN_DIAGONALMATRIX_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 17 |
+
template<typename Derived>
|
| 18 |
+
class DiagonalBase : public EigenBase<Derived>
|
| 19 |
+
{
|
| 20 |
+
public:
|
| 21 |
+
typedef typename internal::traits<Derived>::DiagonalVectorType DiagonalVectorType;
|
| 22 |
+
typedef typename DiagonalVectorType::Scalar Scalar;
|
| 23 |
+
typedef typename DiagonalVectorType::RealScalar RealScalar;
|
| 24 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 25 |
+
typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
|
| 26 |
+
|
| 27 |
+
enum {
|
| 28 |
+
RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
| 29 |
+
ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
| 30 |
+
MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
|
| 31 |
+
MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
|
| 32 |
+
IsVectorAtCompileTime = 0,
|
| 33 |
+
Flags = NoPreferredStorageOrderBit
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime> DenseMatrixType;
|
| 37 |
+
typedef DenseMatrixType DenseType;
|
| 38 |
+
typedef DiagonalMatrix<Scalar,DiagonalVectorType::SizeAtCompileTime,DiagonalVectorType::MaxSizeAtCompileTime> PlainObject;
|
| 39 |
+
|
| 40 |
+
EIGEN_DEVICE_FUNC
|
| 41 |
+
inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
| 42 |
+
EIGEN_DEVICE_FUNC
|
| 43 |
+
inline Derived& derived() { return *static_cast<Derived*>(this); }
|
| 44 |
+
|
| 45 |
+
EIGEN_DEVICE_FUNC
|
| 46 |
+
DenseMatrixType toDenseMatrix() const { return derived(); }
|
| 47 |
+
|
| 48 |
+
EIGEN_DEVICE_FUNC
|
| 49 |
+
inline const DiagonalVectorType& diagonal() const { return derived().diagonal(); }
|
| 50 |
+
EIGEN_DEVICE_FUNC
|
| 51 |
+
inline DiagonalVectorType& diagonal() { return derived().diagonal(); }
|
| 52 |
+
|
| 53 |
+
EIGEN_DEVICE_FUNC
|
| 54 |
+
inline Index rows() const { return diagonal().size(); }
|
| 55 |
+
EIGEN_DEVICE_FUNC
|
| 56 |
+
inline Index cols() const { return diagonal().size(); }
|
| 57 |
+
|
| 58 |
+
template<typename MatrixDerived>
|
| 59 |
+
EIGEN_DEVICE_FUNC
|
| 60 |
+
const Product<Derived,MatrixDerived,LazyProduct>
|
| 61 |
+
operator*(const MatrixBase<MatrixDerived> &matrix) const
|
| 62 |
+
{
|
| 63 |
+
return Product<Derived, MatrixDerived, LazyProduct>(derived(),matrix.derived());
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
typedef DiagonalWrapper<const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const DiagonalVectorType> > InverseReturnType;
|
| 67 |
+
EIGEN_DEVICE_FUNC
|
| 68 |
+
inline const InverseReturnType
|
| 69 |
+
inverse() const
|
| 70 |
+
{
|
| 71 |
+
return InverseReturnType(diagonal().cwiseInverse());
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
EIGEN_DEVICE_FUNC
|
| 75 |
+
inline const DiagonalWrapper<const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DiagonalVectorType,Scalar,product) >
|
| 76 |
+
operator*(const Scalar& scalar) const
|
| 77 |
+
{
|
| 78 |
+
return DiagonalWrapper<const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DiagonalVectorType,Scalar,product) >(diagonal() * scalar);
|
| 79 |
+
}
|
| 80 |
+
EIGEN_DEVICE_FUNC
|
| 81 |
+
friend inline const DiagonalWrapper<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,DiagonalVectorType,product) >
|
| 82 |
+
operator*(const Scalar& scalar, const DiagonalBase& other)
|
| 83 |
+
{
|
| 84 |
+
return DiagonalWrapper<const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,DiagonalVectorType,product) >(scalar * other.diagonal());
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
template<typename OtherDerived>
|
| 88 |
+
EIGEN_DEVICE_FUNC
|
| 89 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 90 |
+
inline unspecified_expression_type
|
| 91 |
+
#else
|
| 92 |
+
inline const DiagonalWrapper<const EIGEN_CWISE_BINARY_RETURN_TYPE(DiagonalVectorType,typename OtherDerived::DiagonalVectorType,sum) >
|
| 93 |
+
#endif
|
| 94 |
+
operator+(const DiagonalBase<OtherDerived>& other) const
|
| 95 |
+
{
|
| 96 |
+
return (diagonal() + other.diagonal()).asDiagonal();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
template<typename OtherDerived>
|
| 100 |
+
EIGEN_DEVICE_FUNC
|
| 101 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 102 |
+
inline unspecified_expression_type
|
| 103 |
+
#else
|
| 104 |
+
inline const DiagonalWrapper<const EIGEN_CWISE_BINARY_RETURN_TYPE(DiagonalVectorType,typename OtherDerived::DiagonalVectorType,difference) >
|
| 105 |
+
#endif
|
| 106 |
+
operator-(const DiagonalBase<OtherDerived>& other) const
|
| 107 |
+
{
|
| 108 |
+
return (diagonal() - other.diagonal()).asDiagonal();
|
| 109 |
+
}
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
#endif
|
| 113 |
+
|
| 114 |
+
/** \class DiagonalMatrix
|
| 115 |
+
* \ingroup Core_Module
|
| 116 |
+
*
|
| 117 |
+
* \brief Represents a diagonal matrix with its storage
|
| 118 |
+
*
|
| 119 |
+
* \param _Scalar the type of coefficients
|
| 120 |
+
* \param SizeAtCompileTime the dimension of the matrix, or Dynamic
|
| 121 |
+
* \param MaxSizeAtCompileTime the dimension of the matrix, or Dynamic. This parameter is optional and defaults
|
| 122 |
+
* to SizeAtCompileTime. Most of the time, you do not need to specify it.
|
| 123 |
+
*
|
| 124 |
+
* \sa class DiagonalWrapper
|
| 125 |
+
*/
|
| 126 |
+
|
| 127 |
+
namespace internal {
|
| 128 |
+
template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
|
| 129 |
+
struct traits<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
|
| 130 |
+
: traits<Matrix<_Scalar,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
|
| 131 |
+
{
|
| 132 |
+
typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
|
| 133 |
+
typedef DiagonalShape StorageKind;
|
| 134 |
+
enum {
|
| 135 |
+
Flags = LvalueBit | NoPreferredStorageOrderBit
|
| 136 |
+
};
|
| 137 |
+
};
|
| 138 |
+
}
|
| 139 |
+
template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
|
| 140 |
+
class DiagonalMatrix
|
| 141 |
+
: public DiagonalBase<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
|
| 142 |
+
{
|
| 143 |
+
public:
|
| 144 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 145 |
+
typedef typename internal::traits<DiagonalMatrix>::DiagonalVectorType DiagonalVectorType;
|
| 146 |
+
typedef const DiagonalMatrix& Nested;
|
| 147 |
+
typedef _Scalar Scalar;
|
| 148 |
+
typedef typename internal::traits<DiagonalMatrix>::StorageKind StorageKind;
|
| 149 |
+
typedef typename internal::traits<DiagonalMatrix>::StorageIndex StorageIndex;
|
| 150 |
+
#endif
|
| 151 |
+
|
| 152 |
+
protected:
|
| 153 |
+
|
| 154 |
+
DiagonalVectorType m_diagonal;
|
| 155 |
+
|
| 156 |
+
public:
|
| 157 |
+
|
| 158 |
+
/** const version of diagonal(). */
|
| 159 |
+
EIGEN_DEVICE_FUNC
|
| 160 |
+
inline const DiagonalVectorType& diagonal() const { return m_diagonal; }
|
| 161 |
+
/** \returns a reference to the stored vector of diagonal coefficients. */
|
| 162 |
+
EIGEN_DEVICE_FUNC
|
| 163 |
+
inline DiagonalVectorType& diagonal() { return m_diagonal; }
|
| 164 |
+
|
| 165 |
+
/** Default constructor without initialization */
|
| 166 |
+
EIGEN_DEVICE_FUNC
|
| 167 |
+
inline DiagonalMatrix() {}
|
| 168 |
+
|
| 169 |
+
/** Constructs a diagonal matrix with given dimension */
|
| 170 |
+
EIGEN_DEVICE_FUNC
|
| 171 |
+
explicit inline DiagonalMatrix(Index dim) : m_diagonal(dim) {}
|
| 172 |
+
|
| 173 |
+
/** 2D constructor. */
|
| 174 |
+
EIGEN_DEVICE_FUNC
|
| 175 |
+
inline DiagonalMatrix(const Scalar& x, const Scalar& y) : m_diagonal(x,y) {}
|
| 176 |
+
|
| 177 |
+
/** 3D constructor. */
|
| 178 |
+
EIGEN_DEVICE_FUNC
|
| 179 |
+
inline DiagonalMatrix(const Scalar& x, const Scalar& y, const Scalar& z) : m_diagonal(x,y,z) {}
|
| 180 |
+
|
| 181 |
+
#if EIGEN_HAS_CXX11
|
| 182 |
+
/** \brief Construct a diagonal matrix with fixed size from an arbitrary number of coefficients. \cpp11
|
| 183 |
+
*
|
| 184 |
+
* There exists C++98 anologue constructors for fixed-size diagonal matrices having 2 or 3 coefficients.
|
| 185 |
+
*
|
| 186 |
+
* \warning To construct a diagonal matrix of fixed size, the number of values passed to this
|
| 187 |
+
* constructor must match the fixed dimension of \c *this.
|
| 188 |
+
*
|
| 189 |
+
* \sa DiagonalMatrix(const Scalar&, const Scalar&)
|
| 190 |
+
* \sa DiagonalMatrix(const Scalar&, const Scalar&, const Scalar&)
|
| 191 |
+
*/
|
| 192 |
+
template <typename... ArgTypes>
|
| 193 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 194 |
+
DiagonalMatrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const ArgTypes&... args)
|
| 195 |
+
: m_diagonal(a0, a1, a2, args...) {}
|
| 196 |
+
|
| 197 |
+
/** \brief Constructs a DiagonalMatrix and initializes it by elements given by an initializer list of initializer
|
| 198 |
+
* lists \cpp11
|
| 199 |
+
*/
|
| 200 |
+
EIGEN_DEVICE_FUNC
|
| 201 |
+
explicit EIGEN_STRONG_INLINE DiagonalMatrix(const std::initializer_list<std::initializer_list<Scalar>>& list)
|
| 202 |
+
: m_diagonal(list) {}
|
| 203 |
+
#endif // EIGEN_HAS_CXX11
|
| 204 |
+
|
| 205 |
+
/** Copy constructor. */
|
| 206 |
+
template<typename OtherDerived>
|
| 207 |
+
EIGEN_DEVICE_FUNC
|
| 208 |
+
inline DiagonalMatrix(const DiagonalBase<OtherDerived>& other) : m_diagonal(other.diagonal()) {}
|
| 209 |
+
|
| 210 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 211 |
+
/** copy constructor. prevent a default copy constructor from hiding the other templated constructor */
|
| 212 |
+
inline DiagonalMatrix(const DiagonalMatrix& other) : m_diagonal(other.diagonal()) {}
|
| 213 |
+
#endif
|
| 214 |
+
|
| 215 |
+
/** generic constructor from expression of the diagonal coefficients */
|
| 216 |
+
template<typename OtherDerived>
|
| 217 |
+
EIGEN_DEVICE_FUNC
|
| 218 |
+
explicit inline DiagonalMatrix(const MatrixBase<OtherDerived>& other) : m_diagonal(other)
|
| 219 |
+
{}
|
| 220 |
+
|
| 221 |
+
/** Copy operator. */
|
| 222 |
+
template<typename OtherDerived>
|
| 223 |
+
EIGEN_DEVICE_FUNC
|
| 224 |
+
DiagonalMatrix& operator=(const DiagonalBase<OtherDerived>& other)
|
| 225 |
+
{
|
| 226 |
+
m_diagonal = other.diagonal();
|
| 227 |
+
return *this;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 231 |
+
/** This is a special case of the templated operator=. Its purpose is to
|
| 232 |
+
* prevent a default operator= from hiding the templated operator=.
|
| 233 |
+
*/
|
| 234 |
+
EIGEN_DEVICE_FUNC
|
| 235 |
+
DiagonalMatrix& operator=(const DiagonalMatrix& other)
|
| 236 |
+
{
|
| 237 |
+
m_diagonal = other.diagonal();
|
| 238 |
+
return *this;
|
| 239 |
+
}
|
| 240 |
+
#endif
|
| 241 |
+
|
| 242 |
+
/** Resizes to given size. */
|
| 243 |
+
EIGEN_DEVICE_FUNC
|
| 244 |
+
inline void resize(Index size) { m_diagonal.resize(size); }
|
| 245 |
+
/** Sets all coefficients to zero. */
|
| 246 |
+
EIGEN_DEVICE_FUNC
|
| 247 |
+
inline void setZero() { m_diagonal.setZero(); }
|
| 248 |
+
/** Resizes and sets all coefficients to zero. */
|
| 249 |
+
EIGEN_DEVICE_FUNC
|
| 250 |
+
inline void setZero(Index size) { m_diagonal.setZero(size); }
|
| 251 |
+
/** Sets this matrix to be the identity matrix of the current size. */
|
| 252 |
+
EIGEN_DEVICE_FUNC
|
| 253 |
+
inline void setIdentity() { m_diagonal.setOnes(); }
|
| 254 |
+
/** Sets this matrix to be the identity matrix of the given size. */
|
| 255 |
+
EIGEN_DEVICE_FUNC
|
| 256 |
+
inline void setIdentity(Index size) { m_diagonal.setOnes(size); }
|
| 257 |
+
};
|
| 258 |
+
|
| 259 |
+
/** \class DiagonalWrapper
|
| 260 |
+
* \ingroup Core_Module
|
| 261 |
+
*
|
| 262 |
+
* \brief Expression of a diagonal matrix
|
| 263 |
+
*
|
| 264 |
+
* \param _DiagonalVectorType the type of the vector of diagonal coefficients
|
| 265 |
+
*
|
| 266 |
+
* This class is an expression of a diagonal matrix, but not storing its own vector of diagonal coefficients,
|
| 267 |
+
* instead wrapping an existing vector expression. It is the return type of MatrixBase::asDiagonal()
|
| 268 |
+
* and most of the time this is the only way that it is used.
|
| 269 |
+
*
|
| 270 |
+
* \sa class DiagonalMatrix, class DiagonalBase, MatrixBase::asDiagonal()
|
| 271 |
+
*/
|
| 272 |
+
|
| 273 |
+
namespace internal {
|
| 274 |
+
template<typename _DiagonalVectorType>
|
| 275 |
+
struct traits<DiagonalWrapper<_DiagonalVectorType> >
|
| 276 |
+
{
|
| 277 |
+
typedef _DiagonalVectorType DiagonalVectorType;
|
| 278 |
+
typedef typename DiagonalVectorType::Scalar Scalar;
|
| 279 |
+
typedef typename DiagonalVectorType::StorageIndex StorageIndex;
|
| 280 |
+
typedef DiagonalShape StorageKind;
|
| 281 |
+
typedef typename traits<DiagonalVectorType>::XprKind XprKind;
|
| 282 |
+
enum {
|
| 283 |
+
RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
| 284 |
+
ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
| 285 |
+
MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
|
| 286 |
+
MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
|
| 287 |
+
Flags = (traits<DiagonalVectorType>::Flags & LvalueBit) | NoPreferredStorageOrderBit
|
| 288 |
+
};
|
| 289 |
+
};
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
template<typename _DiagonalVectorType>
|
| 293 |
+
class DiagonalWrapper
|
| 294 |
+
: public DiagonalBase<DiagonalWrapper<_DiagonalVectorType> >, internal::no_assignment_operator
|
| 295 |
+
{
|
| 296 |
+
public:
|
| 297 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 298 |
+
typedef _DiagonalVectorType DiagonalVectorType;
|
| 299 |
+
typedef DiagonalWrapper Nested;
|
| 300 |
+
#endif
|
| 301 |
+
|
| 302 |
+
/** Constructor from expression of diagonal coefficients to wrap. */
|
| 303 |
+
EIGEN_DEVICE_FUNC
|
| 304 |
+
explicit inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {}
|
| 305 |
+
|
| 306 |
+
/** \returns a const reference to the wrapped expression of diagonal coefficients. */
|
| 307 |
+
EIGEN_DEVICE_FUNC
|
| 308 |
+
const DiagonalVectorType& diagonal() const { return m_diagonal; }
|
| 309 |
+
|
| 310 |
+
protected:
|
| 311 |
+
typename DiagonalVectorType::Nested m_diagonal;
|
| 312 |
+
};
|
| 313 |
+
|
| 314 |
+
/** \returns a pseudo-expression of a diagonal matrix with *this as vector of diagonal coefficients
|
| 315 |
+
*
|
| 316 |
+
* \only_for_vectors
|
| 317 |
+
*
|
| 318 |
+
* Example: \include MatrixBase_asDiagonal.cpp
|
| 319 |
+
* Output: \verbinclude MatrixBase_asDiagonal.out
|
| 320 |
+
*
|
| 321 |
+
* \sa class DiagonalWrapper, class DiagonalMatrix, diagonal(), isDiagonal()
|
| 322 |
+
**/
|
| 323 |
+
template<typename Derived>
|
| 324 |
+
EIGEN_DEVICE_FUNC inline const DiagonalWrapper<const Derived>
|
| 325 |
+
MatrixBase<Derived>::asDiagonal() const
|
| 326 |
+
{
|
| 327 |
+
return DiagonalWrapper<const Derived>(derived());
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
/** \returns true if *this is approximately equal to a diagonal matrix,
|
| 331 |
+
* within the precision given by \a prec.
|
| 332 |
+
*
|
| 333 |
+
* Example: \include MatrixBase_isDiagonal.cpp
|
| 334 |
+
* Output: \verbinclude MatrixBase_isDiagonal.out
|
| 335 |
+
*
|
| 336 |
+
* \sa asDiagonal()
|
| 337 |
+
*/
|
| 338 |
+
template<typename Derived>
|
| 339 |
+
bool MatrixBase<Derived>::isDiagonal(const RealScalar& prec) const
|
| 340 |
+
{
|
| 341 |
+
if(cols() != rows()) return false;
|
| 342 |
+
RealScalar maxAbsOnDiagonal = static_cast<RealScalar>(-1);
|
| 343 |
+
for(Index j = 0; j < cols(); ++j)
|
| 344 |
+
{
|
| 345 |
+
RealScalar absOnDiagonal = numext::abs(coeff(j,j));
|
| 346 |
+
if(absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal;
|
| 347 |
+
}
|
| 348 |
+
for(Index j = 0; j < cols(); ++j)
|
| 349 |
+
for(Index i = 0; i < j; ++i)
|
| 350 |
+
{
|
| 351 |
+
if(!internal::isMuchSmallerThan(coeff(i, j), maxAbsOnDiagonal, prec)) return false;
|
| 352 |
+
if(!internal::isMuchSmallerThan(coeff(j, i), maxAbsOnDiagonal, prec)) return false;
|
| 353 |
+
}
|
| 354 |
+
return true;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
namespace internal {
|
| 358 |
+
|
| 359 |
+
template<> struct storage_kind_to_shape<DiagonalShape> { typedef DiagonalShape Shape; };
|
| 360 |
+
|
| 361 |
+
struct Diagonal2Dense {};
|
| 362 |
+
|
| 363 |
+
template<> struct AssignmentKind<DenseShape,DiagonalShape> { typedef Diagonal2Dense Kind; };
|
| 364 |
+
|
| 365 |
+
// Diagonal matrix to Dense assignment
|
| 366 |
+
template< typename DstXprType, typename SrcXprType, typename Functor>
|
| 367 |
+
struct Assignment<DstXprType, SrcXprType, Functor, Diagonal2Dense>
|
| 368 |
+
{
|
| 369 |
+
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
|
| 370 |
+
{
|
| 371 |
+
Index dstRows = src.rows();
|
| 372 |
+
Index dstCols = src.cols();
|
| 373 |
+
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
|
| 374 |
+
dst.resize(dstRows, dstCols);
|
| 375 |
+
|
| 376 |
+
dst.setZero();
|
| 377 |
+
dst.diagonal() = src.diagonal();
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
|
| 381 |
+
{ dst.diagonal() += src.diagonal(); }
|
| 382 |
+
|
| 383 |
+
static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
|
| 384 |
+
{ dst.diagonal() -= src.diagonal(); }
|
| 385 |
+
};
|
| 386 |
+
|
| 387 |
+
} // namespace internal
|
| 388 |
+
|
| 389 |
+
} // end namespace Eigen
|
| 390 |
+
|
| 391 |
+
#endif // EIGEN_DIAGONALMATRIX_H
|
include/eigen/Eigen/src/Core/DiagonalProduct.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_DIAGONALPRODUCT_H
|
| 12 |
+
#define EIGEN_DIAGONALPRODUCT_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
/** \returns the diagonal matrix product of \c *this by the diagonal matrix \a diagonal.
|
| 17 |
+
*/
|
| 18 |
+
template<typename Derived>
|
| 19 |
+
template<typename DiagonalDerived>
|
| 20 |
+
EIGEN_DEVICE_FUNC inline const Product<Derived, DiagonalDerived, LazyProduct>
|
| 21 |
+
MatrixBase<Derived>::operator*(const DiagonalBase<DiagonalDerived> &a_diagonal) const
|
| 22 |
+
{
|
| 23 |
+
return Product<Derived, DiagonalDerived, LazyProduct>(derived(),a_diagonal.derived());
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
} // end namespace Eigen
|
| 27 |
+
|
| 28 |
+
#endif // EIGEN_DIAGONALPRODUCT_H
|
include/eigen/Eigen/src/Core/Dot.h
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2006-2008, 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_DOT_H
|
| 11 |
+
#define EIGEN_DOT_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
// helper function for dot(). The problem is that if we put that in the body of dot(), then upon calling dot
|
| 18 |
+
// with mismatched types, the compiler emits errors about failing to instantiate cwiseProduct BEFORE
|
| 19 |
+
// looking at the static assertions. Thus this is a trick to get better compile errors.
|
| 20 |
+
template<typename T, typename U,
|
| 21 |
+
bool NeedToTranspose = T::IsVectorAtCompileTime && U::IsVectorAtCompileTime &&
|
| 22 |
+
((int(T::RowsAtCompileTime) == 1 && int(U::ColsAtCompileTime) == 1) ||
|
| 23 |
+
(int(T::ColsAtCompileTime) == 1 && int(U::RowsAtCompileTime) == 1))>
|
| 24 |
+
struct dot_nocheck
|
| 25 |
+
{
|
| 26 |
+
typedef scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> conj_prod;
|
| 27 |
+
typedef typename conj_prod::result_type ResScalar;
|
| 28 |
+
EIGEN_DEVICE_FUNC
|
| 29 |
+
EIGEN_STRONG_INLINE
|
| 30 |
+
static ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
|
| 31 |
+
{
|
| 32 |
+
return a.template binaryExpr<conj_prod>(b).sum();
|
| 33 |
+
}
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
template<typename T, typename U>
|
| 37 |
+
struct dot_nocheck<T, U, true>
|
| 38 |
+
{
|
| 39 |
+
typedef scalar_conj_product_op<typename traits<T>::Scalar,typename traits<U>::Scalar> conj_prod;
|
| 40 |
+
typedef typename conj_prod::result_type ResScalar;
|
| 41 |
+
EIGEN_DEVICE_FUNC
|
| 42 |
+
EIGEN_STRONG_INLINE
|
| 43 |
+
static ResScalar run(const MatrixBase<T>& a, const MatrixBase<U>& b)
|
| 44 |
+
{
|
| 45 |
+
return a.transpose().template binaryExpr<conj_prod>(b).sum();
|
| 46 |
+
}
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
} // end namespace internal
|
| 50 |
+
|
| 51 |
+
/** \fn MatrixBase::dot
|
| 52 |
+
* \returns the dot product of *this with other.
|
| 53 |
+
*
|
| 54 |
+
* \only_for_vectors
|
| 55 |
+
*
|
| 56 |
+
* \note If the scalar type is complex numbers, then this function returns the hermitian
|
| 57 |
+
* (sesquilinear) dot product, conjugate-linear in the first variable and linear in the
|
| 58 |
+
* second variable.
|
| 59 |
+
*
|
| 60 |
+
* \sa squaredNorm(), norm()
|
| 61 |
+
*/
|
| 62 |
+
template<typename Derived>
|
| 63 |
+
template<typename OtherDerived>
|
| 64 |
+
EIGEN_DEVICE_FUNC
|
| 65 |
+
EIGEN_STRONG_INLINE
|
| 66 |
+
typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
|
| 67 |
+
MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
|
| 68 |
+
{
|
| 69 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 70 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
|
| 71 |
+
EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived)
|
| 72 |
+
#if !(defined(EIGEN_NO_STATIC_ASSERT) && defined(EIGEN_NO_DEBUG))
|
| 73 |
+
typedef internal::scalar_conj_product_op<Scalar,typename OtherDerived::Scalar> func;
|
| 74 |
+
EIGEN_CHECK_BINARY_COMPATIBILIY(func,Scalar,typename OtherDerived::Scalar);
|
| 75 |
+
#endif
|
| 76 |
+
|
| 77 |
+
eigen_assert(size() == other.size());
|
| 78 |
+
|
| 79 |
+
return internal::dot_nocheck<Derived,OtherDerived>::run(*this, other);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
//---------- implementation of L2 norm and related functions ----------
|
| 83 |
+
|
| 84 |
+
/** \returns, for vectors, the squared \em l2 norm of \c *this, and for matrices the squared Frobenius norm.
|
| 85 |
+
* In both cases, it consists in the sum of the square of all the matrix entries.
|
| 86 |
+
* For vectors, this is also equals to the dot product of \c *this with itself.
|
| 87 |
+
*
|
| 88 |
+
* \sa dot(), norm(), lpNorm()
|
| 89 |
+
*/
|
| 90 |
+
template<typename Derived>
|
| 91 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits<typename internal::traits<Derived>::Scalar>::Real MatrixBase<Derived>::squaredNorm() const
|
| 92 |
+
{
|
| 93 |
+
return numext::real((*this).cwiseAbs2().sum());
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/** \returns, for vectors, the \em l2 norm of \c *this, and for matrices the Frobenius norm.
|
| 97 |
+
* In both cases, it consists in the square root of the sum of the square of all the matrix entries.
|
| 98 |
+
* For vectors, this is also equals to the square root of the dot product of \c *this with itself.
|
| 99 |
+
*
|
| 100 |
+
* \sa lpNorm(), dot(), squaredNorm()
|
| 101 |
+
*/
|
| 102 |
+
template<typename Derived>
|
| 103 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits<typename internal::traits<Derived>::Scalar>::Real MatrixBase<Derived>::norm() const
|
| 104 |
+
{
|
| 105 |
+
return numext::sqrt(squaredNorm());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/** \returns an expression of the quotient of \c *this by its own norm.
|
| 109 |
+
*
|
| 110 |
+
* \warning If the input vector is too small (i.e., this->norm()==0),
|
| 111 |
+
* then this function returns a copy of the input.
|
| 112 |
+
*
|
| 113 |
+
* \only_for_vectors
|
| 114 |
+
*
|
| 115 |
+
* \sa norm(), normalize()
|
| 116 |
+
*/
|
| 117 |
+
template<typename Derived>
|
| 118 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::PlainObject
|
| 119 |
+
MatrixBase<Derived>::normalized() const
|
| 120 |
+
{
|
| 121 |
+
typedef typename internal::nested_eval<Derived,2>::type _Nested;
|
| 122 |
+
_Nested n(derived());
|
| 123 |
+
RealScalar z = n.squaredNorm();
|
| 124 |
+
// NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU
|
| 125 |
+
if(z>RealScalar(0))
|
| 126 |
+
return n / numext::sqrt(z);
|
| 127 |
+
else
|
| 128 |
+
return n;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/** Normalizes the vector, i.e. divides it by its own norm.
|
| 132 |
+
*
|
| 133 |
+
* \only_for_vectors
|
| 134 |
+
*
|
| 135 |
+
* \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged.
|
| 136 |
+
*
|
| 137 |
+
* \sa norm(), normalized()
|
| 138 |
+
*/
|
| 139 |
+
template<typename Derived>
|
| 140 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase<Derived>::normalize()
|
| 141 |
+
{
|
| 142 |
+
RealScalar z = squaredNorm();
|
| 143 |
+
// NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU
|
| 144 |
+
if(z>RealScalar(0))
|
| 145 |
+
derived() /= numext::sqrt(z);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/** \returns an expression of the quotient of \c *this by its own norm while avoiding underflow and overflow.
|
| 149 |
+
*
|
| 150 |
+
* \only_for_vectors
|
| 151 |
+
*
|
| 152 |
+
* This method is analogue to the normalized() method, but it reduces the risk of
|
| 153 |
+
* underflow and overflow when computing the norm.
|
| 154 |
+
*
|
| 155 |
+
* \warning If the input vector is too small (i.e., this->norm()==0),
|
| 156 |
+
* then this function returns a copy of the input.
|
| 157 |
+
*
|
| 158 |
+
* \sa stableNorm(), stableNormalize(), normalized()
|
| 159 |
+
*/
|
| 160 |
+
template<typename Derived>
|
| 161 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::PlainObject
|
| 162 |
+
MatrixBase<Derived>::stableNormalized() const
|
| 163 |
+
{
|
| 164 |
+
typedef typename internal::nested_eval<Derived,3>::type _Nested;
|
| 165 |
+
_Nested n(derived());
|
| 166 |
+
RealScalar w = n.cwiseAbs().maxCoeff();
|
| 167 |
+
RealScalar z = (n/w).squaredNorm();
|
| 168 |
+
if(z>RealScalar(0))
|
| 169 |
+
return n / (numext::sqrt(z)*w);
|
| 170 |
+
else
|
| 171 |
+
return n;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/** Normalizes the vector while avoid underflow and overflow
|
| 175 |
+
*
|
| 176 |
+
* \only_for_vectors
|
| 177 |
+
*
|
| 178 |
+
* This method is analogue to the normalize() method, but it reduces the risk of
|
| 179 |
+
* underflow and overflow when computing the norm.
|
| 180 |
+
*
|
| 181 |
+
* \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged.
|
| 182 |
+
*
|
| 183 |
+
* \sa stableNorm(), stableNormalized(), normalize()
|
| 184 |
+
*/
|
| 185 |
+
template<typename Derived>
|
| 186 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase<Derived>::stableNormalize()
|
| 187 |
+
{
|
| 188 |
+
RealScalar w = cwiseAbs().maxCoeff();
|
| 189 |
+
RealScalar z = (derived()/w).squaredNorm();
|
| 190 |
+
if(z>RealScalar(0))
|
| 191 |
+
derived() /= numext::sqrt(z)*w;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
//---------- implementation of other norms ----------
|
| 195 |
+
|
| 196 |
+
namespace internal {
|
| 197 |
+
|
| 198 |
+
template<typename Derived, int p>
|
| 199 |
+
struct lpNorm_selector
|
| 200 |
+
{
|
| 201 |
+
typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar;
|
| 202 |
+
EIGEN_DEVICE_FUNC
|
| 203 |
+
static inline RealScalar run(const MatrixBase<Derived>& m)
|
| 204 |
+
{
|
| 205 |
+
EIGEN_USING_STD(pow)
|
| 206 |
+
return pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p);
|
| 207 |
+
}
|
| 208 |
+
};
|
| 209 |
+
|
| 210 |
+
template<typename Derived>
|
| 211 |
+
struct lpNorm_selector<Derived, 1>
|
| 212 |
+
{
|
| 213 |
+
EIGEN_DEVICE_FUNC
|
| 214 |
+
static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
|
| 215 |
+
{
|
| 216 |
+
return m.cwiseAbs().sum();
|
| 217 |
+
}
|
| 218 |
+
};
|
| 219 |
+
|
| 220 |
+
template<typename Derived>
|
| 221 |
+
struct lpNorm_selector<Derived, 2>
|
| 222 |
+
{
|
| 223 |
+
EIGEN_DEVICE_FUNC
|
| 224 |
+
static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
|
| 225 |
+
{
|
| 226 |
+
return m.norm();
|
| 227 |
+
}
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
template<typename Derived>
|
| 231 |
+
struct lpNorm_selector<Derived, Infinity>
|
| 232 |
+
{
|
| 233 |
+
typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar;
|
| 234 |
+
EIGEN_DEVICE_FUNC
|
| 235 |
+
static inline RealScalar run(const MatrixBase<Derived>& m)
|
| 236 |
+
{
|
| 237 |
+
if(Derived::SizeAtCompileTime==0 || (Derived::SizeAtCompileTime==Dynamic && m.size()==0))
|
| 238 |
+
return RealScalar(0);
|
| 239 |
+
return m.cwiseAbs().maxCoeff();
|
| 240 |
+
}
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
} // end namespace internal
|
| 244 |
+
|
| 245 |
+
/** \returns the \b coefficient-wise \f$ \ell^p \f$ norm of \c *this, that is, returns the p-th root of the sum of the p-th powers of the absolute values
|
| 246 |
+
* of the coefficients of \c *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^\infty \f$
|
| 247 |
+
* norm, that is the maximum of the absolute values of the coefficients of \c *this.
|
| 248 |
+
*
|
| 249 |
+
* In all cases, if \c *this is empty, then the value 0 is returned.
|
| 250 |
+
*
|
| 251 |
+
* \note For matrices, this function does not compute the <a href="https://en.wikipedia.org/wiki/Operator_norm">operator-norm</a>. That is, if \c *this is a matrix, then its coefficients are interpreted as a 1D vector. Nonetheless, you can easily compute the 1-norm and \f$\infty\f$-norm matrix operator norms using \link TutorialReductionsVisitorsBroadcastingReductionsNorm partial reductions \endlink.
|
| 252 |
+
*
|
| 253 |
+
* \sa norm()
|
| 254 |
+
*/
|
| 255 |
+
template<typename Derived>
|
| 256 |
+
template<int p>
|
| 257 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 258 |
+
EIGEN_DEVICE_FUNC inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
|
| 259 |
+
#else
|
| 260 |
+
EIGEN_DEVICE_FUNC MatrixBase<Derived>::RealScalar
|
| 261 |
+
#endif
|
| 262 |
+
MatrixBase<Derived>::lpNorm() const
|
| 263 |
+
{
|
| 264 |
+
return internal::lpNorm_selector<Derived, p>::run(*this);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
//---------- implementation of isOrthogonal / isUnitary ----------
|
| 268 |
+
|
| 269 |
+
/** \returns true if *this is approximately orthogonal to \a other,
|
| 270 |
+
* within the precision given by \a prec.
|
| 271 |
+
*
|
| 272 |
+
* Example: \include MatrixBase_isOrthogonal.cpp
|
| 273 |
+
* Output: \verbinclude MatrixBase_isOrthogonal.out
|
| 274 |
+
*/
|
| 275 |
+
template<typename Derived>
|
| 276 |
+
template<typename OtherDerived>
|
| 277 |
+
bool MatrixBase<Derived>::isOrthogonal
|
| 278 |
+
(const MatrixBase<OtherDerived>& other, const RealScalar& prec) const
|
| 279 |
+
{
|
| 280 |
+
typename internal::nested_eval<Derived,2>::type nested(derived());
|
| 281 |
+
typename internal::nested_eval<OtherDerived,2>::type otherNested(other.derived());
|
| 282 |
+
return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm();
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/** \returns true if *this is approximately an unitary matrix,
|
| 286 |
+
* within the precision given by \a prec. In the case where the \a Scalar
|
| 287 |
+
* type is real numbers, a unitary matrix is an orthogonal matrix, whence the name.
|
| 288 |
+
*
|
| 289 |
+
* \note This can be used to check whether a family of vectors forms an orthonormal basis.
|
| 290 |
+
* Indeed, \c m.isUnitary() returns true if and only if the columns (equivalently, the rows) of m form an
|
| 291 |
+
* orthonormal basis.
|
| 292 |
+
*
|
| 293 |
+
* Example: \include MatrixBase_isUnitary.cpp
|
| 294 |
+
* Output: \verbinclude MatrixBase_isUnitary.out
|
| 295 |
+
*/
|
| 296 |
+
template<typename Derived>
|
| 297 |
+
bool MatrixBase<Derived>::isUnitary(const RealScalar& prec) const
|
| 298 |
+
{
|
| 299 |
+
typename internal::nested_eval<Derived,1>::type self(derived());
|
| 300 |
+
for(Index i = 0; i < cols(); ++i)
|
| 301 |
+
{
|
| 302 |
+
if(!internal::isApprox(self.col(i).squaredNorm(), static_cast<RealScalar>(1), prec))
|
| 303 |
+
return false;
|
| 304 |
+
for(Index j = 0; j < i; ++j)
|
| 305 |
+
if(!internal::isMuchSmallerThan(self.col(i).dot(self.col(j)), static_cast<Scalar>(1), prec))
|
| 306 |
+
return false;
|
| 307 |
+
}
|
| 308 |
+
return true;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
} // end namespace Eigen
|
| 312 |
+
|
| 313 |
+
#endif // EIGEN_DOT_H
|
include/eigen/Eigen/src/Core/EigenBase.h
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_EIGENBASE_H
|
| 12 |
+
#define EIGEN_EIGENBASE_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
/** \class EigenBase
|
| 17 |
+
* \ingroup Core_Module
|
| 18 |
+
*
|
| 19 |
+
* Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T).
|
| 20 |
+
*
|
| 21 |
+
* In other words, an EigenBase object is an object that can be copied into a MatrixBase.
|
| 22 |
+
*
|
| 23 |
+
* Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc.
|
| 24 |
+
*
|
| 25 |
+
* Notice that this class is trivial, it is only used to disambiguate overloaded functions.
|
| 26 |
+
*
|
| 27 |
+
* \sa \blank \ref TopicClassHierarchy
|
| 28 |
+
*/
|
| 29 |
+
template<typename Derived> struct EigenBase
|
| 30 |
+
{
|
| 31 |
+
// typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
|
| 32 |
+
|
| 33 |
+
/** \brief The interface type of indices
|
| 34 |
+
* \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE.
|
| 35 |
+
* \sa StorageIndex, \ref TopicPreprocessorDirectives.
|
| 36 |
+
* DEPRECATED: Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead.
|
| 37 |
+
* Deprecation is not marked with a doxygen comment because there are too many existing usages to add the deprecation attribute.
|
| 38 |
+
*/
|
| 39 |
+
typedef Eigen::Index Index;
|
| 40 |
+
|
| 41 |
+
// FIXME is it needed?
|
| 42 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 43 |
+
|
| 44 |
+
/** \returns a reference to the derived object */
|
| 45 |
+
EIGEN_DEVICE_FUNC
|
| 46 |
+
Derived& derived() { return *static_cast<Derived*>(this); }
|
| 47 |
+
/** \returns a const reference to the derived object */
|
| 48 |
+
EIGEN_DEVICE_FUNC
|
| 49 |
+
const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
| 50 |
+
|
| 51 |
+
EIGEN_DEVICE_FUNC
|
| 52 |
+
inline Derived& const_cast_derived() const
|
| 53 |
+
{ return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
|
| 54 |
+
EIGEN_DEVICE_FUNC
|
| 55 |
+
inline const Derived& const_derived() const
|
| 56 |
+
{ return *static_cast<const Derived*>(this); }
|
| 57 |
+
|
| 58 |
+
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */
|
| 59 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 60 |
+
inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); }
|
| 61 |
+
/** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
|
| 62 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 63 |
+
inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); }
|
| 64 |
+
/** \returns the number of coefficients, which is rows()*cols().
|
| 65 |
+
* \sa rows(), cols(), SizeAtCompileTime. */
|
| 66 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 67 |
+
inline Index size() const EIGEN_NOEXCEPT { return rows() * cols(); }
|
| 68 |
+
|
| 69 |
+
/** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */
|
| 70 |
+
template<typename Dest>
|
| 71 |
+
EIGEN_DEVICE_FUNC
|
| 72 |
+
inline void evalTo(Dest& dst) const
|
| 73 |
+
{ derived().evalTo(dst); }
|
| 74 |
+
|
| 75 |
+
/** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */
|
| 76 |
+
template<typename Dest>
|
| 77 |
+
EIGEN_DEVICE_FUNC
|
| 78 |
+
inline void addTo(Dest& dst) const
|
| 79 |
+
{
|
| 80 |
+
// This is the default implementation,
|
| 81 |
+
// derived class can reimplement it in a more optimized way.
|
| 82 |
+
typename Dest::PlainObject res(rows(),cols());
|
| 83 |
+
evalTo(res);
|
| 84 |
+
dst += res;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */
|
| 88 |
+
template<typename Dest>
|
| 89 |
+
EIGEN_DEVICE_FUNC
|
| 90 |
+
inline void subTo(Dest& dst) const
|
| 91 |
+
{
|
| 92 |
+
// This is the default implementation,
|
| 93 |
+
// derived class can reimplement it in a more optimized way.
|
| 94 |
+
typename Dest::PlainObject res(rows(),cols());
|
| 95 |
+
evalTo(res);
|
| 96 |
+
dst -= res;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */
|
| 100 |
+
template<typename Dest>
|
| 101 |
+
EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
|
| 102 |
+
{
|
| 103 |
+
// This is the default implementation,
|
| 104 |
+
// derived class can reimplement it in a more optimized way.
|
| 105 |
+
dst = dst * this->derived();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */
|
| 109 |
+
template<typename Dest>
|
| 110 |
+
EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
|
| 111 |
+
{
|
| 112 |
+
// This is the default implementation,
|
| 113 |
+
// derived class can reimplement it in a more optimized way.
|
| 114 |
+
dst = this->derived() * dst;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
+
/***************************************************************************
|
| 120 |
+
* Implementation of matrix base methods
|
| 121 |
+
***************************************************************************/
|
| 122 |
+
|
| 123 |
+
/** \brief Copies the generic expression \a other into *this.
|
| 124 |
+
*
|
| 125 |
+
* \details The expression must provide a (templated) evalTo(Derived& dst) const
|
| 126 |
+
* function which does the actual job. In practice, this allows any user to write
|
| 127 |
+
* its own special matrix without having to modify MatrixBase
|
| 128 |
+
*
|
| 129 |
+
* \returns a reference to *this.
|
| 130 |
+
*/
|
| 131 |
+
template<typename Derived>
|
| 132 |
+
template<typename OtherDerived>
|
| 133 |
+
EIGEN_DEVICE_FUNC
|
| 134 |
+
Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other)
|
| 135 |
+
{
|
| 136 |
+
call_assignment(derived(), other.derived());
|
| 137 |
+
return derived();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
template<typename Derived>
|
| 141 |
+
template<typename OtherDerived>
|
| 142 |
+
EIGEN_DEVICE_FUNC
|
| 143 |
+
Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other)
|
| 144 |
+
{
|
| 145 |
+
call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 146 |
+
return derived();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
template<typename Derived>
|
| 150 |
+
template<typename OtherDerived>
|
| 151 |
+
EIGEN_DEVICE_FUNC
|
| 152 |
+
Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other)
|
| 153 |
+
{
|
| 154 |
+
call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 155 |
+
return derived();
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
} // end namespace Eigen
|
| 159 |
+
|
| 160 |
+
#endif // EIGEN_EIGENBASE_H
|
include/eigen/Eigen/src/Core/ForceAlignedAccess.h
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_FORCEALIGNEDACCESS_H
|
| 11 |
+
#define EIGEN_FORCEALIGNEDACCESS_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
/** \class ForceAlignedAccess
|
| 16 |
+
* \ingroup Core_Module
|
| 17 |
+
*
|
| 18 |
+
* \brief Enforce aligned packet loads and stores regardless of what is requested
|
| 19 |
+
*
|
| 20 |
+
* \param ExpressionType the type of the object of which we are forcing aligned packet access
|
| 21 |
+
*
|
| 22 |
+
* This class is the return type of MatrixBase::forceAlignedAccess()
|
| 23 |
+
* and most of the time this is the only way it is used.
|
| 24 |
+
*
|
| 25 |
+
* \sa MatrixBase::forceAlignedAccess()
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
namespace internal {
|
| 29 |
+
template<typename ExpressionType>
|
| 30 |
+
struct traits<ForceAlignedAccess<ExpressionType> > : public traits<ExpressionType>
|
| 31 |
+
{};
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
template<typename ExpressionType> class ForceAlignedAccess
|
| 35 |
+
: public internal::dense_xpr_base< ForceAlignedAccess<ExpressionType> >::type
|
| 36 |
+
{
|
| 37 |
+
public:
|
| 38 |
+
|
| 39 |
+
typedef typename internal::dense_xpr_base<ForceAlignedAccess>::type Base;
|
| 40 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess)
|
| 41 |
+
|
| 42 |
+
EIGEN_DEVICE_FUNC explicit inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {}
|
| 43 |
+
|
| 44 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 45 |
+
inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
|
| 46 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 47 |
+
inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
|
| 48 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 49 |
+
inline Index outerStride() const EIGEN_NOEXCEPT { return m_expression.outerStride(); }
|
| 50 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 51 |
+
inline Index innerStride() const EIGEN_NOEXCEPT { return m_expression.innerStride(); }
|
| 52 |
+
|
| 53 |
+
EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const
|
| 54 |
+
{
|
| 55 |
+
return m_expression.coeff(row, col);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col)
|
| 59 |
+
{
|
| 60 |
+
return m_expression.const_cast_derived().coeffRef(row, col);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const
|
| 64 |
+
{
|
| 65 |
+
return m_expression.coeff(index);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index)
|
| 69 |
+
{
|
| 70 |
+
return m_expression.const_cast_derived().coeffRef(index);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
template<int LoadMode>
|
| 74 |
+
inline const PacketScalar packet(Index row, Index col) const
|
| 75 |
+
{
|
| 76 |
+
return m_expression.template packet<Aligned>(row, col);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
template<int LoadMode>
|
| 80 |
+
inline void writePacket(Index row, Index col, const PacketScalar& x)
|
| 81 |
+
{
|
| 82 |
+
m_expression.const_cast_derived().template writePacket<Aligned>(row, col, x);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
template<int LoadMode>
|
| 86 |
+
inline const PacketScalar packet(Index index) const
|
| 87 |
+
{
|
| 88 |
+
return m_expression.template packet<Aligned>(index);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
template<int LoadMode>
|
| 92 |
+
inline void writePacket(Index index, const PacketScalar& x)
|
| 93 |
+
{
|
| 94 |
+
m_expression.const_cast_derived().template writePacket<Aligned>(index, x);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
|
| 98 |
+
|
| 99 |
+
protected:
|
| 100 |
+
const ExpressionType& m_expression;
|
| 101 |
+
|
| 102 |
+
private:
|
| 103 |
+
ForceAlignedAccess& operator=(const ForceAlignedAccess&);
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
/** \returns an expression of *this with forced aligned access
|
| 107 |
+
* \sa forceAlignedAccessIf(),class ForceAlignedAccess
|
| 108 |
+
*/
|
| 109 |
+
template<typename Derived>
|
| 110 |
+
inline const ForceAlignedAccess<Derived>
|
| 111 |
+
MatrixBase<Derived>::forceAlignedAccess() const
|
| 112 |
+
{
|
| 113 |
+
return ForceAlignedAccess<Derived>(derived());
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/** \returns an expression of *this with forced aligned access
|
| 117 |
+
* \sa forceAlignedAccessIf(), class ForceAlignedAccess
|
| 118 |
+
*/
|
| 119 |
+
template<typename Derived>
|
| 120 |
+
inline ForceAlignedAccess<Derived>
|
| 121 |
+
MatrixBase<Derived>::forceAlignedAccess()
|
| 122 |
+
{
|
| 123 |
+
return ForceAlignedAccess<Derived>(derived());
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/** \returns an expression of *this with forced aligned access if \a Enable is true.
|
| 127 |
+
* \sa forceAlignedAccess(), class ForceAlignedAccess
|
| 128 |
+
*/
|
| 129 |
+
template<typename Derived>
|
| 130 |
+
template<bool Enable>
|
| 131 |
+
inline typename internal::add_const_on_value_type<typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type>::type
|
| 132 |
+
MatrixBase<Derived>::forceAlignedAccessIf() const
|
| 133 |
+
{
|
| 134 |
+
return derived(); // FIXME This should not work but apparently is never used
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/** \returns an expression of *this with forced aligned access if \a Enable is true.
|
| 138 |
+
* \sa forceAlignedAccess(), class ForceAlignedAccess
|
| 139 |
+
*/
|
| 140 |
+
template<typename Derived>
|
| 141 |
+
template<bool Enable>
|
| 142 |
+
inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type
|
| 143 |
+
MatrixBase<Derived>::forceAlignedAccessIf()
|
| 144 |
+
{
|
| 145 |
+
return derived(); // FIXME This should not work but apparently is never used
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
} // end namespace Eigen
|
| 149 |
+
|
| 150 |
+
#endif // EIGEN_FORCEALIGNEDACCESS_H
|
include/eigen/Eigen/src/Core/Fuzzy.h
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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<gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_FUZZY_H
|
| 12 |
+
#define EIGEN_FUZZY_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal
|
| 17 |
+
{
|
| 18 |
+
|
| 19 |
+
template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
|
| 20 |
+
struct isApprox_selector
|
| 21 |
+
{
|
| 22 |
+
EIGEN_DEVICE_FUNC
|
| 23 |
+
static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
|
| 24 |
+
{
|
| 25 |
+
typename internal::nested_eval<Derived,2>::type nested(x);
|
| 26 |
+
typename internal::nested_eval<OtherDerived,2>::type otherNested(y);
|
| 27 |
+
return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
|
| 28 |
+
}
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
template<typename Derived, typename OtherDerived>
|
| 32 |
+
struct isApprox_selector<Derived, OtherDerived, true>
|
| 33 |
+
{
|
| 34 |
+
EIGEN_DEVICE_FUNC
|
| 35 |
+
static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&)
|
| 36 |
+
{
|
| 37 |
+
return x.matrix() == y.matrix();
|
| 38 |
+
}
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
|
| 42 |
+
struct isMuchSmallerThan_object_selector
|
| 43 |
+
{
|
| 44 |
+
EIGEN_DEVICE_FUNC
|
| 45 |
+
static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
|
| 46 |
+
{
|
| 47 |
+
return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum();
|
| 48 |
+
}
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
template<typename Derived, typename OtherDerived>
|
| 52 |
+
struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
|
| 53 |
+
{
|
| 54 |
+
EIGEN_DEVICE_FUNC
|
| 55 |
+
static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&)
|
| 56 |
+
{
|
| 57 |
+
return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
|
| 58 |
+
}
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
|
| 62 |
+
struct isMuchSmallerThan_scalar_selector
|
| 63 |
+
{
|
| 64 |
+
EIGEN_DEVICE_FUNC
|
| 65 |
+
static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec)
|
| 66 |
+
{
|
| 67 |
+
return x.cwiseAbs2().sum() <= numext::abs2(prec * y);
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
template<typename Derived>
|
| 72 |
+
struct isMuchSmallerThan_scalar_selector<Derived, true>
|
| 73 |
+
{
|
| 74 |
+
EIGEN_DEVICE_FUNC
|
| 75 |
+
static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&)
|
| 76 |
+
{
|
| 77 |
+
return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
|
| 78 |
+
}
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
} // end namespace internal
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
/** \returns \c true if \c *this is approximately equal to \a other, within the precision
|
| 85 |
+
* determined by \a prec.
|
| 86 |
+
*
|
| 87 |
+
* \note The fuzzy compares are done multiplicatively. Two vectors \f$ v \f$ and \f$ w \f$
|
| 88 |
+
* are considered to be approximately equal within precision \f$ p \f$ if
|
| 89 |
+
* \f[ \Vert v - w \Vert \leqslant p\,\min(\Vert v\Vert, \Vert w\Vert). \f]
|
| 90 |
+
* For matrices, the comparison is done using the Hilbert-Schmidt norm (aka Frobenius norm
|
| 91 |
+
* L2 norm).
|
| 92 |
+
*
|
| 93 |
+
* \note Because of the multiplicativeness of this comparison, one can't use this function
|
| 94 |
+
* to check whether \c *this is approximately equal to the zero matrix or vector.
|
| 95 |
+
* Indeed, \c isApprox(zero) returns false unless \c *this itself is exactly the zero matrix
|
| 96 |
+
* or vector. If you want to test whether \c *this is zero, use internal::isMuchSmallerThan(const
|
| 97 |
+
* RealScalar&, RealScalar) instead.
|
| 98 |
+
*
|
| 99 |
+
* \sa internal::isMuchSmallerThan(const RealScalar&, RealScalar) const
|
| 100 |
+
*/
|
| 101 |
+
template<typename Derived>
|
| 102 |
+
template<typename OtherDerived>
|
| 103 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApprox(
|
| 104 |
+
const DenseBase<OtherDerived>& other,
|
| 105 |
+
const RealScalar& prec
|
| 106 |
+
) const
|
| 107 |
+
{
|
| 108 |
+
return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/** \returns \c true if the norm of \c *this is much smaller than \a other,
|
| 112 |
+
* within the precision determined by \a prec.
|
| 113 |
+
*
|
| 114 |
+
* \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is
|
| 115 |
+
* considered to be much smaller than \f$ x \f$ within precision \f$ p \f$ if
|
| 116 |
+
* \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f]
|
| 117 |
+
*
|
| 118 |
+
* For matrices, the comparison is done using the Hilbert-Schmidt norm. For this reason,
|
| 119 |
+
* the value of the reference scalar \a other should come from the Hilbert-Schmidt norm
|
| 120 |
+
* of a reference matrix of same dimensions.
|
| 121 |
+
*
|
| 122 |
+
* \sa isApprox(), isMuchSmallerThan(const DenseBase<OtherDerived>&, RealScalar) const
|
| 123 |
+
*/
|
| 124 |
+
template<typename Derived>
|
| 125 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(
|
| 126 |
+
const typename NumTraits<Scalar>::Real& other,
|
| 127 |
+
const RealScalar& prec
|
| 128 |
+
) const
|
| 129 |
+
{
|
| 130 |
+
return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/** \returns \c true if the norm of \c *this is much smaller than the norm of \a other,
|
| 134 |
+
* within the precision determined by \a prec.
|
| 135 |
+
*
|
| 136 |
+
* \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is
|
| 137 |
+
* considered to be much smaller than a vector \f$ w \f$ within precision \f$ p \f$ if
|
| 138 |
+
* \f[ \Vert v \Vert \leqslant p\,\Vert w\Vert. \f]
|
| 139 |
+
* For matrices, the comparison is done using the Hilbert-Schmidt norm.
|
| 140 |
+
*
|
| 141 |
+
* \sa isApprox(), isMuchSmallerThan(const RealScalar&, RealScalar) const
|
| 142 |
+
*/
|
| 143 |
+
template<typename Derived>
|
| 144 |
+
template<typename OtherDerived>
|
| 145 |
+
EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(
|
| 146 |
+
const DenseBase<OtherDerived>& other,
|
| 147 |
+
const RealScalar& prec
|
| 148 |
+
) const
|
| 149 |
+
{
|
| 150 |
+
return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
} // end namespace Eigen
|
| 154 |
+
|
| 155 |
+
#endif // EIGEN_FUZZY_H
|
include/eigen/Eigen/src/Core/GeneralProduct.h
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_GENERAL_PRODUCT_H
|
| 12 |
+
#define EIGEN_GENERAL_PRODUCT_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
enum {
|
| 17 |
+
Large = 2,
|
| 18 |
+
Small = 3
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
// Define the threshold value to fallback from the generic matrix-matrix product
|
| 22 |
+
// implementation (heavy) to the lightweight coeff-based product one.
|
| 23 |
+
// See generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct>
|
| 24 |
+
// in products/GeneralMatrixMatrix.h for more details.
|
| 25 |
+
// TODO This threshold should also be used in the compile-time selector below.
|
| 26 |
+
#ifndef EIGEN_GEMM_TO_COEFFBASED_THRESHOLD
|
| 27 |
+
// This default value has been obtained on a Haswell architecture.
|
| 28 |
+
#define EIGEN_GEMM_TO_COEFFBASED_THRESHOLD 20
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
namespace internal {
|
| 32 |
+
|
| 33 |
+
template<int Rows, int Cols, int Depth> struct product_type_selector;
|
| 34 |
+
|
| 35 |
+
template<int Size, int MaxSize> struct product_size_category
|
| 36 |
+
{
|
| 37 |
+
enum {
|
| 38 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 39 |
+
is_large = MaxSize == Dynamic ||
|
| 40 |
+
Size >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ||
|
| 41 |
+
(Size==Dynamic && MaxSize>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD),
|
| 42 |
+
#else
|
| 43 |
+
is_large = 0,
|
| 44 |
+
#endif
|
| 45 |
+
value = is_large ? Large
|
| 46 |
+
: Size == 1 ? 1
|
| 47 |
+
: Small
|
| 48 |
+
};
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
template<typename Lhs, typename Rhs> struct product_type
|
| 52 |
+
{
|
| 53 |
+
typedef typename remove_all<Lhs>::type _Lhs;
|
| 54 |
+
typedef typename remove_all<Rhs>::type _Rhs;
|
| 55 |
+
enum {
|
| 56 |
+
MaxRows = traits<_Lhs>::MaxRowsAtCompileTime,
|
| 57 |
+
Rows = traits<_Lhs>::RowsAtCompileTime,
|
| 58 |
+
MaxCols = traits<_Rhs>::MaxColsAtCompileTime,
|
| 59 |
+
Cols = traits<_Rhs>::ColsAtCompileTime,
|
| 60 |
+
MaxDepth = EIGEN_SIZE_MIN_PREFER_FIXED(traits<_Lhs>::MaxColsAtCompileTime,
|
| 61 |
+
traits<_Rhs>::MaxRowsAtCompileTime),
|
| 62 |
+
Depth = EIGEN_SIZE_MIN_PREFER_FIXED(traits<_Lhs>::ColsAtCompileTime,
|
| 63 |
+
traits<_Rhs>::RowsAtCompileTime)
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
// the splitting into different lines of code here, introducing the _select enums and the typedef below,
|
| 67 |
+
// is to work around an internal compiler error with gcc 4.1 and 4.2.
|
| 68 |
+
private:
|
| 69 |
+
enum {
|
| 70 |
+
rows_select = product_size_category<Rows,MaxRows>::value,
|
| 71 |
+
cols_select = product_size_category<Cols,MaxCols>::value,
|
| 72 |
+
depth_select = product_size_category<Depth,MaxDepth>::value
|
| 73 |
+
};
|
| 74 |
+
typedef product_type_selector<rows_select, cols_select, depth_select> selector;
|
| 75 |
+
|
| 76 |
+
public:
|
| 77 |
+
enum {
|
| 78 |
+
value = selector::ret,
|
| 79 |
+
ret = selector::ret
|
| 80 |
+
};
|
| 81 |
+
#ifdef EIGEN_DEBUG_PRODUCT
|
| 82 |
+
static void debug()
|
| 83 |
+
{
|
| 84 |
+
EIGEN_DEBUG_VAR(Rows);
|
| 85 |
+
EIGEN_DEBUG_VAR(Cols);
|
| 86 |
+
EIGEN_DEBUG_VAR(Depth);
|
| 87 |
+
EIGEN_DEBUG_VAR(rows_select);
|
| 88 |
+
EIGEN_DEBUG_VAR(cols_select);
|
| 89 |
+
EIGEN_DEBUG_VAR(depth_select);
|
| 90 |
+
EIGEN_DEBUG_VAR(value);
|
| 91 |
+
}
|
| 92 |
+
#endif
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
/* The following allows to select the kind of product at compile time
|
| 96 |
+
* based on the three dimensions of the product.
|
| 97 |
+
* This is a compile time mapping from {1,Small,Large}^3 -> {product types} */
|
| 98 |
+
// FIXME I'm not sure the current mapping is the ideal one.
|
| 99 |
+
template<int M, int N> struct product_type_selector<M,N,1> { enum { ret = OuterProduct }; };
|
| 100 |
+
template<int M> struct product_type_selector<M, 1, 1> { enum { ret = LazyCoeffBasedProductMode }; };
|
| 101 |
+
template<int N> struct product_type_selector<1, N, 1> { enum { ret = LazyCoeffBasedProductMode }; };
|
| 102 |
+
template<int Depth> struct product_type_selector<1, 1, Depth> { enum { ret = InnerProduct }; };
|
| 103 |
+
template<> struct product_type_selector<1, 1, 1> { enum { ret = InnerProduct }; };
|
| 104 |
+
template<> struct product_type_selector<Small,1, Small> { enum { ret = CoeffBasedProductMode }; };
|
| 105 |
+
template<> struct product_type_selector<1, Small,Small> { enum { ret = CoeffBasedProductMode }; };
|
| 106 |
+
template<> struct product_type_selector<Small,Small,Small> { enum { ret = CoeffBasedProductMode }; };
|
| 107 |
+
template<> struct product_type_selector<Small, Small, 1> { enum { ret = LazyCoeffBasedProductMode }; };
|
| 108 |
+
template<> struct product_type_selector<Small, Large, 1> { enum { ret = LazyCoeffBasedProductMode }; };
|
| 109 |
+
template<> struct product_type_selector<Large, Small, 1> { enum { ret = LazyCoeffBasedProductMode }; };
|
| 110 |
+
template<> struct product_type_selector<1, Large,Small> { enum { ret = CoeffBasedProductMode }; };
|
| 111 |
+
template<> struct product_type_selector<1, Large,Large> { enum { ret = GemvProduct }; };
|
| 112 |
+
template<> struct product_type_selector<1, Small,Large> { enum { ret = CoeffBasedProductMode }; };
|
| 113 |
+
template<> struct product_type_selector<Large,1, Small> { enum { ret = CoeffBasedProductMode }; };
|
| 114 |
+
template<> struct product_type_selector<Large,1, Large> { enum { ret = GemvProduct }; };
|
| 115 |
+
template<> struct product_type_selector<Small,1, Large> { enum { ret = CoeffBasedProductMode }; };
|
| 116 |
+
template<> struct product_type_selector<Small,Small,Large> { enum { ret = GemmProduct }; };
|
| 117 |
+
template<> struct product_type_selector<Large,Small,Large> { enum { ret = GemmProduct }; };
|
| 118 |
+
template<> struct product_type_selector<Small,Large,Large> { enum { ret = GemmProduct }; };
|
| 119 |
+
template<> struct product_type_selector<Large,Large,Large> { enum { ret = GemmProduct }; };
|
| 120 |
+
template<> struct product_type_selector<Large,Small,Small> { enum { ret = CoeffBasedProductMode }; };
|
| 121 |
+
template<> struct product_type_selector<Small,Large,Small> { enum { ret = CoeffBasedProductMode }; };
|
| 122 |
+
template<> struct product_type_selector<Large,Large,Small> { enum { ret = GemmProduct }; };
|
| 123 |
+
|
| 124 |
+
} // end namespace internal
|
| 125 |
+
|
| 126 |
+
/***********************************************************************
|
| 127 |
+
* Implementation of Inner Vector Vector Product
|
| 128 |
+
***********************************************************************/
|
| 129 |
+
|
| 130 |
+
// FIXME : maybe the "inner product" could return a Scalar
|
| 131 |
+
// instead of a 1x1 matrix ??
|
| 132 |
+
// Pro: more natural for the user
|
| 133 |
+
// Cons: this could be a problem if in a meta unrolled algorithm a matrix-matrix
|
| 134 |
+
// product ends up to a row-vector times col-vector product... To tackle this use
|
| 135 |
+
// case, we could have a specialization for Block<MatrixType,1,1> with: operator=(Scalar x);
|
| 136 |
+
|
| 137 |
+
/***********************************************************************
|
| 138 |
+
* Implementation of Outer Vector Vector Product
|
| 139 |
+
***********************************************************************/
|
| 140 |
+
|
| 141 |
+
/***********************************************************************
|
| 142 |
+
* Implementation of General Matrix Vector Product
|
| 143 |
+
***********************************************************************/
|
| 144 |
+
|
| 145 |
+
/* According to the shape/flags of the matrix we have to distinghish 3 different cases:
|
| 146 |
+
* 1 - the matrix is col-major, BLAS compatible and M is large => call fast BLAS-like colmajor routine
|
| 147 |
+
* 2 - the matrix is row-major, BLAS compatible and N is large => call fast BLAS-like rowmajor routine
|
| 148 |
+
* 3 - all other cases are handled using a simple loop along the outer-storage direction.
|
| 149 |
+
* Therefore we need a lower level meta selector.
|
| 150 |
+
* Furthermore, if the matrix is the rhs, then the product has to be transposed.
|
| 151 |
+
*/
|
| 152 |
+
namespace internal {
|
| 153 |
+
|
| 154 |
+
template<int Side, int StorageOrder, bool BlasCompatible>
|
| 155 |
+
struct gemv_dense_selector;
|
| 156 |
+
|
| 157 |
+
} // end namespace internal
|
| 158 |
+
|
| 159 |
+
namespace internal {
|
| 160 |
+
|
| 161 |
+
template<typename Scalar,int Size,int MaxSize,bool Cond> struct gemv_static_vector_if;
|
| 162 |
+
|
| 163 |
+
template<typename Scalar,int Size,int MaxSize>
|
| 164 |
+
struct gemv_static_vector_if<Scalar,Size,MaxSize,false>
|
| 165 |
+
{
|
| 166 |
+
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { eigen_internal_assert(false && "should never be called"); return 0; }
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
template<typename Scalar,int Size>
|
| 170 |
+
struct gemv_static_vector_if<Scalar,Size,Dynamic,true>
|
| 171 |
+
{
|
| 172 |
+
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { return 0; }
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
template<typename Scalar,int Size,int MaxSize>
|
| 176 |
+
struct gemv_static_vector_if<Scalar,Size,MaxSize,true>
|
| 177 |
+
{
|
| 178 |
+
enum {
|
| 179 |
+
ForceAlignment = internal::packet_traits<Scalar>::Vectorizable,
|
| 180 |
+
PacketSize = internal::packet_traits<Scalar>::size
|
| 181 |
+
};
|
| 182 |
+
#if EIGEN_MAX_STATIC_ALIGN_BYTES!=0
|
| 183 |
+
internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize),0,EIGEN_PLAIN_ENUM_MIN(AlignedMax,PacketSize)> m_data;
|
| 184 |
+
EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; }
|
| 185 |
+
#else
|
| 186 |
+
// Some architectures cannot align on the stack,
|
| 187 |
+
// => let's manually enforce alignment by allocating more data and return the address of the first aligned element.
|
| 188 |
+
internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize)+(ForceAlignment?EIGEN_MAX_ALIGN_BYTES:0),0> m_data;
|
| 189 |
+
EIGEN_STRONG_INLINE Scalar* data() {
|
| 190 |
+
return ForceAlignment
|
| 191 |
+
? reinterpret_cast<Scalar*>((internal::UIntPtr(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES-1))) + EIGEN_MAX_ALIGN_BYTES)
|
| 192 |
+
: m_data.array;
|
| 193 |
+
}
|
| 194 |
+
#endif
|
| 195 |
+
};
|
| 196 |
+
|
| 197 |
+
// The vector is on the left => transposition
|
| 198 |
+
template<int StorageOrder, bool BlasCompatible>
|
| 199 |
+
struct gemv_dense_selector<OnTheLeft,StorageOrder,BlasCompatible>
|
| 200 |
+
{
|
| 201 |
+
template<typename Lhs, typename Rhs, typename Dest>
|
| 202 |
+
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
|
| 203 |
+
{
|
| 204 |
+
Transpose<Dest> destT(dest);
|
| 205 |
+
enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor };
|
| 206 |
+
gemv_dense_selector<OnTheRight,OtherStorageOrder,BlasCompatible>
|
| 207 |
+
::run(rhs.transpose(), lhs.transpose(), destT, alpha);
|
| 208 |
+
}
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
template<> struct gemv_dense_selector<OnTheRight,ColMajor,true>
|
| 212 |
+
{
|
| 213 |
+
template<typename Lhs, typename Rhs, typename Dest>
|
| 214 |
+
static inline void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
|
| 215 |
+
{
|
| 216 |
+
typedef typename Lhs::Scalar LhsScalar;
|
| 217 |
+
typedef typename Rhs::Scalar RhsScalar;
|
| 218 |
+
typedef typename Dest::Scalar ResScalar;
|
| 219 |
+
typedef typename Dest::RealScalar RealScalar;
|
| 220 |
+
|
| 221 |
+
typedef internal::blas_traits<Lhs> LhsBlasTraits;
|
| 222 |
+
typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
|
| 223 |
+
typedef internal::blas_traits<Rhs> RhsBlasTraits;
|
| 224 |
+
typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
|
| 225 |
+
|
| 226 |
+
typedef Map<Matrix<ResScalar,Dynamic,1>, EIGEN_PLAIN_ENUM_MIN(AlignedMax,internal::packet_traits<ResScalar>::size)> MappedDest;
|
| 227 |
+
|
| 228 |
+
ActualLhsType actualLhs = LhsBlasTraits::extract(lhs);
|
| 229 |
+
ActualRhsType actualRhs = RhsBlasTraits::extract(rhs);
|
| 230 |
+
|
| 231 |
+
ResScalar actualAlpha = combine_scalar_factors(alpha, lhs, rhs);
|
| 232 |
+
|
| 233 |
+
// make sure Dest is a compile-time vector type (bug 1166)
|
| 234 |
+
typedef typename conditional<Dest::IsVectorAtCompileTime, Dest, typename Dest::ColXpr>::type ActualDest;
|
| 235 |
+
|
| 236 |
+
enum {
|
| 237 |
+
// FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1
|
| 238 |
+
// on, the other hand it is good for the cache to pack the vector anyways...
|
| 239 |
+
EvalToDestAtCompileTime = (ActualDest::InnerStrideAtCompileTime==1),
|
| 240 |
+
ComplexByReal = (NumTraits<LhsScalar>::IsComplex) && (!NumTraits<RhsScalar>::IsComplex),
|
| 241 |
+
MightCannotUseDest = ((!EvalToDestAtCompileTime) || ComplexByReal) && (ActualDest::MaxSizeAtCompileTime!=0)
|
| 242 |
+
};
|
| 243 |
+
|
| 244 |
+
typedef const_blas_data_mapper<LhsScalar,Index,ColMajor> LhsMapper;
|
| 245 |
+
typedef const_blas_data_mapper<RhsScalar,Index,RowMajor> RhsMapper;
|
| 246 |
+
RhsScalar compatibleAlpha = get_factor<ResScalar,RhsScalar>::run(actualAlpha);
|
| 247 |
+
|
| 248 |
+
if(!MightCannotUseDest)
|
| 249 |
+
{
|
| 250 |
+
// shortcut if we are sure to be able to use dest directly,
|
| 251 |
+
// this ease the compiler to generate cleaner and more optimzized code for most common cases
|
| 252 |
+
general_matrix_vector_product
|
| 253 |
+
<Index,LhsScalar,LhsMapper,ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run(
|
| 254 |
+
actualLhs.rows(), actualLhs.cols(),
|
| 255 |
+
LhsMapper(actualLhs.data(), actualLhs.outerStride()),
|
| 256 |
+
RhsMapper(actualRhs.data(), actualRhs.innerStride()),
|
| 257 |
+
dest.data(), 1,
|
| 258 |
+
compatibleAlpha);
|
| 259 |
+
}
|
| 260 |
+
else
|
| 261 |
+
{
|
| 262 |
+
gemv_static_vector_if<ResScalar,ActualDest::SizeAtCompileTime,ActualDest::MaxSizeAtCompileTime,MightCannotUseDest> static_dest;
|
| 263 |
+
|
| 264 |
+
const bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0));
|
| 265 |
+
const bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible;
|
| 266 |
+
|
| 267 |
+
ei_declare_aligned_stack_constructed_variable(ResScalar,actualDestPtr,dest.size(),
|
| 268 |
+
evalToDest ? dest.data() : static_dest.data());
|
| 269 |
+
|
| 270 |
+
if(!evalToDest)
|
| 271 |
+
{
|
| 272 |
+
#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
| 273 |
+
Index size = dest.size();
|
| 274 |
+
EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
| 275 |
+
#endif
|
| 276 |
+
if(!alphaIsCompatible)
|
| 277 |
+
{
|
| 278 |
+
MappedDest(actualDestPtr, dest.size()).setZero();
|
| 279 |
+
compatibleAlpha = RhsScalar(1);
|
| 280 |
+
}
|
| 281 |
+
else
|
| 282 |
+
MappedDest(actualDestPtr, dest.size()) = dest;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
general_matrix_vector_product
|
| 286 |
+
<Index,LhsScalar,LhsMapper,ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run(
|
| 287 |
+
actualLhs.rows(), actualLhs.cols(),
|
| 288 |
+
LhsMapper(actualLhs.data(), actualLhs.outerStride()),
|
| 289 |
+
RhsMapper(actualRhs.data(), actualRhs.innerStride()),
|
| 290 |
+
actualDestPtr, 1,
|
| 291 |
+
compatibleAlpha);
|
| 292 |
+
|
| 293 |
+
if (!evalToDest)
|
| 294 |
+
{
|
| 295 |
+
if(!alphaIsCompatible)
|
| 296 |
+
dest.matrix() += actualAlpha * MappedDest(actualDestPtr, dest.size());
|
| 297 |
+
else
|
| 298 |
+
dest = MappedDest(actualDestPtr, dest.size());
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
};
|
| 303 |
+
|
| 304 |
+
template<> struct gemv_dense_selector<OnTheRight,RowMajor,true>
|
| 305 |
+
{
|
| 306 |
+
template<typename Lhs, typename Rhs, typename Dest>
|
| 307 |
+
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
|
| 308 |
+
{
|
| 309 |
+
typedef typename Lhs::Scalar LhsScalar;
|
| 310 |
+
typedef typename Rhs::Scalar RhsScalar;
|
| 311 |
+
typedef typename Dest::Scalar ResScalar;
|
| 312 |
+
|
| 313 |
+
typedef internal::blas_traits<Lhs> LhsBlasTraits;
|
| 314 |
+
typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
|
| 315 |
+
typedef internal::blas_traits<Rhs> RhsBlasTraits;
|
| 316 |
+
typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
|
| 317 |
+
typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
|
| 318 |
+
|
| 319 |
+
typename add_const<ActualLhsType>::type actualLhs = LhsBlasTraits::extract(lhs);
|
| 320 |
+
typename add_const<ActualRhsType>::type actualRhs = RhsBlasTraits::extract(rhs);
|
| 321 |
+
|
| 322 |
+
ResScalar actualAlpha = combine_scalar_factors(alpha, lhs, rhs);
|
| 323 |
+
|
| 324 |
+
enum {
|
| 325 |
+
// FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1
|
| 326 |
+
// on, the other hand it is good for the cache to pack the vector anyways...
|
| 327 |
+
DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime==1 || ActualRhsTypeCleaned::MaxSizeAtCompileTime==0
|
| 328 |
+
};
|
| 329 |
+
|
| 330 |
+
gemv_static_vector_if<RhsScalar,ActualRhsTypeCleaned::SizeAtCompileTime,ActualRhsTypeCleaned::MaxSizeAtCompileTime,!DirectlyUseRhs> static_rhs;
|
| 331 |
+
|
| 332 |
+
ei_declare_aligned_stack_constructed_variable(RhsScalar,actualRhsPtr,actualRhs.size(),
|
| 333 |
+
DirectlyUseRhs ? const_cast<RhsScalar*>(actualRhs.data()) : static_rhs.data());
|
| 334 |
+
|
| 335 |
+
if(!DirectlyUseRhs)
|
| 336 |
+
{
|
| 337 |
+
#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
| 338 |
+
Index size = actualRhs.size();
|
| 339 |
+
EIGEN_DENSE_STORAGE_CTOR_PLUGIN
|
| 340 |
+
#endif
|
| 341 |
+
Map<typename ActualRhsTypeCleaned::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper;
|
| 345 |
+
typedef const_blas_data_mapper<RhsScalar,Index,ColMajor> RhsMapper;
|
| 346 |
+
general_matrix_vector_product
|
| 347 |
+
<Index,LhsScalar,LhsMapper,RowMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsMapper,RhsBlasTraits::NeedToConjugate>::run(
|
| 348 |
+
actualLhs.rows(), actualLhs.cols(),
|
| 349 |
+
LhsMapper(actualLhs.data(), actualLhs.outerStride()),
|
| 350 |
+
RhsMapper(actualRhsPtr, 1),
|
| 351 |
+
dest.data(), dest.col(0).innerStride(), //NOTE if dest is not a vector at compile-time, then dest.innerStride() might be wrong. (bug 1166)
|
| 352 |
+
actualAlpha);
|
| 353 |
+
}
|
| 354 |
+
};
|
| 355 |
+
|
| 356 |
+
template<> struct gemv_dense_selector<OnTheRight,ColMajor,false>
|
| 357 |
+
{
|
| 358 |
+
template<typename Lhs, typename Rhs, typename Dest>
|
| 359 |
+
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
|
| 360 |
+
{
|
| 361 |
+
EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE);
|
| 362 |
+
// TODO if rhs is large enough it might be beneficial to make sure that dest is sequentially stored in memory, otherwise use a temp
|
| 363 |
+
typename nested_eval<Rhs,1>::type actual_rhs(rhs);
|
| 364 |
+
const Index size = rhs.rows();
|
| 365 |
+
for(Index k=0; k<size; ++k)
|
| 366 |
+
dest += (alpha*actual_rhs.coeff(k)) * lhs.col(k);
|
| 367 |
+
}
|
| 368 |
+
};
|
| 369 |
+
|
| 370 |
+
template<> struct gemv_dense_selector<OnTheRight,RowMajor,false>
|
| 371 |
+
{
|
| 372 |
+
template<typename Lhs, typename Rhs, typename Dest>
|
| 373 |
+
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
|
| 374 |
+
{
|
| 375 |
+
EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE);
|
| 376 |
+
typename nested_eval<Rhs,Lhs::RowsAtCompileTime>::type actual_rhs(rhs);
|
| 377 |
+
const Index rows = dest.rows();
|
| 378 |
+
for(Index i=0; i<rows; ++i)
|
| 379 |
+
dest.coeffRef(i) += alpha * (lhs.row(i).cwiseProduct(actual_rhs.transpose())).sum();
|
| 380 |
+
}
|
| 381 |
+
};
|
| 382 |
+
|
| 383 |
+
} // end namespace internal
|
| 384 |
+
|
| 385 |
+
/***************************************************************************
|
| 386 |
+
* Implementation of matrix base methods
|
| 387 |
+
***************************************************************************/
|
| 388 |
+
|
| 389 |
+
/** \returns the matrix product of \c *this and \a other.
|
| 390 |
+
*
|
| 391 |
+
* \note If instead of the matrix product you want the coefficient-wise product, see Cwise::operator*().
|
| 392 |
+
*
|
| 393 |
+
* \sa lazyProduct(), operator*=(const MatrixBase&), Cwise::operator*()
|
| 394 |
+
*/
|
| 395 |
+
template<typename Derived>
|
| 396 |
+
template<typename OtherDerived>
|
| 397 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 398 |
+
const Product<Derived, OtherDerived>
|
| 399 |
+
MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
|
| 400 |
+
{
|
| 401 |
+
// A note regarding the function declaration: In MSVC, this function will sometimes
|
| 402 |
+
// not be inlined since DenseStorage is an unwindable object for dynamic
|
| 403 |
+
// matrices and product types are holding a member to store the result.
|
| 404 |
+
// Thus it does not help tagging this function with EIGEN_STRONG_INLINE.
|
| 405 |
+
enum {
|
| 406 |
+
ProductIsValid = Derived::ColsAtCompileTime==Dynamic
|
| 407 |
+
|| OtherDerived::RowsAtCompileTime==Dynamic
|
| 408 |
+
|| int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
|
| 409 |
+
AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
|
| 410 |
+
SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived)
|
| 411 |
+
};
|
| 412 |
+
// note to the lost user:
|
| 413 |
+
// * for a dot product use: v1.dot(v2)
|
| 414 |
+
// * for a coeff-wise product use: v1.cwiseProduct(v2)
|
| 415 |
+
EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
|
| 416 |
+
INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
|
| 417 |
+
EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
|
| 418 |
+
INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
|
| 419 |
+
EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
|
| 420 |
+
#ifdef EIGEN_DEBUG_PRODUCT
|
| 421 |
+
internal::product_type<Derived,OtherDerived>::debug();
|
| 422 |
+
#endif
|
| 423 |
+
|
| 424 |
+
return Product<Derived, OtherDerived>(derived(), other.derived());
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/** \returns an expression of the matrix product of \c *this and \a other without implicit evaluation.
|
| 428 |
+
*
|
| 429 |
+
* The returned product will behave like any other expressions: the coefficients of the product will be
|
| 430 |
+
* computed once at a time as requested. This might be useful in some extremely rare cases when only
|
| 431 |
+
* a small and no coherent fraction of the result's coefficients have to be computed.
|
| 432 |
+
*
|
| 433 |
+
* \warning This version of the matrix product can be much much slower. So use it only if you know
|
| 434 |
+
* what you are doing and that you measured a true speed improvement.
|
| 435 |
+
*
|
| 436 |
+
* \sa operator*(const MatrixBase&)
|
| 437 |
+
*/
|
| 438 |
+
template<typename Derived>
|
| 439 |
+
template<typename OtherDerived>
|
| 440 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 441 |
+
const Product<Derived,OtherDerived,LazyProduct>
|
| 442 |
+
MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const
|
| 443 |
+
{
|
| 444 |
+
enum {
|
| 445 |
+
ProductIsValid = Derived::ColsAtCompileTime==Dynamic
|
| 446 |
+
|| OtherDerived::RowsAtCompileTime==Dynamic
|
| 447 |
+
|| int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
|
| 448 |
+
AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
|
| 449 |
+
SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived)
|
| 450 |
+
};
|
| 451 |
+
// note to the lost user:
|
| 452 |
+
// * for a dot product use: v1.dot(v2)
|
| 453 |
+
// * for a coeff-wise product use: v1.cwiseProduct(v2)
|
| 454 |
+
EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
|
| 455 |
+
INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
|
| 456 |
+
EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
|
| 457 |
+
INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
|
| 458 |
+
EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
|
| 459 |
+
|
| 460 |
+
return Product<Derived,OtherDerived,LazyProduct>(derived(), other.derived());
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
} // end namespace Eigen
|
| 464 |
+
|
| 465 |
+
#endif // EIGEN_PRODUCT_H
|
include/eigen/Eigen/src/Core/GenericPacketMath.h
ADDED
|
@@ -0,0 +1,1040 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_GENERIC_PACKET_MATH_H
|
| 12 |
+
#define EIGEN_GENERIC_PACKET_MATH_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
|
| 18 |
+
/** \internal
|
| 19 |
+
* \file GenericPacketMath.h
|
| 20 |
+
*
|
| 21 |
+
* Default implementation for types not supported by the vectorization.
|
| 22 |
+
* In practice these functions are provided to make easier the writing
|
| 23 |
+
* of generic vectorized code.
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#ifndef EIGEN_DEBUG_ALIGNED_LOAD
|
| 27 |
+
#define EIGEN_DEBUG_ALIGNED_LOAD
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
#ifndef EIGEN_DEBUG_UNALIGNED_LOAD
|
| 31 |
+
#define EIGEN_DEBUG_UNALIGNED_LOAD
|
| 32 |
+
#endif
|
| 33 |
+
|
| 34 |
+
#ifndef EIGEN_DEBUG_ALIGNED_STORE
|
| 35 |
+
#define EIGEN_DEBUG_ALIGNED_STORE
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
#ifndef EIGEN_DEBUG_UNALIGNED_STORE
|
| 39 |
+
#define EIGEN_DEBUG_UNALIGNED_STORE
|
| 40 |
+
#endif
|
| 41 |
+
|
| 42 |
+
struct default_packet_traits
|
| 43 |
+
{
|
| 44 |
+
enum {
|
| 45 |
+
HasHalfPacket = 0,
|
| 46 |
+
|
| 47 |
+
HasAdd = 1,
|
| 48 |
+
HasSub = 1,
|
| 49 |
+
HasShift = 1,
|
| 50 |
+
HasMul = 1,
|
| 51 |
+
HasNegate = 1,
|
| 52 |
+
HasAbs = 1,
|
| 53 |
+
HasArg = 0,
|
| 54 |
+
HasAbs2 = 1,
|
| 55 |
+
HasAbsDiff = 0,
|
| 56 |
+
HasMin = 1,
|
| 57 |
+
HasMax = 1,
|
| 58 |
+
HasConj = 1,
|
| 59 |
+
HasSetLinear = 1,
|
| 60 |
+
HasBlend = 0,
|
| 61 |
+
// This flag is used to indicate whether packet comparison is supported.
|
| 62 |
+
// pcmp_eq, pcmp_lt and pcmp_le should be defined for it to be true.
|
| 63 |
+
HasCmp = 0,
|
| 64 |
+
|
| 65 |
+
HasDiv = 0,
|
| 66 |
+
HasSqrt = 0,
|
| 67 |
+
HasRsqrt = 0,
|
| 68 |
+
HasExp = 0,
|
| 69 |
+
HasExpm1 = 0,
|
| 70 |
+
HasLog = 0,
|
| 71 |
+
HasLog1p = 0,
|
| 72 |
+
HasLog10 = 0,
|
| 73 |
+
HasPow = 0,
|
| 74 |
+
|
| 75 |
+
HasSin = 0,
|
| 76 |
+
HasCos = 0,
|
| 77 |
+
HasTan = 0,
|
| 78 |
+
HasASin = 0,
|
| 79 |
+
HasACos = 0,
|
| 80 |
+
HasATan = 0,
|
| 81 |
+
HasSinh = 0,
|
| 82 |
+
HasCosh = 0,
|
| 83 |
+
HasTanh = 0,
|
| 84 |
+
HasLGamma = 0,
|
| 85 |
+
HasDiGamma = 0,
|
| 86 |
+
HasZeta = 0,
|
| 87 |
+
HasPolygamma = 0,
|
| 88 |
+
HasErf = 0,
|
| 89 |
+
HasErfc = 0,
|
| 90 |
+
HasNdtri = 0,
|
| 91 |
+
HasBessel = 0,
|
| 92 |
+
HasIGamma = 0,
|
| 93 |
+
HasIGammaDerA = 0,
|
| 94 |
+
HasGammaSampleDerAlpha = 0,
|
| 95 |
+
HasIGammac = 0,
|
| 96 |
+
HasBetaInc = 0,
|
| 97 |
+
|
| 98 |
+
HasRound = 0,
|
| 99 |
+
HasRint = 0,
|
| 100 |
+
HasFloor = 0,
|
| 101 |
+
HasCeil = 0,
|
| 102 |
+
HasSign = 0
|
| 103 |
+
};
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
template<typename T> struct packet_traits : default_packet_traits
|
| 107 |
+
{
|
| 108 |
+
typedef T type;
|
| 109 |
+
typedef T half;
|
| 110 |
+
enum {
|
| 111 |
+
Vectorizable = 0,
|
| 112 |
+
size = 1,
|
| 113 |
+
AlignedOnScalar = 0,
|
| 114 |
+
HasHalfPacket = 0
|
| 115 |
+
};
|
| 116 |
+
enum {
|
| 117 |
+
HasAdd = 0,
|
| 118 |
+
HasSub = 0,
|
| 119 |
+
HasMul = 0,
|
| 120 |
+
HasNegate = 0,
|
| 121 |
+
HasAbs = 0,
|
| 122 |
+
HasAbs2 = 0,
|
| 123 |
+
HasMin = 0,
|
| 124 |
+
HasMax = 0,
|
| 125 |
+
HasConj = 0,
|
| 126 |
+
HasSetLinear = 0
|
| 127 |
+
};
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
template<typename T> struct packet_traits<const T> : packet_traits<T> { };
|
| 131 |
+
|
| 132 |
+
template<typename T> struct unpacket_traits
|
| 133 |
+
{
|
| 134 |
+
typedef T type;
|
| 135 |
+
typedef T half;
|
| 136 |
+
enum
|
| 137 |
+
{
|
| 138 |
+
size = 1,
|
| 139 |
+
alignment = 1,
|
| 140 |
+
vectorizable = false,
|
| 141 |
+
masked_load_available=false,
|
| 142 |
+
masked_store_available=false
|
| 143 |
+
};
|
| 144 |
+
};
|
| 145 |
+
|
| 146 |
+
template<typename T> struct unpacket_traits<const T> : unpacket_traits<T> { };
|
| 147 |
+
|
| 148 |
+
template <typename Src, typename Tgt> struct type_casting_traits {
|
| 149 |
+
enum {
|
| 150 |
+
VectorizedCast = 0,
|
| 151 |
+
SrcCoeffRatio = 1,
|
| 152 |
+
TgtCoeffRatio = 1
|
| 153 |
+
};
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
/** \internal Wrapper to ensure that multiple packet types can map to the same
|
| 157 |
+
same underlying vector type. */
|
| 158 |
+
template<typename T, int unique_id = 0>
|
| 159 |
+
struct eigen_packet_wrapper
|
| 160 |
+
{
|
| 161 |
+
EIGEN_ALWAYS_INLINE operator T&() { return m_val; }
|
| 162 |
+
EIGEN_ALWAYS_INLINE operator const T&() const { return m_val; }
|
| 163 |
+
EIGEN_ALWAYS_INLINE eigen_packet_wrapper() {};
|
| 164 |
+
EIGEN_ALWAYS_INLINE eigen_packet_wrapper(const T &v) : m_val(v) {}
|
| 165 |
+
EIGEN_ALWAYS_INLINE eigen_packet_wrapper& operator=(const T &v) {
|
| 166 |
+
m_val = v;
|
| 167 |
+
return *this;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
T m_val;
|
| 171 |
+
};
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
/** \internal A convenience utility for determining if the type is a scalar.
|
| 175 |
+
* This is used to enable some generic packet implementations.
|
| 176 |
+
*/
|
| 177 |
+
template<typename Packet>
|
| 178 |
+
struct is_scalar {
|
| 179 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 180 |
+
enum {
|
| 181 |
+
value = internal::is_same<Packet, Scalar>::value
|
| 182 |
+
};
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
/** \internal \returns static_cast<TgtType>(a) (coeff-wise) */
|
| 186 |
+
template <typename SrcPacket, typename TgtPacket>
|
| 187 |
+
EIGEN_DEVICE_FUNC inline TgtPacket
|
| 188 |
+
pcast(const SrcPacket& a) {
|
| 189 |
+
return static_cast<TgtPacket>(a);
|
| 190 |
+
}
|
| 191 |
+
template <typename SrcPacket, typename TgtPacket>
|
| 192 |
+
EIGEN_DEVICE_FUNC inline TgtPacket
|
| 193 |
+
pcast(const SrcPacket& a, const SrcPacket& /*b*/) {
|
| 194 |
+
return static_cast<TgtPacket>(a);
|
| 195 |
+
}
|
| 196 |
+
template <typename SrcPacket, typename TgtPacket>
|
| 197 |
+
EIGEN_DEVICE_FUNC inline TgtPacket
|
| 198 |
+
pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/) {
|
| 199 |
+
return static_cast<TgtPacket>(a);
|
| 200 |
+
}
|
| 201 |
+
template <typename SrcPacket, typename TgtPacket>
|
| 202 |
+
EIGEN_DEVICE_FUNC inline TgtPacket
|
| 203 |
+
pcast(const SrcPacket& a, const SrcPacket& /*b*/, const SrcPacket& /*c*/, const SrcPacket& /*d*/,
|
| 204 |
+
const SrcPacket& /*e*/, const SrcPacket& /*f*/, const SrcPacket& /*g*/, const SrcPacket& /*h*/) {
|
| 205 |
+
return static_cast<TgtPacket>(a);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/** \internal \returns reinterpret_cast<Target>(a) */
|
| 209 |
+
template <typename Target, typename Packet>
|
| 210 |
+
EIGEN_DEVICE_FUNC inline Target
|
| 211 |
+
preinterpret(const Packet& a); /* { return reinterpret_cast<const Target&>(a); } */
|
| 212 |
+
|
| 213 |
+
/** \internal \returns a + b (coeff-wise) */
|
| 214 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 215 |
+
padd(const Packet& a, const Packet& b) { return a+b; }
|
| 216 |
+
// Avoid compiler warning for boolean algebra.
|
| 217 |
+
template<> EIGEN_DEVICE_FUNC inline bool
|
| 218 |
+
padd(const bool& a, const bool& b) { return a || b; }
|
| 219 |
+
|
| 220 |
+
/** \internal \returns a - b (coeff-wise) */
|
| 221 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 222 |
+
psub(const Packet& a, const Packet& b) { return a-b; }
|
| 223 |
+
|
| 224 |
+
/** \internal \returns -a (coeff-wise) */
|
| 225 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 226 |
+
pnegate(const Packet& a) { return -a; }
|
| 227 |
+
|
| 228 |
+
template<> EIGEN_DEVICE_FUNC inline bool
|
| 229 |
+
pnegate(const bool& a) { return !a; }
|
| 230 |
+
|
| 231 |
+
/** \internal \returns conj(a) (coeff-wise) */
|
| 232 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 233 |
+
pconj(const Packet& a) { return numext::conj(a); }
|
| 234 |
+
|
| 235 |
+
/** \internal \returns a * b (coeff-wise) */
|
| 236 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 237 |
+
pmul(const Packet& a, const Packet& b) { return a*b; }
|
| 238 |
+
// Avoid compiler warning for boolean algebra.
|
| 239 |
+
template<> EIGEN_DEVICE_FUNC inline bool
|
| 240 |
+
pmul(const bool& a, const bool& b) { return a && b; }
|
| 241 |
+
|
| 242 |
+
/** \internal \returns a / b (coeff-wise) */
|
| 243 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 244 |
+
pdiv(const Packet& a, const Packet& b) { return a/b; }
|
| 245 |
+
|
| 246 |
+
// In the generic case, memset to all one bits.
|
| 247 |
+
template<typename Packet, typename EnableIf = void>
|
| 248 |
+
struct ptrue_impl {
|
| 249 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& /*a*/){
|
| 250 |
+
Packet b;
|
| 251 |
+
memset(static_cast<void*>(&b), 0xff, sizeof(Packet));
|
| 252 |
+
return b;
|
| 253 |
+
}
|
| 254 |
+
};
|
| 255 |
+
|
| 256 |
+
// For non-trivial scalars, set to Scalar(1) (i.e. a non-zero value).
|
| 257 |
+
// Although this is technically not a valid bitmask, the scalar path for pselect
|
| 258 |
+
// uses a comparison to zero, so this should still work in most cases. We don't
|
| 259 |
+
// have another option, since the scalar type requires initialization.
|
| 260 |
+
template<typename T>
|
| 261 |
+
struct ptrue_impl<T,
|
| 262 |
+
typename internal::enable_if<is_scalar<T>::value && NumTraits<T>::RequireInitialization>::type > {
|
| 263 |
+
static EIGEN_DEVICE_FUNC inline T run(const T& /*a*/){
|
| 264 |
+
return T(1);
|
| 265 |
+
}
|
| 266 |
+
};
|
| 267 |
+
|
| 268 |
+
/** \internal \returns one bits. */
|
| 269 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 270 |
+
ptrue(const Packet& a) {
|
| 271 |
+
return ptrue_impl<Packet>::run(a);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// In the general case, memset to zero.
|
| 275 |
+
template<typename Packet, typename EnableIf = void>
|
| 276 |
+
struct pzero_impl {
|
| 277 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& /*a*/) {
|
| 278 |
+
Packet b;
|
| 279 |
+
memset(static_cast<void*>(&b), 0x00, sizeof(Packet));
|
| 280 |
+
return b;
|
| 281 |
+
}
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
// For scalars, explicitly set to Scalar(0), since the underlying representation
|
| 285 |
+
// for zero may not consist of all-zero bits.
|
| 286 |
+
template<typename T>
|
| 287 |
+
struct pzero_impl<T,
|
| 288 |
+
typename internal::enable_if<is_scalar<T>::value>::type> {
|
| 289 |
+
static EIGEN_DEVICE_FUNC inline T run(const T& /*a*/) {
|
| 290 |
+
return T(0);
|
| 291 |
+
}
|
| 292 |
+
};
|
| 293 |
+
|
| 294 |
+
/** \internal \returns packet of zeros */
|
| 295 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 296 |
+
pzero(const Packet& a) {
|
| 297 |
+
return pzero_impl<Packet>::run(a);
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
/** \internal \returns a <= b as a bit mask */
|
| 301 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 302 |
+
pcmp_le(const Packet& a, const Packet& b) { return a<=b ? ptrue(a) : pzero(a); }
|
| 303 |
+
|
| 304 |
+
/** \internal \returns a < b as a bit mask */
|
| 305 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 306 |
+
pcmp_lt(const Packet& a, const Packet& b) { return a<b ? ptrue(a) : pzero(a); }
|
| 307 |
+
|
| 308 |
+
/** \internal \returns a == b as a bit mask */
|
| 309 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 310 |
+
pcmp_eq(const Packet& a, const Packet& b) { return a==b ? ptrue(a) : pzero(a); }
|
| 311 |
+
|
| 312 |
+
/** \internal \returns a < b or a==NaN or b==NaN as a bit mask */
|
| 313 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 314 |
+
pcmp_lt_or_nan(const Packet& a, const Packet& b) { return a>=b ? pzero(a) : ptrue(a); }
|
| 315 |
+
|
| 316 |
+
template<typename T>
|
| 317 |
+
struct bit_and {
|
| 318 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const {
|
| 319 |
+
return a & b;
|
| 320 |
+
}
|
| 321 |
+
};
|
| 322 |
+
|
| 323 |
+
template<typename T>
|
| 324 |
+
struct bit_or {
|
| 325 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const {
|
| 326 |
+
return a | b;
|
| 327 |
+
}
|
| 328 |
+
};
|
| 329 |
+
|
| 330 |
+
template<typename T>
|
| 331 |
+
struct bit_xor {
|
| 332 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const {
|
| 333 |
+
return a ^ b;
|
| 334 |
+
}
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
template<typename T>
|
| 338 |
+
struct bit_not {
|
| 339 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a) const {
|
| 340 |
+
return ~a;
|
| 341 |
+
}
|
| 342 |
+
};
|
| 343 |
+
|
| 344 |
+
// Use operators &, |, ^, ~.
|
| 345 |
+
template<typename T>
|
| 346 |
+
struct operator_bitwise_helper {
|
| 347 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_and(const T& a, const T& b) { return bit_and<T>()(a, b); }
|
| 348 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_or(const T& a, const T& b) { return bit_or<T>()(a, b); }
|
| 349 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_xor(const T& a, const T& b) { return bit_xor<T>()(a, b); }
|
| 350 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_not(const T& a) { return bit_not<T>()(a); }
|
| 351 |
+
};
|
| 352 |
+
|
| 353 |
+
// Apply binary operations byte-by-byte
|
| 354 |
+
template<typename T>
|
| 355 |
+
struct bytewise_bitwise_helper {
|
| 356 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_and(const T& a, const T& b) {
|
| 357 |
+
return binary(a, b, bit_and<unsigned char>());
|
| 358 |
+
}
|
| 359 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_or(const T& a, const T& b) {
|
| 360 |
+
return binary(a, b, bit_or<unsigned char>());
|
| 361 |
+
}
|
| 362 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_xor(const T& a, const T& b) {
|
| 363 |
+
return binary(a, b, bit_xor<unsigned char>());
|
| 364 |
+
}
|
| 365 |
+
EIGEN_DEVICE_FUNC static inline T bitwise_not(const T& a) {
|
| 366 |
+
return unary(a,bit_not<unsigned char>());
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
private:
|
| 370 |
+
template<typename Op>
|
| 371 |
+
EIGEN_DEVICE_FUNC static inline T unary(const T& a, Op op) {
|
| 372 |
+
const unsigned char* a_ptr = reinterpret_cast<const unsigned char*>(&a);
|
| 373 |
+
T c;
|
| 374 |
+
unsigned char* c_ptr = reinterpret_cast<unsigned char*>(&c);
|
| 375 |
+
for (size_t i = 0; i < sizeof(T); ++i) {
|
| 376 |
+
*c_ptr++ = op(*a_ptr++);
|
| 377 |
+
}
|
| 378 |
+
return c;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
template<typename Op>
|
| 382 |
+
EIGEN_DEVICE_FUNC static inline T binary(const T& a, const T& b, Op op) {
|
| 383 |
+
const unsigned char* a_ptr = reinterpret_cast<const unsigned char*>(&a);
|
| 384 |
+
const unsigned char* b_ptr = reinterpret_cast<const unsigned char*>(&b);
|
| 385 |
+
T c;
|
| 386 |
+
unsigned char* c_ptr = reinterpret_cast<unsigned char*>(&c);
|
| 387 |
+
for (size_t i = 0; i < sizeof(T); ++i) {
|
| 388 |
+
*c_ptr++ = op(*a_ptr++, *b_ptr++);
|
| 389 |
+
}
|
| 390 |
+
return c;
|
| 391 |
+
}
|
| 392 |
+
};
|
| 393 |
+
|
| 394 |
+
// In the general case, use byte-by-byte manipulation.
|
| 395 |
+
template<typename T, typename EnableIf = void>
|
| 396 |
+
struct bitwise_helper : public bytewise_bitwise_helper<T> {};
|
| 397 |
+
|
| 398 |
+
// For integers or non-trivial scalars, use binary operators.
|
| 399 |
+
template<typename T>
|
| 400 |
+
struct bitwise_helper<T,
|
| 401 |
+
typename internal::enable_if<
|
| 402 |
+
is_scalar<T>::value && (NumTraits<T>::IsInteger || NumTraits<T>::RequireInitialization)>::type
|
| 403 |
+
> : public operator_bitwise_helper<T> {};
|
| 404 |
+
|
| 405 |
+
/** \internal \returns the bitwise and of \a a and \a b */
|
| 406 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 407 |
+
pand(const Packet& a, const Packet& b) {
|
| 408 |
+
return bitwise_helper<Packet>::bitwise_and(a, b);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
/** \internal \returns the bitwise or of \a a and \a b */
|
| 412 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 413 |
+
por(const Packet& a, const Packet& b) {
|
| 414 |
+
return bitwise_helper<Packet>::bitwise_or(a, b);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/** \internal \returns the bitwise xor of \a a and \a b */
|
| 418 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 419 |
+
pxor(const Packet& a, const Packet& b) {
|
| 420 |
+
return bitwise_helper<Packet>::bitwise_xor(a, b);
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
/** \internal \returns the bitwise not of \a a */
|
| 424 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 425 |
+
pnot(const Packet& a) {
|
| 426 |
+
return bitwise_helper<Packet>::bitwise_not(a);
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
/** \internal \returns the bitwise and of \a a and not \a b */
|
| 430 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 431 |
+
pandnot(const Packet& a, const Packet& b) { return pand(a, pnot(b)); }
|
| 432 |
+
|
| 433 |
+
// In the general case, use bitwise select.
|
| 434 |
+
template<typename Packet, typename EnableIf = void>
|
| 435 |
+
struct pselect_impl {
|
| 436 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& mask, const Packet& a, const Packet& b) {
|
| 437 |
+
return por(pand(a,mask),pandnot(b,mask));
|
| 438 |
+
}
|
| 439 |
+
};
|
| 440 |
+
|
| 441 |
+
// For scalars, use ternary select.
|
| 442 |
+
template<typename Packet>
|
| 443 |
+
struct pselect_impl<Packet,
|
| 444 |
+
typename internal::enable_if<is_scalar<Packet>::value>::type > {
|
| 445 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& mask, const Packet& a, const Packet& b) {
|
| 446 |
+
return numext::equal_strict(mask, Packet(0)) ? b : a;
|
| 447 |
+
}
|
| 448 |
+
};
|
| 449 |
+
|
| 450 |
+
/** \internal \returns \a or \b for each field in packet according to \mask */
|
| 451 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 452 |
+
pselect(const Packet& mask, const Packet& a, const Packet& b) {
|
| 453 |
+
return pselect_impl<Packet>::run(mask, a, b);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
template<> EIGEN_DEVICE_FUNC inline bool pselect<bool>(
|
| 457 |
+
const bool& cond, const bool& a, const bool& b) {
|
| 458 |
+
return cond ? a : b;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
/** \internal \returns the min or of \a a and \a b (coeff-wise)
|
| 462 |
+
If either \a a or \a b are NaN, the result is implementation defined. */
|
| 463 |
+
template<int NaNPropagation>
|
| 464 |
+
struct pminmax_impl {
|
| 465 |
+
template <typename Packet, typename Op>
|
| 466 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) {
|
| 467 |
+
return op(a,b);
|
| 468 |
+
}
|
| 469 |
+
};
|
| 470 |
+
|
| 471 |
+
/** \internal \returns the min or max of \a a and \a b (coeff-wise)
|
| 472 |
+
If either \a a or \a b are NaN, NaN is returned. */
|
| 473 |
+
template<>
|
| 474 |
+
struct pminmax_impl<PropagateNaN> {
|
| 475 |
+
template <typename Packet, typename Op>
|
| 476 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) {
|
| 477 |
+
Packet not_nan_mask_a = pcmp_eq(a, a);
|
| 478 |
+
Packet not_nan_mask_b = pcmp_eq(b, b);
|
| 479 |
+
return pselect(not_nan_mask_a,
|
| 480 |
+
pselect(not_nan_mask_b, op(a, b), b),
|
| 481 |
+
a);
|
| 482 |
+
}
|
| 483 |
+
};
|
| 484 |
+
|
| 485 |
+
/** \internal \returns the min or max of \a a and \a b (coeff-wise)
|
| 486 |
+
If both \a a and \a b are NaN, NaN is returned.
|
| 487 |
+
Equivalent to std::fmin(a, b). */
|
| 488 |
+
template<>
|
| 489 |
+
struct pminmax_impl<PropagateNumbers> {
|
| 490 |
+
template <typename Packet, typename Op>
|
| 491 |
+
static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) {
|
| 492 |
+
Packet not_nan_mask_a = pcmp_eq(a, a);
|
| 493 |
+
Packet not_nan_mask_b = pcmp_eq(b, b);
|
| 494 |
+
return pselect(not_nan_mask_a,
|
| 495 |
+
pselect(not_nan_mask_b, op(a, b), a),
|
| 496 |
+
b);
|
| 497 |
+
}
|
| 498 |
+
};
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
#ifndef SYCL_DEVICE_ONLY
|
| 502 |
+
#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) Func
|
| 503 |
+
#else
|
| 504 |
+
#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) \
|
| 505 |
+
[](const Type& a, const Type& b) { \
|
| 506 |
+
return Func(a, b);}
|
| 507 |
+
#endif
|
| 508 |
+
|
| 509 |
+
/** \internal \returns the min of \a a and \a b (coeff-wise).
|
| 510 |
+
If \a a or \b b is NaN, the return value is implementation defined. */
|
| 511 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 512 |
+
pmin(const Packet& a, const Packet& b) { return numext::mini(a,b); }
|
| 513 |
+
|
| 514 |
+
/** \internal \returns the min of \a a and \a b (coeff-wise).
|
| 515 |
+
NaNPropagation determines the NaN propagation semantics. */
|
| 516 |
+
template <int NaNPropagation, typename Packet>
|
| 517 |
+
EIGEN_DEVICE_FUNC inline Packet pmin(const Packet& a, const Packet& b) {
|
| 518 |
+
return pminmax_impl<NaNPropagation>::run(a, b, EIGEN_BINARY_OP_NAN_PROPAGATION(Packet, (pmin<Packet>)));
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
/** \internal \returns the max of \a a and \a b (coeff-wise)
|
| 522 |
+
If \a a or \b b is NaN, the return value is implementation defined. */
|
| 523 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 524 |
+
pmax(const Packet& a, const Packet& b) { return numext::maxi(a, b); }
|
| 525 |
+
|
| 526 |
+
/** \internal \returns the max of \a a and \a b (coeff-wise).
|
| 527 |
+
NaNPropagation determines the NaN propagation semantics. */
|
| 528 |
+
template <int NaNPropagation, typename Packet>
|
| 529 |
+
EIGEN_DEVICE_FUNC inline Packet pmax(const Packet& a, const Packet& b) {
|
| 530 |
+
return pminmax_impl<NaNPropagation>::run(a, b, EIGEN_BINARY_OP_NAN_PROPAGATION(Packet,(pmax<Packet>)));
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
/** \internal \returns the absolute value of \a a */
|
| 534 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 535 |
+
pabs(const Packet& a) { return numext::abs(a); }
|
| 536 |
+
template<> EIGEN_DEVICE_FUNC inline unsigned int
|
| 537 |
+
pabs(const unsigned int& a) { return a; }
|
| 538 |
+
template<> EIGEN_DEVICE_FUNC inline unsigned long
|
| 539 |
+
pabs(const unsigned long& a) { return a; }
|
| 540 |
+
template<> EIGEN_DEVICE_FUNC inline unsigned long long
|
| 541 |
+
pabs(const unsigned long long& a) { return a; }
|
| 542 |
+
|
| 543 |
+
/** \internal \returns the addsub value of \a a,b */
|
| 544 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 545 |
+
paddsub(const Packet& a, const Packet& b) {
|
| 546 |
+
return pselect(peven_mask(a), padd(a, b), psub(a, b));
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
/** \internal \returns the phase angle of \a a */
|
| 550 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 551 |
+
parg(const Packet& a) { using numext::arg; return arg(a); }
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
/** \internal \returns \a a logically shifted by N bits to the right */
|
| 555 |
+
template<int N> EIGEN_DEVICE_FUNC inline int
|
| 556 |
+
parithmetic_shift_right(const int& a) { return a >> N; }
|
| 557 |
+
template<int N> EIGEN_DEVICE_FUNC inline long int
|
| 558 |
+
parithmetic_shift_right(const long int& a) { return a >> N; }
|
| 559 |
+
|
| 560 |
+
/** \internal \returns \a a arithmetically shifted by N bits to the right */
|
| 561 |
+
template<int N> EIGEN_DEVICE_FUNC inline int
|
| 562 |
+
plogical_shift_right(const int& a) { return static_cast<int>(static_cast<unsigned int>(a) >> N); }
|
| 563 |
+
template<int N> EIGEN_DEVICE_FUNC inline long int
|
| 564 |
+
plogical_shift_right(const long int& a) { return static_cast<long>(static_cast<unsigned long>(a) >> N); }
|
| 565 |
+
|
| 566 |
+
/** \internal \returns \a a shifted by N bits to the left */
|
| 567 |
+
template<int N> EIGEN_DEVICE_FUNC inline int
|
| 568 |
+
plogical_shift_left(const int& a) { return a << N; }
|
| 569 |
+
template<int N> EIGEN_DEVICE_FUNC inline long int
|
| 570 |
+
plogical_shift_left(const long int& a) { return a << N; }
|
| 571 |
+
|
| 572 |
+
/** \internal \returns the significant and exponent of the underlying floating point numbers
|
| 573 |
+
* See https://en.cppreference.com/w/cpp/numeric/math/frexp
|
| 574 |
+
*/
|
| 575 |
+
template <typename Packet>
|
| 576 |
+
EIGEN_DEVICE_FUNC inline Packet pfrexp(const Packet& a, Packet& exponent) {
|
| 577 |
+
int exp;
|
| 578 |
+
EIGEN_USING_STD(frexp);
|
| 579 |
+
Packet result = static_cast<Packet>(frexp(a, &exp));
|
| 580 |
+
exponent = static_cast<Packet>(exp);
|
| 581 |
+
return result;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
/** \internal \returns a * 2^((int)exponent)
|
| 585 |
+
* See https://en.cppreference.com/w/cpp/numeric/math/ldexp
|
| 586 |
+
*/
|
| 587 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 588 |
+
pldexp(const Packet &a, const Packet &exponent) {
|
| 589 |
+
EIGEN_USING_STD(ldexp)
|
| 590 |
+
return static_cast<Packet>(ldexp(a, static_cast<int>(exponent)));
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
/** \internal \returns the min of \a a and \a b (coeff-wise) */
|
| 594 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 595 |
+
pabsdiff(const Packet& a, const Packet& b) { return pselect(pcmp_lt(a, b), psub(b, a), psub(a, b)); }
|
| 596 |
+
|
| 597 |
+
/** \internal \returns a packet version of \a *from, from must be 16 bytes aligned */
|
| 598 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 599 |
+
pload(const typename unpacket_traits<Packet>::type* from) { return *from; }
|
| 600 |
+
|
| 601 |
+
/** \internal \returns a packet version of \a *from, (un-aligned load) */
|
| 602 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 603 |
+
ploadu(const typename unpacket_traits<Packet>::type* from) { return *from; }
|
| 604 |
+
|
| 605 |
+
/** \internal \returns a packet version of \a *from, (un-aligned masked load)
|
| 606 |
+
* There is no generic implementation. We only have implementations for specialized
|
| 607 |
+
* cases. Generic case should not be called.
|
| 608 |
+
*/
|
| 609 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline
|
| 610 |
+
typename enable_if<unpacket_traits<Packet>::masked_load_available, Packet>::type
|
| 611 |
+
ploadu(const typename unpacket_traits<Packet>::type* from, typename unpacket_traits<Packet>::mask_t umask);
|
| 612 |
+
|
| 613 |
+
/** \internal \returns a packet with constant coefficients \a a, e.g.: (a,a,a,a) */
|
| 614 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 615 |
+
pset1(const typename unpacket_traits<Packet>::type& a) { return a; }
|
| 616 |
+
|
| 617 |
+
/** \internal \returns a packet with constant coefficients set from bits */
|
| 618 |
+
template<typename Packet,typename BitsType> EIGEN_DEVICE_FUNC inline Packet
|
| 619 |
+
pset1frombits(BitsType a);
|
| 620 |
+
|
| 621 |
+
/** \internal \returns a packet with constant coefficients \a a[0], e.g.: (a[0],a[0],a[0],a[0]) */
|
| 622 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 623 |
+
pload1(const typename unpacket_traits<Packet>::type *a) { return pset1<Packet>(*a); }
|
| 624 |
+
|
| 625 |
+
/** \internal \returns a packet with elements of \a *from duplicated.
|
| 626 |
+
* For instance, for a packet of 8 elements, 4 scalars will be read from \a *from and
|
| 627 |
+
* duplicated to form: {from[0],from[0],from[1],from[1],from[2],from[2],from[3],from[3]}
|
| 628 |
+
* Currently, this function is only used for scalar * complex products.
|
| 629 |
+
*/
|
| 630 |
+
template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet
|
| 631 |
+
ploaddup(const typename unpacket_traits<Packet>::type* from) { return *from; }
|
| 632 |
+
|
| 633 |
+
/** \internal \returns a packet with elements of \a *from quadrupled.
|
| 634 |
+
* For instance, for a packet of 8 elements, 2 scalars will be read from \a *from and
|
| 635 |
+
* replicated to form: {from[0],from[0],from[0],from[0],from[1],from[1],from[1],from[1]}
|
| 636 |
+
* Currently, this function is only used in matrix products.
|
| 637 |
+
* For packet-size smaller or equal to 4, this function is equivalent to pload1
|
| 638 |
+
*/
|
| 639 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 640 |
+
ploadquad(const typename unpacket_traits<Packet>::type* from)
|
| 641 |
+
{ return pload1<Packet>(from); }
|
| 642 |
+
|
| 643 |
+
/** \internal equivalent to
|
| 644 |
+
* \code
|
| 645 |
+
* a0 = pload1(a+0);
|
| 646 |
+
* a1 = pload1(a+1);
|
| 647 |
+
* a2 = pload1(a+2);
|
| 648 |
+
* a3 = pload1(a+3);
|
| 649 |
+
* \endcode
|
| 650 |
+
* \sa pset1, pload1, ploaddup, pbroadcast2
|
| 651 |
+
*/
|
| 652 |
+
template<typename Packet> EIGEN_DEVICE_FUNC
|
| 653 |
+
inline void pbroadcast4(const typename unpacket_traits<Packet>::type *a,
|
| 654 |
+
Packet& a0, Packet& a1, Packet& a2, Packet& a3)
|
| 655 |
+
{
|
| 656 |
+
a0 = pload1<Packet>(a+0);
|
| 657 |
+
a1 = pload1<Packet>(a+1);
|
| 658 |
+
a2 = pload1<Packet>(a+2);
|
| 659 |
+
a3 = pload1<Packet>(a+3);
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
/** \internal equivalent to
|
| 663 |
+
* \code
|
| 664 |
+
* a0 = pload1(a+0);
|
| 665 |
+
* a1 = pload1(a+1);
|
| 666 |
+
* \endcode
|
| 667 |
+
* \sa pset1, pload1, ploaddup, pbroadcast4
|
| 668 |
+
*/
|
| 669 |
+
template<typename Packet> EIGEN_DEVICE_FUNC
|
| 670 |
+
inline void pbroadcast2(const typename unpacket_traits<Packet>::type *a,
|
| 671 |
+
Packet& a0, Packet& a1)
|
| 672 |
+
{
|
| 673 |
+
a0 = pload1<Packet>(a+0);
|
| 674 |
+
a1 = pload1<Packet>(a+1);
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
/** \internal \brief Returns a packet with coefficients (a,a+1,...,a+packet_size-1). */
|
| 678 |
+
template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet
|
| 679 |
+
plset(const typename unpacket_traits<Packet>::type& a) { return a; }
|
| 680 |
+
|
| 681 |
+
/** \internal \returns a packet with constant coefficients \a a, e.g.: (x, 0, x, 0),
|
| 682 |
+
where x is the value of all 1-bits. */
|
| 683 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 684 |
+
peven_mask(const Packet& /*a*/) {
|
| 685 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 686 |
+
const size_t n = unpacket_traits<Packet>::size;
|
| 687 |
+
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) Scalar elements[n];
|
| 688 |
+
for(size_t i = 0; i < n; ++i) {
|
| 689 |
+
memset(elements+i, ((i & 1) == 0 ? 0xff : 0), sizeof(Scalar));
|
| 690 |
+
}
|
| 691 |
+
return ploadu<Packet>(elements);
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
/** \internal copy the packet \a from to \a *to, \a to must be 16 bytes aligned */
|
| 696 |
+
template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pstore(Scalar* to, const Packet& from)
|
| 697 |
+
{ (*to) = from; }
|
| 698 |
+
|
| 699 |
+
/** \internal copy the packet \a from to \a *to, (un-aligned store) */
|
| 700 |
+
template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pstoreu(Scalar* to, const Packet& from)
|
| 701 |
+
{ (*to) = from; }
|
| 702 |
+
|
| 703 |
+
/** \internal copy the packet \a from to \a *to, (un-aligned store with a mask)
|
| 704 |
+
* There is no generic implementation. We only have implementations for specialized
|
| 705 |
+
* cases. Generic case should not be called.
|
| 706 |
+
*/
|
| 707 |
+
template<typename Scalar, typename Packet>
|
| 708 |
+
EIGEN_DEVICE_FUNC inline
|
| 709 |
+
typename enable_if<unpacket_traits<Packet>::masked_store_available, void>::type
|
| 710 |
+
pstoreu(Scalar* to, const Packet& from, typename unpacket_traits<Packet>::mask_t umask);
|
| 711 |
+
|
| 712 |
+
template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline Packet pgather(const Scalar* from, Index /*stride*/)
|
| 713 |
+
{ return ploadu<Packet>(from); }
|
| 714 |
+
|
| 715 |
+
template<typename Scalar, typename Packet> EIGEN_DEVICE_FUNC inline void pscatter(Scalar* to, const Packet& from, Index /*stride*/)
|
| 716 |
+
{ pstore(to, from); }
|
| 717 |
+
|
| 718 |
+
/** \internal tries to do cache prefetching of \a addr */
|
| 719 |
+
template<typename Scalar> EIGEN_DEVICE_FUNC inline void prefetch(const Scalar* addr)
|
| 720 |
+
{
|
| 721 |
+
#if defined(EIGEN_HIP_DEVICE_COMPILE)
|
| 722 |
+
// do nothing
|
| 723 |
+
#elif defined(EIGEN_CUDA_ARCH)
|
| 724 |
+
#if defined(__LP64__) || EIGEN_OS_WIN64
|
| 725 |
+
// 64-bit pointer operand constraint for inlined asm
|
| 726 |
+
asm(" prefetch.L1 [ %1 ];" : "=l"(addr) : "l"(addr));
|
| 727 |
+
#else
|
| 728 |
+
// 32-bit pointer operand constraint for inlined asm
|
| 729 |
+
asm(" prefetch.L1 [ %1 ];" : "=r"(addr) : "r"(addr));
|
| 730 |
+
#endif
|
| 731 |
+
#elif (!EIGEN_COMP_MSVC) && (EIGEN_COMP_GNUC || EIGEN_COMP_CLANG || EIGEN_COMP_ICC)
|
| 732 |
+
__builtin_prefetch(addr);
|
| 733 |
+
#endif
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
/** \internal \returns the reversed elements of \a a*/
|
| 737 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet preverse(const Packet& a)
|
| 738 |
+
{ return a; }
|
| 739 |
+
|
| 740 |
+
/** \internal \returns \a a with real and imaginary part flipped (for complex type only) */
|
| 741 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet pcplxflip(const Packet& a)
|
| 742 |
+
{
|
| 743 |
+
return Packet(numext::imag(a),numext::real(a));
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
/**************************
|
| 747 |
+
* Special math functions
|
| 748 |
+
***************************/
|
| 749 |
+
|
| 750 |
+
/** \internal \returns the sine of \a a (coeff-wise) */
|
| 751 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 752 |
+
Packet psin(const Packet& a) { EIGEN_USING_STD(sin); return sin(a); }
|
| 753 |
+
|
| 754 |
+
/** \internal \returns the cosine of \a a (coeff-wise) */
|
| 755 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 756 |
+
Packet pcos(const Packet& a) { EIGEN_USING_STD(cos); return cos(a); }
|
| 757 |
+
|
| 758 |
+
/** \internal \returns the tan of \a a (coeff-wise) */
|
| 759 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 760 |
+
Packet ptan(const Packet& a) { EIGEN_USING_STD(tan); return tan(a); }
|
| 761 |
+
|
| 762 |
+
/** \internal \returns the arc sine of \a a (coeff-wise) */
|
| 763 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 764 |
+
Packet pasin(const Packet& a) { EIGEN_USING_STD(asin); return asin(a); }
|
| 765 |
+
|
| 766 |
+
/** \internal \returns the arc cosine of \a a (coeff-wise) */
|
| 767 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 768 |
+
Packet pacos(const Packet& a) { EIGEN_USING_STD(acos); return acos(a); }
|
| 769 |
+
|
| 770 |
+
/** \internal \returns the arc tangent of \a a (coeff-wise) */
|
| 771 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 772 |
+
Packet patan(const Packet& a) { EIGEN_USING_STD(atan); return atan(a); }
|
| 773 |
+
|
| 774 |
+
/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */
|
| 775 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 776 |
+
Packet psinh(const Packet& a) { EIGEN_USING_STD(sinh); return sinh(a); }
|
| 777 |
+
|
| 778 |
+
/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */
|
| 779 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 780 |
+
Packet pcosh(const Packet& a) { EIGEN_USING_STD(cosh); return cosh(a); }
|
| 781 |
+
|
| 782 |
+
/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */
|
| 783 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 784 |
+
Packet ptanh(const Packet& a) { EIGEN_USING_STD(tanh); return tanh(a); }
|
| 785 |
+
|
| 786 |
+
/** \internal \returns the exp of \a a (coeff-wise) */
|
| 787 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 788 |
+
Packet pexp(const Packet& a) { EIGEN_USING_STD(exp); return exp(a); }
|
| 789 |
+
|
| 790 |
+
/** \internal \returns the expm1 of \a a (coeff-wise) */
|
| 791 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 792 |
+
Packet pexpm1(const Packet& a) { return numext::expm1(a); }
|
| 793 |
+
|
| 794 |
+
/** \internal \returns the log of \a a (coeff-wise) */
|
| 795 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 796 |
+
Packet plog(const Packet& a) { EIGEN_USING_STD(log); return log(a); }
|
| 797 |
+
|
| 798 |
+
/** \internal \returns the log1p of \a a (coeff-wise) */
|
| 799 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 800 |
+
Packet plog1p(const Packet& a) { return numext::log1p(a); }
|
| 801 |
+
|
| 802 |
+
/** \internal \returns the log10 of \a a (coeff-wise) */
|
| 803 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 804 |
+
Packet plog10(const Packet& a) { EIGEN_USING_STD(log10); return log10(a); }
|
| 805 |
+
|
| 806 |
+
/** \internal \returns the log10 of \a a (coeff-wise) */
|
| 807 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 808 |
+
Packet plog2(const Packet& a) {
|
| 809 |
+
typedef typename internal::unpacket_traits<Packet>::type Scalar;
|
| 810 |
+
return pmul(pset1<Packet>(Scalar(EIGEN_LOG2E)), plog(a));
|
| 811 |
+
}
|
| 812 |
+
|
| 813 |
+
/** \internal \returns the square-root of \a a (coeff-wise) */
|
| 814 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 815 |
+
Packet psqrt(const Packet& a) { return numext::sqrt(a); }
|
| 816 |
+
|
| 817 |
+
/** \internal \returns the reciprocal square-root of \a a (coeff-wise) */
|
| 818 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 819 |
+
Packet prsqrt(const Packet& a) {
|
| 820 |
+
typedef typename internal::unpacket_traits<Packet>::type Scalar;
|
| 821 |
+
return pdiv(pset1<Packet>(Scalar(1)), psqrt(a));
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
/** \internal \returns the rounded value of \a a (coeff-wise) */
|
| 825 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 826 |
+
Packet pround(const Packet& a) { using numext::round; return round(a); }
|
| 827 |
+
|
| 828 |
+
/** \internal \returns the floor of \a a (coeff-wise) */
|
| 829 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 830 |
+
Packet pfloor(const Packet& a) { using numext::floor; return floor(a); }
|
| 831 |
+
|
| 832 |
+
/** \internal \returns the rounded value of \a a (coeff-wise) with current
|
| 833 |
+
* rounding mode */
|
| 834 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 835 |
+
Packet print(const Packet& a) { using numext::rint; return rint(a); }
|
| 836 |
+
|
| 837 |
+
/** \internal \returns the ceil of \a a (coeff-wise) */
|
| 838 |
+
template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
| 839 |
+
Packet pceil(const Packet& a) { using numext::ceil; return ceil(a); }
|
| 840 |
+
|
| 841 |
+
/** \internal \returns the first element of a packet */
|
| 842 |
+
template<typename Packet>
|
| 843 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type
|
| 844 |
+
pfirst(const Packet& a)
|
| 845 |
+
{ return a; }
|
| 846 |
+
|
| 847 |
+
/** \internal \returns the sum of the elements of upper and lower half of \a a if \a a is larger than 4.
|
| 848 |
+
* For a packet {a0, a1, a2, a3, a4, a5, a6, a7}, it returns a half packet {a0+a4, a1+a5, a2+a6, a3+a7}
|
| 849 |
+
* For packet-size smaller or equal to 4, this boils down to a noop.
|
| 850 |
+
*/
|
| 851 |
+
template<typename Packet>
|
| 852 |
+
EIGEN_DEVICE_FUNC inline typename conditional<(unpacket_traits<Packet>::size%8)==0,typename unpacket_traits<Packet>::half,Packet>::type
|
| 853 |
+
predux_half_dowto4(const Packet& a)
|
| 854 |
+
{ return a; }
|
| 855 |
+
|
| 856 |
+
// Slow generic implementation of Packet reduction.
|
| 857 |
+
template <typename Packet, typename Op>
|
| 858 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type
|
| 859 |
+
predux_helper(const Packet& a, Op op) {
|
| 860 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 861 |
+
const size_t n = unpacket_traits<Packet>::size;
|
| 862 |
+
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) Scalar elements[n];
|
| 863 |
+
pstoreu<Scalar>(elements, a);
|
| 864 |
+
for(size_t k = n / 2; k > 0; k /= 2) {
|
| 865 |
+
for(size_t i = 0; i < k; ++i) {
|
| 866 |
+
elements[i] = op(elements[i], elements[i + k]);
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
return elements[0];
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
/** \internal \returns the sum of the elements of \a a*/
|
| 873 |
+
template<typename Packet>
|
| 874 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type
|
| 875 |
+
predux(const Packet& a)
|
| 876 |
+
{
|
| 877 |
+
return a;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
/** \internal \returns the product of the elements of \a a */
|
| 881 |
+
template <typename Packet>
|
| 882 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_mul(
|
| 883 |
+
const Packet& a) {
|
| 884 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 885 |
+
return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmul<Scalar>)));
|
| 886 |
+
}
|
| 887 |
+
|
| 888 |
+
/** \internal \returns the min of the elements of \a a */
|
| 889 |
+
template <typename Packet>
|
| 890 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_min(
|
| 891 |
+
const Packet &a) {
|
| 892 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 893 |
+
return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmin<PropagateFast, Scalar>)));
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
template <int NaNPropagation, typename Packet>
|
| 897 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_min(
|
| 898 |
+
const Packet& a) {
|
| 899 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 900 |
+
return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmin<NaNPropagation, Scalar>)));
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
/** \internal \returns the min of the elements of \a a */
|
| 904 |
+
template <typename Packet>
|
| 905 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_max(
|
| 906 |
+
const Packet &a) {
|
| 907 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 908 |
+
return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmax<PropagateFast, Scalar>)));
|
| 909 |
+
}
|
| 910 |
+
|
| 911 |
+
template <int NaNPropagation, typename Packet>
|
| 912 |
+
EIGEN_DEVICE_FUNC inline typename unpacket_traits<Packet>::type predux_max(
|
| 913 |
+
const Packet& a) {
|
| 914 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 915 |
+
return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmax<NaNPropagation, Scalar>)));
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
#undef EIGEN_BINARY_OP_NAN_PROPAGATION
|
| 919 |
+
|
| 920 |
+
/** \internal \returns true if all coeffs of \a a means "true"
|
| 921 |
+
* It is supposed to be called on values returned by pcmp_*.
|
| 922 |
+
*/
|
| 923 |
+
// not needed yet
|
| 924 |
+
// template<typename Packet> EIGEN_DEVICE_FUNC inline bool predux_all(const Packet& a)
|
| 925 |
+
// { return bool(a); }
|
| 926 |
+
|
| 927 |
+
/** \internal \returns true if any coeffs of \a a means "true"
|
| 928 |
+
* It is supposed to be called on values returned by pcmp_*.
|
| 929 |
+
*/
|
| 930 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline bool predux_any(const Packet& a)
|
| 931 |
+
{
|
| 932 |
+
// Dirty but generic implementation where "true" is assumed to be non 0 and all the sames.
|
| 933 |
+
// It is expected that "true" is either:
|
| 934 |
+
// - Scalar(1)
|
| 935 |
+
// - bits full of ones (NaN for floats),
|
| 936 |
+
// - or first bit equals to 1 (1 for ints, smallest denormal for floats).
|
| 937 |
+
// For all these cases, taking the sum is just fine, and this boils down to a no-op for scalars.
|
| 938 |
+
typedef typename unpacket_traits<Packet>::type Scalar;
|
| 939 |
+
return numext::not_equal_strict(predux(a), Scalar(0));
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
/***************************************************************************
|
| 943 |
+
* The following functions might not have to be overwritten for vectorized types
|
| 944 |
+
***************************************************************************/
|
| 945 |
+
|
| 946 |
+
/** \internal copy a packet with constant coefficient \a a (e.g., [a,a,a,a]) to \a *to. \a to must be 16 bytes aligned */
|
| 947 |
+
// NOTE: this function must really be templated on the packet type (think about different packet types for the same scalar type)
|
| 948 |
+
template<typename Packet>
|
| 949 |
+
inline void pstore1(typename unpacket_traits<Packet>::type* to, const typename unpacket_traits<Packet>::type& a)
|
| 950 |
+
{
|
| 951 |
+
pstore(to, pset1<Packet>(a));
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
/** \internal \returns a * b + c (coeff-wise) */
|
| 955 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 956 |
+
pmadd(const Packet& a,
|
| 957 |
+
const Packet& b,
|
| 958 |
+
const Packet& c)
|
| 959 |
+
{ return padd(pmul(a, b),c); }
|
| 960 |
+
|
| 961 |
+
/** \internal \returns a packet version of \a *from.
|
| 962 |
+
* The pointer \a from must be aligned on a \a Alignment bytes boundary. */
|
| 963 |
+
template<typename Packet, int Alignment>
|
| 964 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt(const typename unpacket_traits<Packet>::type* from)
|
| 965 |
+
{
|
| 966 |
+
if(Alignment >= unpacket_traits<Packet>::alignment)
|
| 967 |
+
return pload<Packet>(from);
|
| 968 |
+
else
|
| 969 |
+
return ploadu<Packet>(from);
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
/** \internal copy the packet \a from to \a *to.
|
| 973 |
+
* The pointer \a from must be aligned on a \a Alignment bytes boundary. */
|
| 974 |
+
template<typename Scalar, typename Packet, int Alignment>
|
| 975 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret(Scalar* to, const Packet& from)
|
| 976 |
+
{
|
| 977 |
+
if(Alignment >= unpacket_traits<Packet>::alignment)
|
| 978 |
+
pstore(to, from);
|
| 979 |
+
else
|
| 980 |
+
pstoreu(to, from);
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
/** \internal \returns a packet version of \a *from.
|
| 984 |
+
* Unlike ploadt, ploadt_ro takes advantage of the read-only memory path on the
|
| 985 |
+
* hardware if available to speedup the loading of data that won't be modified
|
| 986 |
+
* by the current computation.
|
| 987 |
+
*/
|
| 988 |
+
template<typename Packet, int LoadMode>
|
| 989 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt_ro(const typename unpacket_traits<Packet>::type* from)
|
| 990 |
+
{
|
| 991 |
+
return ploadt<Packet, LoadMode>(from);
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
/***************************************************************************
|
| 995 |
+
* Fast complex products (GCC generates a function call which is very slow)
|
| 996 |
+
***************************************************************************/
|
| 997 |
+
|
| 998 |
+
// Eigen+CUDA does not support complexes.
|
| 999 |
+
#if !defined(EIGEN_GPUCC)
|
| 1000 |
+
|
| 1001 |
+
template<> inline std::complex<float> pmul(const std::complex<float>& a, const std::complex<float>& b)
|
| 1002 |
+
{ return std::complex<float>(a.real()*b.real() - a.imag()*b.imag(), a.imag()*b.real() + a.real()*b.imag()); }
|
| 1003 |
+
|
| 1004 |
+
template<> inline std::complex<double> pmul(const std::complex<double>& a, const std::complex<double>& b)
|
| 1005 |
+
{ return std::complex<double>(a.real()*b.real() - a.imag()*b.imag(), a.imag()*b.real() + a.real()*b.imag()); }
|
| 1006 |
+
|
| 1007 |
+
#endif
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
/***************************************************************************
|
| 1011 |
+
* PacketBlock, that is a collection of N packets where the number of words
|
| 1012 |
+
* in the packet is a multiple of N.
|
| 1013 |
+
***************************************************************************/
|
| 1014 |
+
template <typename Packet,int N=unpacket_traits<Packet>::size> struct PacketBlock {
|
| 1015 |
+
Packet packet[N];
|
| 1016 |
+
};
|
| 1017 |
+
|
| 1018 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline void
|
| 1019 |
+
ptranspose(PacketBlock<Packet,1>& /*kernel*/) {
|
| 1020 |
+
// Nothing to do in the scalar case, i.e. a 1x1 matrix.
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
/***************************************************************************
|
| 1024 |
+
* Selector, i.e. vector of N boolean values used to select (i.e. blend)
|
| 1025 |
+
* words from 2 packets.
|
| 1026 |
+
***************************************************************************/
|
| 1027 |
+
template <size_t N> struct Selector {
|
| 1028 |
+
bool select[N];
|
| 1029 |
+
};
|
| 1030 |
+
|
| 1031 |
+
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
|
| 1032 |
+
pblend(const Selector<unpacket_traits<Packet>::size>& ifPacket, const Packet& thenPacket, const Packet& elsePacket) {
|
| 1033 |
+
return ifPacket.select[0] ? thenPacket : elsePacket;
|
| 1034 |
+
}
|
| 1035 |
+
|
| 1036 |
+
} // end namespace internal
|
| 1037 |
+
|
| 1038 |
+
} // end namespace Eigen
|
| 1039 |
+
|
| 1040 |
+
#endif // EIGEN_GENERIC_PACKET_MATH_H
|
include/eigen/Eigen/src/Core/GlobalFunctions.h
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2010-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_GLOBAL_FUNCTIONS_H
|
| 12 |
+
#define EIGEN_GLOBAL_FUNCTIONS_H
|
| 13 |
+
|
| 14 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 15 |
+
|
| 16 |
+
#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR,DOC_OP,DOC_DETAILS) \
|
| 17 |
+
/** \returns an expression of the coefficient-wise DOC_OP of \a x
|
| 18 |
+
|
| 19 |
+
DOC_DETAILS
|
| 20 |
+
|
| 21 |
+
\sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_##NAME">Math functions</a>, class CwiseUnaryOp
|
| 22 |
+
*/ \
|
| 23 |
+
template<typename Derived> \
|
| 24 |
+
inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
|
| 25 |
+
NAME(const Eigen::ArrayBase<Derived>& x);
|
| 26 |
+
|
| 27 |
+
#else
|
| 28 |
+
|
| 29 |
+
#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR,DOC_OP,DOC_DETAILS) \
|
| 30 |
+
template<typename Derived> \
|
| 31 |
+
inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
|
| 32 |
+
(NAME)(const Eigen::ArrayBase<Derived>& x) { \
|
| 33 |
+
return Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived>(x.derived()); \
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
#endif // EIGEN_PARSED_BY_DOXYGEN
|
| 37 |
+
|
| 38 |
+
#define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \
|
| 39 |
+
\
|
| 40 |
+
template<typename Derived> \
|
| 41 |
+
struct NAME##_retval<ArrayBase<Derived> > \
|
| 42 |
+
{ \
|
| 43 |
+
typedef const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> type; \
|
| 44 |
+
}; \
|
| 45 |
+
template<typename Derived> \
|
| 46 |
+
struct NAME##_impl<ArrayBase<Derived> > \
|
| 47 |
+
{ \
|
| 48 |
+
static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \
|
| 49 |
+
{ \
|
| 50 |
+
return typename NAME##_retval<ArrayBase<Derived> >::type(x.derived()); \
|
| 51 |
+
} \
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
namespace Eigen
|
| 55 |
+
{
|
| 56 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op,real part,\sa ArrayBase::real)
|
| 57 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op,imaginary part,\sa ArrayBase::imag)
|
| 58 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op,complex conjugate,\sa ArrayBase::conjugate)
|
| 59 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(inverse,scalar_inverse_op,inverse,\sa ArrayBase::inverse)
|
| 60 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op,sine,\sa ArrayBase::sin)
|
| 61 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op,cosine,\sa ArrayBase::cos)
|
| 62 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op,tangent,\sa ArrayBase::tan)
|
| 63 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan,scalar_atan_op,arc-tangent,\sa ArrayBase::atan)
|
| 64 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op,arc-sine,\sa ArrayBase::asin)
|
| 65 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos,scalar_acos_op,arc-consine,\sa ArrayBase::acos)
|
| 66 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh)
|
| 67 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh)
|
| 68 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh)
|
| 69 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 70 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asinh,scalar_asinh_op,inverse hyperbolic sine,\sa ArrayBase::asinh)
|
| 71 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acosh,scalar_acosh_op,inverse hyperbolic cosine,\sa ArrayBase::acosh)
|
| 72 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atanh,scalar_atanh_op,inverse hyperbolic tangent,\sa ArrayBase::atanh)
|
| 73 |
+
#endif
|
| 74 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic,scalar_logistic_op,logistic function,\sa ArrayBase::logistic)
|
| 75 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma)
|
| 76 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma)
|
| 77 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op,error function,\sa ArrayBase::erf)
|
| 78 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op,complement error function,\sa ArrayBase::erfc)
|
| 79 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ndtri,scalar_ndtri_op,inverse normal distribution function,\sa ArrayBase::ndtri)
|
| 80 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op,exponential,\sa ArrayBase::exp)
|
| 81 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(expm1,scalar_expm1_op,exponential of a value minus 1,\sa ArrayBase::expm1)
|
| 82 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op,natural logarithm,\sa Eigen::log10 DOXCOMMA ArrayBase::log)
|
| 83 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log1p,scalar_log1p_op,natural logarithm of 1 plus the value,\sa ArrayBase::log1p)
|
| 84 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10,scalar_log10_op,base 10 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log10)
|
| 85 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log2,scalar_log2_op,base 2 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log2)
|
| 86 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op,absolute value,\sa ArrayBase::abs DOXCOMMA MatrixBase::cwiseAbs)
|
| 87 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2,scalar_abs2_op,squared absolute value,\sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2)
|
| 88 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg,scalar_arg_op,complex argument,\sa ArrayBase::arg DOXCOMMA MatrixBase::cwiseArg)
|
| 89 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op,square root,\sa ArrayBase::sqrt DOXCOMMA MatrixBase::cwiseSqrt)
|
| 90 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rsqrt,scalar_rsqrt_op,reciprocal square root,\sa ArrayBase::rsqrt)
|
| 91 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square,scalar_square_op,square (power 2),\sa Eigen::abs2 DOXCOMMA Eigen::pow DOXCOMMA ArrayBase::square)
|
| 92 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube,scalar_cube_op,cube (power 3),\sa Eigen::pow DOXCOMMA ArrayBase::cube)
|
| 93 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rint,scalar_rint_op,nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round)
|
| 94 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op,nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round)
|
| 95 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op,nearest integer not greater than the giben value,\sa Eigen::ceil DOXCOMMA ArrayBase::floor)
|
| 96 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op,nearest integer not less than the giben value,\sa Eigen::floor DOXCOMMA ArrayBase::ceil)
|
| 97 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op,not-a-number test,\sa Eigen::isinf DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isnan)
|
| 98 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op,infinite value test,\sa Eigen::isnan DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isinf)
|
| 99 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op,finite value test,\sa Eigen::isinf DOXCOMMA Eigen::isnan DOXCOMMA ArrayBase::isfinite)
|
| 100 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign,scalar_sign_op,sign (or 0),\sa ArrayBase::sign)
|
| 101 |
+
|
| 102 |
+
/** \returns an expression of the coefficient-wise power of \a x to the given constant \a exponent.
|
| 103 |
+
*
|
| 104 |
+
* \tparam ScalarExponent is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression (\c Derived::Scalar).
|
| 105 |
+
*
|
| 106 |
+
* \sa ArrayBase::pow()
|
| 107 |
+
*
|
| 108 |
+
* \relates ArrayBase
|
| 109 |
+
*/
|
| 110 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 111 |
+
template<typename Derived,typename ScalarExponent>
|
| 112 |
+
inline const CwiseBinaryOp<internal::scalar_pow_op<Derived::Scalar,ScalarExponent>,Derived,Constant<ScalarExponent> >
|
| 113 |
+
pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent);
|
| 114 |
+
#else
|
| 115 |
+
template <typename Derived,typename ScalarExponent>
|
| 116 |
+
EIGEN_DEVICE_FUNC inline
|
| 117 |
+
EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(
|
| 118 |
+
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<typename Derived::Scalar
|
| 119 |
+
EIGEN_COMMA ScalarExponent EIGEN_COMMA
|
| 120 |
+
EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type,pow))
|
| 121 |
+
pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent)
|
| 122 |
+
{
|
| 123 |
+
typedef typename internal::promote_scalar_arg<typename Derived::Scalar,ScalarExponent,
|
| 124 |
+
EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type PromotedExponent;
|
| 125 |
+
return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedExponent,pow)(x.derived(),
|
| 126 |
+
typename internal::plain_constant_type<Derived,PromotedExponent>::type(x.derived().rows(), x.derived().cols(), internal::scalar_constant_op<PromotedExponent>(exponent)));
|
| 127 |
+
}
|
| 128 |
+
#endif
|
| 129 |
+
|
| 130 |
+
/** \returns an expression of the coefficient-wise power of \a x to the given array of \a exponents.
|
| 131 |
+
*
|
| 132 |
+
* This function computes the coefficient-wise power.
|
| 133 |
+
*
|
| 134 |
+
* Example: \include Cwise_array_power_array.cpp
|
| 135 |
+
* Output: \verbinclude Cwise_array_power_array.out
|
| 136 |
+
*
|
| 137 |
+
* \sa ArrayBase::pow()
|
| 138 |
+
*
|
| 139 |
+
* \relates ArrayBase
|
| 140 |
+
*/
|
| 141 |
+
template<typename Derived,typename ExponentDerived>
|
| 142 |
+
inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>
|
| 143 |
+
pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<ExponentDerived>& exponents)
|
| 144 |
+
{
|
| 145 |
+
return Eigen::CwiseBinaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>(
|
| 146 |
+
x.derived(),
|
| 147 |
+
exponents.derived()
|
| 148 |
+
);
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/** \returns an expression of the coefficient-wise power of the scalar \a x to the given array of \a exponents.
|
| 152 |
+
*
|
| 153 |
+
* This function computes the coefficient-wise power between a scalar and an array of exponents.
|
| 154 |
+
*
|
| 155 |
+
* \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression (\c Derived::Scalar).
|
| 156 |
+
*
|
| 157 |
+
* Example: \include Cwise_scalar_power_array.cpp
|
| 158 |
+
* Output: \verbinclude Cwise_scalar_power_array.out
|
| 159 |
+
*
|
| 160 |
+
* \sa ArrayBase::pow()
|
| 161 |
+
*
|
| 162 |
+
* \relates ArrayBase
|
| 163 |
+
*/
|
| 164 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 165 |
+
template<typename Scalar,typename Derived>
|
| 166 |
+
inline const CwiseBinaryOp<internal::scalar_pow_op<Scalar,Derived::Scalar>,Constant<Scalar>,Derived>
|
| 167 |
+
pow(const Scalar& x,const Eigen::ArrayBase<Derived>& x);
|
| 168 |
+
#else
|
| 169 |
+
template <typename Scalar, typename Derived>
|
| 170 |
+
EIGEN_DEVICE_FUNC inline
|
| 171 |
+
EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(
|
| 172 |
+
const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<typename Derived::Scalar
|
| 173 |
+
EIGEN_COMMA Scalar EIGEN_COMMA
|
| 174 |
+
EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type,Derived,pow))
|
| 175 |
+
pow(const Scalar& x, const Eigen::ArrayBase<Derived>& exponents) {
|
| 176 |
+
typedef typename internal::promote_scalar_arg<typename Derived::Scalar,Scalar,
|
| 177 |
+
EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type PromotedScalar;
|
| 178 |
+
return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedScalar,Derived,pow)(
|
| 179 |
+
typename internal::plain_constant_type<Derived,PromotedScalar>::type(exponents.derived().rows(), exponents.derived().cols(), internal::scalar_constant_op<PromotedScalar>(x)), exponents.derived());
|
| 180 |
+
}
|
| 181 |
+
#endif
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
namespace internal
|
| 185 |
+
{
|
| 186 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op)
|
| 187 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op)
|
| 188 |
+
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op)
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...)
|
| 193 |
+
|
| 194 |
+
#endif // EIGEN_GLOBAL_FUNCTIONS_H
|
include/eigen/Eigen/src/Core/IO.h
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_IO_H
|
| 12 |
+
#define EIGEN_IO_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
enum { DontAlignCols = 1 };
|
| 17 |
+
enum { StreamPrecision = -1,
|
| 18 |
+
FullPrecision = -2 };
|
| 19 |
+
|
| 20 |
+
namespace internal {
|
| 21 |
+
template<typename Derived>
|
| 22 |
+
std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/** \class IOFormat
|
| 26 |
+
* \ingroup Core_Module
|
| 27 |
+
*
|
| 28 |
+
* \brief Stores a set of parameters controlling the way matrices are printed
|
| 29 |
+
*
|
| 30 |
+
* List of available parameters:
|
| 31 |
+
* - \b precision number of digits for floating point values, or one of the special constants \c StreamPrecision and \c FullPrecision.
|
| 32 |
+
* The default is the special value \c StreamPrecision which means to use the
|
| 33 |
+
* stream's own precision setting, as set for instance using \c cout.precision(3). The other special value
|
| 34 |
+
* \c FullPrecision means that the number of digits will be computed to match the full precision of each floating-point
|
| 35 |
+
* type.
|
| 36 |
+
* - \b flags an OR-ed combination of flags, the default value is 0, the only currently available flag is \c DontAlignCols which
|
| 37 |
+
* allows to disable the alignment of columns, resulting in faster code.
|
| 38 |
+
* - \b coeffSeparator string printed between two coefficients of the same row
|
| 39 |
+
* - \b rowSeparator string printed between two rows
|
| 40 |
+
* - \b rowPrefix string printed at the beginning of each row
|
| 41 |
+
* - \b rowSuffix string printed at the end of each row
|
| 42 |
+
* - \b matPrefix string printed at the beginning of the matrix
|
| 43 |
+
* - \b matSuffix string printed at the end of the matrix
|
| 44 |
+
* - \b fill character printed to fill the empty space in aligned columns
|
| 45 |
+
*
|
| 46 |
+
* Example: \include IOFormat.cpp
|
| 47 |
+
* Output: \verbinclude IOFormat.out
|
| 48 |
+
*
|
| 49 |
+
* \sa DenseBase::format(), class WithFormat
|
| 50 |
+
*/
|
| 51 |
+
struct IOFormat
|
| 52 |
+
{
|
| 53 |
+
/** Default constructor, see class IOFormat for the meaning of the parameters */
|
| 54 |
+
IOFormat(int _precision = StreamPrecision, int _flags = 0,
|
| 55 |
+
const std::string& _coeffSeparator = " ",
|
| 56 |
+
const std::string& _rowSeparator = "\n", const std::string& _rowPrefix="", const std::string& _rowSuffix="",
|
| 57 |
+
const std::string& _matPrefix="", const std::string& _matSuffix="", const char _fill=' ')
|
| 58 |
+
: matPrefix(_matPrefix), matSuffix(_matSuffix), rowPrefix(_rowPrefix), rowSuffix(_rowSuffix), rowSeparator(_rowSeparator),
|
| 59 |
+
rowSpacer(""), coeffSeparator(_coeffSeparator), fill(_fill), precision(_precision), flags(_flags)
|
| 60 |
+
{
|
| 61 |
+
// TODO check if rowPrefix, rowSuffix or rowSeparator contains a newline
|
| 62 |
+
// don't add rowSpacer if columns are not to be aligned
|
| 63 |
+
if((flags & DontAlignCols))
|
| 64 |
+
return;
|
| 65 |
+
int i = int(matSuffix.length())-1;
|
| 66 |
+
while (i>=0 && matSuffix[i]!='\n')
|
| 67 |
+
{
|
| 68 |
+
rowSpacer += ' ';
|
| 69 |
+
i--;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
std::string matPrefix, matSuffix;
|
| 73 |
+
std::string rowPrefix, rowSuffix, rowSeparator, rowSpacer;
|
| 74 |
+
std::string coeffSeparator;
|
| 75 |
+
char fill;
|
| 76 |
+
int precision;
|
| 77 |
+
int flags;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
/** \class WithFormat
|
| 81 |
+
* \ingroup Core_Module
|
| 82 |
+
*
|
| 83 |
+
* \brief Pseudo expression providing matrix output with given format
|
| 84 |
+
*
|
| 85 |
+
* \tparam ExpressionType the type of the object on which IO stream operations are performed
|
| 86 |
+
*
|
| 87 |
+
* This class represents an expression with stream operators controlled by a given IOFormat.
|
| 88 |
+
* It is the return type of DenseBase::format()
|
| 89 |
+
* and most of the time this is the only way it is used.
|
| 90 |
+
*
|
| 91 |
+
* See class IOFormat for some examples.
|
| 92 |
+
*
|
| 93 |
+
* \sa DenseBase::format(), class IOFormat
|
| 94 |
+
*/
|
| 95 |
+
template<typename ExpressionType>
|
| 96 |
+
class WithFormat
|
| 97 |
+
{
|
| 98 |
+
public:
|
| 99 |
+
|
| 100 |
+
WithFormat(const ExpressionType& matrix, const IOFormat& format)
|
| 101 |
+
: m_matrix(matrix), m_format(format)
|
| 102 |
+
{}
|
| 103 |
+
|
| 104 |
+
friend std::ostream & operator << (std::ostream & s, const WithFormat& wf)
|
| 105 |
+
{
|
| 106 |
+
return internal::print_matrix(s, wf.m_matrix.eval(), wf.m_format);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
protected:
|
| 110 |
+
typename ExpressionType::Nested m_matrix;
|
| 111 |
+
IOFormat m_format;
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
namespace internal {
|
| 115 |
+
|
| 116 |
+
// NOTE: This helper is kept for backward compatibility with previous code specializing
|
| 117 |
+
// this internal::significant_decimals_impl structure. In the future we should directly
|
| 118 |
+
// call digits10() which has been introduced in July 2016 in 3.3.
|
| 119 |
+
template<typename Scalar>
|
| 120 |
+
struct significant_decimals_impl
|
| 121 |
+
{
|
| 122 |
+
static inline int run()
|
| 123 |
+
{
|
| 124 |
+
return NumTraits<Scalar>::digits10();
|
| 125 |
+
}
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
/** \internal
|
| 129 |
+
* print the matrix \a _m to the output stream \a s using the output format \a fmt */
|
| 130 |
+
template<typename Derived>
|
| 131 |
+
std::ostream & print_matrix(std::ostream & s, const Derived& _m, const IOFormat& fmt)
|
| 132 |
+
{
|
| 133 |
+
using internal::is_same;
|
| 134 |
+
using internal::conditional;
|
| 135 |
+
|
| 136 |
+
if(_m.size() == 0)
|
| 137 |
+
{
|
| 138 |
+
s << fmt.matPrefix << fmt.matSuffix;
|
| 139 |
+
return s;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
typename Derived::Nested m = _m;
|
| 143 |
+
typedef typename Derived::Scalar Scalar;
|
| 144 |
+
typedef typename
|
| 145 |
+
conditional<
|
| 146 |
+
is_same<Scalar, char>::value ||
|
| 147 |
+
is_same<Scalar, unsigned char>::value ||
|
| 148 |
+
is_same<Scalar, numext::int8_t>::value ||
|
| 149 |
+
is_same<Scalar, numext::uint8_t>::value,
|
| 150 |
+
int,
|
| 151 |
+
typename conditional<
|
| 152 |
+
is_same<Scalar, std::complex<char> >::value ||
|
| 153 |
+
is_same<Scalar, std::complex<unsigned char> >::value ||
|
| 154 |
+
is_same<Scalar, std::complex<numext::int8_t> >::value ||
|
| 155 |
+
is_same<Scalar, std::complex<numext::uint8_t> >::value,
|
| 156 |
+
std::complex<int>,
|
| 157 |
+
const Scalar&
|
| 158 |
+
>::type
|
| 159 |
+
>::type PrintType;
|
| 160 |
+
|
| 161 |
+
Index width = 0;
|
| 162 |
+
|
| 163 |
+
std::streamsize explicit_precision;
|
| 164 |
+
if(fmt.precision == StreamPrecision)
|
| 165 |
+
{
|
| 166 |
+
explicit_precision = 0;
|
| 167 |
+
}
|
| 168 |
+
else if(fmt.precision == FullPrecision)
|
| 169 |
+
{
|
| 170 |
+
if (NumTraits<Scalar>::IsInteger)
|
| 171 |
+
{
|
| 172 |
+
explicit_precision = 0;
|
| 173 |
+
}
|
| 174 |
+
else
|
| 175 |
+
{
|
| 176 |
+
explicit_precision = significant_decimals_impl<Scalar>::run();
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
else
|
| 180 |
+
{
|
| 181 |
+
explicit_precision = fmt.precision;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
std::streamsize old_precision = 0;
|
| 185 |
+
if(explicit_precision) old_precision = s.precision(explicit_precision);
|
| 186 |
+
|
| 187 |
+
bool align_cols = !(fmt.flags & DontAlignCols);
|
| 188 |
+
if(align_cols)
|
| 189 |
+
{
|
| 190 |
+
// compute the largest width
|
| 191 |
+
for(Index j = 0; j < m.cols(); ++j)
|
| 192 |
+
for(Index i = 0; i < m.rows(); ++i)
|
| 193 |
+
{
|
| 194 |
+
std::stringstream sstr;
|
| 195 |
+
sstr.copyfmt(s);
|
| 196 |
+
sstr << static_cast<PrintType>(m.coeff(i,j));
|
| 197 |
+
width = std::max<Index>(width, Index(sstr.str().length()));
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
std::streamsize old_width = s.width();
|
| 201 |
+
char old_fill_character = s.fill();
|
| 202 |
+
s << fmt.matPrefix;
|
| 203 |
+
for(Index i = 0; i < m.rows(); ++i)
|
| 204 |
+
{
|
| 205 |
+
if (i)
|
| 206 |
+
s << fmt.rowSpacer;
|
| 207 |
+
s << fmt.rowPrefix;
|
| 208 |
+
if(width) {
|
| 209 |
+
s.fill(fmt.fill);
|
| 210 |
+
s.width(width);
|
| 211 |
+
}
|
| 212 |
+
s << static_cast<PrintType>(m.coeff(i, 0));
|
| 213 |
+
for(Index j = 1; j < m.cols(); ++j)
|
| 214 |
+
{
|
| 215 |
+
s << fmt.coeffSeparator;
|
| 216 |
+
if(width) {
|
| 217 |
+
s.fill(fmt.fill);
|
| 218 |
+
s.width(width);
|
| 219 |
+
}
|
| 220 |
+
s << static_cast<PrintType>(m.coeff(i, j));
|
| 221 |
+
}
|
| 222 |
+
s << fmt.rowSuffix;
|
| 223 |
+
if( i < m.rows() - 1)
|
| 224 |
+
s << fmt.rowSeparator;
|
| 225 |
+
}
|
| 226 |
+
s << fmt.matSuffix;
|
| 227 |
+
if(explicit_precision) s.precision(old_precision);
|
| 228 |
+
if(width) {
|
| 229 |
+
s.fill(old_fill_character);
|
| 230 |
+
s.width(old_width);
|
| 231 |
+
}
|
| 232 |
+
return s;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
} // end namespace internal
|
| 236 |
+
|
| 237 |
+
/** \relates DenseBase
|
| 238 |
+
*
|
| 239 |
+
* Outputs the matrix, to the given stream.
|
| 240 |
+
*
|
| 241 |
+
* If you wish to print the matrix with a format different than the default, use DenseBase::format().
|
| 242 |
+
*
|
| 243 |
+
* It is also possible to change the default format by defining EIGEN_DEFAULT_IO_FORMAT before including Eigen headers.
|
| 244 |
+
* If not defined, this will automatically be defined to Eigen::IOFormat(), that is the Eigen::IOFormat with default parameters.
|
| 245 |
+
*
|
| 246 |
+
* \sa DenseBase::format()
|
| 247 |
+
*/
|
| 248 |
+
template<typename Derived>
|
| 249 |
+
std::ostream & operator <<
|
| 250 |
+
(std::ostream & s,
|
| 251 |
+
const DenseBase<Derived> & m)
|
| 252 |
+
{
|
| 253 |
+
return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT);
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
} // end namespace Eigen
|
| 257 |
+
|
| 258 |
+
#endif // EIGEN_IO_H
|
include/eigen/Eigen/src/Core/IndexedView.h
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_INDEXED_VIEW_H
|
| 11 |
+
#define EIGEN_INDEXED_VIEW_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
template<typename XprType, typename RowIndices, typename ColIndices>
|
| 18 |
+
struct traits<IndexedView<XprType, RowIndices, ColIndices> >
|
| 19 |
+
: traits<XprType>
|
| 20 |
+
{
|
| 21 |
+
enum {
|
| 22 |
+
RowsAtCompileTime = int(array_size<RowIndices>::value),
|
| 23 |
+
ColsAtCompileTime = int(array_size<ColIndices>::value),
|
| 24 |
+
MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : Dynamic,
|
| 25 |
+
MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : Dynamic,
|
| 26 |
+
|
| 27 |
+
XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
|
| 28 |
+
IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
|
| 29 |
+
: (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
|
| 30 |
+
: XprTypeIsRowMajor,
|
| 31 |
+
|
| 32 |
+
RowIncr = int(get_compile_time_incr<RowIndices>::value),
|
| 33 |
+
ColIncr = int(get_compile_time_incr<ColIndices>::value),
|
| 34 |
+
InnerIncr = IsRowMajor ? ColIncr : RowIncr,
|
| 35 |
+
OuterIncr = IsRowMajor ? RowIncr : ColIncr,
|
| 36 |
+
|
| 37 |
+
HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
|
| 38 |
+
XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret),
|
| 39 |
+
XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret),
|
| 40 |
+
|
| 41 |
+
InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
|
| 42 |
+
IsBlockAlike = InnerIncr==1 && OuterIncr==1,
|
| 43 |
+
IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value,
|
| 44 |
+
|
| 45 |
+
InnerStrideAtCompileTime = InnerIncr<0 || InnerIncr==DynamicIndex || XprInnerStride==Dynamic ? Dynamic : XprInnerStride * InnerIncr,
|
| 46 |
+
OuterStrideAtCompileTime = OuterIncr<0 || OuterIncr==DynamicIndex || XprOuterstride==Dynamic ? Dynamic : XprOuterstride * OuterIncr,
|
| 47 |
+
|
| 48 |
+
ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value,
|
| 49 |
+
ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
|
| 50 |
+
ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
|
| 51 |
+
|
| 52 |
+
// FIXME we deal with compile-time strides if and only if we have DirectAccessBit flag,
|
| 53 |
+
// but this is too strict regarding negative strides...
|
| 54 |
+
DirectAccessMask = (int(InnerIncr)!=UndefinedIncr && int(OuterIncr)!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0,
|
| 55 |
+
FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
|
| 56 |
+
FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
|
| 57 |
+
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
|
| 58 |
+
Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask )) | FlagsLvalueBit | FlagsRowMajorBit | FlagsLinearAccessBit
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
typedef Block<XprType,RowsAtCompileTime,ColsAtCompileTime,IsInnerPannel> BlockType;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
|
| 67 |
+
class IndexedViewImpl;
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
/** \class IndexedView
|
| 71 |
+
* \ingroup Core_Module
|
| 72 |
+
*
|
| 73 |
+
* \brief Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices
|
| 74 |
+
*
|
| 75 |
+
* \tparam XprType the type of the expression in which we are taking the intersections of sub-rows and sub-columns
|
| 76 |
+
* \tparam RowIndices the type of the object defining the sequence of row indices
|
| 77 |
+
* \tparam ColIndices the type of the object defining the sequence of column indices
|
| 78 |
+
*
|
| 79 |
+
* This class represents an expression of a sub-matrix (or sub-vector) defined as the intersection
|
| 80 |
+
* of sub-sets of rows and columns, that are themself defined by generic sequences of row indices \f$ \{r_0,r_1,..r_{m-1}\} \f$
|
| 81 |
+
* and column indices \f$ \{c_0,c_1,..c_{n-1} \}\f$. Let \f$ A \f$ be the nested matrix, then the resulting matrix \f$ B \f$ has \c m
|
| 82 |
+
* rows and \c n columns, and its entries are given by: \f$ B(i,j) = A(r_i,c_j) \f$.
|
| 83 |
+
*
|
| 84 |
+
* The \c RowIndices and \c ColIndices types must be compatible with the following API:
|
| 85 |
+
* \code
|
| 86 |
+
* <integral type> operator[](Index) const;
|
| 87 |
+
* Index size() const;
|
| 88 |
+
* \endcode
|
| 89 |
+
*
|
| 90 |
+
* Typical supported types thus include:
|
| 91 |
+
* - std::vector<int>
|
| 92 |
+
* - std::valarray<int>
|
| 93 |
+
* - std::array<int>
|
| 94 |
+
* - Plain C arrays: int[N]
|
| 95 |
+
* - Eigen::ArrayXi
|
| 96 |
+
* - decltype(ArrayXi::LinSpaced(...))
|
| 97 |
+
* - Any view/expressions of the previous types
|
| 98 |
+
* - Eigen::ArithmeticSequence
|
| 99 |
+
* - Eigen::internal::AllRange (helper for Eigen::all)
|
| 100 |
+
* - Eigen::internal::SingleRange (helper for single index)
|
| 101 |
+
* - etc.
|
| 102 |
+
*
|
| 103 |
+
* In typical usages of %Eigen, this class should never be used directly. It is the return type of
|
| 104 |
+
* DenseBase::operator()(const RowIndices&, const ColIndices&).
|
| 105 |
+
*
|
| 106 |
+
* \sa class Block
|
| 107 |
+
*/
|
| 108 |
+
template<typename XprType, typename RowIndices, typename ColIndices>
|
| 109 |
+
class IndexedView : public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>
|
| 110 |
+
{
|
| 111 |
+
public:
|
| 112 |
+
typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base;
|
| 113 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView)
|
| 114 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView)
|
| 115 |
+
|
| 116 |
+
typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
|
| 117 |
+
typedef typename internal::remove_all<XprType>::type NestedExpression;
|
| 118 |
+
|
| 119 |
+
template<typename T0, typename T1>
|
| 120 |
+
IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices)
|
| 121 |
+
: m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
|
| 122 |
+
{}
|
| 123 |
+
|
| 124 |
+
/** \returns number of rows */
|
| 125 |
+
Index rows() const { return internal::index_list_size(m_rowIndices); }
|
| 126 |
+
|
| 127 |
+
/** \returns number of columns */
|
| 128 |
+
Index cols() const { return internal::index_list_size(m_colIndices); }
|
| 129 |
+
|
| 130 |
+
/** \returns the nested expression */
|
| 131 |
+
const typename internal::remove_all<XprType>::type&
|
| 132 |
+
nestedExpression() const { return m_xpr; }
|
| 133 |
+
|
| 134 |
+
/** \returns the nested expression */
|
| 135 |
+
typename internal::remove_reference<XprType>::type&
|
| 136 |
+
nestedExpression() { return m_xpr; }
|
| 137 |
+
|
| 138 |
+
/** \returns a const reference to the object storing/generating the row indices */
|
| 139 |
+
const RowIndices& rowIndices() const { return m_rowIndices; }
|
| 140 |
+
|
| 141 |
+
/** \returns a const reference to the object storing/generating the column indices */
|
| 142 |
+
const ColIndices& colIndices() const { return m_colIndices; }
|
| 143 |
+
|
| 144 |
+
protected:
|
| 145 |
+
MatrixTypeNested m_xpr;
|
| 146 |
+
RowIndices m_rowIndices;
|
| 147 |
+
ColIndices m_colIndices;
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
// Generic API dispatcher
|
| 152 |
+
template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
|
| 153 |
+
class IndexedViewImpl
|
| 154 |
+
: public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
|
| 155 |
+
{
|
| 156 |
+
public:
|
| 157 |
+
typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type Base;
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
namespace internal {
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
template<typename ArgType, typename RowIndices, typename ColIndices>
|
| 164 |
+
struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
|
| 165 |
+
: evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
|
| 166 |
+
{
|
| 167 |
+
typedef IndexedView<ArgType, RowIndices, ColIndices> XprType;
|
| 168 |
+
|
| 169 |
+
enum {
|
| 170 |
+
CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of row/col index */,
|
| 171 |
+
|
| 172 |
+
FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ? LinearAccessBit : 0,
|
| 173 |
+
|
| 174 |
+
FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
|
| 175 |
+
|
| 176 |
+
Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit /*| LinearAccessBit | DirectAccessBit*/)) | FlagsLinearAccessBit | FlagsRowMajorBit,
|
| 177 |
+
|
| 178 |
+
Alignment = 0
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
|
| 182 |
+
{
|
| 183 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
typedef typename XprType::Scalar Scalar;
|
| 187 |
+
typedef typename XprType::CoeffReturnType CoeffReturnType;
|
| 188 |
+
|
| 189 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 190 |
+
CoeffReturnType coeff(Index row, Index col) const
|
| 191 |
+
{
|
| 192 |
+
eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows()
|
| 193 |
+
&& m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
|
| 194 |
+
return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 198 |
+
Scalar& coeffRef(Index row, Index col)
|
| 199 |
+
{
|
| 200 |
+
eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows()
|
| 201 |
+
&& m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
|
| 202 |
+
return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 206 |
+
Scalar& coeffRef(Index index)
|
| 207 |
+
{
|
| 208 |
+
EIGEN_STATIC_ASSERT_LVALUE(XprType)
|
| 209 |
+
Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
|
| 210 |
+
Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
|
| 211 |
+
eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows()
|
| 212 |
+
&& m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
|
| 213 |
+
return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 217 |
+
const Scalar& coeffRef(Index index) const
|
| 218 |
+
{
|
| 219 |
+
Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
|
| 220 |
+
Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
|
| 221 |
+
eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows()
|
| 222 |
+
&& m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
|
| 223 |
+
return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 227 |
+
const CoeffReturnType coeff(Index index) const
|
| 228 |
+
{
|
| 229 |
+
Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
|
| 230 |
+
Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
|
| 231 |
+
eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows()
|
| 232 |
+
&& m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
|
| 233 |
+
return m_argImpl.coeff( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
protected:
|
| 237 |
+
|
| 238 |
+
evaluator<ArgType> m_argImpl;
|
| 239 |
+
const XprType& m_xpr;
|
| 240 |
+
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
} // end namespace internal
|
| 244 |
+
|
| 245 |
+
} // end namespace Eigen
|
| 246 |
+
|
| 247 |
+
#endif // EIGEN_INDEXED_VIEW_H
|
include/eigen/Eigen/src/Core/Inverse.h
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2014-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_INVERSE_H
|
| 11 |
+
#define EIGEN_INVERSE_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
template<typename XprType,typename StorageKind> class InverseImpl;
|
| 16 |
+
|
| 17 |
+
namespace internal {
|
| 18 |
+
|
| 19 |
+
template<typename XprType>
|
| 20 |
+
struct traits<Inverse<XprType> >
|
| 21 |
+
: traits<typename XprType::PlainObject>
|
| 22 |
+
{
|
| 23 |
+
typedef typename XprType::PlainObject PlainObject;
|
| 24 |
+
typedef traits<PlainObject> BaseTraits;
|
| 25 |
+
enum {
|
| 26 |
+
Flags = BaseTraits::Flags & RowMajorBit
|
| 27 |
+
};
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
} // end namespace internal
|
| 31 |
+
|
| 32 |
+
/** \class Inverse
|
| 33 |
+
*
|
| 34 |
+
* \brief Expression of the inverse of another expression
|
| 35 |
+
*
|
| 36 |
+
* \tparam XprType the type of the expression we are taking the inverse
|
| 37 |
+
*
|
| 38 |
+
* This class represents an abstract expression of A.inverse()
|
| 39 |
+
* and most of the time this is the only way it is used.
|
| 40 |
+
*
|
| 41 |
+
*/
|
| 42 |
+
template<typename XprType>
|
| 43 |
+
class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
|
| 44 |
+
{
|
| 45 |
+
public:
|
| 46 |
+
typedef typename XprType::StorageIndex StorageIndex;
|
| 47 |
+
typedef typename XprType::Scalar Scalar;
|
| 48 |
+
typedef typename internal::ref_selector<XprType>::type XprTypeNested;
|
| 49 |
+
typedef typename internal::remove_all<XprTypeNested>::type XprTypeNestedCleaned;
|
| 50 |
+
typedef typename internal::ref_selector<Inverse>::type Nested;
|
| 51 |
+
typedef typename internal::remove_all<XprType>::type NestedExpression;
|
| 52 |
+
|
| 53 |
+
explicit EIGEN_DEVICE_FUNC Inverse(const XprType &xpr)
|
| 54 |
+
: m_xpr(xpr)
|
| 55 |
+
{}
|
| 56 |
+
|
| 57 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
|
| 58 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
|
| 59 |
+
|
| 60 |
+
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
|
| 61 |
+
|
| 62 |
+
protected:
|
| 63 |
+
XprTypeNested m_xpr;
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
// Generic API dispatcher
|
| 67 |
+
template<typename XprType, typename StorageKind>
|
| 68 |
+
class InverseImpl
|
| 69 |
+
: public internal::generic_xpr_base<Inverse<XprType> >::type
|
| 70 |
+
{
|
| 71 |
+
public:
|
| 72 |
+
typedef typename internal::generic_xpr_base<Inverse<XprType> >::type Base;
|
| 73 |
+
typedef typename XprType::Scalar Scalar;
|
| 74 |
+
private:
|
| 75 |
+
|
| 76 |
+
Scalar coeff(Index row, Index col) const;
|
| 77 |
+
Scalar coeff(Index i) const;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
namespace internal {
|
| 81 |
+
|
| 82 |
+
/** \internal
|
| 83 |
+
* \brief Default evaluator for Inverse expression.
|
| 84 |
+
*
|
| 85 |
+
* This default evaluator for Inverse expression simply evaluate the inverse into a temporary
|
| 86 |
+
* by a call to internal::call_assignment_no_alias.
|
| 87 |
+
* Therefore, inverse implementers only have to specialize Assignment<Dst,Inverse<...>, ...> for
|
| 88 |
+
* there own nested expression.
|
| 89 |
+
*
|
| 90 |
+
* \sa class Inverse
|
| 91 |
+
*/
|
| 92 |
+
template<typename ArgType>
|
| 93 |
+
struct unary_evaluator<Inverse<ArgType> >
|
| 94 |
+
: public evaluator<typename Inverse<ArgType>::PlainObject>
|
| 95 |
+
{
|
| 96 |
+
typedef Inverse<ArgType> InverseType;
|
| 97 |
+
typedef typename InverseType::PlainObject PlainObject;
|
| 98 |
+
typedef evaluator<PlainObject> Base;
|
| 99 |
+
|
| 100 |
+
enum { Flags = Base::Flags | EvalBeforeNestingBit };
|
| 101 |
+
|
| 102 |
+
unary_evaluator(const InverseType& inv_xpr)
|
| 103 |
+
: m_result(inv_xpr.rows(), inv_xpr.cols())
|
| 104 |
+
{
|
| 105 |
+
::new (static_cast<Base*>(this)) Base(m_result);
|
| 106 |
+
internal::call_assignment_no_alias(m_result, inv_xpr);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
protected:
|
| 110 |
+
PlainObject m_result;
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
} // end namespace internal
|
| 114 |
+
|
| 115 |
+
} // end namespace Eigen
|
| 116 |
+
|
| 117 |
+
#endif // EIGEN_INVERSE_H
|
include/eigen/Eigen/src/Core/Map.h
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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yright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_MAP_H
|
| 12 |
+
#define EIGEN_MAP_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
template<typename PlainObjectType, int MapOptions, typename StrideType>
|
| 18 |
+
struct traits<Map<PlainObjectType, MapOptions, StrideType> >
|
| 19 |
+
: public traits<PlainObjectType>
|
| 20 |
+
{
|
| 21 |
+
typedef traits<PlainObjectType> TraitsBase;
|
| 22 |
+
enum {
|
| 23 |
+
PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags&RowMajorBit)==RowMajorBit)
|
| 24 |
+
? PlainObjectType::ColsAtCompileTime
|
| 25 |
+
: PlainObjectType::RowsAtCompileTime,
|
| 26 |
+
|
| 27 |
+
InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
|
| 28 |
+
? int(PlainObjectType::InnerStrideAtCompileTime)
|
| 29 |
+
: int(StrideType::InnerStrideAtCompileTime),
|
| 30 |
+
OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
|
| 31 |
+
? (InnerStrideAtCompileTime==Dynamic || PlainObjectTypeInnerSize==Dynamic
|
| 32 |
+
? Dynamic
|
| 33 |
+
: int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize))
|
| 34 |
+
: int(StrideType::OuterStrideAtCompileTime),
|
| 35 |
+
Alignment = int(MapOptions)&int(AlignedMask),
|
| 36 |
+
Flags0 = TraitsBase::Flags & (~NestByRefBit),
|
| 37 |
+
Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit)
|
| 38 |
+
};
|
| 39 |
+
private:
|
| 40 |
+
enum { Options }; // Expressions don't have Options
|
| 41 |
+
};
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/** \class Map
|
| 45 |
+
* \ingroup Core_Module
|
| 46 |
+
*
|
| 47 |
+
* \brief A matrix or vector expression mapping an existing array of data.
|
| 48 |
+
*
|
| 49 |
+
* \tparam PlainObjectType the equivalent matrix type of the mapped data
|
| 50 |
+
* \tparam MapOptions specifies the pointer alignment in bytes. It can be: \c #Aligned128, \c #Aligned64, \c #Aligned32, \c #Aligned16, \c #Aligned8 or \c #Unaligned.
|
| 51 |
+
* The default is \c #Unaligned.
|
| 52 |
+
* \tparam StrideType optionally specifies strides. By default, Map assumes the memory layout
|
| 53 |
+
* of an ordinary, contiguous array. This can be overridden by specifying strides.
|
| 54 |
+
* The type passed here must be a specialization of the Stride template, see examples below.
|
| 55 |
+
*
|
| 56 |
+
* This class represents a matrix or vector expression mapping an existing array of data.
|
| 57 |
+
* It can be used to let Eigen interface without any overhead with non-Eigen data structures,
|
| 58 |
+
* such as plain C arrays or structures from other libraries. By default, it assumes that the
|
| 59 |
+
* data is laid out contiguously in memory. You can however override this by explicitly specifying
|
| 60 |
+
* inner and outer strides.
|
| 61 |
+
*
|
| 62 |
+
* Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix:
|
| 63 |
+
* \include Map_simple.cpp
|
| 64 |
+
* Output: \verbinclude Map_simple.out
|
| 65 |
+
*
|
| 66 |
+
* If you need to map non-contiguous arrays, you can do so by specifying strides:
|
| 67 |
+
*
|
| 68 |
+
* Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer
|
| 69 |
+
* increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time
|
| 70 |
+
* fixed value.
|
| 71 |
+
* \include Map_inner_stride.cpp
|
| 72 |
+
* Output: \verbinclude Map_inner_stride.out
|
| 73 |
+
*
|
| 74 |
+
* Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping
|
| 75 |
+
* as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns.
|
| 76 |
+
* Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is
|
| 77 |
+
* a short version of \c OuterStride<Dynamic> because the default template parameter of OuterStride
|
| 78 |
+
* is \c Dynamic
|
| 79 |
+
* \include Map_outer_stride.cpp
|
| 80 |
+
* Output: \verbinclude Map_outer_stride.out
|
| 81 |
+
*
|
| 82 |
+
* For more details and for an example of specifying both an inner and an outer stride, see class Stride.
|
| 83 |
+
*
|
| 84 |
+
* \b Tip: to change the array of data mapped by a Map object, you can use the C++
|
| 85 |
+
* placement new syntax:
|
| 86 |
+
*
|
| 87 |
+
* Example: \include Map_placement_new.cpp
|
| 88 |
+
* Output: \verbinclude Map_placement_new.out
|
| 89 |
+
*
|
| 90 |
+
* This class is the return type of PlainObjectBase::Map() but can also be used directly.
|
| 91 |
+
*
|
| 92 |
+
* \sa PlainObjectBase::Map(), \ref TopicStorageOrders
|
| 93 |
+
*/
|
| 94 |
+
template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
|
| 95 |
+
: public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
|
| 96 |
+
{
|
| 97 |
+
public:
|
| 98 |
+
|
| 99 |
+
typedef MapBase<Map> Base;
|
| 100 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(Map)
|
| 101 |
+
|
| 102 |
+
typedef typename Base::PointerType PointerType;
|
| 103 |
+
typedef PointerType PointerArgType;
|
| 104 |
+
EIGEN_DEVICE_FUNC
|
| 105 |
+
inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
|
| 106 |
+
|
| 107 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 108 |
+
inline Index innerStride() const
|
| 109 |
+
{
|
| 110 |
+
return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 114 |
+
inline Index outerStride() const
|
| 115 |
+
{
|
| 116 |
+
return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
|
| 117 |
+
: internal::traits<Map>::OuterStrideAtCompileTime != Dynamic ? Index(internal::traits<Map>::OuterStrideAtCompileTime)
|
| 118 |
+
: IsVectorAtCompileTime ? (this->size() * innerStride())
|
| 119 |
+
: int(Flags)&RowMajorBit ? (this->cols() * innerStride())
|
| 120 |
+
: (this->rows() * innerStride());
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/** Constructor in the fixed-size case.
|
| 124 |
+
*
|
| 125 |
+
* \param dataPtr pointer to the array to map
|
| 126 |
+
* \param stride optional Stride object, passing the strides.
|
| 127 |
+
*/
|
| 128 |
+
EIGEN_DEVICE_FUNC
|
| 129 |
+
explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType())
|
| 130 |
+
: Base(cast_to_pointer_type(dataPtr)), m_stride(stride)
|
| 131 |
+
{
|
| 132 |
+
PlainObjectType::Base::_check_template_params();
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/** Constructor in the dynamic-size vector case.
|
| 136 |
+
*
|
| 137 |
+
* \param dataPtr pointer to the array to map
|
| 138 |
+
* \param size the size of the vector expression
|
| 139 |
+
* \param stride optional Stride object, passing the strides.
|
| 140 |
+
*/
|
| 141 |
+
EIGEN_DEVICE_FUNC
|
| 142 |
+
inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
|
| 143 |
+
: Base(cast_to_pointer_type(dataPtr), size), m_stride(stride)
|
| 144 |
+
{
|
| 145 |
+
PlainObjectType::Base::_check_template_params();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/** Constructor in the dynamic-size matrix case.
|
| 149 |
+
*
|
| 150 |
+
* \param dataPtr pointer to the array to map
|
| 151 |
+
* \param rows the number of rows of the matrix expression
|
| 152 |
+
* \param cols the number of columns of the matrix expression
|
| 153 |
+
* \param stride optional Stride object, passing the strides.
|
| 154 |
+
*/
|
| 155 |
+
EIGEN_DEVICE_FUNC
|
| 156 |
+
inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType())
|
| 157 |
+
: Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride)
|
| 158 |
+
{
|
| 159 |
+
PlainObjectType::Base::_check_template_params();
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
|
| 163 |
+
|
| 164 |
+
protected:
|
| 165 |
+
StrideType m_stride;
|
| 166 |
+
};
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
} // end namespace Eigen
|
| 170 |
+
|
| 171 |
+
#endif // EIGEN_MAP_H
|
include/eigen/Eigen/src/Core/MapBase.h
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_MAPBASE_H
|
| 12 |
+
#define EIGEN_MAPBASE_H
|
| 13 |
+
|
| 14 |
+
#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \
|
| 15 |
+
EIGEN_STATIC_ASSERT((int(internal::evaluator<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \
|
| 16 |
+
YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT)
|
| 17 |
+
|
| 18 |
+
namespace Eigen {
|
| 19 |
+
|
| 20 |
+
/** \ingroup Core_Module
|
| 21 |
+
*
|
| 22 |
+
* \brief Base class for dense Map and Block expression with direct access
|
| 23 |
+
*
|
| 24 |
+
* This base class provides the const low-level accessors (e.g. coeff, coeffRef) of dense
|
| 25 |
+
* Map and Block objects with direct access.
|
| 26 |
+
* Typical users do not have to directly deal with this class.
|
| 27 |
+
*
|
| 28 |
+
* This class can be extended by through the macro plugin \c EIGEN_MAPBASE_PLUGIN.
|
| 29 |
+
* See \link TopicCustomizing_Plugins customizing Eigen \endlink for details.
|
| 30 |
+
*
|
| 31 |
+
* The \c Derived class has to provide the following two methods describing the memory layout:
|
| 32 |
+
* \code Index innerStride() const; \endcode
|
| 33 |
+
* \code Index outerStride() const; \endcode
|
| 34 |
+
*
|
| 35 |
+
* \sa class Map, class Block
|
| 36 |
+
*/
|
| 37 |
+
template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
|
| 38 |
+
: public internal::dense_xpr_base<Derived>::type
|
| 39 |
+
{
|
| 40 |
+
public:
|
| 41 |
+
|
| 42 |
+
typedef typename internal::dense_xpr_base<Derived>::type Base;
|
| 43 |
+
enum {
|
| 44 |
+
RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
|
| 45 |
+
ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
|
| 46 |
+
InnerStrideAtCompileTime = internal::traits<Derived>::InnerStrideAtCompileTime,
|
| 47 |
+
SizeAtCompileTime = Base::SizeAtCompileTime
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 51 |
+
typedef typename internal::traits<Derived>::Scalar Scalar;
|
| 52 |
+
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
|
| 53 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 54 |
+
typedef typename internal::conditional<
|
| 55 |
+
bool(internal::is_lvalue<Derived>::value),
|
| 56 |
+
Scalar *,
|
| 57 |
+
const Scalar *>::type
|
| 58 |
+
PointerType;
|
| 59 |
+
|
| 60 |
+
using Base::derived;
|
| 61 |
+
// using Base::RowsAtCompileTime;
|
| 62 |
+
// using Base::ColsAtCompileTime;
|
| 63 |
+
// using Base::SizeAtCompileTime;
|
| 64 |
+
using Base::MaxRowsAtCompileTime;
|
| 65 |
+
using Base::MaxColsAtCompileTime;
|
| 66 |
+
using Base::MaxSizeAtCompileTime;
|
| 67 |
+
using Base::IsVectorAtCompileTime;
|
| 68 |
+
using Base::Flags;
|
| 69 |
+
using Base::IsRowMajor;
|
| 70 |
+
|
| 71 |
+
using Base::rows;
|
| 72 |
+
using Base::cols;
|
| 73 |
+
using Base::size;
|
| 74 |
+
using Base::coeff;
|
| 75 |
+
using Base::coeffRef;
|
| 76 |
+
using Base::lazyAssign;
|
| 77 |
+
using Base::eval;
|
| 78 |
+
|
| 79 |
+
using Base::innerStride;
|
| 80 |
+
using Base::outerStride;
|
| 81 |
+
using Base::rowStride;
|
| 82 |
+
using Base::colStride;
|
| 83 |
+
|
| 84 |
+
// bug 217 - compile error on ICC 11.1
|
| 85 |
+
using Base::operator=;
|
| 86 |
+
|
| 87 |
+
typedef typename Base::CoeffReturnType CoeffReturnType;
|
| 88 |
+
|
| 89 |
+
/** \copydoc DenseBase::rows() */
|
| 90 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 91 |
+
inline Index rows() const EIGEN_NOEXCEPT { return m_rows.value(); }
|
| 92 |
+
/** \copydoc DenseBase::cols() */
|
| 93 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 94 |
+
inline Index cols() const EIGEN_NOEXCEPT { return m_cols.value(); }
|
| 95 |
+
|
| 96 |
+
/** Returns a pointer to the first coefficient of the matrix or vector.
|
| 97 |
+
*
|
| 98 |
+
* \note When addressing this data, make sure to honor the strides returned by innerStride() and outerStride().
|
| 99 |
+
*
|
| 100 |
+
* \sa innerStride(), outerStride()
|
| 101 |
+
*/
|
| 102 |
+
EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; }
|
| 103 |
+
|
| 104 |
+
/** \copydoc PlainObjectBase::coeff(Index,Index) const */
|
| 105 |
+
EIGEN_DEVICE_FUNC
|
| 106 |
+
inline const Scalar& coeff(Index rowId, Index colId) const
|
| 107 |
+
{
|
| 108 |
+
return m_data[colId * colStride() + rowId * rowStride()];
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/** \copydoc PlainObjectBase::coeff(Index) const */
|
| 112 |
+
EIGEN_DEVICE_FUNC
|
| 113 |
+
inline const Scalar& coeff(Index index) const
|
| 114 |
+
{
|
| 115 |
+
EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
|
| 116 |
+
return m_data[index * innerStride()];
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/** \copydoc PlainObjectBase::coeffRef(Index,Index) const */
|
| 120 |
+
EIGEN_DEVICE_FUNC
|
| 121 |
+
inline const Scalar& coeffRef(Index rowId, Index colId) const
|
| 122 |
+
{
|
| 123 |
+
return this->m_data[colId * colStride() + rowId * rowStride()];
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/** \copydoc PlainObjectBase::coeffRef(Index) const */
|
| 127 |
+
EIGEN_DEVICE_FUNC
|
| 128 |
+
inline const Scalar& coeffRef(Index index) const
|
| 129 |
+
{
|
| 130 |
+
EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
|
| 131 |
+
return this->m_data[index * innerStride()];
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/** \internal */
|
| 135 |
+
template<int LoadMode>
|
| 136 |
+
inline PacketScalar packet(Index rowId, Index colId) const
|
| 137 |
+
{
|
| 138 |
+
return internal::ploadt<PacketScalar, LoadMode>
|
| 139 |
+
(m_data + (colId * colStride() + rowId * rowStride()));
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
/** \internal */
|
| 143 |
+
template<int LoadMode>
|
| 144 |
+
inline PacketScalar packet(Index index) const
|
| 145 |
+
{
|
| 146 |
+
EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
|
| 147 |
+
return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride());
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/** \internal Constructor for fixed size matrices or vectors */
|
| 151 |
+
EIGEN_DEVICE_FUNC
|
| 152 |
+
explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime)
|
| 153 |
+
{
|
| 154 |
+
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
|
| 155 |
+
checkSanity<Derived>();
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/** \internal Constructor for dynamically sized vectors */
|
| 159 |
+
EIGEN_DEVICE_FUNC
|
| 160 |
+
inline MapBase(PointerType dataPtr, Index vecSize)
|
| 161 |
+
: m_data(dataPtr),
|
| 162 |
+
m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)),
|
| 163 |
+
m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime))
|
| 164 |
+
{
|
| 165 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
| 166 |
+
eigen_assert(vecSize >= 0);
|
| 167 |
+
eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize);
|
| 168 |
+
checkSanity<Derived>();
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/** \internal Constructor for dynamically sized matrices */
|
| 172 |
+
EIGEN_DEVICE_FUNC
|
| 173 |
+
inline MapBase(PointerType dataPtr, Index rows, Index cols)
|
| 174 |
+
: m_data(dataPtr), m_rows(rows), m_cols(cols)
|
| 175 |
+
{
|
| 176 |
+
eigen_assert( (dataPtr == 0)
|
| 177 |
+
|| ( rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
|
| 178 |
+
&& cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)));
|
| 179 |
+
checkSanity<Derived>();
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
#ifdef EIGEN_MAPBASE_PLUGIN
|
| 183 |
+
#include EIGEN_MAPBASE_PLUGIN
|
| 184 |
+
#endif
|
| 185 |
+
|
| 186 |
+
protected:
|
| 187 |
+
EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
|
| 188 |
+
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)
|
| 189 |
+
|
| 190 |
+
template<typename T>
|
| 191 |
+
EIGEN_DEVICE_FUNC
|
| 192 |
+
void checkSanity(typename internal::enable_if<(internal::traits<T>::Alignment>0),void*>::type = 0) const
|
| 193 |
+
{
|
| 194 |
+
#if EIGEN_MAX_ALIGN_BYTES>0
|
| 195 |
+
// innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value:
|
| 196 |
+
const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime);
|
| 197 |
+
EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride);
|
| 198 |
+
eigen_assert(( ((internal::UIntPtr(m_data) % internal::traits<Derived>::Alignment) == 0)
|
| 199 |
+
|| (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits<Derived>::Alignment ) && "data is not aligned");
|
| 200 |
+
#endif
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
template<typename T>
|
| 204 |
+
EIGEN_DEVICE_FUNC
|
| 205 |
+
void checkSanity(typename internal::enable_if<internal::traits<T>::Alignment==0,void*>::type = 0) const
|
| 206 |
+
{}
|
| 207 |
+
|
| 208 |
+
PointerType m_data;
|
| 209 |
+
const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
|
| 210 |
+
const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
|
| 211 |
+
};
|
| 212 |
+
|
| 213 |
+
/** \ingroup Core_Module
|
| 214 |
+
*
|
| 215 |
+
* \brief Base class for non-const dense Map and Block expression with direct access
|
| 216 |
+
*
|
| 217 |
+
* This base class provides the non-const low-level accessors (e.g. coeff and coeffRef) of
|
| 218 |
+
* dense Map and Block objects with direct access.
|
| 219 |
+
* It inherits MapBase<Derived, ReadOnlyAccessors> which defines the const variant for reading specific entries.
|
| 220 |
+
*
|
| 221 |
+
* \sa class Map, class Block
|
| 222 |
+
*/
|
| 223 |
+
template<typename Derived> class MapBase<Derived, WriteAccessors>
|
| 224 |
+
: public MapBase<Derived, ReadOnlyAccessors>
|
| 225 |
+
{
|
| 226 |
+
typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase;
|
| 227 |
+
public:
|
| 228 |
+
|
| 229 |
+
typedef MapBase<Derived, ReadOnlyAccessors> Base;
|
| 230 |
+
|
| 231 |
+
typedef typename Base::Scalar Scalar;
|
| 232 |
+
typedef typename Base::PacketScalar PacketScalar;
|
| 233 |
+
typedef typename Base::StorageIndex StorageIndex;
|
| 234 |
+
typedef typename Base::PointerType PointerType;
|
| 235 |
+
|
| 236 |
+
using Base::derived;
|
| 237 |
+
using Base::rows;
|
| 238 |
+
using Base::cols;
|
| 239 |
+
using Base::size;
|
| 240 |
+
using Base::coeff;
|
| 241 |
+
using Base::coeffRef;
|
| 242 |
+
|
| 243 |
+
using Base::innerStride;
|
| 244 |
+
using Base::outerStride;
|
| 245 |
+
using Base::rowStride;
|
| 246 |
+
using Base::colStride;
|
| 247 |
+
|
| 248 |
+
typedef typename internal::conditional<
|
| 249 |
+
internal::is_lvalue<Derived>::value,
|
| 250 |
+
Scalar,
|
| 251 |
+
const Scalar
|
| 252 |
+
>::type ScalarWithConstIfNotLvalue;
|
| 253 |
+
|
| 254 |
+
EIGEN_DEVICE_FUNC
|
| 255 |
+
inline const Scalar* data() const { return this->m_data; }
|
| 256 |
+
EIGEN_DEVICE_FUNC
|
| 257 |
+
inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
|
| 258 |
+
|
| 259 |
+
EIGEN_DEVICE_FUNC
|
| 260 |
+
inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col)
|
| 261 |
+
{
|
| 262 |
+
return this->m_data[col * colStride() + row * rowStride()];
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
EIGEN_DEVICE_FUNC
|
| 266 |
+
inline ScalarWithConstIfNotLvalue& coeffRef(Index index)
|
| 267 |
+
{
|
| 268 |
+
EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
|
| 269 |
+
return this->m_data[index * innerStride()];
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
template<int StoreMode>
|
| 273 |
+
inline void writePacket(Index row, Index col, const PacketScalar& val)
|
| 274 |
+
{
|
| 275 |
+
internal::pstoret<Scalar, PacketScalar, StoreMode>
|
| 276 |
+
(this->m_data + (col * colStride() + row * rowStride()), val);
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
template<int StoreMode>
|
| 280 |
+
inline void writePacket(Index index, const PacketScalar& val)
|
| 281 |
+
{
|
| 282 |
+
EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived)
|
| 283 |
+
internal::pstoret<Scalar, PacketScalar, StoreMode>
|
| 284 |
+
(this->m_data + index * innerStride(), val);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {}
|
| 288 |
+
EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {}
|
| 289 |
+
EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {}
|
| 290 |
+
|
| 291 |
+
EIGEN_DEVICE_FUNC
|
| 292 |
+
Derived& operator=(const MapBase& other)
|
| 293 |
+
{
|
| 294 |
+
ReadOnlyMapBase::Base::operator=(other);
|
| 295 |
+
return derived();
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
// In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
|
| 299 |
+
// see bugs 821 and 920.
|
| 300 |
+
using ReadOnlyMapBase::Base::operator=;
|
| 301 |
+
protected:
|
| 302 |
+
EIGEN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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_MATHFUNCTIONS_H
|
| 12 |
+
#define EIGEN_MATHFUNCTIONS_H
|
| 13 |
+
|
| 14 |
+
// TODO this should better be moved to NumTraits
|
| 15 |
+
// Source: WolframAlpha
|
| 16 |
+
#define EIGEN_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406L
|
| 17 |
+
#define EIGEN_LOG2E 1.442695040888963407359924681001892137426645954152985934135449406931109219L
|
| 18 |
+
#define EIGEN_LN2 0.693147180559945309417232121458176568075500134360255254120680009493393621L
|
| 19 |
+
|
| 20 |
+
namespace Eigen {
|
| 21 |
+
|
| 22 |
+
// On WINCE, std::abs is defined for int only, so let's defined our own overloads:
|
| 23 |
+
// This issue has been confirmed with MSVC 2008 only, but the issue might exist for more recent versions too.
|
| 24 |
+
#if EIGEN_OS_WINCE && EIGEN_COMP_MSVC && EIGEN_COMP_MSVC<=1500
|
| 25 |
+
long abs(long x) { return (labs(x)); }
|
| 26 |
+
double abs(double x) { return (fabs(x)); }
|
| 27 |
+
float abs(float x) { return (fabsf(x)); }
|
| 28 |
+
long double abs(long double x) { return (fabsl(x)); }
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
namespace internal {
|
| 32 |
+
|
| 33 |
+
/** \internal \class global_math_functions_filtering_base
|
| 34 |
+
*
|
| 35 |
+
* What it does:
|
| 36 |
+
* Defines a typedef 'type' as follows:
|
| 37 |
+
* - if type T has a member typedef Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl, then
|
| 38 |
+
* global_math_functions_filtering_base<T>::type is a typedef for it.
|
| 39 |
+
* - otherwise, global_math_functions_filtering_base<T>::type is a typedef for T.
|
| 40 |
+
*
|
| 41 |
+
* How it's used:
|
| 42 |
+
* To allow to defined the global math functions (like sin...) in certain cases, like the Array expressions.
|
| 43 |
+
* When you do sin(array1+array2), the object array1+array2 has a complicated expression type, all what you want to know
|
| 44 |
+
* is that it inherits ArrayBase. So we implement a partial specialization of sin_impl for ArrayBase<Derived>.
|
| 45 |
+
* So we must make sure to use sin_impl<ArrayBase<Derived> > and not sin_impl<Derived>, otherwise our partial specialization
|
| 46 |
+
* won't be used. How does sin know that? That's exactly what global_math_functions_filtering_base tells it.
|
| 47 |
+
*
|
| 48 |
+
* How it's implemented:
|
| 49 |
+
* SFINAE in the style of enable_if. Highly susceptible of breaking compilers. With GCC, it sure does work, but if you replace
|
| 50 |
+
* the typename dummy by an integer template parameter, it doesn't work anymore!
|
| 51 |
+
*/
|
| 52 |
+
|
| 53 |
+
template<typename T, typename dummy = void>
|
| 54 |
+
struct global_math_functions_filtering_base
|
| 55 |
+
{
|
| 56 |
+
typedef T type;
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
template<typename T> struct always_void { typedef void type; };
|
| 60 |
+
|
| 61 |
+
template<typename T>
|
| 62 |
+
struct global_math_functions_filtering_base
|
| 63 |
+
<T,
|
| 64 |
+
typename always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
|
| 65 |
+
>
|
| 66 |
+
{
|
| 67 |
+
typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
#define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>
|
| 71 |
+
#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>::type
|
| 72 |
+
|
| 73 |
+
/****************************************************************************
|
| 74 |
+
* Implementation of real *
|
| 75 |
+
****************************************************************************/
|
| 76 |
+
|
| 77 |
+
template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
|
| 78 |
+
struct real_default_impl
|
| 79 |
+
{
|
| 80 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 81 |
+
EIGEN_DEVICE_FUNC
|
| 82 |
+
static inline RealScalar run(const Scalar& x)
|
| 83 |
+
{
|
| 84 |
+
return x;
|
| 85 |
+
}
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
template<typename Scalar>
|
| 89 |
+
struct real_default_impl<Scalar,true>
|
| 90 |
+
{
|
| 91 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 92 |
+
EIGEN_DEVICE_FUNC
|
| 93 |
+
static inline RealScalar run(const Scalar& x)
|
| 94 |
+
{
|
| 95 |
+
using std::real;
|
| 96 |
+
return real(x);
|
| 97 |
+
}
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
template<typename Scalar> struct real_impl : real_default_impl<Scalar> {};
|
| 101 |
+
|
| 102 |
+
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
| 103 |
+
template<typename T>
|
| 104 |
+
struct real_impl<std::complex<T> >
|
| 105 |
+
{
|
| 106 |
+
typedef T RealScalar;
|
| 107 |
+
EIGEN_DEVICE_FUNC
|
| 108 |
+
static inline T run(const std::complex<T>& x)
|
| 109 |
+
{
|
| 110 |
+
return x.real();
|
| 111 |
+
}
|
| 112 |
+
};
|
| 113 |
+
#endif
|
| 114 |
+
|
| 115 |
+
template<typename Scalar>
|
| 116 |
+
struct real_retval
|
| 117 |
+
{
|
| 118 |
+
typedef typename NumTraits<Scalar>::Real type;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
/****************************************************************************
|
| 122 |
+
* Implementation of imag *
|
| 123 |
+
****************************************************************************/
|
| 124 |
+
|
| 125 |
+
template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
|
| 126 |
+
struct imag_default_impl
|
| 127 |
+
{
|
| 128 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 129 |
+
EIGEN_DEVICE_FUNC
|
| 130 |
+
static inline RealScalar run(const Scalar&)
|
| 131 |
+
{
|
| 132 |
+
return RealScalar(0);
|
| 133 |
+
}
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
template<typename Scalar>
|
| 137 |
+
struct imag_default_impl<Scalar,true>
|
| 138 |
+
{
|
| 139 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 140 |
+
EIGEN_DEVICE_FUNC
|
| 141 |
+
static inline RealScalar run(const Scalar& x)
|
| 142 |
+
{
|
| 143 |
+
using std::imag;
|
| 144 |
+
return imag(x);
|
| 145 |
+
}
|
| 146 |
+
};
|
| 147 |
+
|
| 148 |
+
template<typename Scalar> struct imag_impl : imag_default_impl<Scalar> {};
|
| 149 |
+
|
| 150 |
+
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
| 151 |
+
template<typename T>
|
| 152 |
+
struct imag_impl<std::complex<T> >
|
| 153 |
+
{
|
| 154 |
+
typedef T RealScalar;
|
| 155 |
+
EIGEN_DEVICE_FUNC
|
| 156 |
+
static inline T run(const std::complex<T>& x)
|
| 157 |
+
{
|
| 158 |
+
return x.imag();
|
| 159 |
+
}
|
| 160 |
+
};
|
| 161 |
+
#endif
|
| 162 |
+
|
| 163 |
+
template<typename Scalar>
|
| 164 |
+
struct imag_retval
|
| 165 |
+
{
|
| 166 |
+
typedef typename NumTraits<Scalar>::Real type;
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
/****************************************************************************
|
| 170 |
+
* Implementation of real_ref *
|
| 171 |
+
****************************************************************************/
|
| 172 |
+
|
| 173 |
+
template<typename Scalar>
|
| 174 |
+
struct real_ref_impl
|
| 175 |
+
{
|
| 176 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 177 |
+
EIGEN_DEVICE_FUNC
|
| 178 |
+
static inline RealScalar& run(Scalar& x)
|
| 179 |
+
{
|
| 180 |
+
return reinterpret_cast<RealScalar*>(&x)[0];
|
| 181 |
+
}
|
| 182 |
+
EIGEN_DEVICE_FUNC
|
| 183 |
+
static inline const RealScalar& run(const Scalar& x)
|
| 184 |
+
{
|
| 185 |
+
return reinterpret_cast<const RealScalar*>(&x)[0];
|
| 186 |
+
}
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
template<typename Scalar>
|
| 190 |
+
struct real_ref_retval
|
| 191 |
+
{
|
| 192 |
+
typedef typename NumTraits<Scalar>::Real & type;
|
| 193 |
+
};
|
| 194 |
+
|
| 195 |
+
/****************************************************************************
|
| 196 |
+
* Implementation of imag_ref *
|
| 197 |
+
****************************************************************************/
|
| 198 |
+
|
| 199 |
+
template<typename Scalar, bool IsComplex>
|
| 200 |
+
struct imag_ref_default_impl
|
| 201 |
+
{
|
| 202 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 203 |
+
EIGEN_DEVICE_FUNC
|
| 204 |
+
static inline RealScalar& run(Scalar& x)
|
| 205 |
+
{
|
| 206 |
+
return reinterpret_cast<RealScalar*>(&x)[1];
|
| 207 |
+
}
|
| 208 |
+
EIGEN_DEVICE_FUNC
|
| 209 |
+
static inline const RealScalar& run(const Scalar& x)
|
| 210 |
+
{
|
| 211 |
+
return reinterpret_cast<RealScalar*>(&x)[1];
|
| 212 |
+
}
|
| 213 |
+
};
|
| 214 |
+
|
| 215 |
+
template<typename Scalar>
|
| 216 |
+
struct imag_ref_default_impl<Scalar, false>
|
| 217 |
+
{
|
| 218 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 219 |
+
static inline Scalar run(Scalar&)
|
| 220 |
+
{
|
| 221 |
+
return Scalar(0);
|
| 222 |
+
}
|
| 223 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 224 |
+
static inline const Scalar run(const Scalar&)
|
| 225 |
+
{
|
| 226 |
+
return Scalar(0);
|
| 227 |
+
}
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
template<typename Scalar>
|
| 231 |
+
struct imag_ref_impl : imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
|
| 232 |
+
|
| 233 |
+
template<typename Scalar>
|
| 234 |
+
struct imag_ref_retval
|
| 235 |
+
{
|
| 236 |
+
typedef typename NumTraits<Scalar>::Real & type;
|
| 237 |
+
};
|
| 238 |
+
|
| 239 |
+
/****************************************************************************
|
| 240 |
+
* Implementation of conj *
|
| 241 |
+
****************************************************************************/
|
| 242 |
+
|
| 243 |
+
template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
|
| 244 |
+
struct conj_default_impl
|
| 245 |
+
{
|
| 246 |
+
EIGEN_DEVICE_FUNC
|
| 247 |
+
static inline Scalar run(const Scalar& x)
|
| 248 |
+
{
|
| 249 |
+
return x;
|
| 250 |
+
}
|
| 251 |
+
};
|
| 252 |
+
|
| 253 |
+
template<typename Scalar>
|
| 254 |
+
struct conj_default_impl<Scalar,true>
|
| 255 |
+
{
|
| 256 |
+
EIGEN_DEVICE_FUNC
|
| 257 |
+
static inline Scalar run(const Scalar& x)
|
| 258 |
+
{
|
| 259 |
+
using std::conj;
|
| 260 |
+
return conj(x);
|
| 261 |
+
}
|
| 262 |
+
};
|
| 263 |
+
|
| 264 |
+
template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
|
| 265 |
+
struct conj_impl : conj_default_impl<Scalar, IsComplex> {};
|
| 266 |
+
|
| 267 |
+
template<typename Scalar>
|
| 268 |
+
struct conj_retval
|
| 269 |
+
{
|
| 270 |
+
typedef Scalar type;
|
| 271 |
+
};
|
| 272 |
+
|
| 273 |
+
/****************************************************************************
|
| 274 |
+
* Implementation of abs2 *
|
| 275 |
+
****************************************************************************/
|
| 276 |
+
|
| 277 |
+
template<typename Scalar,bool IsComplex>
|
| 278 |
+
struct abs2_impl_default
|
| 279 |
+
{
|
| 280 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 281 |
+
EIGEN_DEVICE_FUNC
|
| 282 |
+
static inline RealScalar run(const Scalar& x)
|
| 283 |
+
{
|
| 284 |
+
return x*x;
|
| 285 |
+
}
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
template<typename Scalar>
|
| 289 |
+
struct abs2_impl_default<Scalar, true> // IsComplex
|
| 290 |
+
{
|
| 291 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 292 |
+
EIGEN_DEVICE_FUNC
|
| 293 |
+
static inline RealScalar run(const Scalar& x)
|
| 294 |
+
{
|
| 295 |
+
return x.real()*x.real() + x.imag()*x.imag();
|
| 296 |
+
}
|
| 297 |
+
};
|
| 298 |
+
|
| 299 |
+
template<typename Scalar>
|
| 300 |
+
struct abs2_impl
|
| 301 |
+
{
|
| 302 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 303 |
+
EIGEN_DEVICE_FUNC
|
| 304 |
+
static inline RealScalar run(const Scalar& x)
|
| 305 |
+
{
|
| 306 |
+
return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(x);
|
| 307 |
+
}
|
| 308 |
+
};
|
| 309 |
+
|
| 310 |
+
template<typename Scalar>
|
| 311 |
+
struct abs2_retval
|
| 312 |
+
{
|
| 313 |
+
typedef typename NumTraits<Scalar>::Real type;
|
| 314 |
+
};
|
| 315 |
+
|
| 316 |
+
/****************************************************************************
|
| 317 |
+
* Implementation of sqrt/rsqrt *
|
| 318 |
+
****************************************************************************/
|
| 319 |
+
|
| 320 |
+
template<typename Scalar>
|
| 321 |
+
struct sqrt_impl
|
| 322 |
+
{
|
| 323 |
+
EIGEN_DEVICE_FUNC
|
| 324 |
+
static EIGEN_ALWAYS_INLINE Scalar run(const Scalar& x)
|
| 325 |
+
{
|
| 326 |
+
EIGEN_USING_STD(sqrt);
|
| 327 |
+
return sqrt(x);
|
| 328 |
+
}
|
| 329 |
+
};
|
| 330 |
+
|
| 331 |
+
// Complex sqrt defined in MathFunctionsImpl.h.
|
| 332 |
+
template<typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_sqrt(const std::complex<T>& a_x);
|
| 333 |
+
|
| 334 |
+
// Custom implementation is faster than `std::sqrt`, works on
|
| 335 |
+
// GPU, and correctly handles special cases (unlike MSVC).
|
| 336 |
+
template<typename T>
|
| 337 |
+
struct sqrt_impl<std::complex<T> >
|
| 338 |
+
{
|
| 339 |
+
EIGEN_DEVICE_FUNC
|
| 340 |
+
static EIGEN_ALWAYS_INLINE std::complex<T> run(const std::complex<T>& x)
|
| 341 |
+
{
|
| 342 |
+
return complex_sqrt<T>(x);
|
| 343 |
+
}
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
template<typename Scalar>
|
| 347 |
+
struct sqrt_retval
|
| 348 |
+
{
|
| 349 |
+
typedef Scalar type;
|
| 350 |
+
};
|
| 351 |
+
|
| 352 |
+
// Default implementation relies on numext::sqrt, at bottom of file.
|
| 353 |
+
template<typename T>
|
| 354 |
+
struct rsqrt_impl;
|
| 355 |
+
|
| 356 |
+
// Complex rsqrt defined in MathFunctionsImpl.h.
|
| 357 |
+
template<typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_rsqrt(const std::complex<T>& a_x);
|
| 358 |
+
|
| 359 |
+
template<typename T>
|
| 360 |
+
struct rsqrt_impl<std::complex<T> >
|
| 361 |
+
{
|
| 362 |
+
EIGEN_DEVICE_FUNC
|
| 363 |
+
static EIGEN_ALWAYS_INLINE std::complex<T> run(const std::complex<T>& x)
|
| 364 |
+
{
|
| 365 |
+
return complex_rsqrt<T>(x);
|
| 366 |
+
}
|
| 367 |
+
};
|
| 368 |
+
|
| 369 |
+
template<typename Scalar>
|
| 370 |
+
struct rsqrt_retval
|
| 371 |
+
{
|
| 372 |
+
typedef Scalar type;
|
| 373 |
+
};
|
| 374 |
+
|
| 375 |
+
/****************************************************************************
|
| 376 |
+
* Implementation of norm1 *
|
| 377 |
+
****************************************************************************/
|
| 378 |
+
|
| 379 |
+
template<typename Scalar, bool IsComplex>
|
| 380 |
+
struct norm1_default_impl;
|
| 381 |
+
|
| 382 |
+
template<typename Scalar>
|
| 383 |
+
struct norm1_default_impl<Scalar,true>
|
| 384 |
+
{
|
| 385 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 386 |
+
EIGEN_DEVICE_FUNC
|
| 387 |
+
static inline RealScalar run(const Scalar& x)
|
| 388 |
+
{
|
| 389 |
+
EIGEN_USING_STD(abs);
|
| 390 |
+
return abs(x.real()) + abs(x.imag());
|
| 391 |
+
}
|
| 392 |
+
};
|
| 393 |
+
|
| 394 |
+
template<typename Scalar>
|
| 395 |
+
struct norm1_default_impl<Scalar, false>
|
| 396 |
+
{
|
| 397 |
+
EIGEN_DEVICE_FUNC
|
| 398 |
+
static inline Scalar run(const Scalar& x)
|
| 399 |
+
{
|
| 400 |
+
EIGEN_USING_STD(abs);
|
| 401 |
+
return abs(x);
|
| 402 |
+
}
|
| 403 |
+
};
|
| 404 |
+
|
| 405 |
+
template<typename Scalar>
|
| 406 |
+
struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
|
| 407 |
+
|
| 408 |
+
template<typename Scalar>
|
| 409 |
+
struct norm1_retval
|
| 410 |
+
{
|
| 411 |
+
typedef typename NumTraits<Scalar>::Real type;
|
| 412 |
+
};
|
| 413 |
+
|
| 414 |
+
/****************************************************************************
|
| 415 |
+
* Implementation of hypot *
|
| 416 |
+
****************************************************************************/
|
| 417 |
+
|
| 418 |
+
template<typename Scalar> struct hypot_impl;
|
| 419 |
+
|
| 420 |
+
template<typename Scalar>
|
| 421 |
+
struct hypot_retval
|
| 422 |
+
{
|
| 423 |
+
typedef typename NumTraits<Scalar>::Real type;
|
| 424 |
+
};
|
| 425 |
+
|
| 426 |
+
/****************************************************************************
|
| 427 |
+
* Implementation of cast *
|
| 428 |
+
****************************************************************************/
|
| 429 |
+
|
| 430 |
+
template<typename OldType, typename NewType, typename EnableIf = void>
|
| 431 |
+
struct cast_impl
|
| 432 |
+
{
|
| 433 |
+
EIGEN_DEVICE_FUNC
|
| 434 |
+
static inline NewType run(const OldType& x)
|
| 435 |
+
{
|
| 436 |
+
return static_cast<NewType>(x);
|
| 437 |
+
}
|
| 438 |
+
};
|
| 439 |
+
|
| 440 |
+
// Casting from S -> Complex<T> leads to an implicit conversion from S to T,
|
| 441 |
+
// generating warnings on clang. Here we explicitly cast the real component.
|
| 442 |
+
template<typename OldType, typename NewType>
|
| 443 |
+
struct cast_impl<OldType, NewType,
|
| 444 |
+
typename internal::enable_if<
|
| 445 |
+
!NumTraits<OldType>::IsComplex && NumTraits<NewType>::IsComplex
|
| 446 |
+
>::type>
|
| 447 |
+
{
|
| 448 |
+
EIGEN_DEVICE_FUNC
|
| 449 |
+
static inline NewType run(const OldType& x)
|
| 450 |
+
{
|
| 451 |
+
typedef typename NumTraits<NewType>::Real NewReal;
|
| 452 |
+
return static_cast<NewType>(static_cast<NewReal>(x));
|
| 453 |
+
}
|
| 454 |
+
};
|
| 455 |
+
|
| 456 |
+
// here, for once, we're plainly returning NewType: we don't want cast to do weird things.
|
| 457 |
+
|
| 458 |
+
template<typename OldType, typename NewType>
|
| 459 |
+
EIGEN_DEVICE_FUNC
|
| 460 |
+
inline NewType cast(const OldType& x)
|
| 461 |
+
{
|
| 462 |
+
return cast_impl<OldType, NewType>::run(x);
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
/****************************************************************************
|
| 466 |
+
* Implementation of round *
|
| 467 |
+
****************************************************************************/
|
| 468 |
+
|
| 469 |
+
template<typename Scalar>
|
| 470 |
+
struct round_impl
|
| 471 |
+
{
|
| 472 |
+
EIGEN_DEVICE_FUNC
|
| 473 |
+
static inline Scalar run(const Scalar& x)
|
| 474 |
+
{
|
| 475 |
+
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
|
| 476 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 477 |
+
EIGEN_USING_STD(round);
|
| 478 |
+
#endif
|
| 479 |
+
return Scalar(round(x));
|
| 480 |
+
}
|
| 481 |
+
};
|
| 482 |
+
|
| 483 |
+
#if !EIGEN_HAS_CXX11_MATH
|
| 484 |
+
#if EIGEN_HAS_C99_MATH
|
| 485 |
+
// Use ::roundf for float.
|
| 486 |
+
template<>
|
| 487 |
+
struct round_impl<float> {
|
| 488 |
+
EIGEN_DEVICE_FUNC
|
| 489 |
+
static inline float run(const float& x)
|
| 490 |
+
{
|
| 491 |
+
return ::roundf(x);
|
| 492 |
+
}
|
| 493 |
+
};
|
| 494 |
+
#else
|
| 495 |
+
template<typename Scalar>
|
| 496 |
+
struct round_using_floor_ceil_impl
|
| 497 |
+
{
|
| 498 |
+
EIGEN_DEVICE_FUNC
|
| 499 |
+
static inline Scalar run(const Scalar& x)
|
| 500 |
+
{
|
| 501 |
+
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
|
| 502 |
+
// Without C99 round/roundf, resort to floor/ceil.
|
| 503 |
+
EIGEN_USING_STD(floor);
|
| 504 |
+
EIGEN_USING_STD(ceil);
|
| 505 |
+
// If not enough precision to resolve a decimal at all, return the input.
|
| 506 |
+
// Otherwise, adding 0.5 can trigger an increment by 1.
|
| 507 |
+
const Scalar limit = Scalar(1ull << (NumTraits<Scalar>::digits() - 1));
|
| 508 |
+
if (x >= limit || x <= -limit) {
|
| 509 |
+
return x;
|
| 510 |
+
}
|
| 511 |
+
return (x > Scalar(0)) ? Scalar(floor(x + Scalar(0.5))) : Scalar(ceil(x - Scalar(0.5)));
|
| 512 |
+
}
|
| 513 |
+
};
|
| 514 |
+
|
| 515 |
+
template<>
|
| 516 |
+
struct round_impl<float> : round_using_floor_ceil_impl<float> {};
|
| 517 |
+
|
| 518 |
+
template<>
|
| 519 |
+
struct round_impl<double> : round_using_floor_ceil_impl<double> {};
|
| 520 |
+
#endif // EIGEN_HAS_C99_MATH
|
| 521 |
+
#endif // !EIGEN_HAS_CXX11_MATH
|
| 522 |
+
|
| 523 |
+
template<typename Scalar>
|
| 524 |
+
struct round_retval
|
| 525 |
+
{
|
| 526 |
+
typedef Scalar type;
|
| 527 |
+
};
|
| 528 |
+
|
| 529 |
+
/****************************************************************************
|
| 530 |
+
* Implementation of rint *
|
| 531 |
+
****************************************************************************/
|
| 532 |
+
|
| 533 |
+
template<typename Scalar>
|
| 534 |
+
struct rint_impl {
|
| 535 |
+
EIGEN_DEVICE_FUNC
|
| 536 |
+
static inline Scalar run(const Scalar& x)
|
| 537 |
+
{
|
| 538 |
+
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
|
| 539 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 540 |
+
EIGEN_USING_STD(rint);
|
| 541 |
+
#endif
|
| 542 |
+
return rint(x);
|
| 543 |
+
}
|
| 544 |
+
};
|
| 545 |
+
|
| 546 |
+
#if !EIGEN_HAS_CXX11_MATH
|
| 547 |
+
template<>
|
| 548 |
+
struct rint_impl<double> {
|
| 549 |
+
EIGEN_DEVICE_FUNC
|
| 550 |
+
static inline double run(const double& x)
|
| 551 |
+
{
|
| 552 |
+
return ::rint(x);
|
| 553 |
+
}
|
| 554 |
+
};
|
| 555 |
+
template<>
|
| 556 |
+
struct rint_impl<float> {
|
| 557 |
+
EIGEN_DEVICE_FUNC
|
| 558 |
+
static inline float run(const float& x)
|
| 559 |
+
{
|
| 560 |
+
return ::rintf(x);
|
| 561 |
+
}
|
| 562 |
+
};
|
| 563 |
+
#endif
|
| 564 |
+
|
| 565 |
+
template<typename Scalar>
|
| 566 |
+
struct rint_retval
|
| 567 |
+
{
|
| 568 |
+
typedef Scalar type;
|
| 569 |
+
};
|
| 570 |
+
|
| 571 |
+
/****************************************************************************
|
| 572 |
+
* Implementation of arg *
|
| 573 |
+
****************************************************************************/
|
| 574 |
+
|
| 575 |
+
// Visual Studio 2017 has a bug where arg(float) returns 0 for negative inputs.
|
| 576 |
+
// This seems to be fixed in VS 2019.
|
| 577 |
+
#if EIGEN_HAS_CXX11_MATH && (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
|
| 578 |
+
// std::arg is only defined for types of std::complex, or integer types or float/double/long double
|
| 579 |
+
template<typename Scalar,
|
| 580 |
+
bool HasStdImpl = NumTraits<Scalar>::IsComplex || is_integral<Scalar>::value
|
| 581 |
+
|| is_same<Scalar, float>::value || is_same<Scalar, double>::value
|
| 582 |
+
|| is_same<Scalar, long double>::value >
|
| 583 |
+
struct arg_default_impl;
|
| 584 |
+
|
| 585 |
+
template<typename Scalar>
|
| 586 |
+
struct arg_default_impl<Scalar, true> {
|
| 587 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 588 |
+
EIGEN_DEVICE_FUNC
|
| 589 |
+
static inline RealScalar run(const Scalar& x)
|
| 590 |
+
{
|
| 591 |
+
// There is no official ::arg on device in CUDA/HIP, so we always need to use std::arg.
|
| 592 |
+
using std::arg;
|
| 593 |
+
return static_cast<RealScalar>(arg(x));
|
| 594 |
+
}
|
| 595 |
+
};
|
| 596 |
+
|
| 597 |
+
// Must be non-complex floating-point type (e.g. half/bfloat16).
|
| 598 |
+
template<typename Scalar>
|
| 599 |
+
struct arg_default_impl<Scalar, false> {
|
| 600 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 601 |
+
EIGEN_DEVICE_FUNC
|
| 602 |
+
static inline RealScalar run(const Scalar& x)
|
| 603 |
+
{
|
| 604 |
+
return (x < Scalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
|
| 605 |
+
}
|
| 606 |
+
};
|
| 607 |
+
#else
|
| 608 |
+
template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
|
| 609 |
+
struct arg_default_impl
|
| 610 |
+
{
|
| 611 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 612 |
+
EIGEN_DEVICE_FUNC
|
| 613 |
+
static inline RealScalar run(const Scalar& x)
|
| 614 |
+
{
|
| 615 |
+
return (x < RealScalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
|
| 616 |
+
}
|
| 617 |
+
};
|
| 618 |
+
|
| 619 |
+
template<typename Scalar>
|
| 620 |
+
struct arg_default_impl<Scalar,true>
|
| 621 |
+
{
|
| 622 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 623 |
+
EIGEN_DEVICE_FUNC
|
| 624 |
+
static inline RealScalar run(const Scalar& x)
|
| 625 |
+
{
|
| 626 |
+
EIGEN_USING_STD(arg);
|
| 627 |
+
return arg(x);
|
| 628 |
+
}
|
| 629 |
+
};
|
| 630 |
+
#endif
|
| 631 |
+
template<typename Scalar> struct arg_impl : arg_default_impl<Scalar> {};
|
| 632 |
+
|
| 633 |
+
template<typename Scalar>
|
| 634 |
+
struct arg_retval
|
| 635 |
+
{
|
| 636 |
+
typedef typename NumTraits<Scalar>::Real type;
|
| 637 |
+
};
|
| 638 |
+
|
| 639 |
+
/****************************************************************************
|
| 640 |
+
* Implementation of expm1 *
|
| 641 |
+
****************************************************************************/
|
| 642 |
+
|
| 643 |
+
// This implementation is based on GSL Math's expm1.
|
| 644 |
+
namespace std_fallback {
|
| 645 |
+
// fallback expm1 implementation in case there is no expm1(Scalar) function in namespace of Scalar,
|
| 646 |
+
// or that there is no suitable std::expm1 function available. Implementation
|
| 647 |
+
// attributed to Kahan. See: http://www.plunk.org/~hatch/rightway.php.
|
| 648 |
+
template<typename Scalar>
|
| 649 |
+
EIGEN_DEVICE_FUNC inline Scalar expm1(const Scalar& x) {
|
| 650 |
+
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
| 651 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 652 |
+
|
| 653 |
+
EIGEN_USING_STD(exp);
|
| 654 |
+
Scalar u = exp(x);
|
| 655 |
+
if (numext::equal_strict(u, Scalar(1))) {
|
| 656 |
+
return x;
|
| 657 |
+
}
|
| 658 |
+
Scalar um1 = u - RealScalar(1);
|
| 659 |
+
if (numext::equal_strict(um1, Scalar(-1))) {
|
| 660 |
+
return RealScalar(-1);
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
EIGEN_USING_STD(log);
|
| 664 |
+
Scalar logu = log(u);
|
| 665 |
+
return numext::equal_strict(u, logu) ? u : (u - RealScalar(1)) * x / logu;
|
| 666 |
+
}
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
template<typename Scalar>
|
| 670 |
+
struct expm1_impl {
|
| 671 |
+
EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
|
| 672 |
+
{
|
| 673 |
+
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
| 674 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 675 |
+
using std::expm1;
|
| 676 |
+
#else
|
| 677 |
+
using std_fallback::expm1;
|
| 678 |
+
#endif
|
| 679 |
+
return expm1(x);
|
| 680 |
+
}
|
| 681 |
+
};
|
| 682 |
+
|
| 683 |
+
template<typename Scalar>
|
| 684 |
+
struct expm1_retval
|
| 685 |
+
{
|
| 686 |
+
typedef Scalar type;
|
| 687 |
+
};
|
| 688 |
+
|
| 689 |
+
/****************************************************************************
|
| 690 |
+
* Implementation of log *
|
| 691 |
+
****************************************************************************/
|
| 692 |
+
|
| 693 |
+
// Complex log defined in MathFunctionsImpl.h.
|
| 694 |
+
template<typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_log(const std::complex<T>& z);
|
| 695 |
+
|
| 696 |
+
template<typename Scalar>
|
| 697 |
+
struct log_impl {
|
| 698 |
+
EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
|
| 699 |
+
{
|
| 700 |
+
EIGEN_USING_STD(log);
|
| 701 |
+
return static_cast<Scalar>(log(x));
|
| 702 |
+
}
|
| 703 |
+
};
|
| 704 |
+
|
| 705 |
+
template<typename Scalar>
|
| 706 |
+
struct log_impl<std::complex<Scalar> > {
|
| 707 |
+
EIGEN_DEVICE_FUNC static inline std::complex<Scalar> run(const std::complex<Scalar>& z)
|
| 708 |
+
{
|
| 709 |
+
return complex_log(z);
|
| 710 |
+
}
|
| 711 |
+
};
|
| 712 |
+
|
| 713 |
+
/****************************************************************************
|
| 714 |
+
* Implementation of log1p *
|
| 715 |
+
****************************************************************************/
|
| 716 |
+
|
| 717 |
+
namespace std_fallback {
|
| 718 |
+
// fallback log1p implementation in case there is no log1p(Scalar) function in namespace of Scalar,
|
| 719 |
+
// or that there is no suitable std::log1p function available
|
| 720 |
+
template<typename Scalar>
|
| 721 |
+
EIGEN_DEVICE_FUNC inline Scalar log1p(const Scalar& x) {
|
| 722 |
+
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
| 723 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 724 |
+
EIGEN_USING_STD(log);
|
| 725 |
+
Scalar x1p = RealScalar(1) + x;
|
| 726 |
+
Scalar log_1p = log_impl<Scalar>::run(x1p);
|
| 727 |
+
const bool is_small = numext::equal_strict(x1p, Scalar(1));
|
| 728 |
+
const bool is_inf = numext::equal_strict(x1p, log_1p);
|
| 729 |
+
return (is_small || is_inf) ? x : x * (log_1p / (x1p - RealScalar(1)));
|
| 730 |
+
}
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
template<typename Scalar>
|
| 734 |
+
struct log1p_impl {
|
| 735 |
+
EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
|
| 736 |
+
{
|
| 737 |
+
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
| 738 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 739 |
+
using std::log1p;
|
| 740 |
+
#else
|
| 741 |
+
using std_fallback::log1p;
|
| 742 |
+
#endif
|
| 743 |
+
return log1p(x);
|
| 744 |
+
}
|
| 745 |
+
};
|
| 746 |
+
|
| 747 |
+
// Specialization for complex types that are not supported by std::log1p.
|
| 748 |
+
template <typename RealScalar>
|
| 749 |
+
struct log1p_impl<std::complex<RealScalar> > {
|
| 750 |
+
EIGEN_DEVICE_FUNC static inline std::complex<RealScalar> run(
|
| 751 |
+
const std::complex<RealScalar>& x) {
|
| 752 |
+
EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
|
| 753 |
+
return std_fallback::log1p(x);
|
| 754 |
+
}
|
| 755 |
+
};
|
| 756 |
+
|
| 757 |
+
template<typename Scalar>
|
| 758 |
+
struct log1p_retval
|
| 759 |
+
{
|
| 760 |
+
typedef Scalar type;
|
| 761 |
+
};
|
| 762 |
+
|
| 763 |
+
/****************************************************************************
|
| 764 |
+
* Implementation of pow *
|
| 765 |
+
****************************************************************************/
|
| 766 |
+
|
| 767 |
+
template<typename ScalarX,typename ScalarY, bool IsInteger = NumTraits<ScalarX>::IsInteger&&NumTraits<ScalarY>::IsInteger>
|
| 768 |
+
struct pow_impl
|
| 769 |
+
{
|
| 770 |
+
//typedef Scalar retval;
|
| 771 |
+
typedef typename ScalarBinaryOpTraits<ScalarX,ScalarY,internal::scalar_pow_op<ScalarX,ScalarY> >::ReturnType result_type;
|
| 772 |
+
static EIGEN_DEVICE_FUNC inline result_type run(const ScalarX& x, const ScalarY& y)
|
| 773 |
+
{
|
| 774 |
+
EIGEN_USING_STD(pow);
|
| 775 |
+
return pow(x, y);
|
| 776 |
+
}
|
| 777 |
+
};
|
| 778 |
+
|
| 779 |
+
template<typename ScalarX,typename ScalarY>
|
| 780 |
+
struct pow_impl<ScalarX,ScalarY, true>
|
| 781 |
+
{
|
| 782 |
+
typedef ScalarX result_type;
|
| 783 |
+
static EIGEN_DEVICE_FUNC inline ScalarX run(ScalarX x, ScalarY y)
|
| 784 |
+
{
|
| 785 |
+
ScalarX res(1);
|
| 786 |
+
eigen_assert(!NumTraits<ScalarY>::IsSigned || y >= 0);
|
| 787 |
+
if(y & 1) res *= x;
|
| 788 |
+
y >>= 1;
|
| 789 |
+
while(y)
|
| 790 |
+
{
|
| 791 |
+
x *= x;
|
| 792 |
+
if(y&1) res *= x;
|
| 793 |
+
y >>= 1;
|
| 794 |
+
}
|
| 795 |
+
return res;
|
| 796 |
+
}
|
| 797 |
+
};
|
| 798 |
+
|
| 799 |
+
/****************************************************************************
|
| 800 |
+
* Implementation of random *
|
| 801 |
+
****************************************************************************/
|
| 802 |
+
|
| 803 |
+
template<typename Scalar,
|
| 804 |
+
bool IsComplex,
|
| 805 |
+
bool IsInteger>
|
| 806 |
+
struct random_default_impl {};
|
| 807 |
+
|
| 808 |
+
template<typename Scalar>
|
| 809 |
+
struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
|
| 810 |
+
|
| 811 |
+
template<typename Scalar>
|
| 812 |
+
struct random_retval
|
| 813 |
+
{
|
| 814 |
+
typedef Scalar type;
|
| 815 |
+
};
|
| 816 |
+
|
| 817 |
+
template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y);
|
| 818 |
+
template<typename Scalar> inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random();
|
| 819 |
+
|
| 820 |
+
template<typename Scalar>
|
| 821 |
+
struct random_default_impl<Scalar, false, false>
|
| 822 |
+
{
|
| 823 |
+
static inline Scalar run(const Scalar& x, const Scalar& y)
|
| 824 |
+
{
|
| 825 |
+
return x + (y-x) * Scalar(std::rand()) / Scalar(RAND_MAX);
|
| 826 |
+
}
|
| 827 |
+
static inline Scalar run()
|
| 828 |
+
{
|
| 829 |
+
return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1));
|
| 830 |
+
}
|
| 831 |
+
};
|
| 832 |
+
|
| 833 |
+
enum {
|
| 834 |
+
meta_floor_log2_terminate,
|
| 835 |
+
meta_floor_log2_move_up,
|
| 836 |
+
meta_floor_log2_move_down,
|
| 837 |
+
meta_floor_log2_bogus
|
| 838 |
+
};
|
| 839 |
+
|
| 840 |
+
template<unsigned int n, int lower, int upper> struct meta_floor_log2_selector
|
| 841 |
+
{
|
| 842 |
+
enum { middle = (lower + upper) / 2,
|
| 843 |
+
value = (upper <= lower + 1) ? int(meta_floor_log2_terminate)
|
| 844 |
+
: (n < (1 << middle)) ? int(meta_floor_log2_move_down)
|
| 845 |
+
: (n==0) ? int(meta_floor_log2_bogus)
|
| 846 |
+
: int(meta_floor_log2_move_up)
|
| 847 |
+
};
|
| 848 |
+
};
|
| 849 |
+
|
| 850 |
+
template<unsigned int n,
|
| 851 |
+
int lower = 0,
|
| 852 |
+
int upper = sizeof(unsigned int) * CHAR_BIT - 1,
|
| 853 |
+
int selector = meta_floor_log2_selector<n, lower, upper>::value>
|
| 854 |
+
struct meta_floor_log2 {};
|
| 855 |
+
|
| 856 |
+
template<unsigned int n, int lower, int upper>
|
| 857 |
+
struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_down>
|
| 858 |
+
{
|
| 859 |
+
enum { value = meta_floor_log2<n, lower, meta_floor_log2_selector<n, lower, upper>::middle>::value };
|
| 860 |
+
};
|
| 861 |
+
|
| 862 |
+
template<unsigned int n, int lower, int upper>
|
| 863 |
+
struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_up>
|
| 864 |
+
{
|
| 865 |
+
enum { value = meta_floor_log2<n, meta_floor_log2_selector<n, lower, upper>::middle, upper>::value };
|
| 866 |
+
};
|
| 867 |
+
|
| 868 |
+
template<unsigned int n, int lower, int upper>
|
| 869 |
+
struct meta_floor_log2<n, lower, upper, meta_floor_log2_terminate>
|
| 870 |
+
{
|
| 871 |
+
enum { value = (n >= ((unsigned int)(1) << (lower+1))) ? lower+1 : lower };
|
| 872 |
+
};
|
| 873 |
+
|
| 874 |
+
template<unsigned int n, int lower, int upper>
|
| 875 |
+
struct meta_floor_log2<n, lower, upper, meta_floor_log2_bogus>
|
| 876 |
+
{
|
| 877 |
+
// no value, error at compile time
|
| 878 |
+
};
|
| 879 |
+
|
| 880 |
+
template <typename BitsType, typename EnableIf = void>
|
| 881 |
+
struct count_bits_impl {
|
| 882 |
+
static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 883 |
+
EIGEN_STATIC_ASSERT(
|
| 884 |
+
is_integral<BitsType>::value && !NumTraits<BitsType>::IsSigned,
|
| 885 |
+
THIS_TYPE_IS_NOT_SUPPORTED);
|
| 886 |
+
int n = CHAR_BIT * sizeof(BitsType);
|
| 887 |
+
int shift = n / 2;
|
| 888 |
+
while (bits > 0 && shift > 0) {
|
| 889 |
+
BitsType y = bits >> shift;
|
| 890 |
+
if (y > 0) {
|
| 891 |
+
n -= shift;
|
| 892 |
+
bits = y;
|
| 893 |
+
}
|
| 894 |
+
shift /= 2;
|
| 895 |
+
}
|
| 896 |
+
if (shift == 0) {
|
| 897 |
+
--n;
|
| 898 |
+
}
|
| 899 |
+
return n;
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 903 |
+
EIGEN_STATIC_ASSERT(
|
| 904 |
+
is_integral<BitsType>::value && !NumTraits<BitsType>::IsSigned,
|
| 905 |
+
THIS_TYPE_IS_NOT_SUPPORTED);
|
| 906 |
+
int n = CHAR_BIT * sizeof(BitsType);
|
| 907 |
+
int shift = n / 2;
|
| 908 |
+
while (bits > 0 && shift > 0) {
|
| 909 |
+
BitsType y = bits << shift;
|
| 910 |
+
if (y > 0) {
|
| 911 |
+
n -= shift;
|
| 912 |
+
bits = y;
|
| 913 |
+
}
|
| 914 |
+
shift /= 2;
|
| 915 |
+
}
|
| 916 |
+
if (shift == 0) {
|
| 917 |
+
--n;
|
| 918 |
+
}
|
| 919 |
+
return n;
|
| 920 |
+
}
|
| 921 |
+
};
|
| 922 |
+
|
| 923 |
+
// Count leading zeros.
|
| 924 |
+
template <typename BitsType>
|
| 925 |
+
EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 926 |
+
return count_bits_impl<BitsType>::clz(bits);
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
// Count trailing zeros.
|
| 930 |
+
template <typename BitsType>
|
| 931 |
+
EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 932 |
+
return count_bits_impl<BitsType>::ctz(bits);
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
#if EIGEN_COMP_GNUC || EIGEN_COMP_CLANG
|
| 936 |
+
|
| 937 |
+
template <typename BitsType>
|
| 938 |
+
struct count_bits_impl<BitsType, typename enable_if<sizeof(BitsType) <= sizeof(unsigned int)>::type> {
|
| 939 |
+
static const int kNumBits = static_cast<int>(sizeof(BitsType) * CHAR_BIT);
|
| 940 |
+
static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 941 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 942 |
+
static const int kLeadingBitsOffset = (sizeof(unsigned int) - sizeof(BitsType)) * CHAR_BIT;
|
| 943 |
+
return bits == 0 ? kNumBits : __builtin_clz(static_cast<unsigned int>(bits)) - kLeadingBitsOffset;
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 947 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 948 |
+
return bits == 0 ? kNumBits : __builtin_ctz(static_cast<unsigned int>(bits));
|
| 949 |
+
}
|
| 950 |
+
};
|
| 951 |
+
|
| 952 |
+
template <typename BitsType>
|
| 953 |
+
struct count_bits_impl<
|
| 954 |
+
BitsType, typename enable_if<sizeof(unsigned int) < sizeof(BitsType) && sizeof(BitsType) <= sizeof(unsigned long)>::type> {
|
| 955 |
+
static const int kNumBits = static_cast<int>(sizeof(BitsType) * CHAR_BIT);
|
| 956 |
+
static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 957 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 958 |
+
static const int kLeadingBitsOffset = (sizeof(unsigned long) - sizeof(BitsType)) * CHAR_BIT;
|
| 959 |
+
return bits == 0 ? kNumBits : __builtin_clzl(static_cast<unsigned long>(bits)) - kLeadingBitsOffset;
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 963 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 964 |
+
return bits == 0 ? kNumBits : __builtin_ctzl(static_cast<unsigned long>(bits));
|
| 965 |
+
}
|
| 966 |
+
};
|
| 967 |
+
|
| 968 |
+
template <typename BitsType>
|
| 969 |
+
struct count_bits_impl<BitsType, typename enable_if<sizeof(unsigned long) < sizeof(BitsType) &&
|
| 970 |
+
sizeof(BitsType) <= sizeof(unsigned long long)>::type> {
|
| 971 |
+
static const int kNumBits = static_cast<int>(sizeof(BitsType) * CHAR_BIT);
|
| 972 |
+
static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 973 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 974 |
+
static const int kLeadingBitsOffset = (sizeof(unsigned long long) - sizeof(BitsType)) * CHAR_BIT;
|
| 975 |
+
return bits == 0 ? kNumBits : __builtin_clzll(static_cast<unsigned long long>(bits)) - kLeadingBitsOffset;
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 979 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 980 |
+
return bits == 0 ? kNumBits : __builtin_ctzll(static_cast<unsigned long long>(bits));
|
| 981 |
+
}
|
| 982 |
+
};
|
| 983 |
+
|
| 984 |
+
#elif EIGEN_COMP_MSVC
|
| 985 |
+
|
| 986 |
+
template <typename BitsType>
|
| 987 |
+
struct count_bits_impl<BitsType, typename enable_if<sizeof(BitsType) <= sizeof(unsigned long)>::type> {
|
| 988 |
+
static const int kNumBits = static_cast<int>(sizeof(BitsType) * CHAR_BIT);
|
| 989 |
+
static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 990 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 991 |
+
unsigned long out;
|
| 992 |
+
_BitScanReverse(&out, static_cast<unsigned long>(bits));
|
| 993 |
+
return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast<int>(out);
|
| 994 |
+
}
|
| 995 |
+
|
| 996 |
+
static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 997 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 998 |
+
unsigned long out;
|
| 999 |
+
_BitScanForward(&out, static_cast<unsigned long>(bits));
|
| 1000 |
+
return bits == 0 ? kNumBits : static_cast<int>(out);
|
| 1001 |
+
}
|
| 1002 |
+
};
|
| 1003 |
+
|
| 1004 |
+
#ifdef _WIN64
|
| 1005 |
+
|
| 1006 |
+
template <typename BitsType>
|
| 1007 |
+
struct count_bits_impl<
|
| 1008 |
+
BitsType, typename enable_if<sizeof(unsigned long) < sizeof(BitsType) && sizeof(BitsType) <= sizeof(__int64)>::type> {
|
| 1009 |
+
static const int kNumBits = static_cast<int>(sizeof(BitsType) * CHAR_BIT);
|
| 1010 |
+
static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) {
|
| 1011 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 1012 |
+
unsigned long out;
|
| 1013 |
+
_BitScanReverse64(&out, static_cast<unsigned __int64>(bits));
|
| 1014 |
+
return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast<int>(out);
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) {
|
| 1018 |
+
EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 1019 |
+
unsigned long out;
|
| 1020 |
+
_BitScanForward64(&out, static_cast<unsigned __int64>(bits));
|
| 1021 |
+
return bits == 0 ? kNumBits : static_cast<int>(out);
|
| 1022 |
+
}
|
| 1023 |
+
};
|
| 1024 |
+
|
| 1025 |
+
#endif // _WIN64
|
| 1026 |
+
|
| 1027 |
+
#endif // EIGEN_COMP_GNUC || EIGEN_COMP_CLANG
|
| 1028 |
+
|
| 1029 |
+
template <typename Scalar>
|
| 1030 |
+
struct random_default_impl<Scalar, false, true> {
|
| 1031 |
+
static inline Scalar run(const Scalar& x, const Scalar& y) {
|
| 1032 |
+
if (y <= x) return x;
|
| 1033 |
+
// ScalarU is the unsigned counterpart of Scalar, possibly Scalar itself.
|
| 1034 |
+
typedef typename make_unsigned<Scalar>::type ScalarU;
|
| 1035 |
+
// ScalarX is the widest of ScalarU and unsigned int.
|
| 1036 |
+
// We'll deal only with ScalarX and unsigned int below thus avoiding signed
|
| 1037 |
+
// types and arithmetic and signed overflows (which are undefined behavior).
|
| 1038 |
+
typedef typename conditional<(ScalarU(-1) > unsigned(-1)), ScalarU, unsigned>::type ScalarX;
|
| 1039 |
+
// The following difference doesn't overflow, provided our integer types are two's
|
| 1040 |
+
// complement and have the same number of padding bits in signed and unsigned variants.
|
| 1041 |
+
// This is the case in most modern implementations of C++.
|
| 1042 |
+
ScalarX range = ScalarX(y) - ScalarX(x);
|
| 1043 |
+
ScalarX offset = 0;
|
| 1044 |
+
ScalarX divisor = 1;
|
| 1045 |
+
ScalarX multiplier = 1;
|
| 1046 |
+
const unsigned rand_max = RAND_MAX;
|
| 1047 |
+
if (range <= rand_max) divisor = (rand_max + 1) / (range + 1);
|
| 1048 |
+
else multiplier = 1 + range / (rand_max + 1);
|
| 1049 |
+
// Rejection sampling.
|
| 1050 |
+
do {
|
| 1051 |
+
offset = (unsigned(std::rand()) * multiplier) / divisor;
|
| 1052 |
+
} while (offset > range);
|
| 1053 |
+
return Scalar(ScalarX(x) + offset);
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
static inline Scalar run()
|
| 1057 |
+
{
|
| 1058 |
+
#ifdef EIGEN_MAKING_DOCS
|
| 1059 |
+
return run(Scalar(NumTraits<Scalar>::IsSigned ? -10 : 0), Scalar(10));
|
| 1060 |
+
#else
|
| 1061 |
+
enum { rand_bits = meta_floor_log2<(unsigned int)(RAND_MAX)+1>::value,
|
| 1062 |
+
scalar_bits = sizeof(Scalar) * CHAR_BIT,
|
| 1063 |
+
shift = EIGEN_PLAIN_ENUM_MAX(0, int(rand_bits) - int(scalar_bits)),
|
| 1064 |
+
offset = NumTraits<Scalar>::IsSigned ? (1 << (EIGEN_PLAIN_ENUM_MIN(rand_bits,scalar_bits)-1)) : 0
|
| 1065 |
+
};
|
| 1066 |
+
return Scalar((std::rand() >> shift) - offset);
|
| 1067 |
+
#endif
|
| 1068 |
+
}
|
| 1069 |
+
};
|
| 1070 |
+
|
| 1071 |
+
template<typename Scalar>
|
| 1072 |
+
struct random_default_impl<Scalar, true, false>
|
| 1073 |
+
{
|
| 1074 |
+
static inline Scalar run(const Scalar& x, const Scalar& y)
|
| 1075 |
+
{
|
| 1076 |
+
return Scalar(random(x.real(), y.real()),
|
| 1077 |
+
random(x.imag(), y.imag()));
|
| 1078 |
+
}
|
| 1079 |
+
static inline Scalar run()
|
| 1080 |
+
{
|
| 1081 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 1082 |
+
return Scalar(random<RealScalar>(), random<RealScalar>());
|
| 1083 |
+
}
|
| 1084 |
+
};
|
| 1085 |
+
|
| 1086 |
+
template<typename Scalar>
|
| 1087 |
+
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y)
|
| 1088 |
+
{
|
| 1089 |
+
return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y);
|
| 1090 |
+
}
|
| 1091 |
+
|
| 1092 |
+
template<typename Scalar>
|
| 1093 |
+
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
|
| 1094 |
+
{
|
| 1095 |
+
return EIGEN_MATHFUNC_IMPL(random, Scalar)::run();
|
| 1096 |
+
}
|
| 1097 |
+
|
| 1098 |
+
// Implementation of is* functions
|
| 1099 |
+
|
| 1100 |
+
// std::is* do not work with fast-math and gcc, std::is* are available on MSVC 2013 and newer, as well as in clang.
|
| 1101 |
+
#if (EIGEN_HAS_CXX11_MATH && !(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC>=1800) || (EIGEN_COMP_CLANG)
|
| 1102 |
+
#define EIGEN_USE_STD_FPCLASSIFY 1
|
| 1103 |
+
#else
|
| 1104 |
+
#define EIGEN_USE_STD_FPCLASSIFY 0
|
| 1105 |
+
#endif
|
| 1106 |
+
|
| 1107 |
+
template<typename T>
|
| 1108 |
+
EIGEN_DEVICE_FUNC
|
| 1109 |
+
typename internal::enable_if<internal::is_integral<T>::value,bool>::type
|
| 1110 |
+
isnan_impl(const T&) { return false; }
|
| 1111 |
+
|
| 1112 |
+
template<typename T>
|
| 1113 |
+
EIGEN_DEVICE_FUNC
|
| 1114 |
+
typename internal::enable_if<internal::is_integral<T>::value,bool>::type
|
| 1115 |
+
isinf_impl(const T&) { return false; }
|
| 1116 |
+
|
| 1117 |
+
template<typename T>
|
| 1118 |
+
EIGEN_DEVICE_FUNC
|
| 1119 |
+
typename internal::enable_if<internal::is_integral<T>::value,bool>::type
|
| 1120 |
+
isfinite_impl(const T&) { return true; }
|
| 1121 |
+
|
| 1122 |
+
template<typename T>
|
| 1123 |
+
EIGEN_DEVICE_FUNC
|
| 1124 |
+
typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type
|
| 1125 |
+
isfinite_impl(const T& x)
|
| 1126 |
+
{
|
| 1127 |
+
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
| 1128 |
+
return (::isfinite)(x);
|
| 1129 |
+
#elif EIGEN_USE_STD_FPCLASSIFY
|
| 1130 |
+
using std::isfinite;
|
| 1131 |
+
return isfinite EIGEN_NOT_A_MACRO (x);
|
| 1132 |
+
#else
|
| 1133 |
+
return x<=NumTraits<T>::highest() && x>=NumTraits<T>::lowest();
|
| 1134 |
+
#endif
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
template<typename T>
|
| 1138 |
+
EIGEN_DEVICE_FUNC
|
| 1139 |
+
typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type
|
| 1140 |
+
isinf_impl(const T& x)
|
| 1141 |
+
{
|
| 1142 |
+
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
| 1143 |
+
return (::isinf)(x);
|
| 1144 |
+
#elif EIGEN_USE_STD_FPCLASSIFY
|
| 1145 |
+
using std::isinf;
|
| 1146 |
+
return isinf EIGEN_NOT_A_MACRO (x);
|
| 1147 |
+
#else
|
| 1148 |
+
return x>NumTraits<T>::highest() || x<NumTraits<T>::lowest();
|
| 1149 |
+
#endif
|
| 1150 |
+
}
|
| 1151 |
+
|
| 1152 |
+
template<typename T>
|
| 1153 |
+
EIGEN_DEVICE_FUNC
|
| 1154 |
+
typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),bool>::type
|
| 1155 |
+
isnan_impl(const T& x)
|
| 1156 |
+
{
|
| 1157 |
+
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
| 1158 |
+
return (::isnan)(x);
|
| 1159 |
+
#elif EIGEN_USE_STD_FPCLASSIFY
|
| 1160 |
+
using std::isnan;
|
| 1161 |
+
return isnan EIGEN_NOT_A_MACRO (x);
|
| 1162 |
+
#else
|
| 1163 |
+
return x != x;
|
| 1164 |
+
#endif
|
| 1165 |
+
}
|
| 1166 |
+
|
| 1167 |
+
#if (!EIGEN_USE_STD_FPCLASSIFY)
|
| 1168 |
+
|
| 1169 |
+
#if EIGEN_COMP_MSVC
|
| 1170 |
+
|
| 1171 |
+
template<typename T> EIGEN_DEVICE_FUNC bool isinf_msvc_helper(T x)
|
| 1172 |
+
{
|
| 1173 |
+
return _fpclass(x)==_FPCLASS_NINF || _fpclass(x)==_FPCLASS_PINF;
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
//MSVC defines a _isnan builtin function, but for double only
|
| 1177 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1178 |
+
EIGEN_DEVICE_FUNC inline bool isnan_impl(const long double& x) { return _isnan(x)!=0; }
|
| 1179 |
+
#endif
|
| 1180 |
+
EIGEN_DEVICE_FUNC inline bool isnan_impl(const double& x) { return _isnan(x)!=0; }
|
| 1181 |
+
EIGEN_DEVICE_FUNC inline bool isnan_impl(const float& x) { return _isnan(x)!=0; }
|
| 1182 |
+
|
| 1183 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1184 |
+
EIGEN_DEVICE_FUNC inline bool isinf_impl(const long double& x) { return isinf_msvc_helper(x); }
|
| 1185 |
+
#endif
|
| 1186 |
+
EIGEN_DEVICE_FUNC inline bool isinf_impl(const double& x) { return isinf_msvc_helper(x); }
|
| 1187 |
+
EIGEN_DEVICE_FUNC inline bool isinf_impl(const float& x) { return isinf_msvc_helper(x); }
|
| 1188 |
+
|
| 1189 |
+
#elif (defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ && EIGEN_COMP_GNUC)
|
| 1190 |
+
|
| 1191 |
+
#if EIGEN_GNUC_AT_LEAST(5,0)
|
| 1192 |
+
#define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((optimize("no-finite-math-only")))
|
| 1193 |
+
#else
|
| 1194 |
+
// NOTE the inline qualifier and noinline attribute are both needed: the former is to avoid linking issue (duplicate symbol),
|
| 1195 |
+
// while the second prevent too aggressive optimizations in fast-math mode:
|
| 1196 |
+
#define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((noinline,optimize("no-finite-math-only")))
|
| 1197 |
+
#endif
|
| 1198 |
+
|
| 1199 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1200 |
+
template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const long double& x) { return __builtin_isnan(x); }
|
| 1201 |
+
#endif
|
| 1202 |
+
template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const double& x) { return __builtin_isnan(x); }
|
| 1203 |
+
template<> EIGEN_TMP_NOOPT_ATTRIB bool isnan_impl(const float& x) { return __builtin_isnan(x); }
|
| 1204 |
+
template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const double& x) { return __builtin_isinf(x); }
|
| 1205 |
+
template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const float& x) { return __builtin_isinf(x); }
|
| 1206 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1207 |
+
template<> EIGEN_TMP_NOOPT_ATTRIB bool isinf_impl(const long double& x) { return __builtin_isinf(x); }
|
| 1208 |
+
#endif
|
| 1209 |
+
|
| 1210 |
+
#undef EIGEN_TMP_NOOPT_ATTRIB
|
| 1211 |
+
|
| 1212 |
+
#endif
|
| 1213 |
+
|
| 1214 |
+
#endif
|
| 1215 |
+
|
| 1216 |
+
// The following overload are defined at the end of this file
|
| 1217 |
+
template<typename T> EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex<T>& x);
|
| 1218 |
+
template<typename T> EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex<T>& x);
|
| 1219 |
+
template<typename T> EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex<T>& x);
|
| 1220 |
+
|
| 1221 |
+
template<typename T> T generic_fast_tanh_float(const T& a_x);
|
| 1222 |
+
} // end namespace internal
|
| 1223 |
+
|
| 1224 |
+
/****************************************************************************
|
| 1225 |
+
* Generic math functions *
|
| 1226 |
+
****************************************************************************/
|
| 1227 |
+
|
| 1228 |
+
namespace numext {
|
| 1229 |
+
|
| 1230 |
+
#if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
|
| 1231 |
+
template<typename T>
|
| 1232 |
+
EIGEN_DEVICE_FUNC
|
| 1233 |
+
EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y)
|
| 1234 |
+
{
|
| 1235 |
+
EIGEN_USING_STD(min)
|
| 1236 |
+
return min EIGEN_NOT_A_MACRO (x,y);
|
| 1237 |
+
}
|
| 1238 |
+
|
| 1239 |
+
template<typename T>
|
| 1240 |
+
EIGEN_DEVICE_FUNC
|
| 1241 |
+
EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y)
|
| 1242 |
+
{
|
| 1243 |
+
EIGEN_USING_STD(max)
|
| 1244 |
+
return max EIGEN_NOT_A_MACRO (x,y);
|
| 1245 |
+
}
|
| 1246 |
+
#else
|
| 1247 |
+
template<typename T>
|
| 1248 |
+
EIGEN_DEVICE_FUNC
|
| 1249 |
+
EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y)
|
| 1250 |
+
{
|
| 1251 |
+
return y < x ? y : x;
|
| 1252 |
+
}
|
| 1253 |
+
template<>
|
| 1254 |
+
EIGEN_DEVICE_FUNC
|
| 1255 |
+
EIGEN_ALWAYS_INLINE float mini(const float& x, const float& y)
|
| 1256 |
+
{
|
| 1257 |
+
return fminf(x, y);
|
| 1258 |
+
}
|
| 1259 |
+
template<>
|
| 1260 |
+
EIGEN_DEVICE_FUNC
|
| 1261 |
+
EIGEN_ALWAYS_INLINE double mini(const double& x, const double& y)
|
| 1262 |
+
{
|
| 1263 |
+
return fmin(x, y);
|
| 1264 |
+
}
|
| 1265 |
+
|
| 1266 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1267 |
+
template<>
|
| 1268 |
+
EIGEN_DEVICE_FUNC
|
| 1269 |
+
EIGEN_ALWAYS_INLINE long double mini(const long double& x, const long double& y)
|
| 1270 |
+
{
|
| 1271 |
+
#if defined(EIGEN_HIPCC)
|
| 1272 |
+
// no "fminl" on HIP yet
|
| 1273 |
+
return (x < y) ? x : y;
|
| 1274 |
+
#else
|
| 1275 |
+
return fminl(x, y);
|
| 1276 |
+
#endif
|
| 1277 |
+
}
|
| 1278 |
+
#endif
|
| 1279 |
+
|
| 1280 |
+
template<typename T>
|
| 1281 |
+
EIGEN_DEVICE_FUNC
|
| 1282 |
+
EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y)
|
| 1283 |
+
{
|
| 1284 |
+
return x < y ? y : x;
|
| 1285 |
+
}
|
| 1286 |
+
template<>
|
| 1287 |
+
EIGEN_DEVICE_FUNC
|
| 1288 |
+
EIGEN_ALWAYS_INLINE float maxi(const float& x, const float& y)
|
| 1289 |
+
{
|
| 1290 |
+
return fmaxf(x, y);
|
| 1291 |
+
}
|
| 1292 |
+
template<>
|
| 1293 |
+
EIGEN_DEVICE_FUNC
|
| 1294 |
+
EIGEN_ALWAYS_INLINE double maxi(const double& x, const double& y)
|
| 1295 |
+
{
|
| 1296 |
+
return fmax(x, y);
|
| 1297 |
+
}
|
| 1298 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1299 |
+
template<>
|
| 1300 |
+
EIGEN_DEVICE_FUNC
|
| 1301 |
+
EIGEN_ALWAYS_INLINE long double maxi(const long double& x, const long double& y)
|
| 1302 |
+
{
|
| 1303 |
+
#if defined(EIGEN_HIPCC)
|
| 1304 |
+
// no "fmaxl" on HIP yet
|
| 1305 |
+
return (x > y) ? x : y;
|
| 1306 |
+
#else
|
| 1307 |
+
return fmaxl(x, y);
|
| 1308 |
+
#endif
|
| 1309 |
+
}
|
| 1310 |
+
#endif
|
| 1311 |
+
#endif
|
| 1312 |
+
|
| 1313 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1314 |
+
|
| 1315 |
+
|
| 1316 |
+
#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
|
| 1317 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
|
| 1318 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
|
| 1319 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
|
| 1320 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
|
| 1321 |
+
#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
|
| 1322 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
|
| 1323 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
|
| 1324 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
|
| 1325 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
|
| 1326 |
+
#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
|
| 1327 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
|
| 1328 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
|
| 1329 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
|
| 1330 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
|
| 1331 |
+
#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
|
| 1332 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
|
| 1333 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
|
| 1334 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
|
| 1335 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
|
| 1336 |
+
#define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \
|
| 1337 |
+
SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
|
| 1338 |
+
SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC)
|
| 1339 |
+
#define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \
|
| 1340 |
+
SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
|
| 1341 |
+
SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC)
|
| 1342 |
+
#define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \
|
| 1343 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
|
| 1344 |
+
SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
|
| 1345 |
+
#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \
|
| 1346 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
|
| 1347 |
+
SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
|
| 1348 |
+
#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \
|
| 1349 |
+
SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \
|
| 1350 |
+
SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double)
|
| 1351 |
+
|
| 1352 |
+
#define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
|
| 1353 |
+
template<> \
|
| 1354 |
+
EIGEN_DEVICE_FUNC \
|
| 1355 |
+
EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \
|
| 1356 |
+
return cl::sycl::FUNC(x); \
|
| 1357 |
+
}
|
| 1358 |
+
|
| 1359 |
+
#define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) \
|
| 1360 |
+
SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE)
|
| 1361 |
+
|
| 1362 |
+
#define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \
|
| 1363 |
+
template<> \
|
| 1364 |
+
EIGEN_DEVICE_FUNC \
|
| 1365 |
+
EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \
|
| 1366 |
+
return cl::sycl::FUNC(x, y); \
|
| 1367 |
+
}
|
| 1368 |
+
|
| 1369 |
+
#define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
|
| 1370 |
+
SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE)
|
| 1371 |
+
|
| 1372 |
+
#define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) \
|
| 1373 |
+
SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE)
|
| 1374 |
+
|
| 1375 |
+
SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(mini, min)
|
| 1376 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(mini, fmin)
|
| 1377 |
+
SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(maxi, max)
|
| 1378 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(maxi, fmax)
|
| 1379 |
+
|
| 1380 |
+
#endif
|
| 1381 |
+
|
| 1382 |
+
|
| 1383 |
+
template<typename Scalar>
|
| 1384 |
+
EIGEN_DEVICE_FUNC
|
| 1385 |
+
inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x)
|
| 1386 |
+
{
|
| 1387 |
+
return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x);
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
template<typename Scalar>
|
| 1391 |
+
EIGEN_DEVICE_FUNC
|
| 1392 |
+
inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar& x)
|
| 1393 |
+
{
|
| 1394 |
+
return internal::real_ref_impl<Scalar>::run(x);
|
| 1395 |
+
}
|
| 1396 |
+
|
| 1397 |
+
template<typename Scalar>
|
| 1398 |
+
EIGEN_DEVICE_FUNC
|
| 1399 |
+
inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x)
|
| 1400 |
+
{
|
| 1401 |
+
return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x);
|
| 1402 |
+
}
|
| 1403 |
+
|
| 1404 |
+
template<typename Scalar>
|
| 1405 |
+
EIGEN_DEVICE_FUNC
|
| 1406 |
+
inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x)
|
| 1407 |
+
{
|
| 1408 |
+
return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x);
|
| 1409 |
+
}
|
| 1410 |
+
|
| 1411 |
+
template<typename Scalar>
|
| 1412 |
+
EIGEN_DEVICE_FUNC
|
| 1413 |
+
inline EIGEN_MATHFUNC_RETVAL(arg, Scalar) arg(const Scalar& x)
|
| 1414 |
+
{
|
| 1415 |
+
return EIGEN_MATHFUNC_IMPL(arg, Scalar)::run(x);
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
template<typename Scalar>
|
| 1419 |
+
EIGEN_DEVICE_FUNC
|
| 1420 |
+
inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar& x)
|
| 1421 |
+
{
|
| 1422 |
+
return internal::imag_ref_impl<Scalar>::run(x);
|
| 1423 |
+
}
|
| 1424 |
+
|
| 1425 |
+
template<typename Scalar>
|
| 1426 |
+
EIGEN_DEVICE_FUNC
|
| 1427 |
+
inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x)
|
| 1428 |
+
{
|
| 1429 |
+
return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x);
|
| 1430 |
+
}
|
| 1431 |
+
|
| 1432 |
+
template<typename Scalar>
|
| 1433 |
+
EIGEN_DEVICE_FUNC
|
| 1434 |
+
inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x)
|
| 1435 |
+
{
|
| 1436 |
+
return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x);
|
| 1437 |
+
}
|
| 1438 |
+
|
| 1439 |
+
template<typename Scalar>
|
| 1440 |
+
EIGEN_DEVICE_FUNC
|
| 1441 |
+
inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x)
|
| 1442 |
+
{
|
| 1443 |
+
return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x);
|
| 1444 |
+
}
|
| 1445 |
+
|
| 1446 |
+
EIGEN_DEVICE_FUNC
|
| 1447 |
+
inline bool abs2(bool x) { return x; }
|
| 1448 |
+
|
| 1449 |
+
template<typename T>
|
| 1450 |
+
EIGEN_DEVICE_FUNC
|
| 1451 |
+
EIGEN_ALWAYS_INLINE T absdiff(const T& x, const T& y)
|
| 1452 |
+
{
|
| 1453 |
+
return x > y ? x - y : y - x;
|
| 1454 |
+
}
|
| 1455 |
+
template<>
|
| 1456 |
+
EIGEN_DEVICE_FUNC
|
| 1457 |
+
EIGEN_ALWAYS_INLINE float absdiff(const float& x, const float& y)
|
| 1458 |
+
{
|
| 1459 |
+
return fabsf(x - y);
|
| 1460 |
+
}
|
| 1461 |
+
template<>
|
| 1462 |
+
EIGEN_DEVICE_FUNC
|
| 1463 |
+
EIGEN_ALWAYS_INLINE double absdiff(const double& x, const double& y)
|
| 1464 |
+
{
|
| 1465 |
+
return fabs(x - y);
|
| 1466 |
+
}
|
| 1467 |
+
|
| 1468 |
+
// HIP and CUDA do not support long double.
|
| 1469 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 1470 |
+
template<>
|
| 1471 |
+
EIGEN_DEVICE_FUNC
|
| 1472 |
+
EIGEN_ALWAYS_INLINE long double absdiff(const long double& x, const long double& y) {
|
| 1473 |
+
return fabsl(x - y);
|
| 1474 |
+
}
|
| 1475 |
+
#endif
|
| 1476 |
+
|
| 1477 |
+
template<typename Scalar>
|
| 1478 |
+
EIGEN_DEVICE_FUNC
|
| 1479 |
+
inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x)
|
| 1480 |
+
{
|
| 1481 |
+
return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x);
|
| 1482 |
+
}
|
| 1483 |
+
|
| 1484 |
+
template<typename Scalar>
|
| 1485 |
+
EIGEN_DEVICE_FUNC
|
| 1486 |
+
inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y)
|
| 1487 |
+
{
|
| 1488 |
+
return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y);
|
| 1489 |
+
}
|
| 1490 |
+
|
| 1491 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1492 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot)
|
| 1493 |
+
#endif
|
| 1494 |
+
|
| 1495 |
+
template<typename Scalar>
|
| 1496 |
+
EIGEN_DEVICE_FUNC
|
| 1497 |
+
inline EIGEN_MATHFUNC_RETVAL(log1p, Scalar) log1p(const Scalar& x)
|
| 1498 |
+
{
|
| 1499 |
+
return EIGEN_MATHFUNC_IMPL(log1p, Scalar)::run(x);
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1503 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log1p, log1p)
|
| 1504 |
+
#endif
|
| 1505 |
+
|
| 1506 |
+
#if defined(EIGEN_GPUCC)
|
| 1507 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1508 |
+
float log1p(const float &x) { return ::log1pf(x); }
|
| 1509 |
+
|
| 1510 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1511 |
+
double log1p(const double &x) { return ::log1p(x); }
|
| 1512 |
+
#endif
|
| 1513 |
+
|
| 1514 |
+
template<typename ScalarX,typename ScalarY>
|
| 1515 |
+
EIGEN_DEVICE_FUNC
|
| 1516 |
+
inline typename internal::pow_impl<ScalarX,ScalarY>::result_type pow(const ScalarX& x, const ScalarY& y)
|
| 1517 |
+
{
|
| 1518 |
+
return internal::pow_impl<ScalarX,ScalarY>::run(x, y);
|
| 1519 |
+
}
|
| 1520 |
+
|
| 1521 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1522 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(pow, pow)
|
| 1523 |
+
#endif
|
| 1524 |
+
|
| 1525 |
+
template<typename T> EIGEN_DEVICE_FUNC bool (isnan) (const T &x) { return internal::isnan_impl(x); }
|
| 1526 |
+
template<typename T> EIGEN_DEVICE_FUNC bool (isinf) (const T &x) { return internal::isinf_impl(x); }
|
| 1527 |
+
template<typename T> EIGEN_DEVICE_FUNC bool (isfinite)(const T &x) { return internal::isfinite_impl(x); }
|
| 1528 |
+
|
| 1529 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1530 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isnan, isnan, bool)
|
| 1531 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isinf, isinf, bool)
|
| 1532 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isfinite, isfinite, bool)
|
| 1533 |
+
#endif
|
| 1534 |
+
|
| 1535 |
+
template<typename Scalar>
|
| 1536 |
+
EIGEN_DEVICE_FUNC
|
| 1537 |
+
inline EIGEN_MATHFUNC_RETVAL(rint, Scalar) rint(const Scalar& x)
|
| 1538 |
+
{
|
| 1539 |
+
return EIGEN_MATHFUNC_IMPL(rint, Scalar)::run(x);
|
| 1540 |
+
}
|
| 1541 |
+
|
| 1542 |
+
template<typename Scalar>
|
| 1543 |
+
EIGEN_DEVICE_FUNC
|
| 1544 |
+
inline EIGEN_MATHFUNC_RETVAL(round, Scalar) round(const Scalar& x)
|
| 1545 |
+
{
|
| 1546 |
+
return EIGEN_MATHFUNC_IMPL(round, Scalar)::run(x);
|
| 1547 |
+
}
|
| 1548 |
+
|
| 1549 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1550 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(round, round)
|
| 1551 |
+
#endif
|
| 1552 |
+
|
| 1553 |
+
template<typename T>
|
| 1554 |
+
EIGEN_DEVICE_FUNC
|
| 1555 |
+
T (floor)(const T& x)
|
| 1556 |
+
{
|
| 1557 |
+
EIGEN_USING_STD(floor)
|
| 1558 |
+
return floor(x);
|
| 1559 |
+
}
|
| 1560 |
+
|
| 1561 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1562 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(floor, floor)
|
| 1563 |
+
#endif
|
| 1564 |
+
|
| 1565 |
+
#if defined(EIGEN_GPUCC)
|
| 1566 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1567 |
+
float floor(const float &x) { return ::floorf(x); }
|
| 1568 |
+
|
| 1569 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1570 |
+
double floor(const double &x) { return ::floor(x); }
|
| 1571 |
+
#endif
|
| 1572 |
+
|
| 1573 |
+
template<typename T>
|
| 1574 |
+
EIGEN_DEVICE_FUNC
|
| 1575 |
+
T (ceil)(const T& x)
|
| 1576 |
+
{
|
| 1577 |
+
EIGEN_USING_STD(ceil);
|
| 1578 |
+
return ceil(x);
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1582 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(ceil, ceil)
|
| 1583 |
+
#endif
|
| 1584 |
+
|
| 1585 |
+
#if defined(EIGEN_GPUCC)
|
| 1586 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1587 |
+
float ceil(const float &x) { return ::ceilf(x); }
|
| 1588 |
+
|
| 1589 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1590 |
+
double ceil(const double &x) { return ::ceil(x); }
|
| 1591 |
+
#endif
|
| 1592 |
+
|
| 1593 |
+
|
| 1594 |
+
/** Log base 2 for 32 bits positive integers.
|
| 1595 |
+
* Conveniently returns 0 for x==0. */
|
| 1596 |
+
inline int log2(int x)
|
| 1597 |
+
{
|
| 1598 |
+
eigen_assert(x>=0);
|
| 1599 |
+
unsigned int v(x);
|
| 1600 |
+
static const int table[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
|
| 1601 |
+
v |= v >> 1;
|
| 1602 |
+
v |= v >> 2;
|
| 1603 |
+
v |= v >> 4;
|
| 1604 |
+
v |= v >> 8;
|
| 1605 |
+
v |= v >> 16;
|
| 1606 |
+
return table[(v * 0x07C4ACDDU) >> 27];
|
| 1607 |
+
}
|
| 1608 |
+
|
| 1609 |
+
/** \returns the square root of \a x.
|
| 1610 |
+
*
|
| 1611 |
+
* It is essentially equivalent to
|
| 1612 |
+
* \code using std::sqrt; return sqrt(x); \endcode
|
| 1613 |
+
* but slightly faster for float/double and some compilers (e.g., gcc), thanks to
|
| 1614 |
+
* specializations when SSE is enabled.
|
| 1615 |
+
*
|
| 1616 |
+
* It's usage is justified in performance critical functions, like norm/normalize.
|
| 1617 |
+
*/
|
| 1618 |
+
template<typename Scalar>
|
| 1619 |
+
EIGEN_DEVICE_FUNC
|
| 1620 |
+
EIGEN_ALWAYS_INLINE EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(const Scalar& x)
|
| 1621 |
+
{
|
| 1622 |
+
return EIGEN_MATHFUNC_IMPL(sqrt, Scalar)::run(x);
|
| 1623 |
+
}
|
| 1624 |
+
|
| 1625 |
+
// Boolean specialization, avoids implicit float to bool conversion (-Wimplicit-conversion-floating-point-to-bool).
|
| 1626 |
+
template<>
|
| 1627 |
+
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
|
| 1628 |
+
bool sqrt<bool>(const bool &x) { return x; }
|
| 1629 |
+
|
| 1630 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1631 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sqrt, sqrt)
|
| 1632 |
+
#endif
|
| 1633 |
+
|
| 1634 |
+
/** \returns the reciprocal square root of \a x. **/
|
| 1635 |
+
template<typename T>
|
| 1636 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1637 |
+
T rsqrt(const T& x)
|
| 1638 |
+
{
|
| 1639 |
+
return internal::rsqrt_impl<T>::run(x);
|
| 1640 |
+
}
|
| 1641 |
+
|
| 1642 |
+
template<typename T>
|
| 1643 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1644 |
+
T log(const T &x) {
|
| 1645 |
+
return internal::log_impl<T>::run(x);
|
| 1646 |
+
}
|
| 1647 |
+
|
| 1648 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1649 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log, log)
|
| 1650 |
+
#endif
|
| 1651 |
+
|
| 1652 |
+
|
| 1653 |
+
#if defined(EIGEN_GPUCC)
|
| 1654 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1655 |
+
float log(const float &x) { return ::logf(x); }
|
| 1656 |
+
|
| 1657 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1658 |
+
double log(const double &x) { return ::log(x); }
|
| 1659 |
+
#endif
|
| 1660 |
+
|
| 1661 |
+
template<typename T>
|
| 1662 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1663 |
+
typename internal::enable_if<NumTraits<T>::IsSigned || NumTraits<T>::IsComplex,typename NumTraits<T>::Real>::type
|
| 1664 |
+
abs(const T &x) {
|
| 1665 |
+
EIGEN_USING_STD(abs);
|
| 1666 |
+
return abs(x);
|
| 1667 |
+
}
|
| 1668 |
+
|
| 1669 |
+
template<typename T>
|
| 1670 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1671 |
+
typename internal::enable_if<!(NumTraits<T>::IsSigned || NumTraits<T>::IsComplex),typename NumTraits<T>::Real>::type
|
| 1672 |
+
abs(const T &x) {
|
| 1673 |
+
return x;
|
| 1674 |
+
}
|
| 1675 |
+
|
| 1676 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1677 |
+
SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(abs, abs)
|
| 1678 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(abs, fabs)
|
| 1679 |
+
#endif
|
| 1680 |
+
|
| 1681 |
+
#if defined(EIGEN_GPUCC)
|
| 1682 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1683 |
+
float abs(const float &x) { return ::fabsf(x); }
|
| 1684 |
+
|
| 1685 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1686 |
+
double abs(const double &x) { return ::fabs(x); }
|
| 1687 |
+
|
| 1688 |
+
template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1689 |
+
float abs(const std::complex<float>& x) {
|
| 1690 |
+
return ::hypotf(x.real(), x.imag());
|
| 1691 |
+
}
|
| 1692 |
+
|
| 1693 |
+
template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1694 |
+
double abs(const std::complex<double>& x) {
|
| 1695 |
+
return ::hypot(x.real(), x.imag());
|
| 1696 |
+
}
|
| 1697 |
+
#endif
|
| 1698 |
+
|
| 1699 |
+
template<typename T>
|
| 1700 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1701 |
+
T exp(const T &x) {
|
| 1702 |
+
EIGEN_USING_STD(exp);
|
| 1703 |
+
return exp(x);
|
| 1704 |
+
}
|
| 1705 |
+
|
| 1706 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1707 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(exp, exp)
|
| 1708 |
+
#endif
|
| 1709 |
+
|
| 1710 |
+
#if defined(EIGEN_GPUCC)
|
| 1711 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1712 |
+
float exp(const float &x) { return ::expf(x); }
|
| 1713 |
+
|
| 1714 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1715 |
+
double exp(const double &x) { return ::exp(x); }
|
| 1716 |
+
|
| 1717 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1718 |
+
std::complex<float> exp(const std::complex<float>& x) {
|
| 1719 |
+
float com = ::expf(x.real());
|
| 1720 |
+
float res_real = com * ::cosf(x.imag());
|
| 1721 |
+
float res_imag = com * ::sinf(x.imag());
|
| 1722 |
+
return std::complex<float>(res_real, res_imag);
|
| 1723 |
+
}
|
| 1724 |
+
|
| 1725 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1726 |
+
std::complex<double> exp(const std::complex<double>& x) {
|
| 1727 |
+
double com = ::exp(x.real());
|
| 1728 |
+
double res_real = com * ::cos(x.imag());
|
| 1729 |
+
double res_imag = com * ::sin(x.imag());
|
| 1730 |
+
return std::complex<double>(res_real, res_imag);
|
| 1731 |
+
}
|
| 1732 |
+
#endif
|
| 1733 |
+
|
| 1734 |
+
template<typename Scalar>
|
| 1735 |
+
EIGEN_DEVICE_FUNC
|
| 1736 |
+
inline EIGEN_MATHFUNC_RETVAL(expm1, Scalar) expm1(const Scalar& x)
|
| 1737 |
+
{
|
| 1738 |
+
return EIGEN_MATHFUNC_IMPL(expm1, Scalar)::run(x);
|
| 1739 |
+
}
|
| 1740 |
+
|
| 1741 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1742 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(expm1, expm1)
|
| 1743 |
+
#endif
|
| 1744 |
+
|
| 1745 |
+
#if defined(EIGEN_GPUCC)
|
| 1746 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1747 |
+
float expm1(const float &x) { return ::expm1f(x); }
|
| 1748 |
+
|
| 1749 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1750 |
+
double expm1(const double &x) { return ::expm1(x); }
|
| 1751 |
+
#endif
|
| 1752 |
+
|
| 1753 |
+
template<typename T>
|
| 1754 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1755 |
+
T cos(const T &x) {
|
| 1756 |
+
EIGEN_USING_STD(cos);
|
| 1757 |
+
return cos(x);
|
| 1758 |
+
}
|
| 1759 |
+
|
| 1760 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1761 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cos,cos)
|
| 1762 |
+
#endif
|
| 1763 |
+
|
| 1764 |
+
#if defined(EIGEN_GPUCC)
|
| 1765 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1766 |
+
float cos(const float &x) { return ::cosf(x); }
|
| 1767 |
+
|
| 1768 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1769 |
+
double cos(const double &x) { return ::cos(x); }
|
| 1770 |
+
#endif
|
| 1771 |
+
|
| 1772 |
+
template<typename T>
|
| 1773 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1774 |
+
T sin(const T &x) {
|
| 1775 |
+
EIGEN_USING_STD(sin);
|
| 1776 |
+
return sin(x);
|
| 1777 |
+
}
|
| 1778 |
+
|
| 1779 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1780 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sin, sin)
|
| 1781 |
+
#endif
|
| 1782 |
+
|
| 1783 |
+
#if defined(EIGEN_GPUCC)
|
| 1784 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1785 |
+
float sin(const float &x) { return ::sinf(x); }
|
| 1786 |
+
|
| 1787 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1788 |
+
double sin(const double &x) { return ::sin(x); }
|
| 1789 |
+
#endif
|
| 1790 |
+
|
| 1791 |
+
template<typename T>
|
| 1792 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1793 |
+
T tan(const T &x) {
|
| 1794 |
+
EIGEN_USING_STD(tan);
|
| 1795 |
+
return tan(x);
|
| 1796 |
+
}
|
| 1797 |
+
|
| 1798 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1799 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tan, tan)
|
| 1800 |
+
#endif
|
| 1801 |
+
|
| 1802 |
+
#if defined(EIGEN_GPUCC)
|
| 1803 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1804 |
+
float tan(const float &x) { return ::tanf(x); }
|
| 1805 |
+
|
| 1806 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1807 |
+
double tan(const double &x) { return ::tan(x); }
|
| 1808 |
+
#endif
|
| 1809 |
+
|
| 1810 |
+
template<typename T>
|
| 1811 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1812 |
+
T acos(const T &x) {
|
| 1813 |
+
EIGEN_USING_STD(acos);
|
| 1814 |
+
return acos(x);
|
| 1815 |
+
}
|
| 1816 |
+
|
| 1817 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 1818 |
+
template<typename T>
|
| 1819 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1820 |
+
T acosh(const T &x) {
|
| 1821 |
+
EIGEN_USING_STD(acosh);
|
| 1822 |
+
return static_cast<T>(acosh(x));
|
| 1823 |
+
}
|
| 1824 |
+
#endif
|
| 1825 |
+
|
| 1826 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1827 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acos, acos)
|
| 1828 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acosh, acosh)
|
| 1829 |
+
#endif
|
| 1830 |
+
|
| 1831 |
+
#if defined(EIGEN_GPUCC)
|
| 1832 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1833 |
+
float acos(const float &x) { return ::acosf(x); }
|
| 1834 |
+
|
| 1835 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1836 |
+
double acos(const double &x) { return ::acos(x); }
|
| 1837 |
+
#endif
|
| 1838 |
+
|
| 1839 |
+
template<typename T>
|
| 1840 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1841 |
+
T asin(const T &x) {
|
| 1842 |
+
EIGEN_USING_STD(asin);
|
| 1843 |
+
return asin(x);
|
| 1844 |
+
}
|
| 1845 |
+
|
| 1846 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 1847 |
+
template<typename T>
|
| 1848 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1849 |
+
T asinh(const T &x) {
|
| 1850 |
+
EIGEN_USING_STD(asinh);
|
| 1851 |
+
return static_cast<T>(asinh(x));
|
| 1852 |
+
}
|
| 1853 |
+
#endif
|
| 1854 |
+
|
| 1855 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1856 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asin, asin)
|
| 1857 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asinh, asinh)
|
| 1858 |
+
#endif
|
| 1859 |
+
|
| 1860 |
+
#if defined(EIGEN_GPUCC)
|
| 1861 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1862 |
+
float asin(const float &x) { return ::asinf(x); }
|
| 1863 |
+
|
| 1864 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1865 |
+
double asin(const double &x) { return ::asin(x); }
|
| 1866 |
+
#endif
|
| 1867 |
+
|
| 1868 |
+
template<typename T>
|
| 1869 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1870 |
+
T atan(const T &x) {
|
| 1871 |
+
EIGEN_USING_STD(atan);
|
| 1872 |
+
return static_cast<T>(atan(x));
|
| 1873 |
+
}
|
| 1874 |
+
|
| 1875 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 1876 |
+
template<typename T>
|
| 1877 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1878 |
+
T atanh(const T &x) {
|
| 1879 |
+
EIGEN_USING_STD(atanh);
|
| 1880 |
+
return static_cast<T>(atanh(x));
|
| 1881 |
+
}
|
| 1882 |
+
#endif
|
| 1883 |
+
|
| 1884 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1885 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atan, atan)
|
| 1886 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atanh, atanh)
|
| 1887 |
+
#endif
|
| 1888 |
+
|
| 1889 |
+
#if defined(EIGEN_GPUCC)
|
| 1890 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1891 |
+
float atan(const float &x) { return ::atanf(x); }
|
| 1892 |
+
|
| 1893 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1894 |
+
double atan(const double &x) { return ::atan(x); }
|
| 1895 |
+
#endif
|
| 1896 |
+
|
| 1897 |
+
|
| 1898 |
+
template<typename T>
|
| 1899 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1900 |
+
T cosh(const T &x) {
|
| 1901 |
+
EIGEN_USING_STD(cosh);
|
| 1902 |
+
return static_cast<T>(cosh(x));
|
| 1903 |
+
}
|
| 1904 |
+
|
| 1905 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1906 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cosh, cosh)
|
| 1907 |
+
#endif
|
| 1908 |
+
|
| 1909 |
+
#if defined(EIGEN_GPUCC)
|
| 1910 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1911 |
+
float cosh(const float &x) { return ::coshf(x); }
|
| 1912 |
+
|
| 1913 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1914 |
+
double cosh(const double &x) { return ::cosh(x); }
|
| 1915 |
+
#endif
|
| 1916 |
+
|
| 1917 |
+
template<typename T>
|
| 1918 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1919 |
+
T sinh(const T &x) {
|
| 1920 |
+
EIGEN_USING_STD(sinh);
|
| 1921 |
+
return static_cast<T>(sinh(x));
|
| 1922 |
+
}
|
| 1923 |
+
|
| 1924 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1925 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sinh, sinh)
|
| 1926 |
+
#endif
|
| 1927 |
+
|
| 1928 |
+
#if defined(EIGEN_GPUCC)
|
| 1929 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1930 |
+
float sinh(const float &x) { return ::sinhf(x); }
|
| 1931 |
+
|
| 1932 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1933 |
+
double sinh(const double &x) { return ::sinh(x); }
|
| 1934 |
+
#endif
|
| 1935 |
+
|
| 1936 |
+
template<typename T>
|
| 1937 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1938 |
+
T tanh(const T &x) {
|
| 1939 |
+
EIGEN_USING_STD(tanh);
|
| 1940 |
+
return tanh(x);
|
| 1941 |
+
}
|
| 1942 |
+
|
| 1943 |
+
#if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY)
|
| 1944 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1945 |
+
float tanh(float x) { return internal::generic_fast_tanh_float(x); }
|
| 1946 |
+
#endif
|
| 1947 |
+
|
| 1948 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1949 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tanh, tanh)
|
| 1950 |
+
#endif
|
| 1951 |
+
|
| 1952 |
+
#if defined(EIGEN_GPUCC)
|
| 1953 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1954 |
+
float tanh(const float &x) { return ::tanhf(x); }
|
| 1955 |
+
|
| 1956 |
+
template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1957 |
+
double tanh(const double &x) { return ::tanh(x); }
|
| 1958 |
+
#endif
|
| 1959 |
+
|
| 1960 |
+
template <typename T>
|
| 1961 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1962 |
+
T fmod(const T& a, const T& b) {
|
| 1963 |
+
EIGEN_USING_STD(fmod);
|
| 1964 |
+
return fmod(a, b);
|
| 1965 |
+
}
|
| 1966 |
+
|
| 1967 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1968 |
+
SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(fmod, fmod)
|
| 1969 |
+
#endif
|
| 1970 |
+
|
| 1971 |
+
#if defined(EIGEN_GPUCC)
|
| 1972 |
+
template <>
|
| 1973 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1974 |
+
float fmod(const float& a, const float& b) {
|
| 1975 |
+
return ::fmodf(a, b);
|
| 1976 |
+
}
|
| 1977 |
+
|
| 1978 |
+
template <>
|
| 1979 |
+
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
| 1980 |
+
double fmod(const double& a, const double& b) {
|
| 1981 |
+
return ::fmod(a, b);
|
| 1982 |
+
}
|
| 1983 |
+
#endif
|
| 1984 |
+
|
| 1985 |
+
#if defined(SYCL_DEVICE_ONLY)
|
| 1986 |
+
#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY
|
| 1987 |
+
#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY
|
| 1988 |
+
#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY
|
| 1989 |
+
#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
|
| 1990 |
+
#undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY
|
| 1991 |
+
#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
|
| 1992 |
+
#undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY
|
| 1993 |
+
#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY
|
| 1994 |
+
#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE
|
| 1995 |
+
#undef SYCL_SPECIALIZE_GEN_UNARY_FUNC
|
| 1996 |
+
#undef SYCL_SPECIALIZE_UNARY_FUNC
|
| 1997 |
+
#undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC
|
| 1998 |
+
#undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC
|
| 1999 |
+
#undef SYCL_SPECIALIZE_BINARY_FUNC
|
| 2000 |
+
#endif
|
| 2001 |
+
|
| 2002 |
+
} // end namespace numext
|
| 2003 |
+
|
| 2004 |
+
namespace internal {
|
| 2005 |
+
|
| 2006 |
+
template<typename T>
|
| 2007 |
+
EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex<T>& x)
|
| 2008 |
+
{
|
| 2009 |
+
return (numext::isfinite)(numext::real(x)) && (numext::isfinite)(numext::imag(x));
|
| 2010 |
+
}
|
| 2011 |
+
|
| 2012 |
+
template<typename T>
|
| 2013 |
+
EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex<T>& x)
|
| 2014 |
+
{
|
| 2015 |
+
return (numext::isnan)(numext::real(x)) || (numext::isnan)(numext::imag(x));
|
| 2016 |
+
}
|
| 2017 |
+
|
| 2018 |
+
template<typename T>
|
| 2019 |
+
EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex<T>& x)
|
| 2020 |
+
{
|
| 2021 |
+
return ((numext::isinf)(numext::real(x)) || (numext::isinf)(numext::imag(x))) && (!(numext::isnan)(x));
|
| 2022 |
+
}
|
| 2023 |
+
|
| 2024 |
+
/****************************************************************************
|
| 2025 |
+
* Implementation of fuzzy comparisons *
|
| 2026 |
+
****************************************************************************/
|
| 2027 |
+
|
| 2028 |
+
template<typename Scalar,
|
| 2029 |
+
bool IsComplex,
|
| 2030 |
+
bool IsInteger>
|
| 2031 |
+
struct scalar_fuzzy_default_impl {};
|
| 2032 |
+
|
| 2033 |
+
template<typename Scalar>
|
| 2034 |
+
struct scalar_fuzzy_default_impl<Scalar, false, false>
|
| 2035 |
+
{
|
| 2036 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 2037 |
+
template<typename OtherScalar> EIGEN_DEVICE_FUNC
|
| 2038 |
+
static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
|
| 2039 |
+
{
|
| 2040 |
+
return numext::abs(x) <= numext::abs(y) * prec;
|
| 2041 |
+
}
|
| 2042 |
+
EIGEN_DEVICE_FUNC
|
| 2043 |
+
static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
|
| 2044 |
+
{
|
| 2045 |
+
return numext::abs(x - y) <= numext::mini(numext::abs(x), numext::abs(y)) * prec;
|
| 2046 |
+
}
|
| 2047 |
+
EIGEN_DEVICE_FUNC
|
| 2048 |
+
static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar& prec)
|
| 2049 |
+
{
|
| 2050 |
+
return x <= y || isApprox(x, y, prec);
|
| 2051 |
+
}
|
| 2052 |
+
};
|
| 2053 |
+
|
| 2054 |
+
template<typename Scalar>
|
| 2055 |
+
struct scalar_fuzzy_default_impl<Scalar, false, true>
|
| 2056 |
+
{
|
| 2057 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 2058 |
+
template<typename OtherScalar> EIGEN_DEVICE_FUNC
|
| 2059 |
+
static inline bool isMuchSmallerThan(const Scalar& x, const Scalar&, const RealScalar&)
|
| 2060 |
+
{
|
| 2061 |
+
return x == Scalar(0);
|
| 2062 |
+
}
|
| 2063 |
+
EIGEN_DEVICE_FUNC
|
| 2064 |
+
static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar&)
|
| 2065 |
+
{
|
| 2066 |
+
return x == y;
|
| 2067 |
+
}
|
| 2068 |
+
EIGEN_DEVICE_FUNC
|
| 2069 |
+
static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar&)
|
| 2070 |
+
{
|
| 2071 |
+
return x <= y;
|
| 2072 |
+
}
|
| 2073 |
+
};
|
| 2074 |
+
|
| 2075 |
+
template<typename Scalar>
|
| 2076 |
+
struct scalar_fuzzy_default_impl<Scalar, true, false>
|
| 2077 |
+
{
|
| 2078 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 2079 |
+
template<typename OtherScalar> EIGEN_DEVICE_FUNC
|
| 2080 |
+
static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
|
| 2081 |
+
{
|
| 2082 |
+
return numext::abs2(x) <= numext::abs2(y) * prec * prec;
|
| 2083 |
+
}
|
| 2084 |
+
EIGEN_DEVICE_FUNC
|
| 2085 |
+
static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
|
| 2086 |
+
{
|
| 2087 |
+
return numext::abs2(x - y) <= numext::mini(numext::abs2(x), numext::abs2(y)) * prec * prec;
|
| 2088 |
+
}
|
| 2089 |
+
};
|
| 2090 |
+
|
| 2091 |
+
template<typename Scalar>
|
| 2092 |
+
struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
|
| 2093 |
+
|
| 2094 |
+
template<typename Scalar, typename OtherScalar> EIGEN_DEVICE_FUNC
|
| 2095 |
+
inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y,
|
| 2096 |
+
const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
|
| 2097 |
+
{
|
| 2098 |
+
return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision);
|
| 2099 |
+
}
|
| 2100 |
+
|
| 2101 |
+
template<typename Scalar> EIGEN_DEVICE_FUNC
|
| 2102 |
+
inline bool isApprox(const Scalar& x, const Scalar& y,
|
| 2103 |
+
const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
|
| 2104 |
+
{
|
| 2105 |
+
return scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision);
|
| 2106 |
+
}
|
| 2107 |
+
|
| 2108 |
+
template<typename Scalar> EIGEN_DEVICE_FUNC
|
| 2109 |
+
inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y,
|
| 2110 |
+
const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
|
| 2111 |
+
{
|
| 2112 |
+
return scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision);
|
| 2113 |
+
}
|
| 2114 |
+
|
| 2115 |
+
/******************************************
|
| 2116 |
+
*** The special case of the bool type ***
|
| 2117 |
+
******************************************/
|
| 2118 |
+
|
| 2119 |
+
template<> struct random_impl<bool>
|
| 2120 |
+
{
|
| 2121 |
+
static inline bool run()
|
| 2122 |
+
{
|
| 2123 |
+
return random<int>(0,1)==0 ? false : true;
|
| 2124 |
+
}
|
| 2125 |
+
|
| 2126 |
+
static inline bool run(const bool& a, const bool& b)
|
| 2127 |
+
{
|
| 2128 |
+
return random<int>(a, b)==0 ? false : true;
|
| 2129 |
+
}
|
| 2130 |
+
};
|
| 2131 |
+
|
| 2132 |
+
template<> struct scalar_fuzzy_impl<bool>
|
| 2133 |
+
{
|
| 2134 |
+
typedef bool RealScalar;
|
| 2135 |
+
|
| 2136 |
+
template<typename OtherScalar> EIGEN_DEVICE_FUNC
|
| 2137 |
+
static inline bool isMuchSmallerThan(const bool& x, const bool&, const bool&)
|
| 2138 |
+
{
|
| 2139 |
+
return !x;
|
| 2140 |
+
}
|
| 2141 |
+
|
| 2142 |
+
EIGEN_DEVICE_FUNC
|
| 2143 |
+
static inline bool isApprox(bool x, bool y, bool)
|
| 2144 |
+
{
|
| 2145 |
+
return x == y;
|
| 2146 |
+
}
|
| 2147 |
+
|
| 2148 |
+
EIGEN_DEVICE_FUNC
|
| 2149 |
+
static inline bool isApproxOrLessThan(const bool& x, const bool& y, const bool&)
|
| 2150 |
+
{
|
| 2151 |
+
return (!x) || y;
|
| 2152 |
+
}
|
| 2153 |
+
|
| 2154 |
+
};
|
| 2155 |
+
|
| 2156 |
+
} // end namespace internal
|
| 2157 |
+
|
| 2158 |
+
// Default implementations that rely on other numext implementations
|
| 2159 |
+
namespace internal {
|
| 2160 |
+
|
| 2161 |
+
// Specialization for complex types that are not supported by std::expm1.
|
| 2162 |
+
template <typename RealScalar>
|
| 2163 |
+
struct expm1_impl<std::complex<RealScalar> > {
|
| 2164 |
+
EIGEN_DEVICE_FUNC static inline std::complex<RealScalar> run(
|
| 2165 |
+
const std::complex<RealScalar>& x) {
|
| 2166 |
+
EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
|
| 2167 |
+
RealScalar xr = x.real();
|
| 2168 |
+
RealScalar xi = x.imag();
|
| 2169 |
+
// expm1(z) = exp(z) - 1
|
| 2170 |
+
// = exp(x + i * y) - 1
|
| 2171 |
+
// = exp(x) * (cos(y) + i * sin(y)) - 1
|
| 2172 |
+
// = exp(x) * cos(y) - 1 + i * exp(x) * sin(y)
|
| 2173 |
+
// Imag(expm1(z)) = exp(x) * sin(y)
|
| 2174 |
+
// Real(expm1(z)) = exp(x) * cos(y) - 1
|
| 2175 |
+
// = exp(x) * cos(y) - 1.
|
| 2176 |
+
// = expm1(x) + exp(x) * (cos(y) - 1)
|
| 2177 |
+
// = expm1(x) + exp(x) * (2 * sin(y / 2) ** 2)
|
| 2178 |
+
RealScalar erm1 = numext::expm1<RealScalar>(xr);
|
| 2179 |
+
RealScalar er = erm1 + RealScalar(1.);
|
| 2180 |
+
RealScalar sin2 = numext::sin(xi / RealScalar(2.));
|
| 2181 |
+
sin2 = sin2 * sin2;
|
| 2182 |
+
RealScalar s = numext::sin(xi);
|
| 2183 |
+
RealScalar real_part = erm1 - RealScalar(2.) * er * sin2;
|
| 2184 |
+
return std::complex<RealScalar>(real_part, er * s);
|
| 2185 |
+
}
|
| 2186 |
+
};
|
| 2187 |
+
|
| 2188 |
+
template<typename T>
|
| 2189 |
+
struct rsqrt_impl {
|
| 2190 |
+
EIGEN_DEVICE_FUNC
|
| 2191 |
+
static EIGEN_ALWAYS_INLINE T run(const T& x) {
|
| 2192 |
+
return T(1)/numext::sqrt(x);
|
| 2193 |
+
}
|
| 2194 |
+
};
|
| 2195 |
+
|
| 2196 |
+
#if defined(EIGEN_GPU_COMPILE_PHASE)
|
| 2197 |
+
template<typename T>
|
| 2198 |
+
struct conj_impl<std::complex<T>, true>
|
| 2199 |
+
{
|
| 2200 |
+
EIGEN_DEVICE_FUNC
|
| 2201 |
+
static inline std::complex<T> run(const std::complex<T>& x)
|
| 2202 |
+
{
|
| 2203 |
+
return std::complex<T>(numext::real(x), -numext::imag(x));
|
| 2204 |
+
}
|
| 2205 |
+
};
|
| 2206 |
+
#endif
|
| 2207 |
+
|
| 2208 |
+
} // end namespace internal
|
| 2209 |
+
|
| 2210 |
+
} // end namespace Eigen
|
| 2211 |
+
|
| 2212 |
+
#endif // EIGEN_MATHFUNCTIONS_H
|
include/eigen/Eigen/src/Core/MathFunctionsImpl.h
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com)
|
| 5 |
+
// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_MATHFUNCTIONSIMPL_H
|
| 12 |
+
#define EIGEN_MATHFUNCTIONSIMPL_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
|
| 18 |
+
/** \internal \returns the hyperbolic tan of \a a (coeff-wise)
|
| 19 |
+
Doesn't do anything fancy, just a 13/6-degree rational interpolant which
|
| 20 |
+
is accurate up to a couple of ulps in the (approximate) range [-8, 8],
|
| 21 |
+
outside of which tanh(x) = +/-1 in single precision. The input is clamped
|
| 22 |
+
to the range [-c, c]. The value c is chosen as the smallest value where
|
| 23 |
+
the approximation evaluates to exactly 1. In the reange [-0.0004, 0.0004]
|
| 24 |
+
the approxmation tanh(x) ~= x is used for better accuracy as x tends to zero.
|
| 25 |
+
|
| 26 |
+
This implementation works on both scalars and packets.
|
| 27 |
+
*/
|
| 28 |
+
template<typename T>
|
| 29 |
+
T generic_fast_tanh_float(const T& a_x)
|
| 30 |
+
{
|
| 31 |
+
// Clamp the inputs to the range [-c, c]
|
| 32 |
+
#ifdef EIGEN_VECTORIZE_FMA
|
| 33 |
+
const T plus_clamp = pset1<T>(7.99881172180175781f);
|
| 34 |
+
const T minus_clamp = pset1<T>(-7.99881172180175781f);
|
| 35 |
+
#else
|
| 36 |
+
const T plus_clamp = pset1<T>(7.90531110763549805f);
|
| 37 |
+
const T minus_clamp = pset1<T>(-7.90531110763549805f);
|
| 38 |
+
#endif
|
| 39 |
+
const T tiny = pset1<T>(0.0004f);
|
| 40 |
+
const T x = pmax(pmin(a_x, plus_clamp), minus_clamp);
|
| 41 |
+
const T tiny_mask = pcmp_lt(pabs(a_x), tiny);
|
| 42 |
+
// The monomial coefficients of the numerator polynomial (odd).
|
| 43 |
+
const T alpha_1 = pset1<T>(4.89352455891786e-03f);
|
| 44 |
+
const T alpha_3 = pset1<T>(6.37261928875436e-04f);
|
| 45 |
+
const T alpha_5 = pset1<T>(1.48572235717979e-05f);
|
| 46 |
+
const T alpha_7 = pset1<T>(5.12229709037114e-08f);
|
| 47 |
+
const T alpha_9 = pset1<T>(-8.60467152213735e-11f);
|
| 48 |
+
const T alpha_11 = pset1<T>(2.00018790482477e-13f);
|
| 49 |
+
const T alpha_13 = pset1<T>(-2.76076847742355e-16f);
|
| 50 |
+
|
| 51 |
+
// The monomial coefficients of the denominator polynomial (even).
|
| 52 |
+
const T beta_0 = pset1<T>(4.89352518554385e-03f);
|
| 53 |
+
const T beta_2 = pset1<T>(2.26843463243900e-03f);
|
| 54 |
+
const T beta_4 = pset1<T>(1.18534705686654e-04f);
|
| 55 |
+
const T beta_6 = pset1<T>(1.19825839466702e-06f);
|
| 56 |
+
|
| 57 |
+
// Since the polynomials are odd/even, we need x^2.
|
| 58 |
+
const T x2 = pmul(x, x);
|
| 59 |
+
|
| 60 |
+
// Evaluate the numerator polynomial p.
|
| 61 |
+
T p = pmadd(x2, alpha_13, alpha_11);
|
| 62 |
+
p = pmadd(x2, p, alpha_9);
|
| 63 |
+
p = pmadd(x2, p, alpha_7);
|
| 64 |
+
p = pmadd(x2, p, alpha_5);
|
| 65 |
+
p = pmadd(x2, p, alpha_3);
|
| 66 |
+
p = pmadd(x2, p, alpha_1);
|
| 67 |
+
p = pmul(x, p);
|
| 68 |
+
|
| 69 |
+
// Evaluate the denominator polynomial q.
|
| 70 |
+
T q = pmadd(x2, beta_6, beta_4);
|
| 71 |
+
q = pmadd(x2, q, beta_2);
|
| 72 |
+
q = pmadd(x2, q, beta_0);
|
| 73 |
+
|
| 74 |
+
// Divide the numerator by the denominator.
|
| 75 |
+
return pselect(tiny_mask, x, pdiv(p, q));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
template<typename RealScalar>
|
| 79 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 80 |
+
RealScalar positive_real_hypot(const RealScalar& x, const RealScalar& y)
|
| 81 |
+
{
|
| 82 |
+
// IEEE IEC 6059 special cases.
|
| 83 |
+
if ((numext::isinf)(x) || (numext::isinf)(y))
|
| 84 |
+
return NumTraits<RealScalar>::infinity();
|
| 85 |
+
if ((numext::isnan)(x) || (numext::isnan)(y))
|
| 86 |
+
return NumTraits<RealScalar>::quiet_NaN();
|
| 87 |
+
|
| 88 |
+
EIGEN_USING_STD(sqrt);
|
| 89 |
+
RealScalar p, qp;
|
| 90 |
+
p = numext::maxi(x,y);
|
| 91 |
+
if(p==RealScalar(0)) return RealScalar(0);
|
| 92 |
+
qp = numext::mini(y,x) / p;
|
| 93 |
+
return p * sqrt(RealScalar(1) + qp*qp);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
template<typename Scalar>
|
| 97 |
+
struct hypot_impl
|
| 98 |
+
{
|
| 99 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 100 |
+
static EIGEN_DEVICE_FUNC
|
| 101 |
+
inline RealScalar run(const Scalar& x, const Scalar& y)
|
| 102 |
+
{
|
| 103 |
+
EIGEN_USING_STD(abs);
|
| 104 |
+
return positive_real_hypot<RealScalar>(abs(x), abs(y));
|
| 105 |
+
}
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
// Generic complex sqrt implementation that correctly handles corner cases
|
| 109 |
+
// according to https://en.cppreference.com/w/cpp/numeric/complex/sqrt
|
| 110 |
+
template<typename T>
|
| 111 |
+
EIGEN_DEVICE_FUNC std::complex<T> complex_sqrt(const std::complex<T>& z) {
|
| 112 |
+
// Computes the principal sqrt of the input.
|
| 113 |
+
//
|
| 114 |
+
// For a complex square root of the number x + i*y. We want to find real
|
| 115 |
+
// numbers u and v such that
|
| 116 |
+
// (u + i*v)^2 = x + i*y <=>
|
| 117 |
+
// u^2 - v^2 + i*2*u*v = x + i*v.
|
| 118 |
+
// By equating the real and imaginary parts we get:
|
| 119 |
+
// u^2 - v^2 = x
|
| 120 |
+
// 2*u*v = y.
|
| 121 |
+
//
|
| 122 |
+
// For x >= 0, this has the numerically stable solution
|
| 123 |
+
// u = sqrt(0.5 * (x + sqrt(x^2 + y^2)))
|
| 124 |
+
// v = y / (2 * u)
|
| 125 |
+
// and for x < 0,
|
| 126 |
+
// v = sign(y) * sqrt(0.5 * (-x + sqrt(x^2 + y^2)))
|
| 127 |
+
// u = y / (2 * v)
|
| 128 |
+
//
|
| 129 |
+
// Letting w = sqrt(0.5 * (|x| + |z|)),
|
| 130 |
+
// if x == 0: u = w, v = sign(y) * w
|
| 131 |
+
// if x > 0: u = w, v = y / (2 * w)
|
| 132 |
+
// if x < 0: u = |y| / (2 * w), v = sign(y) * w
|
| 133 |
+
|
| 134 |
+
const T x = numext::real(z);
|
| 135 |
+
const T y = numext::imag(z);
|
| 136 |
+
const T zero = T(0);
|
| 137 |
+
const T w = numext::sqrt(T(0.5) * (numext::abs(x) + numext::hypot(x, y)));
|
| 138 |
+
|
| 139 |
+
return
|
| 140 |
+
(numext::isinf)(y) ? std::complex<T>(NumTraits<T>::infinity(), y)
|
| 141 |
+
: x == zero ? std::complex<T>(w, y < zero ? -w : w)
|
| 142 |
+
: x > zero ? std::complex<T>(w, y / (2 * w))
|
| 143 |
+
: std::complex<T>(numext::abs(y) / (2 * w), y < zero ? -w : w );
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Generic complex rsqrt implementation.
|
| 147 |
+
template<typename T>
|
| 148 |
+
EIGEN_DEVICE_FUNC std::complex<T> complex_rsqrt(const std::complex<T>& z) {
|
| 149 |
+
// Computes the principal reciprocal sqrt of the input.
|
| 150 |
+
//
|
| 151 |
+
// For a complex reciprocal square root of the number z = x + i*y. We want to
|
| 152 |
+
// find real numbers u and v such that
|
| 153 |
+
// (u + i*v)^2 = 1 / (x + i*y) <=>
|
| 154 |
+
// u^2 - v^2 + i*2*u*v = x/|z|^2 - i*v/|z|^2.
|
| 155 |
+
// By equating the real and imaginary parts we get:
|
| 156 |
+
// u^2 - v^2 = x/|z|^2
|
| 157 |
+
// 2*u*v = y/|z|^2.
|
| 158 |
+
//
|
| 159 |
+
// For x >= 0, this has the numerically stable solution
|
| 160 |
+
// u = sqrt(0.5 * (x + |z|)) / |z|
|
| 161 |
+
// v = -y / (2 * u * |z|)
|
| 162 |
+
// and for x < 0,
|
| 163 |
+
// v = -sign(y) * sqrt(0.5 * (-x + |z|)) / |z|
|
| 164 |
+
// u = -y / (2 * v * |z|)
|
| 165 |
+
//
|
| 166 |
+
// Letting w = sqrt(0.5 * (|x| + |z|)),
|
| 167 |
+
// if x == 0: u = w / |z|, v = -sign(y) * w / |z|
|
| 168 |
+
// if x > 0: u = w / |z|, v = -y / (2 * w * |z|)
|
| 169 |
+
// if x < 0: u = |y| / (2 * w * |z|), v = -sign(y) * w / |z|
|
| 170 |
+
|
| 171 |
+
const T x = numext::real(z);
|
| 172 |
+
const T y = numext::imag(z);
|
| 173 |
+
const T zero = T(0);
|
| 174 |
+
|
| 175 |
+
const T abs_z = numext::hypot(x, y);
|
| 176 |
+
const T w = numext::sqrt(T(0.5) * (numext::abs(x) + abs_z));
|
| 177 |
+
const T woz = w / abs_z;
|
| 178 |
+
// Corner cases consistent with 1/sqrt(z) on gcc/clang.
|
| 179 |
+
return
|
| 180 |
+
abs_z == zero ? std::complex<T>(NumTraits<T>::infinity(), NumTraits<T>::quiet_NaN())
|
| 181 |
+
: ((numext::isinf)(x) || (numext::isinf)(y)) ? std::complex<T>(zero, zero)
|
| 182 |
+
: x == zero ? std::complex<T>(woz, y < zero ? woz : -woz)
|
| 183 |
+
: x > zero ? std::complex<T>(woz, -y / (2 * w * abs_z))
|
| 184 |
+
: std::complex<T>(numext::abs(y) / (2 * w * abs_z), y < zero ? woz : -woz );
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
template<typename T>
|
| 188 |
+
EIGEN_DEVICE_FUNC std::complex<T> complex_log(const std::complex<T>& z) {
|
| 189 |
+
// Computes complex log.
|
| 190 |
+
T a = numext::abs(z);
|
| 191 |
+
EIGEN_USING_STD(atan2);
|
| 192 |
+
T b = atan2(z.imag(), z.real());
|
| 193 |
+
return std::complex<T>(numext::log(a), b);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
} // end namespace internal
|
| 197 |
+
|
| 198 |
+
} // end namespace Eigen
|
| 199 |
+
|
| 200 |
+
#endif // EIGEN_MATHFUNCTIONSIMPL_H
|
include/eigen/Eigen/src/Core/Matrix.h
ADDED
|
@@ -0,0 +1,578 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_MATRIX_H
|
| 12 |
+
#define EIGEN_MATRIX_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
| 18 |
+
struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
| 19 |
+
{
|
| 20 |
+
private:
|
| 21 |
+
enum { size = internal::size_at_compile_time<_Rows,_Cols>::ret };
|
| 22 |
+
typedef typename find_best_packet<_Scalar,size>::type PacketScalar;
|
| 23 |
+
enum {
|
| 24 |
+
row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
|
| 25 |
+
is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
|
| 26 |
+
max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
|
| 27 |
+
default_alignment = compute_default_alignment<_Scalar,max_size>::value,
|
| 28 |
+
actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
|
| 29 |
+
required_alignment = unpacket_traits<PacketScalar>::alignment,
|
| 30 |
+
packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
public:
|
| 34 |
+
typedef _Scalar Scalar;
|
| 35 |
+
typedef Dense StorageKind;
|
| 36 |
+
typedef Eigen::Index StorageIndex;
|
| 37 |
+
typedef MatrixXpr XprKind;
|
| 38 |
+
enum {
|
| 39 |
+
RowsAtCompileTime = _Rows,
|
| 40 |
+
ColsAtCompileTime = _Cols,
|
| 41 |
+
MaxRowsAtCompileTime = _MaxRows,
|
| 42 |
+
MaxColsAtCompileTime = _MaxCols,
|
| 43 |
+
Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
|
| 44 |
+
Options = _Options,
|
| 45 |
+
InnerStrideAtCompileTime = 1,
|
| 46 |
+
OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
|
| 47 |
+
|
| 48 |
+
// FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
|
| 49 |
+
EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
|
| 50 |
+
Alignment = actual_alignment
|
| 51 |
+
};
|
| 52 |
+
};
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/** \class Matrix
|
| 56 |
+
* \ingroup Core_Module
|
| 57 |
+
*
|
| 58 |
+
* \brief The matrix class, also used for vectors and row-vectors
|
| 59 |
+
*
|
| 60 |
+
* The %Matrix class is the work-horse for all \em dense (\ref dense "note") matrices and vectors within Eigen.
|
| 61 |
+
* Vectors are matrices with one column, and row-vectors are matrices with one row.
|
| 62 |
+
*
|
| 63 |
+
* The %Matrix class encompasses \em both fixed-size and dynamic-size objects (\ref fixedsize "note").
|
| 64 |
+
*
|
| 65 |
+
* The first three template parameters are required:
|
| 66 |
+
* \tparam _Scalar Numeric type, e.g. float, double, int or std::complex<float>.
|
| 67 |
+
* User defined scalar types are supported as well (see \ref user_defined_scalars "here").
|
| 68 |
+
* \tparam _Rows Number of rows, or \b Dynamic
|
| 69 |
+
* \tparam _Cols Number of columns, or \b Dynamic
|
| 70 |
+
*
|
| 71 |
+
* The remaining template parameters are optional -- in most cases you don't have to worry about them.
|
| 72 |
+
* \tparam _Options A combination of either \b #RowMajor or \b #ColMajor, and of either
|
| 73 |
+
* \b #AutoAlign or \b #DontAlign.
|
| 74 |
+
* The former controls \ref TopicStorageOrders "storage order", and defaults to column-major. The latter controls alignment, which is required
|
| 75 |
+
* for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size.
|
| 76 |
+
* \tparam _MaxRows Maximum number of rows. Defaults to \a _Rows (\ref maxrows "note").
|
| 77 |
+
* \tparam _MaxCols Maximum number of columns. Defaults to \a _Cols (\ref maxrows "note").
|
| 78 |
+
*
|
| 79 |
+
* Eigen provides a number of typedefs covering the usual cases. Here are some examples:
|
| 80 |
+
*
|
| 81 |
+
* \li \c Matrix2d is a 2x2 square matrix of doubles (\c Matrix<double, 2, 2>)
|
| 82 |
+
* \li \c Vector4f is a vector of 4 floats (\c Matrix<float, 4, 1>)
|
| 83 |
+
* \li \c RowVector3i is a row-vector of 3 ints (\c Matrix<int, 1, 3>)
|
| 84 |
+
*
|
| 85 |
+
* \li \c MatrixXf is a dynamic-size matrix of floats (\c Matrix<float, Dynamic, Dynamic>)
|
| 86 |
+
* \li \c VectorXf is a dynamic-size vector of floats (\c Matrix<float, Dynamic, 1>)
|
| 87 |
+
*
|
| 88 |
+
* \li \c Matrix2Xf is a partially fixed-size (dynamic-size) matrix of floats (\c Matrix<float, 2, Dynamic>)
|
| 89 |
+
* \li \c MatrixX3d is a partially dynamic-size (fixed-size) matrix of double (\c Matrix<double, Dynamic, 3>)
|
| 90 |
+
*
|
| 91 |
+
* See \link matrixtypedefs this page \endlink for a complete list of predefined \em %Matrix and \em Vector typedefs.
|
| 92 |
+
*
|
| 93 |
+
* You can access elements of vectors and matrices using normal subscripting:
|
| 94 |
+
*
|
| 95 |
+
* \code
|
| 96 |
+
* Eigen::VectorXd v(10);
|
| 97 |
+
* v[0] = 0.1;
|
| 98 |
+
* v[1] = 0.2;
|
| 99 |
+
* v(0) = 0.3;
|
| 100 |
+
* v(1) = 0.4;
|
| 101 |
+
*
|
| 102 |
+
* Eigen::MatrixXi m(10, 10);
|
| 103 |
+
* m(0, 1) = 1;
|
| 104 |
+
* m(0, 2) = 2;
|
| 105 |
+
* m(0, 3) = 3;
|
| 106 |
+
* \endcode
|
| 107 |
+
*
|
| 108 |
+
* This class can be extended with the help of the plugin mechanism described on the page
|
| 109 |
+
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIX_PLUGIN.
|
| 110 |
+
*
|
| 111 |
+
* <i><b>Some notes:</b></i>
|
| 112 |
+
*
|
| 113 |
+
* <dl>
|
| 114 |
+
* <dt><b>\anchor dense Dense versus sparse:</b></dt>
|
| 115 |
+
* <dd>This %Matrix class handles dense, not sparse matrices and vectors. For sparse matrices and vectors, see the Sparse module.
|
| 116 |
+
*
|
| 117 |
+
* Dense matrices and vectors are plain usual arrays of coefficients. All the coefficients are stored, in an ordinary contiguous array.
|
| 118 |
+
* This is unlike Sparse matrices and vectors where the coefficients are stored as a list of nonzero coefficients.</dd>
|
| 119 |
+
*
|
| 120 |
+
* <dt><b>\anchor fixedsize Fixed-size versus dynamic-size:</b></dt>
|
| 121 |
+
* <dd>Fixed-size means that the numbers of rows and columns are known are compile-time. In this case, Eigen allocates the array
|
| 122 |
+
* of coefficients as a fixed-size array, as a class member. This makes sense for very small matrices, typically up to 4x4, sometimes up
|
| 123 |
+
* to 16x16. Larger matrices should be declared as dynamic-size even if one happens to know their size at compile-time.
|
| 124 |
+
*
|
| 125 |
+
* Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime
|
| 126 |
+
* variables, and the array of coefficients is allocated dynamically on the heap.
|
| 127 |
+
*
|
| 128 |
+
* Note that \em dense matrices, be they Fixed-size or Dynamic-size, <em>do not</em> expand dynamically in the sense of a std::map.
|
| 129 |
+
* If you want this behavior, see the Sparse module.</dd>
|
| 130 |
+
*
|
| 131 |
+
* <dt><b>\anchor maxrows _MaxRows and _MaxCols:</b></dt>
|
| 132 |
+
* <dd>In most cases, one just leaves these parameters to the default values.
|
| 133 |
+
* These parameters mean the maximum size of rows and columns that the matrix may have. They are useful in cases
|
| 134 |
+
* when the exact numbers of rows and columns are not known are compile-time, but it is known at compile-time that they cannot
|
| 135 |
+
* exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case _MaxRows and _MaxCols
|
| 136 |
+
* are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.</dd>
|
| 137 |
+
* </dl>
|
| 138 |
+
*
|
| 139 |
+
* <i><b>ABI and storage layout</b></i>
|
| 140 |
+
*
|
| 141 |
+
* The table below summarizes the ABI of some possible Matrix instances which is fixed thorough the lifetime of Eigen 3.
|
| 142 |
+
* <table class="manual">
|
| 143 |
+
* <tr><th>Matrix type</th><th>Equivalent C structure</th></tr>
|
| 144 |
+
* <tr><td>\code Matrix<T,Dynamic,Dynamic> \endcode</td><td>\code
|
| 145 |
+
* struct {
|
| 146 |
+
* T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0
|
| 147 |
+
* Eigen::Index rows, cols;
|
| 148 |
+
* };
|
| 149 |
+
* \endcode</td></tr>
|
| 150 |
+
* <tr class="alt"><td>\code
|
| 151 |
+
* Matrix<T,Dynamic,1>
|
| 152 |
+
* Matrix<T,1,Dynamic> \endcode</td><td>\code
|
| 153 |
+
* struct {
|
| 154 |
+
* T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0
|
| 155 |
+
* Eigen::Index size;
|
| 156 |
+
* };
|
| 157 |
+
* \endcode</td></tr>
|
| 158 |
+
* <tr><td>\code Matrix<T,Rows,Cols> \endcode</td><td>\code
|
| 159 |
+
* struct {
|
| 160 |
+
* T data[Rows*Cols]; // with (size_t(data)%A(Rows*Cols*sizeof(T)))==0
|
| 161 |
+
* };
|
| 162 |
+
* \endcode</td></tr>
|
| 163 |
+
* <tr class="alt"><td>\code Matrix<T,Dynamic,Dynamic,0,MaxRows,MaxCols> \endcode</td><td>\code
|
| 164 |
+
* struct {
|
| 165 |
+
* T data[MaxRows*MaxCols]; // with (size_t(data)%A(MaxRows*MaxCols*sizeof(T)))==0
|
| 166 |
+
* Eigen::Index rows, cols;
|
| 167 |
+
* };
|
| 168 |
+
* \endcode</td></tr>
|
| 169 |
+
* </table>
|
| 170 |
+
* Note that in this table Rows, Cols, MaxRows and MaxCols are all positive integers. A(S) is defined to the largest possible power-of-two
|
| 171 |
+
* smaller to EIGEN_MAX_STATIC_ALIGN_BYTES.
|
| 172 |
+
*
|
| 173 |
+
* \see MatrixBase for the majority of the API methods for matrices, \ref TopicClassHierarchy,
|
| 174 |
+
* \ref TopicStorageOrders
|
| 175 |
+
*/
|
| 176 |
+
|
| 177 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
| 178 |
+
class Matrix
|
| 179 |
+
: public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
| 180 |
+
{
|
| 181 |
+
public:
|
| 182 |
+
|
| 183 |
+
/** \brief Base class typedef.
|
| 184 |
+
* \sa PlainObjectBase
|
| 185 |
+
*/
|
| 186 |
+
typedef PlainObjectBase<Matrix> Base;
|
| 187 |
+
|
| 188 |
+
enum { Options = _Options };
|
| 189 |
+
|
| 190 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
|
| 191 |
+
|
| 192 |
+
typedef typename Base::PlainObject PlainObject;
|
| 193 |
+
|
| 194 |
+
using Base::base;
|
| 195 |
+
using Base::coeffRef;
|
| 196 |
+
|
| 197 |
+
/**
|
| 198 |
+
* \brief Assigns matrices to each other.
|
| 199 |
+
*
|
| 200 |
+
* \note This is a special case of the templated operator=. Its purpose is
|
| 201 |
+
* to prevent a default operator= from hiding the templated operator=.
|
| 202 |
+
*
|
| 203 |
+
* \callgraph
|
| 204 |
+
*/
|
| 205 |
+
EIGEN_DEVICE_FUNC
|
| 206 |
+
EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
|
| 207 |
+
{
|
| 208 |
+
return Base::_set(other);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/** \internal
|
| 212 |
+
* \brief Copies the value of the expression \a other into \c *this with automatic resizing.
|
| 213 |
+
*
|
| 214 |
+
* *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
|
| 215 |
+
* it will be initialized.
|
| 216 |
+
*
|
| 217 |
+
* Note that copying a row-vector into a vector (and conversely) is allowed.
|
| 218 |
+
* The resizing, if any, is then done in the appropriate way so that row-vectors
|
| 219 |
+
* remain row-vectors and vectors remain vectors.
|
| 220 |
+
*/
|
| 221 |
+
template<typename OtherDerived>
|
| 222 |
+
EIGEN_DEVICE_FUNC
|
| 223 |
+
EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other)
|
| 224 |
+
{
|
| 225 |
+
return Base::_set(other);
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* \brief Copies the generic expression \a other into *this.
|
| 230 |
+
* \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other)
|
| 231 |
+
*/
|
| 232 |
+
template<typename OtherDerived>
|
| 233 |
+
EIGEN_DEVICE_FUNC
|
| 234 |
+
EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
|
| 235 |
+
{
|
| 236 |
+
return Base::operator=(other);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
template<typename OtherDerived>
|
| 240 |
+
EIGEN_DEVICE_FUNC
|
| 241 |
+
EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
|
| 242 |
+
{
|
| 243 |
+
return Base::operator=(func);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/** \brief Default constructor.
|
| 247 |
+
*
|
| 248 |
+
* For fixed-size matrices, does nothing.
|
| 249 |
+
*
|
| 250 |
+
* For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix
|
| 251 |
+
* is called a null matrix. This constructor is the unique way to create null matrices: resizing
|
| 252 |
+
* a matrix to 0 is not supported.
|
| 253 |
+
*
|
| 254 |
+
* \sa resize(Index,Index)
|
| 255 |
+
*/
|
| 256 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 257 |
+
Matrix() : Base()
|
| 258 |
+
{
|
| 259 |
+
Base::_check_template_params();
|
| 260 |
+
EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// FIXME is it still needed
|
| 264 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 265 |
+
explicit Matrix(internal::constructor_without_unaligned_array_assert)
|
| 266 |
+
: Base(internal::constructor_without_unaligned_array_assert())
|
| 267 |
+
{ Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
|
| 268 |
+
|
| 269 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 270 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 271 |
+
Matrix(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
|
| 272 |
+
: Base(std::move(other))
|
| 273 |
+
{
|
| 274 |
+
Base::_check_template_params();
|
| 275 |
+
}
|
| 276 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 277 |
+
Matrix& operator=(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
|
| 278 |
+
{
|
| 279 |
+
Base::operator=(std::move(other));
|
| 280 |
+
return *this;
|
| 281 |
+
}
|
| 282 |
+
#endif
|
| 283 |
+
|
| 284 |
+
#if EIGEN_HAS_CXX11
|
| 285 |
+
/** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. \cpp11
|
| 286 |
+
*
|
| 287 |
+
* \only_for_vectors
|
| 288 |
+
*
|
| 289 |
+
* This constructor is for 1D array or vectors with more than 4 coefficients.
|
| 290 |
+
* There exists C++98 analogue constructors for fixed-size array/vector having 1, 2, 3, or 4 coefficients.
|
| 291 |
+
*
|
| 292 |
+
* \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this
|
| 293 |
+
* constructor must match the the fixed number of rows (resp. columns) of \c *this.
|
| 294 |
+
*
|
| 295 |
+
* Example: \include Matrix_variadic_ctor_cxx11.cpp
|
| 296 |
+
* Output: \verbinclude Matrix_variadic_ctor_cxx11.out
|
| 297 |
+
*
|
| 298 |
+
* \sa Matrix(const std::initializer_list<std::initializer_list<Scalar>>&)
|
| 299 |
+
*/
|
| 300 |
+
template <typename... ArgTypes>
|
| 301 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 302 |
+
Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 303 |
+
: Base(a0, a1, a2, a3, args...) {}
|
| 304 |
+
|
| 305 |
+
/** \brief Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by row. \cpp11
|
| 306 |
+
*
|
| 307 |
+
* \anchor matrix_constructor_initializer_list
|
| 308 |
+
*
|
| 309 |
+
* In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients:
|
| 310 |
+
*
|
| 311 |
+
* Example: \include Matrix_initializer_list_23_cxx11.cpp
|
| 312 |
+
* Output: \verbinclude Matrix_initializer_list_23_cxx11.out
|
| 313 |
+
*
|
| 314 |
+
* Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered.
|
| 315 |
+
*
|
| 316 |
+
* In the case of a compile-time column vector, implicit transposition from a single row is allowed.
|
| 317 |
+
* Therefore <code>VectorXd{{1,2,3,4,5}}</code> is legal and the more verbose syntax
|
| 318 |
+
* <code>RowVectorXd{{1},{2},{3},{4},{5}}</code> can be avoided:
|
| 319 |
+
*
|
| 320 |
+
* Example: \include Matrix_initializer_list_vector_cxx11.cpp
|
| 321 |
+
* Output: \verbinclude Matrix_initializer_list_vector_cxx11.out
|
| 322 |
+
*
|
| 323 |
+
* In the case of fixed-sized matrices, the initializer list sizes must exactly match the matrix sizes,
|
| 324 |
+
* and implicit transposition is allowed for compile-time vectors only.
|
| 325 |
+
*
|
| 326 |
+
* \sa Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 327 |
+
*/
|
| 328 |
+
EIGEN_DEVICE_FUNC
|
| 329 |
+
explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
|
| 330 |
+
#endif // end EIGEN_HAS_CXX11
|
| 331 |
+
|
| 332 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 333 |
+
|
| 334 |
+
// This constructor is for both 1x1 matrices and dynamic vectors
|
| 335 |
+
template<typename T>
|
| 336 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 337 |
+
explicit Matrix(const T& x)
|
| 338 |
+
{
|
| 339 |
+
Base::_check_template_params();
|
| 340 |
+
Base::template _init1<T>(x);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
template<typename T0, typename T1>
|
| 344 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 345 |
+
Matrix(const T0& x, const T1& y)
|
| 346 |
+
{
|
| 347 |
+
Base::_check_template_params();
|
| 348 |
+
Base::template _init2<T0,T1>(x, y);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
#else
|
| 353 |
+
/** \brief Constructs a fixed-sized matrix initialized with coefficients starting at \a data */
|
| 354 |
+
EIGEN_DEVICE_FUNC
|
| 355 |
+
explicit Matrix(const Scalar *data);
|
| 356 |
+
|
| 357 |
+
/** \brief Constructs a vector or row-vector with given dimension. \only_for_vectors
|
| 358 |
+
*
|
| 359 |
+
* This is useful for dynamic-size vectors. For fixed-size vectors,
|
| 360 |
+
* it is redundant to pass these parameters, so one should use the default constructor
|
| 361 |
+
* Matrix() instead.
|
| 362 |
+
*
|
| 363 |
+
* \warning This constructor is disabled for fixed-size \c 1x1 matrices. For instance,
|
| 364 |
+
* calling Matrix<double,1,1>(1) will call the initialization constructor: Matrix(const Scalar&).
|
| 365 |
+
* For fixed-size \c 1x1 matrices it is therefore recommended to use the default
|
| 366 |
+
* constructor Matrix() instead, especially when using one of the non standard
|
| 367 |
+
* \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives).
|
| 368 |
+
*/
|
| 369 |
+
EIGEN_STRONG_INLINE explicit Matrix(Index dim);
|
| 370 |
+
/** \brief Constructs an initialized 1x1 matrix with the given coefficient
|
| 371 |
+
* \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */
|
| 372 |
+
Matrix(const Scalar& x);
|
| 373 |
+
/** \brief Constructs an uninitialized matrix with \a rows rows and \a cols columns.
|
| 374 |
+
*
|
| 375 |
+
* This is useful for dynamic-size matrices. For fixed-size matrices,
|
| 376 |
+
* it is redundant to pass these parameters, so one should use the default constructor
|
| 377 |
+
* Matrix() instead.
|
| 378 |
+
*
|
| 379 |
+
* \warning This constructor is disabled for fixed-size \c 1x2 and \c 2x1 vectors. For instance,
|
| 380 |
+
* calling Matrix2f(2,1) will call the initialization constructor: Matrix(const Scalar& x, const Scalar& y).
|
| 381 |
+
* For fixed-size \c 1x2 or \c 2x1 vectors it is therefore recommended to use the default
|
| 382 |
+
* constructor Matrix() instead, especially when using one of the non standard
|
| 383 |
+
* \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives).
|
| 384 |
+
*/
|
| 385 |
+
EIGEN_DEVICE_FUNC
|
| 386 |
+
Matrix(Index rows, Index cols);
|
| 387 |
+
|
| 388 |
+
/** \brief Constructs an initialized 2D vector with given coefficients
|
| 389 |
+
* \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */
|
| 390 |
+
Matrix(const Scalar& x, const Scalar& y);
|
| 391 |
+
#endif // end EIGEN_PARSED_BY_DOXYGEN
|
| 392 |
+
|
| 393 |
+
/** \brief Constructs an initialized 3D vector with given coefficients
|
| 394 |
+
* \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...)
|
| 395 |
+
*/
|
| 396 |
+
EIGEN_DEVICE_FUNC
|
| 397 |
+
EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
|
| 398 |
+
{
|
| 399 |
+
Base::_check_template_params();
|
| 400 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
|
| 401 |
+
m_storage.data()[0] = x;
|
| 402 |
+
m_storage.data()[1] = y;
|
| 403 |
+
m_storage.data()[2] = z;
|
| 404 |
+
}
|
| 405 |
+
/** \brief Constructs an initialized 4D vector with given coefficients
|
| 406 |
+
* \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...)
|
| 407 |
+
*/
|
| 408 |
+
EIGEN_DEVICE_FUNC
|
| 409 |
+
EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
|
| 410 |
+
{
|
| 411 |
+
Base::_check_template_params();
|
| 412 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
|
| 413 |
+
m_storage.data()[0] = x;
|
| 414 |
+
m_storage.data()[1] = y;
|
| 415 |
+
m_storage.data()[2] = z;
|
| 416 |
+
m_storage.data()[3] = w;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
/** \brief Copy constructor */
|
| 421 |
+
EIGEN_DEVICE_FUNC
|
| 422 |
+
EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
|
| 423 |
+
{ }
|
| 424 |
+
|
| 425 |
+
/** \brief Copy constructor for generic expressions.
|
| 426 |
+
* \sa MatrixBase::operator=(const EigenBase<OtherDerived>&)
|
| 427 |
+
*/
|
| 428 |
+
template<typename OtherDerived>
|
| 429 |
+
EIGEN_DEVICE_FUNC
|
| 430 |
+
EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
|
| 431 |
+
: Base(other.derived())
|
| 432 |
+
{ }
|
| 433 |
+
|
| 434 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 435 |
+
inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
|
| 436 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 437 |
+
inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
|
| 438 |
+
|
| 439 |
+
/////////// Geometry module ///////////
|
| 440 |
+
|
| 441 |
+
template<typename OtherDerived>
|
| 442 |
+
EIGEN_DEVICE_FUNC
|
| 443 |
+
explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
|
| 444 |
+
template<typename OtherDerived>
|
| 445 |
+
EIGEN_DEVICE_FUNC
|
| 446 |
+
Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
|
| 447 |
+
|
| 448 |
+
// allow to extend Matrix outside Eigen
|
| 449 |
+
#ifdef EIGEN_MATRIX_PLUGIN
|
| 450 |
+
#include EIGEN_MATRIX_PLUGIN
|
| 451 |
+
#endif
|
| 452 |
+
|
| 453 |
+
protected:
|
| 454 |
+
template <typename Derived, typename OtherDerived, bool IsVector>
|
| 455 |
+
friend struct internal::conservative_resize_like_impl;
|
| 456 |
+
|
| 457 |
+
using Base::m_storage;
|
| 458 |
+
};
|
| 459 |
+
|
| 460 |
+
/** \defgroup matrixtypedefs Global matrix typedefs
|
| 461 |
+
*
|
| 462 |
+
* \ingroup Core_Module
|
| 463 |
+
*
|
| 464 |
+
* %Eigen defines several typedef shortcuts for most common matrix and vector types.
|
| 465 |
+
*
|
| 466 |
+
* The general patterns are the following:
|
| 467 |
+
*
|
| 468 |
+
* \c MatrixSizeType where \c Size can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size,
|
| 469 |
+
* and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd
|
| 470 |
+
* for complex double.
|
| 471 |
+
*
|
| 472 |
+
* For example, \c Matrix3d is a fixed-size 3x3 matrix type of doubles, and \c MatrixXf is a dynamic-size matrix of floats.
|
| 473 |
+
*
|
| 474 |
+
* There are also \c VectorSizeType and \c RowVectorSizeType which are self-explanatory. For example, \c Vector4cf is
|
| 475 |
+
* a fixed-size vector of 4 complex floats.
|
| 476 |
+
*
|
| 477 |
+
* With \cpp11, template alias are also defined for common sizes.
|
| 478 |
+
* They follow the same pattern as above except that the scalar type suffix is replaced by a
|
| 479 |
+
* template parameter, i.e.:
|
| 480 |
+
* - `MatrixSize<Type>` where `Size` can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size.
|
| 481 |
+
* - `MatrixXSize<Type>` and `MatrixSizeX<Type>` where `Size` can be \c 2,\c 3,\c 4 for hybrid dynamic/fixed matrices.
|
| 482 |
+
* - `VectorSize<Type>` and `RowVectorSize<Type>` for column and row vectors.
|
| 483 |
+
*
|
| 484 |
+
* With \cpp11, you can also use fully generic column and row vector types: `Vector<Type,Size>` and `RowVector<Type,Size>`.
|
| 485 |
+
*
|
| 486 |
+
* \sa class Matrix
|
| 487 |
+
*/
|
| 488 |
+
|
| 489 |
+
#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
|
| 490 |
+
/** \ingroup matrixtypedefs */ \
|
| 491 |
+
/** \brief \noop */ \
|
| 492 |
+
typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
|
| 493 |
+
/** \ingroup matrixtypedefs */ \
|
| 494 |
+
/** \brief \noop */ \
|
| 495 |
+
typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
|
| 496 |
+
/** \ingroup matrixtypedefs */ \
|
| 497 |
+
/** \brief \noop */ \
|
| 498 |
+
typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
|
| 499 |
+
|
| 500 |
+
#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
|
| 501 |
+
/** \ingroup matrixtypedefs */ \
|
| 502 |
+
/** \brief \noop */ \
|
| 503 |
+
typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
|
| 504 |
+
/** \ingroup matrixtypedefs */ \
|
| 505 |
+
/** \brief \noop */ \
|
| 506 |
+
typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
|
| 507 |
+
|
| 508 |
+
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
|
| 509 |
+
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
|
| 510 |
+
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
|
| 511 |
+
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
|
| 512 |
+
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
|
| 513 |
+
EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
|
| 514 |
+
EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
|
| 515 |
+
EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
|
| 516 |
+
|
| 517 |
+
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
|
| 518 |
+
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
|
| 519 |
+
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
|
| 520 |
+
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
|
| 521 |
+
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
|
| 522 |
+
|
| 523 |
+
#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
|
| 524 |
+
#undef EIGEN_MAKE_TYPEDEFS
|
| 525 |
+
#undef EIGEN_MAKE_FIXED_TYPEDEFS
|
| 526 |
+
|
| 527 |
+
#if EIGEN_HAS_CXX11
|
| 528 |
+
|
| 529 |
+
#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
|
| 530 |
+
/** \ingroup matrixtypedefs */ \
|
| 531 |
+
/** \brief \cpp11 */ \
|
| 532 |
+
template <typename Type> \
|
| 533 |
+
using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
|
| 534 |
+
/** \ingroup matrixtypedefs */ \
|
| 535 |
+
/** \brief \cpp11 */ \
|
| 536 |
+
template <typename Type> \
|
| 537 |
+
using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
|
| 538 |
+
/** \ingroup matrixtypedefs */ \
|
| 539 |
+
/** \brief \cpp11 */ \
|
| 540 |
+
template <typename Type> \
|
| 541 |
+
using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
|
| 542 |
+
|
| 543 |
+
#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
|
| 544 |
+
/** \ingroup matrixtypedefs */ \
|
| 545 |
+
/** \brief \cpp11 */ \
|
| 546 |
+
template <typename Type> \
|
| 547 |
+
using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
|
| 548 |
+
/** \ingroup matrixtypedefs */ \
|
| 549 |
+
/** \brief \cpp11 */ \
|
| 550 |
+
template <typename Type> \
|
| 551 |
+
using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
|
| 552 |
+
|
| 553 |
+
EIGEN_MAKE_TYPEDEFS(2, 2)
|
| 554 |
+
EIGEN_MAKE_TYPEDEFS(3, 3)
|
| 555 |
+
EIGEN_MAKE_TYPEDEFS(4, 4)
|
| 556 |
+
EIGEN_MAKE_TYPEDEFS(Dynamic, X)
|
| 557 |
+
EIGEN_MAKE_FIXED_TYPEDEFS(2)
|
| 558 |
+
EIGEN_MAKE_FIXED_TYPEDEFS(3)
|
| 559 |
+
EIGEN_MAKE_FIXED_TYPEDEFS(4)
|
| 560 |
+
|
| 561 |
+
/** \ingroup matrixtypedefs
|
| 562 |
+
* \brief \cpp11 */
|
| 563 |
+
template <typename Type, int Size>
|
| 564 |
+
using Vector = Matrix<Type, Size, 1>;
|
| 565 |
+
|
| 566 |
+
/** \ingroup matrixtypedefs
|
| 567 |
+
* \brief \cpp11 */
|
| 568 |
+
template <typename Type, int Size>
|
| 569 |
+
using RowVector = Matrix<Type, 1, Size>;
|
| 570 |
+
|
| 571 |
+
#undef EIGEN_MAKE_TYPEDEFS
|
| 572 |
+
#undef EIGEN_MAKE_FIXED_TYPEDEFS
|
| 573 |
+
|
| 574 |
+
#endif // EIGEN_HAS_CXX11
|
| 575 |
+
|
| 576 |
+
} // end namespace Eigen
|
| 577 |
+
|
| 578 |
+
#endif // EIGEN_MATRIX_H
|
include/eigen/Eigen/src/Core/MatrixBase.h
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_MATRIXBASE_H
|
| 12 |
+
#define EIGEN_MATRIXBASE_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
/** \class MatrixBase
|
| 17 |
+
* \ingroup Core_Module
|
| 18 |
+
*
|
| 19 |
+
* \brief Base class for all dense matrices, vectors, and expressions
|
| 20 |
+
*
|
| 21 |
+
* This class is the base that is inherited by all matrix, vector, and related expression
|
| 22 |
+
* types. Most of the Eigen API is contained in this class, and its base classes. Other important
|
| 23 |
+
* classes for the Eigen API are Matrix, and VectorwiseOp.
|
| 24 |
+
*
|
| 25 |
+
* Note that some methods are defined in other modules such as the \ref LU_Module LU module
|
| 26 |
+
* for all functions related to matrix inversions.
|
| 27 |
+
*
|
| 28 |
+
* \tparam Derived is the derived type, e.g. a matrix type, or an expression, etc.
|
| 29 |
+
*
|
| 30 |
+
* When writing a function taking Eigen objects as argument, if you want your function
|
| 31 |
+
* to take as argument any matrix, vector, or expression, just let it take a
|
| 32 |
+
* MatrixBase argument. As an example, here is a function printFirstRow which, given
|
| 33 |
+
* a matrix, vector, or expression \a x, prints the first row of \a x.
|
| 34 |
+
*
|
| 35 |
+
* \code
|
| 36 |
+
template<typename Derived>
|
| 37 |
+
void printFirstRow(const Eigen::MatrixBase<Derived>& x)
|
| 38 |
+
{
|
| 39 |
+
cout << x.row(0) << endl;
|
| 40 |
+
}
|
| 41 |
+
* \endcode
|
| 42 |
+
*
|
| 43 |
+
* This class can be extended with the help of the plugin mechanism described on the page
|
| 44 |
+
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIXBASE_PLUGIN.
|
| 45 |
+
*
|
| 46 |
+
* \sa \blank \ref TopicClassHierarchy
|
| 47 |
+
*/
|
| 48 |
+
template<typename Derived> class MatrixBase
|
| 49 |
+
: public DenseBase<Derived>
|
| 50 |
+
{
|
| 51 |
+
public:
|
| 52 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 53 |
+
typedef MatrixBase StorageBaseType;
|
| 54 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 55 |
+
typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
|
| 56 |
+
typedef typename internal::traits<Derived>::Scalar Scalar;
|
| 57 |
+
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
|
| 58 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 59 |
+
|
| 60 |
+
typedef DenseBase<Derived> Base;
|
| 61 |
+
using Base::RowsAtCompileTime;
|
| 62 |
+
using Base::ColsAtCompileTime;
|
| 63 |
+
using Base::SizeAtCompileTime;
|
| 64 |
+
using Base::MaxRowsAtCompileTime;
|
| 65 |
+
using Base::MaxColsAtCompileTime;
|
| 66 |
+
using Base::MaxSizeAtCompileTime;
|
| 67 |
+
using Base::IsVectorAtCompileTime;
|
| 68 |
+
using Base::Flags;
|
| 69 |
+
|
| 70 |
+
using Base::derived;
|
| 71 |
+
using Base::const_cast_derived;
|
| 72 |
+
using Base::rows;
|
| 73 |
+
using Base::cols;
|
| 74 |
+
using Base::size;
|
| 75 |
+
using Base::coeff;
|
| 76 |
+
using Base::coeffRef;
|
| 77 |
+
using Base::lazyAssign;
|
| 78 |
+
using Base::eval;
|
| 79 |
+
using Base::operator-;
|
| 80 |
+
using Base::operator+=;
|
| 81 |
+
using Base::operator-=;
|
| 82 |
+
using Base::operator*=;
|
| 83 |
+
using Base::operator/=;
|
| 84 |
+
|
| 85 |
+
typedef typename Base::CoeffReturnType CoeffReturnType;
|
| 86 |
+
typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType;
|
| 87 |
+
typedef typename Base::RowXpr RowXpr;
|
| 88 |
+
typedef typename Base::ColXpr ColXpr;
|
| 89 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 94 |
+
/** type of the equivalent square matrix */
|
| 95 |
+
typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime),
|
| 96 |
+
EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
|
| 97 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 98 |
+
|
| 99 |
+
/** \returns the size of the main diagonal, which is min(rows(),cols()).
|
| 100 |
+
* \sa rows(), cols(), SizeAtCompileTime. */
|
| 101 |
+
EIGEN_DEVICE_FUNC
|
| 102 |
+
inline Index diagonalSize() const { return (numext::mini)(rows(),cols()); }
|
| 103 |
+
|
| 104 |
+
typedef typename Base::PlainObject PlainObject;
|
| 105 |
+
|
| 106 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 107 |
+
/** \internal Represents a matrix with all coefficients equal to one another*/
|
| 108 |
+
typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
|
| 109 |
+
/** \internal the return type of MatrixBase::adjoint() */
|
| 110 |
+
typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
|
| 111 |
+
CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, ConstTransposeReturnType>,
|
| 112 |
+
ConstTransposeReturnType
|
| 113 |
+
>::type AdjointReturnType;
|
| 114 |
+
/** \internal Return type of eigenvalues() */
|
| 115 |
+
typedef Matrix<std::complex<RealScalar>, internal::traits<Derived>::ColsAtCompileTime, 1, ColMajor> EigenvaluesReturnType;
|
| 116 |
+
/** \internal the return type of identity */
|
| 117 |
+
typedef CwiseNullaryOp<internal::scalar_identity_op<Scalar>,PlainObject> IdentityReturnType;
|
| 118 |
+
/** \internal the return type of unit vectors */
|
| 119 |
+
typedef Block<const CwiseNullaryOp<internal::scalar_identity_op<Scalar>, SquareMatrixType>,
|
| 120 |
+
internal::traits<Derived>::RowsAtCompileTime,
|
| 121 |
+
internal::traits<Derived>::ColsAtCompileTime> BasisReturnType;
|
| 122 |
+
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
| 123 |
+
|
| 124 |
+
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase
|
| 125 |
+
#define EIGEN_DOC_UNARY_ADDONS(X,Y)
|
| 126 |
+
# include "../plugins/CommonCwiseBinaryOps.h"
|
| 127 |
+
# include "../plugins/MatrixCwiseUnaryOps.h"
|
| 128 |
+
# include "../plugins/MatrixCwiseBinaryOps.h"
|
| 129 |
+
# ifdef EIGEN_MATRIXBASE_PLUGIN
|
| 130 |
+
# include EIGEN_MATRIXBASE_PLUGIN
|
| 131 |
+
# endif
|
| 132 |
+
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
|
| 133 |
+
#undef EIGEN_DOC_UNARY_ADDONS
|
| 134 |
+
|
| 135 |
+
/** Special case of the template operator=, in order to prevent the compiler
|
| 136 |
+
* from generating a default operator= (issue hit with g++ 4.1)
|
| 137 |
+
*/
|
| 138 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 139 |
+
Derived& operator=(const MatrixBase& other);
|
| 140 |
+
|
| 141 |
+
// We cannot inherit here via Base::operator= since it is causing
|
| 142 |
+
// trouble with MSVC.
|
| 143 |
+
|
| 144 |
+
template <typename OtherDerived>
|
| 145 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 146 |
+
Derived& operator=(const DenseBase<OtherDerived>& other);
|
| 147 |
+
|
| 148 |
+
template <typename OtherDerived>
|
| 149 |
+
EIGEN_DEVICE_FUNC
|
| 150 |
+
Derived& operator=(const EigenBase<OtherDerived>& other);
|
| 151 |
+
|
| 152 |
+
template<typename OtherDerived>
|
| 153 |
+
EIGEN_DEVICE_FUNC
|
| 154 |
+
Derived& operator=(const ReturnByValue<OtherDerived>& other);
|
| 155 |
+
|
| 156 |
+
template<typename OtherDerived>
|
| 157 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 158 |
+
Derived& operator+=(const MatrixBase<OtherDerived>& other);
|
| 159 |
+
template<typename OtherDerived>
|
| 160 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 161 |
+
Derived& operator-=(const MatrixBase<OtherDerived>& other);
|
| 162 |
+
|
| 163 |
+
template<typename OtherDerived>
|
| 164 |
+
EIGEN_DEVICE_FUNC
|
| 165 |
+
const Product<Derived,OtherDerived>
|
| 166 |
+
operator*(const MatrixBase<OtherDerived> &other) const;
|
| 167 |
+
|
| 168 |
+
template<typename OtherDerived>
|
| 169 |
+
EIGEN_DEVICE_FUNC
|
| 170 |
+
const Product<Derived,OtherDerived,LazyProduct>
|
| 171 |
+
lazyProduct(const MatrixBase<OtherDerived> &other) const;
|
| 172 |
+
|
| 173 |
+
template<typename OtherDerived>
|
| 174 |
+
Derived& operator*=(const EigenBase<OtherDerived>& other);
|
| 175 |
+
|
| 176 |
+
template<typename OtherDerived>
|
| 177 |
+
void applyOnTheLeft(const EigenBase<OtherDerived>& other);
|
| 178 |
+
|
| 179 |
+
template<typename OtherDerived>
|
| 180 |
+
void applyOnTheRight(const EigenBase<OtherDerived>& other);
|
| 181 |
+
|
| 182 |
+
template<typename DiagonalDerived>
|
| 183 |
+
EIGEN_DEVICE_FUNC
|
| 184 |
+
const Product<Derived, DiagonalDerived, LazyProduct>
|
| 185 |
+
operator*(const DiagonalBase<DiagonalDerived> &diagonal) const;
|
| 186 |
+
|
| 187 |
+
template<typename OtherDerived>
|
| 188 |
+
EIGEN_DEVICE_FUNC
|
| 189 |
+
typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType
|
| 190 |
+
dot(const MatrixBase<OtherDerived>& other) const;
|
| 191 |
+
|
| 192 |
+
EIGEN_DEVICE_FUNC RealScalar squaredNorm() const;
|
| 193 |
+
EIGEN_DEVICE_FUNC RealScalar norm() const;
|
| 194 |
+
RealScalar stableNorm() const;
|
| 195 |
+
RealScalar blueNorm() const;
|
| 196 |
+
RealScalar hypotNorm() const;
|
| 197 |
+
EIGEN_DEVICE_FUNC const PlainObject normalized() const;
|
| 198 |
+
EIGEN_DEVICE_FUNC const PlainObject stableNormalized() const;
|
| 199 |
+
EIGEN_DEVICE_FUNC void normalize();
|
| 200 |
+
EIGEN_DEVICE_FUNC void stableNormalize();
|
| 201 |
+
|
| 202 |
+
EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const;
|
| 203 |
+
EIGEN_DEVICE_FUNC void adjointInPlace();
|
| 204 |
+
|
| 205 |
+
typedef Diagonal<Derived> DiagonalReturnType;
|
| 206 |
+
EIGEN_DEVICE_FUNC
|
| 207 |
+
DiagonalReturnType diagonal();
|
| 208 |
+
|
| 209 |
+
typedef Diagonal<const Derived> ConstDiagonalReturnType;
|
| 210 |
+
EIGEN_DEVICE_FUNC
|
| 211 |
+
const ConstDiagonalReturnType diagonal() const;
|
| 212 |
+
|
| 213 |
+
template<int Index>
|
| 214 |
+
EIGEN_DEVICE_FUNC
|
| 215 |
+
Diagonal<Derived, Index> diagonal();
|
| 216 |
+
|
| 217 |
+
template<int Index>
|
| 218 |
+
EIGEN_DEVICE_FUNC
|
| 219 |
+
const Diagonal<const Derived, Index> diagonal() const;
|
| 220 |
+
|
| 221 |
+
EIGEN_DEVICE_FUNC
|
| 222 |
+
Diagonal<Derived, DynamicIndex> diagonal(Index index);
|
| 223 |
+
EIGEN_DEVICE_FUNC
|
| 224 |
+
const Diagonal<const Derived, DynamicIndex> diagonal(Index index) const;
|
| 225 |
+
|
| 226 |
+
template<unsigned int Mode> struct TriangularViewReturnType { typedef TriangularView<Derived, Mode> Type; };
|
| 227 |
+
template<unsigned int Mode> struct ConstTriangularViewReturnType { typedef const TriangularView<const Derived, Mode> Type; };
|
| 228 |
+
|
| 229 |
+
template<unsigned int Mode>
|
| 230 |
+
EIGEN_DEVICE_FUNC
|
| 231 |
+
typename TriangularViewReturnType<Mode>::Type triangularView();
|
| 232 |
+
template<unsigned int Mode>
|
| 233 |
+
EIGEN_DEVICE_FUNC
|
| 234 |
+
typename ConstTriangularViewReturnType<Mode>::Type triangularView() const;
|
| 235 |
+
|
| 236 |
+
template<unsigned int UpLo> struct SelfAdjointViewReturnType { typedef SelfAdjointView<Derived, UpLo> Type; };
|
| 237 |
+
template<unsigned int UpLo> struct ConstSelfAdjointViewReturnType { typedef const SelfAdjointView<const Derived, UpLo> Type; };
|
| 238 |
+
|
| 239 |
+
template<unsigned int UpLo>
|
| 240 |
+
EIGEN_DEVICE_FUNC
|
| 241 |
+
typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
|
| 242 |
+
template<unsigned int UpLo>
|
| 243 |
+
EIGEN_DEVICE_FUNC
|
| 244 |
+
typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView() const;
|
| 245 |
+
|
| 246 |
+
const SparseView<Derived> sparseView(const Scalar& m_reference = Scalar(0),
|
| 247 |
+
const typename NumTraits<Scalar>::Real& m_epsilon = NumTraits<Scalar>::dummy_precision()) const;
|
| 248 |
+
EIGEN_DEVICE_FUNC static const IdentityReturnType Identity();
|
| 249 |
+
EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(Index rows, Index cols);
|
| 250 |
+
EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index size, Index i);
|
| 251 |
+
EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index i);
|
| 252 |
+
EIGEN_DEVICE_FUNC static const BasisReturnType UnitX();
|
| 253 |
+
EIGEN_DEVICE_FUNC static const BasisReturnType UnitY();
|
| 254 |
+
EIGEN_DEVICE_FUNC static const BasisReturnType UnitZ();
|
| 255 |
+
EIGEN_DEVICE_FUNC static const BasisReturnType UnitW();
|
| 256 |
+
|
| 257 |
+
EIGEN_DEVICE_FUNC
|
| 258 |
+
const DiagonalWrapper<const Derived> asDiagonal() const;
|
| 259 |
+
const PermutationWrapper<const Derived> asPermutation() const;
|
| 260 |
+
|
| 261 |
+
EIGEN_DEVICE_FUNC
|
| 262 |
+
Derived& setIdentity();
|
| 263 |
+
EIGEN_DEVICE_FUNC
|
| 264 |
+
Derived& setIdentity(Index rows, Index cols);
|
| 265 |
+
EIGEN_DEVICE_FUNC Derived& setUnit(Index i);
|
| 266 |
+
EIGEN_DEVICE_FUNC Derived& setUnit(Index newSize, Index i);
|
| 267 |
+
|
| 268 |
+
bool isIdentity(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 269 |
+
bool isDiagonal(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 270 |
+
|
| 271 |
+
bool isUpperTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 272 |
+
bool isLowerTriangular(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 273 |
+
|
| 274 |
+
template<typename OtherDerived>
|
| 275 |
+
bool isOrthogonal(const MatrixBase<OtherDerived>& other,
|
| 276 |
+
const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 277 |
+
bool isUnitary(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
|
| 278 |
+
|
| 279 |
+
/** \returns true if each coefficients of \c *this and \a other are all exactly equal.
|
| 280 |
+
* \warning When using floating point scalar values you probably should rather use a
|
| 281 |
+
* fuzzy comparison such as isApprox()
|
| 282 |
+
* \sa isApprox(), operator!= */
|
| 283 |
+
template<typename OtherDerived>
|
| 284 |
+
EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase<OtherDerived>& other) const
|
| 285 |
+
{ return cwiseEqual(other).all(); }
|
| 286 |
+
|
| 287 |
+
/** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other.
|
| 288 |
+
* \warning When using floating point scalar values you probably should rather use a
|
| 289 |
+
* fuzzy comparison such as isApprox()
|
| 290 |
+
* \sa isApprox(), operator== */
|
| 291 |
+
template<typename OtherDerived>
|
| 292 |
+
EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase<OtherDerived>& other) const
|
| 293 |
+
{ return cwiseNotEqual(other).any(); }
|
| 294 |
+
|
| 295 |
+
NoAlias<Derived,Eigen::MatrixBase > EIGEN_DEVICE_FUNC noalias();
|
| 296 |
+
|
| 297 |
+
// TODO forceAlignedAccess is temporarily disabled
|
| 298 |
+
// Need to find a nicer workaround.
|
| 299 |
+
inline const Derived& forceAlignedAccess() const { return derived(); }
|
| 300 |
+
inline Derived& forceAlignedAccess() { return derived(); }
|
| 301 |
+
template<bool Enable> inline const Derived& forceAlignedAccessIf() const { return derived(); }
|
| 302 |
+
template<bool Enable> inline Derived& forceAlignedAccessIf() { return derived(); }
|
| 303 |
+
|
| 304 |
+
EIGEN_DEVICE_FUNC Scalar trace() const;
|
| 305 |
+
|
| 306 |
+
template<int p> EIGEN_DEVICE_FUNC RealScalar lpNorm() const;
|
| 307 |
+
|
| 308 |
+
EIGEN_DEVICE_FUNC MatrixBase<Derived>& matrix() { return *this; }
|
| 309 |
+
EIGEN_DEVICE_FUNC const MatrixBase<Derived>& matrix() const { return *this; }
|
| 310 |
+
|
| 311 |
+
/** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix
|
| 312 |
+
* \sa ArrayBase::matrix() */
|
| 313 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper<Derived> array() { return ArrayWrapper<Derived>(derived()); }
|
| 314 |
+
/** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix
|
| 315 |
+
* \sa ArrayBase::matrix() */
|
| 316 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper<const Derived> array() const { return ArrayWrapper<const Derived>(derived()); }
|
| 317 |
+
|
| 318 |
+
/////////// LU module ///////////
|
| 319 |
+
|
| 320 |
+
inline const FullPivLU<PlainObject> fullPivLu() const;
|
| 321 |
+
inline const PartialPivLU<PlainObject> partialPivLu() const;
|
| 322 |
+
|
| 323 |
+
inline const PartialPivLU<PlainObject> lu() const;
|
| 324 |
+
|
| 325 |
+
EIGEN_DEVICE_FUNC
|
| 326 |
+
inline const Inverse<Derived> inverse() const;
|
| 327 |
+
|
| 328 |
+
template<typename ResultType>
|
| 329 |
+
inline void computeInverseAndDetWithCheck(
|
| 330 |
+
ResultType& inverse,
|
| 331 |
+
typename ResultType::Scalar& determinant,
|
| 332 |
+
bool& invertible,
|
| 333 |
+
const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
|
| 334 |
+
) const;
|
| 335 |
+
|
| 336 |
+
template<typename ResultType>
|
| 337 |
+
inline void computeInverseWithCheck(
|
| 338 |
+
ResultType& inverse,
|
| 339 |
+
bool& invertible,
|
| 340 |
+
const RealScalar& absDeterminantThreshold = NumTraits<Scalar>::dummy_precision()
|
| 341 |
+
) const;
|
| 342 |
+
|
| 343 |
+
EIGEN_DEVICE_FUNC
|
| 344 |
+
Scalar determinant() const;
|
| 345 |
+
|
| 346 |
+
/////////// Cholesky module ///////////
|
| 347 |
+
|
| 348 |
+
inline const LLT<PlainObject> llt() const;
|
| 349 |
+
inline const LDLT<PlainObject> ldlt() const;
|
| 350 |
+
|
| 351 |
+
/////////// QR module ///////////
|
| 352 |
+
|
| 353 |
+
inline const HouseholderQR<PlainObject> householderQr() const;
|
| 354 |
+
inline const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
|
| 355 |
+
inline const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
|
| 356 |
+
inline const CompleteOrthogonalDecomposition<PlainObject> completeOrthogonalDecomposition() const;
|
| 357 |
+
|
| 358 |
+
/////////// Eigenvalues module ///////////
|
| 359 |
+
|
| 360 |
+
inline EigenvaluesReturnType eigenvalues() const;
|
| 361 |
+
inline RealScalar operatorNorm() const;
|
| 362 |
+
|
| 363 |
+
/////////// SVD module ///////////
|
| 364 |
+
|
| 365 |
+
inline JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
|
| 366 |
+
inline BDCSVD<PlainObject> bdcSvd(unsigned int computationOptions = 0) const;
|
| 367 |
+
|
| 368 |
+
/////////// Geometry module ///////////
|
| 369 |
+
|
| 370 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 371 |
+
/// \internal helper struct to form the return type of the cross product
|
| 372 |
+
template<typename OtherDerived> struct cross_product_return_type {
|
| 373 |
+
typedef typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,typename internal::traits<OtherDerived>::Scalar>::ReturnType Scalar;
|
| 374 |
+
typedef Matrix<Scalar,MatrixBase::RowsAtCompileTime,MatrixBase::ColsAtCompileTime> type;
|
| 375 |
+
};
|
| 376 |
+
#endif // EIGEN_PARSED_BY_DOXYGEN
|
| 377 |
+
template<typename OtherDerived>
|
| 378 |
+
EIGEN_DEVICE_FUNC
|
| 379 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 380 |
+
inline typename cross_product_return_type<OtherDerived>::type
|
| 381 |
+
#else
|
| 382 |
+
inline PlainObject
|
| 383 |
+
#endif
|
| 384 |
+
cross(const MatrixBase<OtherDerived>& other) const;
|
| 385 |
+
|
| 386 |
+
template<typename OtherDerived>
|
| 387 |
+
EIGEN_DEVICE_FUNC
|
| 388 |
+
inline PlainObject cross3(const MatrixBase<OtherDerived>& other) const;
|
| 389 |
+
|
| 390 |
+
EIGEN_DEVICE_FUNC
|
| 391 |
+
inline PlainObject unitOrthogonal(void) const;
|
| 392 |
+
|
| 393 |
+
EIGEN_DEVICE_FUNC
|
| 394 |
+
inline Matrix<Scalar,3,1> eulerAngles(Index a0, Index a1, Index a2) const;
|
| 395 |
+
|
| 396 |
+
// put this as separate enum value to work around possible GCC 4.3 bug (?)
|
| 397 |
+
enum { HomogeneousReturnTypeDirection = ColsAtCompileTime==1&&RowsAtCompileTime==1 ? ((internal::traits<Derived>::Flags&RowMajorBit)==RowMajorBit ? Horizontal : Vertical)
|
| 398 |
+
: ColsAtCompileTime==1 ? Vertical : Horizontal };
|
| 399 |
+
typedef Homogeneous<Derived, HomogeneousReturnTypeDirection> HomogeneousReturnType;
|
| 400 |
+
EIGEN_DEVICE_FUNC
|
| 401 |
+
inline HomogeneousReturnType homogeneous() const;
|
| 402 |
+
|
| 403 |
+
enum {
|
| 404 |
+
SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
|
| 405 |
+
};
|
| 406 |
+
typedef Block<const Derived,
|
| 407 |
+
internal::traits<Derived>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
|
| 408 |
+
internal::traits<Derived>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> ConstStartMinusOne;
|
| 409 |
+
typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(ConstStartMinusOne,Scalar,quotient) HNormalizedReturnType;
|
| 410 |
+
EIGEN_DEVICE_FUNC
|
| 411 |
+
inline const HNormalizedReturnType hnormalized() const;
|
| 412 |
+
|
| 413 |
+
////////// Householder module ///////////
|
| 414 |
+
|
| 415 |
+
EIGEN_DEVICE_FUNC
|
| 416 |
+
void makeHouseholderInPlace(Scalar& tau, RealScalar& beta);
|
| 417 |
+
template<typename EssentialPart>
|
| 418 |
+
EIGEN_DEVICE_FUNC
|
| 419 |
+
void makeHouseholder(EssentialPart& essential,
|
| 420 |
+
Scalar& tau, RealScalar& beta) const;
|
| 421 |
+
template<typename EssentialPart>
|
| 422 |
+
EIGEN_DEVICE_FUNC
|
| 423 |
+
void applyHouseholderOnTheLeft(const EssentialPart& essential,
|
| 424 |
+
const Scalar& tau,
|
| 425 |
+
Scalar* workspace);
|
| 426 |
+
template<typename EssentialPart>
|
| 427 |
+
EIGEN_DEVICE_FUNC
|
| 428 |
+
void applyHouseholderOnTheRight(const EssentialPart& essential,
|
| 429 |
+
const Scalar& tau,
|
| 430 |
+
Scalar* workspace);
|
| 431 |
+
|
| 432 |
+
///////// Jacobi module /////////
|
| 433 |
+
|
| 434 |
+
template<typename OtherScalar>
|
| 435 |
+
EIGEN_DEVICE_FUNC
|
| 436 |
+
void applyOnTheLeft(Index p, Index q, const JacobiRotation<OtherScalar>& j);
|
| 437 |
+
template<typename OtherScalar>
|
| 438 |
+
EIGEN_DEVICE_FUNC
|
| 439 |
+
void applyOnTheRight(Index p, Index q, const JacobiRotation<OtherScalar>& j);
|
| 440 |
+
|
| 441 |
+
///////// SparseCore module /////////
|
| 442 |
+
|
| 443 |
+
template<typename OtherDerived>
|
| 444 |
+
EIGEN_STRONG_INLINE const typename SparseMatrixBase<OtherDerived>::template CwiseProductDenseReturnType<Derived>::Type
|
| 445 |
+
cwiseProduct(const SparseMatrixBase<OtherDerived> &other) const
|
| 446 |
+
{
|
| 447 |
+
return other.cwiseProduct(derived());
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
///////// MatrixFunctions module /////////
|
| 451 |
+
|
| 452 |
+
typedef typename internal::stem_function<Scalar>::type StemFunction;
|
| 453 |
+
#define EIGEN_MATRIX_FUNCTION(ReturnType, Name, Description) \
|
| 454 |
+
/** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
|
| 455 |
+
const ReturnType<Derived> Name() const;
|
| 456 |
+
#define EIGEN_MATRIX_FUNCTION_1(ReturnType, Name, Description, Argument) \
|
| 457 |
+
/** \returns an expression of the matrix Description of \c *this. \brief This function requires the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>. To compute the coefficient-wise Description use ArrayBase::##Name . */ \
|
| 458 |
+
const ReturnType<Derived> Name(Argument) const;
|
| 459 |
+
|
| 460 |
+
EIGEN_MATRIX_FUNCTION(MatrixExponentialReturnValue, exp, exponential)
|
| 461 |
+
/** \brief Helper function for the <a href="unsupported/group__MatrixFunctions__Module.html"> unsupported MatrixFunctions module</a>.*/
|
| 462 |
+
const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
|
| 463 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine)
|
| 464 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine)
|
| 465 |
+
#if EIGEN_HAS_CXX11_MATH
|
| 466 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine)
|
| 467 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine)
|
| 468 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine)
|
| 469 |
+
#endif
|
| 470 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine)
|
| 471 |
+
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine)
|
| 472 |
+
EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root)
|
| 473 |
+
EIGEN_MATRIX_FUNCTION(MatrixLogarithmReturnValue, log, logarithm)
|
| 474 |
+
EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue, pow, power to \c p, const RealScalar& p)
|
| 475 |
+
EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p)
|
| 476 |
+
|
| 477 |
+
protected:
|
| 478 |
+
EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase)
|
| 479 |
+
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase)
|
| 480 |
+
|
| 481 |
+
private:
|
| 482 |
+
EIGEN_DEVICE_FUNC explicit MatrixBase(int);
|
| 483 |
+
EIGEN_DEVICE_FUNC MatrixBase(int,int);
|
| 484 |
+
template<typename OtherDerived> EIGEN_DEVICE_FUNC explicit MatrixBase(const MatrixBase<OtherDerived>&);
|
| 485 |
+
protected:
|
| 486 |
+
// mixing arrays and matrices is not legal
|
| 487 |
+
template<typename OtherDerived> Derived& operator+=(const ArrayBase<OtherDerived>& )
|
| 488 |
+
{EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
|
| 489 |
+
// mixing arrays and matrices is not legal
|
| 490 |
+
template<typename OtherDerived> Derived& operator-=(const ArrayBase<OtherDerived>& )
|
| 491 |
+
{EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
|
| 492 |
+
};
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
/***************************************************************************
|
| 496 |
+
* Implementation of matrix base methods
|
| 497 |
+
***************************************************************************/
|
| 498 |
+
|
| 499 |
+
/** replaces \c *this by \c *this * \a other.
|
| 500 |
+
*
|
| 501 |
+
* \returns a reference to \c *this
|
| 502 |
+
*
|
| 503 |
+
* Example: \include MatrixBase_applyOnTheRight.cpp
|
| 504 |
+
* Output: \verbinclude MatrixBase_applyOnTheRight.out
|
| 505 |
+
*/
|
| 506 |
+
template<typename Derived>
|
| 507 |
+
template<typename OtherDerived>
|
| 508 |
+
inline Derived&
|
| 509 |
+
MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other)
|
| 510 |
+
{
|
| 511 |
+
other.derived().applyThisOnTheRight(derived());
|
| 512 |
+
return derived();
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=().
|
| 516 |
+
*
|
| 517 |
+
* Example: \include MatrixBase_applyOnTheRight.cpp
|
| 518 |
+
* Output: \verbinclude MatrixBase_applyOnTheRight.out
|
| 519 |
+
*/
|
| 520 |
+
template<typename Derived>
|
| 521 |
+
template<typename OtherDerived>
|
| 522 |
+
inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other)
|
| 523 |
+
{
|
| 524 |
+
other.derived().applyThisOnTheRight(derived());
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
/** replaces \c *this by \a other * \c *this.
|
| 528 |
+
*
|
| 529 |
+
* Example: \include MatrixBase_applyOnTheLeft.cpp
|
| 530 |
+
* Output: \verbinclude MatrixBase_applyOnTheLeft.out
|
| 531 |
+
*/
|
| 532 |
+
template<typename Derived>
|
| 533 |
+
template<typename OtherDerived>
|
| 534 |
+
inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other)
|
| 535 |
+
{
|
| 536 |
+
other.derived().applyThisOnTheLeft(derived());
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
} // end namespace Eigen
|
| 540 |
+
|
| 541 |
+
#endif // EIGEN_MATRIXBASE_H
|
include/eigen/Eigen/src/Core/NestByValue.h
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_NESTBYVALUE_H
|
| 12 |
+
#define EIGEN_NESTBYVALUE_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
template<typename ExpressionType>
|
| 18 |
+
struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
|
| 19 |
+
{
|
| 20 |
+
enum {
|
| 21 |
+
Flags = traits<ExpressionType>::Flags & ~NestByRefBit
|
| 22 |
+
};
|
| 23 |
+
};
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/** \class NestByValue
|
| 27 |
+
* \ingroup Core_Module
|
| 28 |
+
*
|
| 29 |
+
* \brief Expression which must be nested by value
|
| 30 |
+
*
|
| 31 |
+
* \tparam ExpressionType the type of the object of which we are requiring nesting-by-value
|
| 32 |
+
*
|
| 33 |
+
* This class is the return type of MatrixBase::nestByValue()
|
| 34 |
+
* and most of the time this is the only way it is used.
|
| 35 |
+
*
|
| 36 |
+
* \sa MatrixBase::nestByValue()
|
| 37 |
+
*/
|
| 38 |
+
template<typename ExpressionType> class NestByValue
|
| 39 |
+
: public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
|
| 40 |
+
{
|
| 41 |
+
public:
|
| 42 |
+
|
| 43 |
+
typedef typename internal::dense_xpr_base<NestByValue>::type Base;
|
| 44 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue)
|
| 45 |
+
|
| 46 |
+
EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
|
| 47 |
+
|
| 48 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); }
|
| 49 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); }
|
| 50 |
+
|
| 51 |
+
EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
|
| 52 |
+
|
| 53 |
+
EIGEN_DEVICE_FUNC const ExpressionType& nestedExpression() const { return m_expression; }
|
| 54 |
+
|
| 55 |
+
protected:
|
| 56 |
+
const ExpressionType m_expression;
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
/** \returns an expression of the temporary version of *this.
|
| 60 |
+
*/
|
| 61 |
+
template<typename Derived>
|
| 62 |
+
EIGEN_DEVICE_FUNC inline const NestByValue<Derived>
|
| 63 |
+
DenseBase<Derived>::nestByValue() const
|
| 64 |
+
{
|
| 65 |
+
return NestByValue<Derived>(derived());
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
namespace internal {
|
| 69 |
+
|
| 70 |
+
// Evaluator of Solve -> eval into a temporary
|
| 71 |
+
template<typename ArgType>
|
| 72 |
+
struct evaluator<NestByValue<ArgType> >
|
| 73 |
+
: public evaluator<ArgType>
|
| 74 |
+
{
|
| 75 |
+
typedef evaluator<ArgType> Base;
|
| 76 |
+
|
| 77 |
+
EIGEN_DEVICE_FUNC explicit evaluator(const NestByValue<ArgType>& xpr)
|
| 78 |
+
: Base(xpr.nestedExpression())
|
| 79 |
+
{}
|
| 80 |
+
};
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
} // end namespace Eigen
|
| 84 |
+
|
| 85 |
+
#endif // EIGEN_NESTBYVALUE_H
|
include/eigen/Eigen/src/Core/NoAlias.h
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_NOALIAS_H
|
| 11 |
+
#define EIGEN_NOALIAS_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
/** \class NoAlias
|
| 16 |
+
* \ingroup Core_Module
|
| 17 |
+
*
|
| 18 |
+
* \brief Pseudo expression providing an operator = assuming no aliasing
|
| 19 |
+
*
|
| 20 |
+
* \tparam ExpressionType the type of the object on which to do the lazy assignment
|
| 21 |
+
*
|
| 22 |
+
* This class represents an expression with special assignment operators
|
| 23 |
+
* assuming no aliasing between the target expression and the source expression.
|
| 24 |
+
* More precisely it alloas to bypass the EvalBeforeAssignBit flag of the source expression.
|
| 25 |
+
* It is the return type of MatrixBase::noalias()
|
| 26 |
+
* and most of the time this is the only way it is used.
|
| 27 |
+
*
|
| 28 |
+
* \sa MatrixBase::noalias()
|
| 29 |
+
*/
|
| 30 |
+
template<typename ExpressionType, template <typename> class StorageBase>
|
| 31 |
+
class NoAlias
|
| 32 |
+
{
|
| 33 |
+
public:
|
| 34 |
+
typedef typename ExpressionType::Scalar Scalar;
|
| 35 |
+
|
| 36 |
+
EIGEN_DEVICE_FUNC
|
| 37 |
+
explicit NoAlias(ExpressionType& expression) : m_expression(expression) {}
|
| 38 |
+
|
| 39 |
+
template<typename OtherDerived>
|
| 40 |
+
EIGEN_DEVICE_FUNC
|
| 41 |
+
EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
|
| 42 |
+
{
|
| 43 |
+
call_assignment_no_alias(m_expression, other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 44 |
+
return m_expression;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
template<typename OtherDerived>
|
| 48 |
+
EIGEN_DEVICE_FUNC
|
| 49 |
+
EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)
|
| 50 |
+
{
|
| 51 |
+
call_assignment_no_alias(m_expression, other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 52 |
+
return m_expression;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
template<typename OtherDerived>
|
| 56 |
+
EIGEN_DEVICE_FUNC
|
| 57 |
+
EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase<OtherDerived>& other)
|
| 58 |
+
{
|
| 59 |
+
call_assignment_no_alias(m_expression, other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 60 |
+
return m_expression;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
EIGEN_DEVICE_FUNC
|
| 64 |
+
ExpressionType& expression() const
|
| 65 |
+
{
|
| 66 |
+
return m_expression;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
protected:
|
| 70 |
+
ExpressionType& m_expression;
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
/** \returns a pseudo expression of \c *this with an operator= assuming
|
| 74 |
+
* no aliasing between \c *this and the source expression.
|
| 75 |
+
*
|
| 76 |
+
* More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag.
|
| 77 |
+
* Currently, even though several expressions may alias, only product
|
| 78 |
+
* expressions have this flag. Therefore, noalias() is only useful when
|
| 79 |
+
* the source expression contains a matrix product.
|
| 80 |
+
*
|
| 81 |
+
* Here are some examples where noalias is useful:
|
| 82 |
+
* \code
|
| 83 |
+
* D.noalias() = A * B;
|
| 84 |
+
* D.noalias() += A.transpose() * B;
|
| 85 |
+
* D.noalias() -= 2 * A * B.adjoint();
|
| 86 |
+
* \endcode
|
| 87 |
+
*
|
| 88 |
+
* On the other hand the following example will lead to a \b wrong result:
|
| 89 |
+
* \code
|
| 90 |
+
* A.noalias() = A * B;
|
| 91 |
+
* \endcode
|
| 92 |
+
* because the result matrix A is also an operand of the matrix product. Therefore,
|
| 93 |
+
* there is no alternative than evaluating A * B in a temporary, that is the default
|
| 94 |
+
* behavior when you write:
|
| 95 |
+
* \code
|
| 96 |
+
* A = A * B;
|
| 97 |
+
* \endcode
|
| 98 |
+
*
|
| 99 |
+
* \sa class NoAlias
|
| 100 |
+
*/
|
| 101 |
+
template<typename Derived>
|
| 102 |
+
NoAlias<Derived,MatrixBase> EIGEN_DEVICE_FUNC MatrixBase<Derived>::noalias()
|
| 103 |
+
{
|
| 104 |
+
return NoAlias<Derived, Eigen::MatrixBase >(derived());
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
} // end namespace Eigen
|
| 108 |
+
|
| 109 |
+
#endif // EIGEN_NOALIAS_H
|
include/eigen/Eigen/src/Core/NumTraits.h
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ob <jacob.benoit.1@gmail.com>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_NUMTRAITS_H
|
| 11 |
+
#define EIGEN_NUMTRAITS_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
// default implementation of digits10(), based on numeric_limits if specialized,
|
| 18 |
+
// 0 for integer types, and log10(epsilon()) otherwise.
|
| 19 |
+
template< typename T,
|
| 20 |
+
bool use_numeric_limits = std::numeric_limits<T>::is_specialized,
|
| 21 |
+
bool is_integer = NumTraits<T>::IsInteger>
|
| 22 |
+
struct default_digits10_impl
|
| 23 |
+
{
|
| 24 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 25 |
+
static int run() { return std::numeric_limits<T>::digits10; }
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
template<typename T>
|
| 29 |
+
struct default_digits10_impl<T,false,false> // Floating point
|
| 30 |
+
{
|
| 31 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 32 |
+
static int run() {
|
| 33 |
+
using std::log10;
|
| 34 |
+
using std::ceil;
|
| 35 |
+
typedef typename NumTraits<T>::Real Real;
|
| 36 |
+
return int(ceil(-log10(NumTraits<Real>::epsilon())));
|
| 37 |
+
}
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
template<typename T>
|
| 41 |
+
struct default_digits10_impl<T,false,true> // Integer
|
| 42 |
+
{
|
| 43 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 44 |
+
static int run() { return 0; }
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
// default implementation of digits(), based on numeric_limits if specialized,
|
| 49 |
+
// 0 for integer types, and log2(epsilon()) otherwise.
|
| 50 |
+
template< typename T,
|
| 51 |
+
bool use_numeric_limits = std::numeric_limits<T>::is_specialized,
|
| 52 |
+
bool is_integer = NumTraits<T>::IsInteger>
|
| 53 |
+
struct default_digits_impl
|
| 54 |
+
{
|
| 55 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 56 |
+
static int run() { return std::numeric_limits<T>::digits; }
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
template<typename T>
|
| 60 |
+
struct default_digits_impl<T,false,false> // Floating point
|
| 61 |
+
{
|
| 62 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 63 |
+
static int run() {
|
| 64 |
+
using std::log;
|
| 65 |
+
using std::ceil;
|
| 66 |
+
typedef typename NumTraits<T>::Real Real;
|
| 67 |
+
return int(ceil(-log(NumTraits<Real>::epsilon())/log(static_cast<Real>(2))));
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
template<typename T>
|
| 72 |
+
struct default_digits_impl<T,false,true> // Integer
|
| 73 |
+
{
|
| 74 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 75 |
+
static int run() { return 0; }
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
} // end namespace internal
|
| 79 |
+
|
| 80 |
+
namespace numext {
|
| 81 |
+
/** \internal bit-wise cast without changing the underlying bit representation. */
|
| 82 |
+
|
| 83 |
+
// TODO: Replace by std::bit_cast (available in C++20)
|
| 84 |
+
template <typename Tgt, typename Src>
|
| 85 |
+
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src& src) {
|
| 86 |
+
#if EIGEN_HAS_TYPE_TRAITS
|
| 87 |
+
// The behaviour of memcpy is not specified for non-trivially copyable types
|
| 88 |
+
EIGEN_STATIC_ASSERT(std::is_trivially_copyable<Src>::value, THIS_TYPE_IS_NOT_SUPPORTED);
|
| 89 |
+
EIGEN_STATIC_ASSERT(std::is_trivially_copyable<Tgt>::value && std::is_default_constructible<Tgt>::value,
|
| 90 |
+
THIS_TYPE_IS_NOT_SUPPORTED);
|
| 91 |
+
#endif
|
| 92 |
+
|
| 93 |
+
EIGEN_STATIC_ASSERT(sizeof(Src) == sizeof(Tgt), THIS_TYPE_IS_NOT_SUPPORTED);
|
| 94 |
+
Tgt tgt;
|
| 95 |
+
EIGEN_USING_STD(memcpy)
|
| 96 |
+
memcpy(&tgt, &src, sizeof(Tgt));
|
| 97 |
+
return tgt;
|
| 98 |
+
}
|
| 99 |
+
} // namespace numext
|
| 100 |
+
|
| 101 |
+
// clang-format off
|
| 102 |
+
/** \class NumTraits
|
| 103 |
+
* \ingroup Core_Module
|
| 104 |
+
*
|
| 105 |
+
* \brief Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
|
| 106 |
+
*
|
| 107 |
+
* \tparam T the numeric type at hand
|
| 108 |
+
*
|
| 109 |
+
* This class stores enums, typedefs and static methods giving information about a numeric type.
|
| 110 |
+
*
|
| 111 |
+
* The provided data consists of:
|
| 112 |
+
* \li A typedef \c Real, giving the "real part" type of \a T. If \a T is already real,
|
| 113 |
+
* then \c Real is just a typedef to \a T. If \a T is `std::complex<U>` then \c Real
|
| 114 |
+
* is a typedef to \a U.
|
| 115 |
+
* \li A typedef \c NonInteger, giving the type that should be used for operations producing non-integral values,
|
| 116 |
+
* such as quotients, square roots, etc. If \a T is a floating-point type, then this typedef just gives
|
| 117 |
+
* \a T again. Note however that many Eigen functions such as `internal::sqrt` simply refuse to
|
| 118 |
+
* take integers. Outside of a few cases, Eigen doesn't do automatic type promotion. Thus, this typedef is
|
| 119 |
+
* only intended as a helper for code that needs to explicitly promote types.
|
| 120 |
+
* \li A typedef \c Literal giving the type to use for numeric literals such as "2" or "0.5". For instance, for `std::complex<U>`,
|
| 121 |
+
* Literal is defined as \c U.
|
| 122 |
+
* Of course, this type must be fully compatible with \a T. In doubt, just use \a T here.
|
| 123 |
+
* \li A typedef \c Nested giving the type to use to nest a value inside of the expression tree. If you don't know what
|
| 124 |
+
* this means, just use \a T here.
|
| 125 |
+
* \li An enum value \c IsComplex. It is equal to 1 if \a T is a \c std::complex
|
| 126 |
+
* type, and to 0 otherwise.
|
| 127 |
+
* \li An enum value \c IsInteger. It is equal to \c 1 if \a T is an integer type such as \c int,
|
| 128 |
+
* and to \c 0 otherwise.
|
| 129 |
+
* \li Enum values \c ReadCost, \c AddCost and \c MulCost representing a rough estimate of the number of CPU cycles needed
|
| 130 |
+
* to by move / add / mul instructions respectively, assuming the data is already stored in CPU registers.
|
| 131 |
+
* Stay vague here. No need to do architecture-specific stuff. If you don't know what this means, just use \c Eigen::HugeCost.
|
| 132 |
+
* \li An enum value \c IsSigned. It is equal to \c 1 if \a T is a signed type and to 0 if \a T is unsigned.
|
| 133 |
+
* \li An enum value \c RequireInitialization. It is equal to \c 1 if the constructor of the numeric type \a T must
|
| 134 |
+
* be called, and to 0 if it is safe not to call it. Default is 0 if \a T is an arithmetic type, and 1 otherwise.
|
| 135 |
+
* \li An `epsilon()` function which, unlike <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon">`std::numeric_limits::epsilon()`</a>,
|
| 136 |
+
* it returns a \c Real instead of a \a T.
|
| 137 |
+
* \li A `dummy_precision()` function returning a weak epsilon value. It is mainly used as a default
|
| 138 |
+
* value by the fuzzy comparison operators.
|
| 139 |
+
* \li `highest()` and `lowest()` functions returning the highest and lowest possible values respectively.
|
| 140 |
+
* \li `digits()` function returning the number of radix digits (non-sign digits for integers, mantissa for floating-point). This is
|
| 141 |
+
* the analogue of <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/digits">std::numeric_limits<T>::digits</a>
|
| 142 |
+
* which is used as the default implementation if specialized.
|
| 143 |
+
* \li `digits10()` function returning the number of decimal digits that can be represented without change. This is
|
| 144 |
+
* the analogue of <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/digits10">std::numeric_limits<T>::digits10</a>
|
| 145 |
+
* which is used as the default implementation if specialized.
|
| 146 |
+
* \li `min_exponent()` and `max_exponent()` functions returning the highest and lowest possible values, respectively,
|
| 147 |
+
* such that the radix raised to the power exponent-1 is a normalized floating-point number. These are equivalent to
|
| 148 |
+
* <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/min_exponent">`std::numeric_limits<T>::min_exponent`</a>/
|
| 149 |
+
* <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/max_exponent">`std::numeric_limits<T>::max_exponent`</a>.
|
| 150 |
+
* \li `infinity()` function returning a representation of positive infinity, if available.
|
| 151 |
+
* \li `quiet_NaN` function returning a non-signaling "not-a-number", if available.
|
| 152 |
+
*/
|
| 153 |
+
// clang-format on
|
| 154 |
+
|
| 155 |
+
template<typename T> struct GenericNumTraits
|
| 156 |
+
{
|
| 157 |
+
enum {
|
| 158 |
+
IsInteger = std::numeric_limits<T>::is_integer,
|
| 159 |
+
IsSigned = std::numeric_limits<T>::is_signed,
|
| 160 |
+
IsComplex = 0,
|
| 161 |
+
RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1,
|
| 162 |
+
ReadCost = 1,
|
| 163 |
+
AddCost = 1,
|
| 164 |
+
MulCost = 1
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
typedef T Real;
|
| 168 |
+
typedef typename internal::conditional<
|
| 169 |
+
IsInteger,
|
| 170 |
+
typename internal::conditional<sizeof(T)<=2, float, double>::type,
|
| 171 |
+
T
|
| 172 |
+
>::type NonInteger;
|
| 173 |
+
typedef T Nested;
|
| 174 |
+
typedef T Literal;
|
| 175 |
+
|
| 176 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 177 |
+
static inline Real epsilon()
|
| 178 |
+
{
|
| 179 |
+
return numext::numeric_limits<T>::epsilon();
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 183 |
+
static inline int digits10()
|
| 184 |
+
{
|
| 185 |
+
return internal::default_digits10_impl<T>::run();
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 189 |
+
static inline int digits()
|
| 190 |
+
{
|
| 191 |
+
return internal::default_digits_impl<T>::run();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 195 |
+
static inline int min_exponent()
|
| 196 |
+
{
|
| 197 |
+
return numext::numeric_limits<T>::min_exponent;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 201 |
+
static inline int max_exponent()
|
| 202 |
+
{
|
| 203 |
+
return numext::numeric_limits<T>::max_exponent;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 207 |
+
static inline Real dummy_precision()
|
| 208 |
+
{
|
| 209 |
+
// make sure to override this for floating-point types
|
| 210 |
+
return Real(0);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 214 |
+
static inline T highest() {
|
| 215 |
+
return (numext::numeric_limits<T>::max)();
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 219 |
+
static inline T lowest() {
|
| 220 |
+
return IsInteger ? (numext::numeric_limits<T>::min)()
|
| 221 |
+
: static_cast<T>(-(numext::numeric_limits<T>::max)());
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 225 |
+
static inline T infinity() {
|
| 226 |
+
return numext::numeric_limits<T>::infinity();
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 230 |
+
static inline T quiet_NaN() {
|
| 231 |
+
return numext::numeric_limits<T>::quiet_NaN();
|
| 232 |
+
}
|
| 233 |
+
};
|
| 234 |
+
|
| 235 |
+
template<typename T> struct NumTraits : GenericNumTraits<T>
|
| 236 |
+
{};
|
| 237 |
+
|
| 238 |
+
template<> struct NumTraits<float>
|
| 239 |
+
: GenericNumTraits<float>
|
| 240 |
+
{
|
| 241 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 242 |
+
static inline float dummy_precision() { return 1e-5f; }
|
| 243 |
+
};
|
| 244 |
+
|
| 245 |
+
template<> struct NumTraits<double> : GenericNumTraits<double>
|
| 246 |
+
{
|
| 247 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 248 |
+
static inline double dummy_precision() { return 1e-12; }
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
// GPU devices treat `long double` as `double`.
|
| 252 |
+
#ifndef EIGEN_GPU_COMPILE_PHASE
|
| 253 |
+
template<> struct NumTraits<long double>
|
| 254 |
+
: GenericNumTraits<long double>
|
| 255 |
+
{
|
| 256 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 257 |
+
static inline long double dummy_precision() { return static_cast<long double>(1e-15l); }
|
| 258 |
+
|
| 259 |
+
#if defined(EIGEN_ARCH_PPC) && (__LDBL_MANT_DIG__ == 106)
|
| 260 |
+
// PowerPC double double causes issues with some values
|
| 261 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 262 |
+
static inline long double epsilon()
|
| 263 |
+
{
|
| 264 |
+
// 2^(-(__LDBL_MANT_DIG__)+1)
|
| 265 |
+
return static_cast<long double>(2.4651903288156618919116517665087e-32l);
|
| 266 |
+
}
|
| 267 |
+
#endif
|
| 268 |
+
};
|
| 269 |
+
#endif
|
| 270 |
+
|
| 271 |
+
template<typename _Real> struct NumTraits<std::complex<_Real> >
|
| 272 |
+
: GenericNumTraits<std::complex<_Real> >
|
| 273 |
+
{
|
| 274 |
+
typedef _Real Real;
|
| 275 |
+
typedef typename NumTraits<_Real>::Literal Literal;
|
| 276 |
+
enum {
|
| 277 |
+
IsComplex = 1,
|
| 278 |
+
RequireInitialization = NumTraits<_Real>::RequireInitialization,
|
| 279 |
+
ReadCost = 2 * NumTraits<_Real>::ReadCost,
|
| 280 |
+
AddCost = 2 * NumTraits<Real>::AddCost,
|
| 281 |
+
MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 285 |
+
static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
|
| 286 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 287 |
+
static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
|
| 288 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 289 |
+
static inline int digits10() { return NumTraits<Real>::digits10(); }
|
| 290 |
+
};
|
| 291 |
+
|
| 292 |
+
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
| 293 |
+
struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
|
| 294 |
+
{
|
| 295 |
+
typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType;
|
| 296 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 297 |
+
typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real;
|
| 298 |
+
typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar;
|
| 299 |
+
typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger;
|
| 300 |
+
typedef ArrayType & Nested;
|
| 301 |
+
typedef typename NumTraits<Scalar>::Literal Literal;
|
| 302 |
+
|
| 303 |
+
enum {
|
| 304 |
+
IsComplex = NumTraits<Scalar>::IsComplex,
|
| 305 |
+
IsInteger = NumTraits<Scalar>::IsInteger,
|
| 306 |
+
IsSigned = NumTraits<Scalar>::IsSigned,
|
| 307 |
+
RequireInitialization = 1,
|
| 308 |
+
ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * int(NumTraits<Scalar>::ReadCost),
|
| 309 |
+
AddCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * int(NumTraits<Scalar>::AddCost),
|
| 310 |
+
MulCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * int(NumTraits<Scalar>::MulCost)
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 314 |
+
static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); }
|
| 315 |
+
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
|
| 316 |
+
static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); }
|
| 317 |
+
|
| 318 |
+
EIGEN_CONSTEXPR
|
| 319 |
+
static inline int digits10() { return NumTraits<Scalar>::digits10(); }
|
| 320 |
+
};
|
| 321 |
+
|
| 322 |
+
template<> struct NumTraits<std::string>
|
| 323 |
+
: GenericNumTraits<std::string>
|
| 324 |
+
{
|
| 325 |
+
enum {
|
| 326 |
+
RequireInitialization = 1,
|
| 327 |
+
ReadCost = HugeCost,
|
| 328 |
+
AddCost = HugeCost,
|
| 329 |
+
MulCost = HugeCost
|
| 330 |
+
};
|
| 331 |
+
|
| 332 |
+
EIGEN_CONSTEXPR
|
| 333 |
+
static inline int digits10() { return 0; }
|
| 334 |
+
|
| 335 |
+
private:
|
| 336 |
+
static inline std::string epsilon();
|
| 337 |
+
static inline std::string dummy_precision();
|
| 338 |
+
static inline std::string lowest();
|
| 339 |
+
static inline std::string highest();
|
| 340 |
+
static inline std::string infinity();
|
| 341 |
+
static inline std::string quiet_NaN();
|
| 342 |
+
};
|
| 343 |
+
|
| 344 |
+
// Empty specialization for void to allow template specialization based on NumTraits<T>::Real with T==void and SFINAE.
|
| 345 |
+
template<> struct NumTraits<void> {};
|
| 346 |
+
|
| 347 |
+
template<> struct NumTraits<bool> : GenericNumTraits<bool> {};
|
| 348 |
+
|
| 349 |
+
} // end namespace Eigen
|
| 350 |
+
|
| 351 |
+
#endif // EIGEN_NUMTRAITS_H
|
include/eigen/Eigen/src/Core/PartialReduxEvaluator.h
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2011-2018 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_PARTIALREDUX_H
|
| 11 |
+
#define EIGEN_PARTIALREDUX_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
/***************************************************************************
|
| 19 |
+
*
|
| 20 |
+
* This file provides evaluators for partial reductions.
|
| 21 |
+
* There are two modes:
|
| 22 |
+
*
|
| 23 |
+
* - scalar path: simply calls the respective function on the column or row.
|
| 24 |
+
* -> nothing special here, all the tricky part is handled by the return
|
| 25 |
+
* types of VectorwiseOp's members. They embed the functor calling the
|
| 26 |
+
* respective DenseBase's member function.
|
| 27 |
+
*
|
| 28 |
+
* - vectorized path: implements a packet-wise reductions followed by
|
| 29 |
+
* some (optional) processing of the outcome, e.g., division by n for mean.
|
| 30 |
+
*
|
| 31 |
+
* For the vectorized path let's observe that the packet-size and outer-unrolling
|
| 32 |
+
* are both decided by the assignement logic. So all we have to do is to decide
|
| 33 |
+
* on the inner unrolling.
|
| 34 |
+
*
|
| 35 |
+
* For the unrolling, we can reuse "internal::redux_vec_unroller" from Redux.h,
|
| 36 |
+
* but be need to be careful to specify correct increment.
|
| 37 |
+
*
|
| 38 |
+
***************************************************************************/
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
/* logic deciding a strategy for unrolling of vectorized paths */
|
| 42 |
+
template<typename Func, typename Evaluator>
|
| 43 |
+
struct packetwise_redux_traits
|
| 44 |
+
{
|
| 45 |
+
enum {
|
| 46 |
+
OuterSize = int(Evaluator::IsRowMajor) ? Evaluator::RowsAtCompileTime : Evaluator::ColsAtCompileTime,
|
| 47 |
+
Cost = OuterSize == Dynamic ? HugeCost
|
| 48 |
+
: OuterSize * Evaluator::CoeffReadCost + (OuterSize-1) * functor_traits<Func>::Cost,
|
| 49 |
+
Unrolling = Cost <= EIGEN_UNROLLING_LIMIT ? CompleteUnrolling : NoUnrolling
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
/* Value to be returned when size==0 , by default let's return 0 */
|
| 55 |
+
template<typename PacketType,typename Func>
|
| 56 |
+
EIGEN_DEVICE_FUNC
|
| 57 |
+
PacketType packetwise_redux_empty_value(const Func& ) {
|
| 58 |
+
const typename unpacket_traits<PacketType>::type zero(0);
|
| 59 |
+
return pset1<PacketType>(zero);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/* For products the default is 1 */
|
| 63 |
+
template<typename PacketType,typename Scalar>
|
| 64 |
+
EIGEN_DEVICE_FUNC
|
| 65 |
+
PacketType packetwise_redux_empty_value(const scalar_product_op<Scalar,Scalar>& ) {
|
| 66 |
+
return pset1<PacketType>(Scalar(1));
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* Perform the actual reduction */
|
| 70 |
+
template<typename Func, typename Evaluator,
|
| 71 |
+
int Unrolling = packetwise_redux_traits<Func, Evaluator>::Unrolling
|
| 72 |
+
>
|
| 73 |
+
struct packetwise_redux_impl;
|
| 74 |
+
|
| 75 |
+
/* Perform the actual reduction with unrolling */
|
| 76 |
+
template<typename Func, typename Evaluator>
|
| 77 |
+
struct packetwise_redux_impl<Func, Evaluator, CompleteUnrolling>
|
| 78 |
+
{
|
| 79 |
+
typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base;
|
| 80 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 81 |
+
|
| 82 |
+
template<typename PacketType>
|
| 83 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
|
| 84 |
+
PacketType run(const Evaluator &eval, const Func& func, Index /*size*/)
|
| 85 |
+
{
|
| 86 |
+
return redux_vec_unroller<Func, Evaluator, 0, packetwise_redux_traits<Func, Evaluator>::OuterSize>::template run<PacketType>(eval,func);
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
/* Add a specialization of redux_vec_unroller for size==0 at compiletime.
|
| 91 |
+
* This specialization is not required for general reductions, which is
|
| 92 |
+
* why it is defined here.
|
| 93 |
+
*/
|
| 94 |
+
template<typename Func, typename Evaluator, int Start>
|
| 95 |
+
struct redux_vec_unroller<Func, Evaluator, Start, 0>
|
| 96 |
+
{
|
| 97 |
+
template<typename PacketType>
|
| 98 |
+
EIGEN_DEVICE_FUNC
|
| 99 |
+
static EIGEN_STRONG_INLINE PacketType run(const Evaluator &, const Func& f)
|
| 100 |
+
{
|
| 101 |
+
return packetwise_redux_empty_value<PacketType>(f);
|
| 102 |
+
}
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
/* Perform the actual reduction for dynamic sizes */
|
| 106 |
+
template<typename Func, typename Evaluator>
|
| 107 |
+
struct packetwise_redux_impl<Func, Evaluator, NoUnrolling>
|
| 108 |
+
{
|
| 109 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 110 |
+
typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar;
|
| 111 |
+
|
| 112 |
+
template<typename PacketType>
|
| 113 |
+
EIGEN_DEVICE_FUNC
|
| 114 |
+
static PacketType run(const Evaluator &eval, const Func& func, Index size)
|
| 115 |
+
{
|
| 116 |
+
if(size==0)
|
| 117 |
+
return packetwise_redux_empty_value<PacketType>(func);
|
| 118 |
+
|
| 119 |
+
const Index size4 = (size-1)&(~3);
|
| 120 |
+
PacketType p = eval.template packetByOuterInner<Unaligned,PacketType>(0,0);
|
| 121 |
+
Index i = 1;
|
| 122 |
+
// This loop is optimized for instruction pipelining:
|
| 123 |
+
// - each iteration generates two independent instructions
|
| 124 |
+
// - thanks to branch prediction and out-of-order execution we have independent instructions across loops
|
| 125 |
+
for(; i<size4; i+=4)
|
| 126 |
+
p = func.packetOp(p,
|
| 127 |
+
func.packetOp(
|
| 128 |
+
func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+0,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+1,0)),
|
| 129 |
+
func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+2,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+3,0))));
|
| 130 |
+
for(; i<size; ++i)
|
| 131 |
+
p = func.packetOp(p, eval.template packetByOuterInner<Unaligned,PacketType>(i,0));
|
| 132 |
+
return p;
|
| 133 |
+
}
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
template< typename ArgType, typename MemberOp, int Direction>
|
| 137 |
+
struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
|
| 138 |
+
: evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
|
| 139 |
+
{
|
| 140 |
+
typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
|
| 141 |
+
typedef typename internal::nested_eval<ArgType,1>::type ArgTypeNested;
|
| 142 |
+
typedef typename internal::add_const_on_value_type<ArgTypeNested>::type ConstArgTypeNested;
|
| 143 |
+
typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
|
| 144 |
+
typedef typename ArgType::Scalar InputScalar;
|
| 145 |
+
typedef typename XprType::Scalar Scalar;
|
| 146 |
+
enum {
|
| 147 |
+
TraversalSize = Direction==int(Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime)
|
| 148 |
+
};
|
| 149 |
+
typedef typename MemberOp::template Cost<int(TraversalSize)> CostOpType;
|
| 150 |
+
enum {
|
| 151 |
+
CoeffReadCost = TraversalSize==Dynamic ? HugeCost
|
| 152 |
+
: TraversalSize==0 ? 1
|
| 153 |
+
: int(TraversalSize) * int(evaluator<ArgType>::CoeffReadCost) + int(CostOpType::value),
|
| 154 |
+
|
| 155 |
+
_ArgFlags = evaluator<ArgType>::Flags,
|
| 156 |
+
|
| 157 |
+
_Vectorizable = bool(int(_ArgFlags)&PacketAccessBit)
|
| 158 |
+
&& bool(MemberOp::Vectorizable)
|
| 159 |
+
&& (Direction==int(Vertical) ? bool(_ArgFlags&RowMajorBit) : (_ArgFlags&RowMajorBit)==0)
|
| 160 |
+
&& (TraversalSize!=0),
|
| 161 |
+
|
| 162 |
+
Flags = (traits<XprType>::Flags&RowMajorBit)
|
| 163 |
+
| (evaluator<ArgType>::Flags&(HereditaryBits&(~RowMajorBit)))
|
| 164 |
+
| (_Vectorizable ? PacketAccessBit : 0)
|
| 165 |
+
| LinearAccessBit,
|
| 166 |
+
|
| 167 |
+
Alignment = 0 // FIXME this will need to be improved once PartialReduxExpr is vectorized
|
| 168 |
+
};
|
| 169 |
+
|
| 170 |
+
EIGEN_DEVICE_FUNC explicit evaluator(const XprType xpr)
|
| 171 |
+
: m_arg(xpr.nestedExpression()), m_functor(xpr.functor())
|
| 172 |
+
{
|
| 173 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize==Dynamic ? HugeCost : (TraversalSize==0 ? 1 : int(CostOpType::value)));
|
| 174 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
typedef typename XprType::CoeffReturnType CoeffReturnType;
|
| 178 |
+
|
| 179 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 180 |
+
const Scalar coeff(Index i, Index j) const
|
| 181 |
+
{
|
| 182 |
+
return coeff(Direction==Vertical ? j : i);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 186 |
+
const Scalar coeff(Index index) const
|
| 187 |
+
{
|
| 188 |
+
return m_functor(m_arg.template subVector<DirectionType(Direction)>(index));
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
template<int LoadMode,typename PacketType>
|
| 192 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 193 |
+
PacketType packet(Index i, Index j) const
|
| 194 |
+
{
|
| 195 |
+
return packet<LoadMode,PacketType>(Direction==Vertical ? j : i);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
template<int LoadMode,typename PacketType>
|
| 199 |
+
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
|
| 200 |
+
PacketType packet(Index idx) const
|
| 201 |
+
{
|
| 202 |
+
enum { PacketSize = internal::unpacket_traits<PacketType>::size };
|
| 203 |
+
typedef Block<const ArgTypeNestedCleaned,
|
| 204 |
+
Direction==Vertical ? int(ArgType::RowsAtCompileTime) : int(PacketSize),
|
| 205 |
+
Direction==Vertical ? int(PacketSize) : int(ArgType::ColsAtCompileTime),
|
| 206 |
+
true /* InnerPanel */> PanelType;
|
| 207 |
+
|
| 208 |
+
PanelType panel(m_arg,
|
| 209 |
+
Direction==Vertical ? 0 : idx,
|
| 210 |
+
Direction==Vertical ? idx : 0,
|
| 211 |
+
Direction==Vertical ? m_arg.rows() : Index(PacketSize),
|
| 212 |
+
Direction==Vertical ? Index(PacketSize) : m_arg.cols());
|
| 213 |
+
|
| 214 |
+
// FIXME
|
| 215 |
+
// See bug 1612, currently if PacketSize==1 (i.e. complex<double> with 128bits registers) then the storage-order of panel get reversed
|
| 216 |
+
// and methods like packetByOuterInner do not make sense anymore in this context.
|
| 217 |
+
// So let's just by pass "vectorization" in this case:
|
| 218 |
+
if(PacketSize==1)
|
| 219 |
+
return internal::pset1<PacketType>(coeff(idx));
|
| 220 |
+
|
| 221 |
+
typedef typename internal::redux_evaluator<PanelType> PanelEvaluator;
|
| 222 |
+
PanelEvaluator panel_eval(panel);
|
| 223 |
+
typedef typename MemberOp::BinaryOp BinaryOp;
|
| 224 |
+
PacketType p = internal::packetwise_redux_impl<BinaryOp,PanelEvaluator>::template run<PacketType>(panel_eval,m_functor.binaryFunc(),m_arg.outerSize());
|
| 225 |
+
return p;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
protected:
|
| 229 |
+
ConstArgTypeNested m_arg;
|
| 230 |
+
const MemberOp m_functor;
|
| 231 |
+
};
|
| 232 |
+
|
| 233 |
+
} // end namespace internal
|
| 234 |
+
|
| 235 |
+
} // end namespace Eigen
|
| 236 |
+
|
| 237 |
+
#endif // EIGEN_PARTIALREDUX_H
|
include/eigen/Eigen/src/Core/PermutationMatrix.h
ADDED
|
@@ -0,0 +1,605 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_PERMUTATIONMATRIX_H
|
| 12 |
+
#define EIGEN_PERMUTATIONMATRIX_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
|
| 18 |
+
enum PermPermProduct_t {PermPermProduct};
|
| 19 |
+
|
| 20 |
+
} // end namespace internal
|
| 21 |
+
|
| 22 |
+
/** \class PermutationBase
|
| 23 |
+
* \ingroup Core_Module
|
| 24 |
+
*
|
| 25 |
+
* \brief Base class for permutations
|
| 26 |
+
*
|
| 27 |
+
* \tparam Derived the derived class
|
| 28 |
+
*
|
| 29 |
+
* This class is the base class for all expressions representing a permutation matrix,
|
| 30 |
+
* internally stored as a vector of integers.
|
| 31 |
+
* The convention followed here is that if \f$ \sigma \f$ is a permutation, the corresponding permutation matrix
|
| 32 |
+
* \f$ P_\sigma \f$ is such that if \f$ (e_1,\ldots,e_p) \f$ is the canonical basis, we have:
|
| 33 |
+
* \f[ P_\sigma(e_i) = e_{\sigma(i)}. \f]
|
| 34 |
+
* This convention ensures that for any two permutations \f$ \sigma, \tau \f$, we have:
|
| 35 |
+
* \f[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \f]
|
| 36 |
+
*
|
| 37 |
+
* Permutation matrices are square and invertible.
|
| 38 |
+
*
|
| 39 |
+
* Notice that in addition to the member functions and operators listed here, there also are non-member
|
| 40 |
+
* operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase)
|
| 41 |
+
* on either side.
|
| 42 |
+
*
|
| 43 |
+
* \sa class PermutationMatrix, class PermutationWrapper
|
| 44 |
+
*/
|
| 45 |
+
template<typename Derived>
|
| 46 |
+
class PermutationBase : public EigenBase<Derived>
|
| 47 |
+
{
|
| 48 |
+
typedef internal::traits<Derived> Traits;
|
| 49 |
+
typedef EigenBase<Derived> Base;
|
| 50 |
+
public:
|
| 51 |
+
|
| 52 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 53 |
+
typedef typename Traits::IndicesType IndicesType;
|
| 54 |
+
enum {
|
| 55 |
+
Flags = Traits::Flags,
|
| 56 |
+
RowsAtCompileTime = Traits::RowsAtCompileTime,
|
| 57 |
+
ColsAtCompileTime = Traits::ColsAtCompileTime,
|
| 58 |
+
MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
|
| 59 |
+
MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
|
| 60 |
+
};
|
| 61 |
+
typedef typename Traits::StorageIndex StorageIndex;
|
| 62 |
+
typedef Matrix<StorageIndex,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime>
|
| 63 |
+
DenseMatrixType;
|
| 64 |
+
typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndex>
|
| 65 |
+
PlainPermutationType;
|
| 66 |
+
typedef PlainPermutationType PlainObject;
|
| 67 |
+
using Base::derived;
|
| 68 |
+
typedef Inverse<Derived> InverseReturnType;
|
| 69 |
+
typedef void Scalar;
|
| 70 |
+
#endif
|
| 71 |
+
|
| 72 |
+
/** Copies the other permutation into *this */
|
| 73 |
+
template<typename OtherDerived>
|
| 74 |
+
Derived& operator=(const PermutationBase<OtherDerived>& other)
|
| 75 |
+
{
|
| 76 |
+
indices() = other.indices();
|
| 77 |
+
return derived();
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/** Assignment from the Transpositions \a tr */
|
| 81 |
+
template<typename OtherDerived>
|
| 82 |
+
Derived& operator=(const TranspositionsBase<OtherDerived>& tr)
|
| 83 |
+
{
|
| 84 |
+
setIdentity(tr.size());
|
| 85 |
+
for(Index k=size()-1; k>=0; --k)
|
| 86 |
+
applyTranspositionOnTheRight(k,tr.coeff(k));
|
| 87 |
+
return derived();
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/** \returns the number of rows */
|
| 91 |
+
inline EIGEN_DEVICE_FUNC Index rows() const { return Index(indices().size()); }
|
| 92 |
+
|
| 93 |
+
/** \returns the number of columns */
|
| 94 |
+
inline EIGEN_DEVICE_FUNC Index cols() const { return Index(indices().size()); }
|
| 95 |
+
|
| 96 |
+
/** \returns the size of a side of the respective square matrix, i.e., the number of indices */
|
| 97 |
+
inline EIGEN_DEVICE_FUNC Index size() const { return Index(indices().size()); }
|
| 98 |
+
|
| 99 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 100 |
+
template<typename DenseDerived>
|
| 101 |
+
void evalTo(MatrixBase<DenseDerived>& other) const
|
| 102 |
+
{
|
| 103 |
+
other.setZero();
|
| 104 |
+
for (Index i=0; i<rows(); ++i)
|
| 105 |
+
other.coeffRef(indices().coeff(i),i) = typename DenseDerived::Scalar(1);
|
| 106 |
+
}
|
| 107 |
+
#endif
|
| 108 |
+
|
| 109 |
+
/** \returns a Matrix object initialized from this permutation matrix. Notice that it
|
| 110 |
+
* is inefficient to return this Matrix object by value. For efficiency, favor using
|
| 111 |
+
* the Matrix constructor taking EigenBase objects.
|
| 112 |
+
*/
|
| 113 |
+
DenseMatrixType toDenseMatrix() const
|
| 114 |
+
{
|
| 115 |
+
return derived();
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/** const version of indices(). */
|
| 119 |
+
const IndicesType& indices() const { return derived().indices(); }
|
| 120 |
+
/** \returns a reference to the stored array representing the permutation. */
|
| 121 |
+
IndicesType& indices() { return derived().indices(); }
|
| 122 |
+
|
| 123 |
+
/** Resizes to given size.
|
| 124 |
+
*/
|
| 125 |
+
inline void resize(Index newSize)
|
| 126 |
+
{
|
| 127 |
+
indices().resize(newSize);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/** Sets *this to be the identity permutation matrix */
|
| 131 |
+
void setIdentity()
|
| 132 |
+
{
|
| 133 |
+
StorageIndex n = StorageIndex(size());
|
| 134 |
+
for(StorageIndex i = 0; i < n; ++i)
|
| 135 |
+
indices().coeffRef(i) = i;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/** Sets *this to be the identity permutation matrix of given size.
|
| 139 |
+
*/
|
| 140 |
+
void setIdentity(Index newSize)
|
| 141 |
+
{
|
| 142 |
+
resize(newSize);
|
| 143 |
+
setIdentity();
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/** Multiplies *this by the transposition \f$(ij)\f$ on the left.
|
| 147 |
+
*
|
| 148 |
+
* \returns a reference to *this.
|
| 149 |
+
*
|
| 150 |
+
* \warning This is much slower than applyTranspositionOnTheRight(Index,Index):
|
| 151 |
+
* this has linear complexity and requires a lot of branching.
|
| 152 |
+
*
|
| 153 |
+
* \sa applyTranspositionOnTheRight(Index,Index)
|
| 154 |
+
*/
|
| 155 |
+
Derived& applyTranspositionOnTheLeft(Index i, Index j)
|
| 156 |
+
{
|
| 157 |
+
eigen_assert(i>=0 && j>=0 && i<size() && j<size());
|
| 158 |
+
for(Index k = 0; k < size(); ++k)
|
| 159 |
+
{
|
| 160 |
+
if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndex(j);
|
| 161 |
+
else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndex(i);
|
| 162 |
+
}
|
| 163 |
+
return derived();
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/** Multiplies *this by the transposition \f$(ij)\f$ on the right.
|
| 167 |
+
*
|
| 168 |
+
* \returns a reference to *this.
|
| 169 |
+
*
|
| 170 |
+
* This is a fast operation, it only consists in swapping two indices.
|
| 171 |
+
*
|
| 172 |
+
* \sa applyTranspositionOnTheLeft(Index,Index)
|
| 173 |
+
*/
|
| 174 |
+
Derived& applyTranspositionOnTheRight(Index i, Index j)
|
| 175 |
+
{
|
| 176 |
+
eigen_assert(i>=0 && j>=0 && i<size() && j<size());
|
| 177 |
+
std::swap(indices().coeffRef(i), indices().coeffRef(j));
|
| 178 |
+
return derived();
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/** \returns the inverse permutation matrix.
|
| 182 |
+
*
|
| 183 |
+
* \note \blank \note_try_to_help_rvo
|
| 184 |
+
*/
|
| 185 |
+
inline InverseReturnType inverse() const
|
| 186 |
+
{ return InverseReturnType(derived()); }
|
| 187 |
+
/** \returns the tranpose permutation matrix.
|
| 188 |
+
*
|
| 189 |
+
* \note \blank \note_try_to_help_rvo
|
| 190 |
+
*/
|
| 191 |
+
inline InverseReturnType transpose() const
|
| 192 |
+
{ return InverseReturnType(derived()); }
|
| 193 |
+
|
| 194 |
+
/**** multiplication helpers to hopefully get RVO ****/
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 198 |
+
protected:
|
| 199 |
+
template<typename OtherDerived>
|
| 200 |
+
void assignTranspose(const PermutationBase<OtherDerived>& other)
|
| 201 |
+
{
|
| 202 |
+
for (Index i=0; i<rows();++i) indices().coeffRef(other.indices().coeff(i)) = i;
|
| 203 |
+
}
|
| 204 |
+
template<typename Lhs,typename Rhs>
|
| 205 |
+
void assignProduct(const Lhs& lhs, const Rhs& rhs)
|
| 206 |
+
{
|
| 207 |
+
eigen_assert(lhs.cols() == rhs.rows());
|
| 208 |
+
for (Index i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
|
| 209 |
+
}
|
| 210 |
+
#endif
|
| 211 |
+
|
| 212 |
+
public:
|
| 213 |
+
|
| 214 |
+
/** \returns the product permutation matrix.
|
| 215 |
+
*
|
| 216 |
+
* \note \blank \note_try_to_help_rvo
|
| 217 |
+
*/
|
| 218 |
+
template<typename Other>
|
| 219 |
+
inline PlainPermutationType operator*(const PermutationBase<Other>& other) const
|
| 220 |
+
{ return PlainPermutationType(internal::PermPermProduct, derived(), other.derived()); }
|
| 221 |
+
|
| 222 |
+
/** \returns the product of a permutation with another inverse permutation.
|
| 223 |
+
*
|
| 224 |
+
* \note \blank \note_try_to_help_rvo
|
| 225 |
+
*/
|
| 226 |
+
template<typename Other>
|
| 227 |
+
inline PlainPermutationType operator*(const InverseImpl<Other,PermutationStorage>& other) const
|
| 228 |
+
{ return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); }
|
| 229 |
+
|
| 230 |
+
/** \returns the product of an inverse permutation with another permutation.
|
| 231 |
+
*
|
| 232 |
+
* \note \blank \note_try_to_help_rvo
|
| 233 |
+
*/
|
| 234 |
+
template<typename Other> friend
|
| 235 |
+
inline PlainPermutationType operator*(const InverseImpl<Other, PermutationStorage>& other, const PermutationBase& perm)
|
| 236 |
+
{ return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
|
| 237 |
+
|
| 238 |
+
/** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation.
|
| 239 |
+
*
|
| 240 |
+
* This function is O(\c n) procedure allocating a buffer of \c n booleans.
|
| 241 |
+
*/
|
| 242 |
+
Index determinant() const
|
| 243 |
+
{
|
| 244 |
+
Index res = 1;
|
| 245 |
+
Index n = size();
|
| 246 |
+
Matrix<bool,RowsAtCompileTime,1,0,MaxRowsAtCompileTime> mask(n);
|
| 247 |
+
mask.fill(false);
|
| 248 |
+
Index r = 0;
|
| 249 |
+
while(r < n)
|
| 250 |
+
{
|
| 251 |
+
// search for the next seed
|
| 252 |
+
while(r<n && mask[r]) r++;
|
| 253 |
+
if(r>=n)
|
| 254 |
+
break;
|
| 255 |
+
// we got one, let's follow it until we are back to the seed
|
| 256 |
+
Index k0 = r++;
|
| 257 |
+
mask.coeffRef(k0) = true;
|
| 258 |
+
for(Index k=indices().coeff(k0); k!=k0; k=indices().coeff(k))
|
| 259 |
+
{
|
| 260 |
+
mask.coeffRef(k) = true;
|
| 261 |
+
res = -res;
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
return res;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
protected:
|
| 268 |
+
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
namespace internal {
|
| 272 |
+
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
|
| 273 |
+
struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
|
| 274 |
+
: traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
|
| 275 |
+
{
|
| 276 |
+
typedef PermutationStorage StorageKind;
|
| 277 |
+
typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
|
| 278 |
+
typedef _StorageIndex StorageIndex;
|
| 279 |
+
typedef void Scalar;
|
| 280 |
+
};
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/** \class PermutationMatrix
|
| 284 |
+
* \ingroup Core_Module
|
| 285 |
+
*
|
| 286 |
+
* \brief Permutation matrix
|
| 287 |
+
*
|
| 288 |
+
* \tparam SizeAtCompileTime the number of rows/cols, or Dynamic
|
| 289 |
+
* \tparam MaxSizeAtCompileTime the maximum number of rows/cols, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it.
|
| 290 |
+
* \tparam _StorageIndex the integer type of the indices
|
| 291 |
+
*
|
| 292 |
+
* This class represents a permutation matrix, internally stored as a vector of integers.
|
| 293 |
+
*
|
| 294 |
+
* \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix
|
| 295 |
+
*/
|
| 296 |
+
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
|
| 297 |
+
class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
|
| 298 |
+
{
|
| 299 |
+
typedef PermutationBase<PermutationMatrix> Base;
|
| 300 |
+
typedef internal::traits<PermutationMatrix> Traits;
|
| 301 |
+
public:
|
| 302 |
+
|
| 303 |
+
typedef const PermutationMatrix& Nested;
|
| 304 |
+
|
| 305 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 306 |
+
typedef typename Traits::IndicesType IndicesType;
|
| 307 |
+
typedef typename Traits::StorageIndex StorageIndex;
|
| 308 |
+
#endif
|
| 309 |
+
|
| 310 |
+
inline PermutationMatrix()
|
| 311 |
+
{}
|
| 312 |
+
|
| 313 |
+
/** Constructs an uninitialized permutation matrix of given size.
|
| 314 |
+
*/
|
| 315 |
+
explicit inline PermutationMatrix(Index size) : m_indices(size)
|
| 316 |
+
{
|
| 317 |
+
eigen_internal_assert(size <= NumTraits<StorageIndex>::highest());
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
/** Copy constructor. */
|
| 321 |
+
template<typename OtherDerived>
|
| 322 |
+
inline PermutationMatrix(const PermutationBase<OtherDerived>& other)
|
| 323 |
+
: m_indices(other.indices()) {}
|
| 324 |
+
|
| 325 |
+
/** Generic constructor from expression of the indices. The indices
|
| 326 |
+
* array has the meaning that the permutations sends each integer i to indices[i].
|
| 327 |
+
*
|
| 328 |
+
* \warning It is your responsibility to check that the indices array that you passes actually
|
| 329 |
+
* describes a permutation, i.e., each value between 0 and n-1 occurs exactly once, where n is the
|
| 330 |
+
* array's size.
|
| 331 |
+
*/
|
| 332 |
+
template<typename Other>
|
| 333 |
+
explicit inline PermutationMatrix(const MatrixBase<Other>& indices) : m_indices(indices)
|
| 334 |
+
{}
|
| 335 |
+
|
| 336 |
+
/** Convert the Transpositions \a tr to a permutation matrix */
|
| 337 |
+
template<typename Other>
|
| 338 |
+
explicit PermutationMatrix(const TranspositionsBase<Other>& tr)
|
| 339 |
+
: m_indices(tr.size())
|
| 340 |
+
{
|
| 341 |
+
*this = tr;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
/** Copies the other permutation into *this */
|
| 345 |
+
template<typename Other>
|
| 346 |
+
PermutationMatrix& operator=(const PermutationBase<Other>& other)
|
| 347 |
+
{
|
| 348 |
+
m_indices = other.indices();
|
| 349 |
+
return *this;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
/** Assignment from the Transpositions \a tr */
|
| 353 |
+
template<typename Other>
|
| 354 |
+
PermutationMatrix& operator=(const TranspositionsBase<Other>& tr)
|
| 355 |
+
{
|
| 356 |
+
return Base::operator=(tr.derived());
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
/** const version of indices(). */
|
| 360 |
+
const IndicesType& indices() const { return m_indices; }
|
| 361 |
+
/** \returns a reference to the stored array representing the permutation. */
|
| 362 |
+
IndicesType& indices() { return m_indices; }
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
/**** multiplication helpers to hopefully get RVO ****/
|
| 366 |
+
|
| 367 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 368 |
+
template<typename Other>
|
| 369 |
+
PermutationMatrix(const InverseImpl<Other,PermutationStorage>& other)
|
| 370 |
+
: m_indices(other.derived().nestedExpression().size())
|
| 371 |
+
{
|
| 372 |
+
eigen_internal_assert(m_indices.size() <= NumTraits<StorageIndex>::highest());
|
| 373 |
+
StorageIndex end = StorageIndex(m_indices.size());
|
| 374 |
+
for (StorageIndex i=0; i<end;++i)
|
| 375 |
+
m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
|
| 376 |
+
}
|
| 377 |
+
template<typename Lhs,typename Rhs>
|
| 378 |
+
PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs)
|
| 379 |
+
: m_indices(lhs.indices().size())
|
| 380 |
+
{
|
| 381 |
+
Base::assignProduct(lhs,rhs);
|
| 382 |
+
}
|
| 383 |
+
#endif
|
| 384 |
+
|
| 385 |
+
protected:
|
| 386 |
+
|
| 387 |
+
IndicesType m_indices;
|
| 388 |
+
};
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
namespace internal {
|
| 392 |
+
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
|
| 393 |
+
struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
|
| 394 |
+
: traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
|
| 395 |
+
{
|
| 396 |
+
typedef PermutationStorage StorageKind;
|
| 397 |
+
typedef Map<const Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType;
|
| 398 |
+
typedef _StorageIndex StorageIndex;
|
| 399 |
+
typedef void Scalar;
|
| 400 |
+
};
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
|
| 404 |
+
class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess>
|
| 405 |
+
: public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
|
| 406 |
+
{
|
| 407 |
+
typedef PermutationBase<Map> Base;
|
| 408 |
+
typedef internal::traits<Map> Traits;
|
| 409 |
+
public:
|
| 410 |
+
|
| 411 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 412 |
+
typedef typename Traits::IndicesType IndicesType;
|
| 413 |
+
typedef typename IndicesType::Scalar StorageIndex;
|
| 414 |
+
#endif
|
| 415 |
+
|
| 416 |
+
inline Map(const StorageIndex* indicesPtr)
|
| 417 |
+
: m_indices(indicesPtr)
|
| 418 |
+
{}
|
| 419 |
+
|
| 420 |
+
inline Map(const StorageIndex* indicesPtr, Index size)
|
| 421 |
+
: m_indices(indicesPtr,size)
|
| 422 |
+
{}
|
| 423 |
+
|
| 424 |
+
/** Copies the other permutation into *this */
|
| 425 |
+
template<typename Other>
|
| 426 |
+
Map& operator=(const PermutationBase<Other>& other)
|
| 427 |
+
{ return Base::operator=(other.derived()); }
|
| 428 |
+
|
| 429 |
+
/** Assignment from the Transpositions \a tr */
|
| 430 |
+
template<typename Other>
|
| 431 |
+
Map& operator=(const TranspositionsBase<Other>& tr)
|
| 432 |
+
{ return Base::operator=(tr.derived()); }
|
| 433 |
+
|
| 434 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 435 |
+
/** This is a special case of the templated operator=. Its purpose is to
|
| 436 |
+
* prevent a default operator= from hiding the templated operator=.
|
| 437 |
+
*/
|
| 438 |
+
Map& operator=(const Map& other)
|
| 439 |
+
{
|
| 440 |
+
m_indices = other.m_indices;
|
| 441 |
+
return *this;
|
| 442 |
+
}
|
| 443 |
+
#endif
|
| 444 |
+
|
| 445 |
+
/** const version of indices(). */
|
| 446 |
+
const IndicesType& indices() const { return m_indices; }
|
| 447 |
+
/** \returns a reference to the stored array representing the permutation. */
|
| 448 |
+
IndicesType& indices() { return m_indices; }
|
| 449 |
+
|
| 450 |
+
protected:
|
| 451 |
+
|
| 452 |
+
IndicesType m_indices;
|
| 453 |
+
};
|
| 454 |
+
|
| 455 |
+
template<typename _IndicesType> class TranspositionsWrapper;
|
| 456 |
+
namespace internal {
|
| 457 |
+
template<typename _IndicesType>
|
| 458 |
+
struct traits<PermutationWrapper<_IndicesType> >
|
| 459 |
+
{
|
| 460 |
+
typedef PermutationStorage StorageKind;
|
| 461 |
+
typedef void Scalar;
|
| 462 |
+
typedef typename _IndicesType::Scalar StorageIndex;
|
| 463 |
+
typedef _IndicesType IndicesType;
|
| 464 |
+
enum {
|
| 465 |
+
RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
|
| 466 |
+
ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
|
| 467 |
+
MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
|
| 468 |
+
MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
|
| 469 |
+
Flags = 0
|
| 470 |
+
};
|
| 471 |
+
};
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
/** \class PermutationWrapper
|
| 475 |
+
* \ingroup Core_Module
|
| 476 |
+
*
|
| 477 |
+
* \brief Class to view a vector of integers as a permutation matrix
|
| 478 |
+
*
|
| 479 |
+
* \tparam _IndicesType the type of the vector of integer (can be any compatible expression)
|
| 480 |
+
*
|
| 481 |
+
* This class allows to view any vector expression of integers as a permutation matrix.
|
| 482 |
+
*
|
| 483 |
+
* \sa class PermutationBase, class PermutationMatrix
|
| 484 |
+
*/
|
| 485 |
+
template<typename _IndicesType>
|
| 486 |
+
class PermutationWrapper : public PermutationBase<PermutationWrapper<_IndicesType> >
|
| 487 |
+
{
|
| 488 |
+
typedef PermutationBase<PermutationWrapper> Base;
|
| 489 |
+
typedef internal::traits<PermutationWrapper> Traits;
|
| 490 |
+
public:
|
| 491 |
+
|
| 492 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 493 |
+
typedef typename Traits::IndicesType IndicesType;
|
| 494 |
+
#endif
|
| 495 |
+
|
| 496 |
+
inline PermutationWrapper(const IndicesType& indices)
|
| 497 |
+
: m_indices(indices)
|
| 498 |
+
{}
|
| 499 |
+
|
| 500 |
+
/** const version of indices(). */
|
| 501 |
+
const typename internal::remove_all<typename IndicesType::Nested>::type&
|
| 502 |
+
indices() const { return m_indices; }
|
| 503 |
+
|
| 504 |
+
protected:
|
| 505 |
+
|
| 506 |
+
typename IndicesType::Nested m_indices;
|
| 507 |
+
};
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
/** \returns the matrix with the permutation applied to the columns.
|
| 511 |
+
*/
|
| 512 |
+
template<typename MatrixDerived, typename PermutationDerived>
|
| 513 |
+
EIGEN_DEVICE_FUNC
|
| 514 |
+
const Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
|
| 515 |
+
operator*(const MatrixBase<MatrixDerived> &matrix,
|
| 516 |
+
const PermutationBase<PermutationDerived>& permutation)
|
| 517 |
+
{
|
| 518 |
+
return Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
|
| 519 |
+
(matrix.derived(), permutation.derived());
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
/** \returns the matrix with the permutation applied to the rows.
|
| 523 |
+
*/
|
| 524 |
+
template<typename PermutationDerived, typename MatrixDerived>
|
| 525 |
+
EIGEN_DEVICE_FUNC
|
| 526 |
+
const Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
|
| 527 |
+
operator*(const PermutationBase<PermutationDerived> &permutation,
|
| 528 |
+
const MatrixBase<MatrixDerived>& matrix)
|
| 529 |
+
{
|
| 530 |
+
return Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
|
| 531 |
+
(permutation.derived(), matrix.derived());
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
template<typename PermutationType>
|
| 536 |
+
class InverseImpl<PermutationType, PermutationStorage>
|
| 537 |
+
: public EigenBase<Inverse<PermutationType> >
|
| 538 |
+
{
|
| 539 |
+
typedef typename PermutationType::PlainPermutationType PlainPermutationType;
|
| 540 |
+
typedef internal::traits<PermutationType> PermTraits;
|
| 541 |
+
protected:
|
| 542 |
+
InverseImpl() {}
|
| 543 |
+
public:
|
| 544 |
+
typedef Inverse<PermutationType> InverseType;
|
| 545 |
+
using EigenBase<Inverse<PermutationType> >::derived;
|
| 546 |
+
|
| 547 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 548 |
+
typedef typename PermutationType::DenseMatrixType DenseMatrixType;
|
| 549 |
+
enum {
|
| 550 |
+
RowsAtCompileTime = PermTraits::RowsAtCompileTime,
|
| 551 |
+
ColsAtCompileTime = PermTraits::ColsAtCompileTime,
|
| 552 |
+
MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
|
| 553 |
+
MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
|
| 554 |
+
};
|
| 555 |
+
#endif
|
| 556 |
+
|
| 557 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 558 |
+
template<typename DenseDerived>
|
| 559 |
+
void evalTo(MatrixBase<DenseDerived>& other) const
|
| 560 |
+
{
|
| 561 |
+
other.setZero();
|
| 562 |
+
for (Index i=0; i<derived().rows();++i)
|
| 563 |
+
other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) = typename DenseDerived::Scalar(1);
|
| 564 |
+
}
|
| 565 |
+
#endif
|
| 566 |
+
|
| 567 |
+
/** \return the equivalent permutation matrix */
|
| 568 |
+
PlainPermutationType eval() const { return derived(); }
|
| 569 |
+
|
| 570 |
+
DenseMatrixType toDenseMatrix() const { return derived(); }
|
| 571 |
+
|
| 572 |
+
/** \returns the matrix with the inverse permutation applied to the columns.
|
| 573 |
+
*/
|
| 574 |
+
template<typename OtherDerived> friend
|
| 575 |
+
const Product<OtherDerived, InverseType, AliasFreeProduct>
|
| 576 |
+
operator*(const MatrixBase<OtherDerived>& matrix, const InverseType& trPerm)
|
| 577 |
+
{
|
| 578 |
+
return Product<OtherDerived, InverseType, AliasFreeProduct>(matrix.derived(), trPerm.derived());
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
/** \returns the matrix with the inverse permutation applied to the rows.
|
| 582 |
+
*/
|
| 583 |
+
template<typename OtherDerived>
|
| 584 |
+
const Product<InverseType, OtherDerived, AliasFreeProduct>
|
| 585 |
+
operator*(const MatrixBase<OtherDerived>& matrix) const
|
| 586 |
+
{
|
| 587 |
+
return Product<InverseType, OtherDerived, AliasFreeProduct>(derived(), matrix.derived());
|
| 588 |
+
}
|
| 589 |
+
};
|
| 590 |
+
|
| 591 |
+
template<typename Derived>
|
| 592 |
+
const PermutationWrapper<const Derived> MatrixBase<Derived>::asPermutation() const
|
| 593 |
+
{
|
| 594 |
+
return derived();
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
namespace internal {
|
| 598 |
+
|
| 599 |
+
template<> struct AssignmentKind<DenseShape,PermutationShape> { typedef EigenBase2EigenBase Kind; };
|
| 600 |
+
|
| 601 |
+
} // end namespace internal
|
| 602 |
+
|
| 603 |
+
} // end namespace Eigen
|
| 604 |
+
|
| 605 |
+
#endif // EIGEN_PERMUTATIONMATRIX_H
|
include/eigen/Eigen/src/Core/PlainObjectBase.h
ADDED
|
@@ -0,0 +1,1128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_DENSESTORAGEBASE_H
|
| 12 |
+
#define EIGEN_DENSESTORAGEBASE_H
|
| 13 |
+
|
| 14 |
+
#if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO)
|
| 15 |
+
# define EIGEN_INITIALIZE_COEFFS
|
| 16 |
+
# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(Index i=0;i<base().size();++i) coeffRef(i)=Scalar(0);
|
| 17 |
+
#elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN)
|
| 18 |
+
# define EIGEN_INITIALIZE_COEFFS
|
| 19 |
+
# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(Index i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN();
|
| 20 |
+
#else
|
| 21 |
+
# undef EIGEN_INITIALIZE_COEFFS
|
| 22 |
+
# define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
namespace Eigen {
|
| 26 |
+
|
| 27 |
+
namespace internal {
|
| 28 |
+
|
| 29 |
+
template<int MaxSizeAtCompileTime> struct check_rows_cols_for_overflow {
|
| 30 |
+
template<typename Index>
|
| 31 |
+
EIGEN_DEVICE_FUNC
|
| 32 |
+
static EIGEN_ALWAYS_INLINE void run(Index, Index)
|
| 33 |
+
{
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
template<> struct check_rows_cols_for_overflow<Dynamic> {
|
| 38 |
+
template<typename Index>
|
| 39 |
+
EIGEN_DEVICE_FUNC
|
| 40 |
+
static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols)
|
| 41 |
+
{
|
| 42 |
+
// http://hg.mozilla.org/mozilla-central/file/6c8a909977d3/xpcom/ds/CheckedInt.h#l242
|
| 43 |
+
// we assume Index is signed
|
| 44 |
+
Index max_index = (std::size_t(1) << (8 * sizeof(Index) - 1)) - 1; // assume Index is signed
|
| 45 |
+
bool error = (rows == 0 || cols == 0) ? false
|
| 46 |
+
: (rows > max_index / cols);
|
| 47 |
+
if (error)
|
| 48 |
+
throw_std_bad_alloc();
|
| 49 |
+
}
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
template <typename Derived,
|
| 53 |
+
typename OtherDerived = Derived,
|
| 54 |
+
bool IsVector = bool(Derived::IsVectorAtCompileTime) && bool(OtherDerived::IsVectorAtCompileTime)>
|
| 55 |
+
struct conservative_resize_like_impl;
|
| 56 |
+
|
| 57 |
+
template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct matrix_swap_impl;
|
| 58 |
+
|
| 59 |
+
} // end namespace internal
|
| 60 |
+
|
| 61 |
+
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
| 62 |
+
namespace doxygen {
|
| 63 |
+
|
| 64 |
+
// This is a workaround to doxygen not being able to understand the inheritance logic
|
| 65 |
+
// when it is hidden by the dense_xpr_base helper struct.
|
| 66 |
+
// Moreover, doxygen fails to include members that are not documented in the declaration body of
|
| 67 |
+
// MatrixBase if we inherits MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >,
|
| 68 |
+
// this is why we simply inherits MatrixBase, though this does not make sense.
|
| 69 |
+
|
| 70 |
+
/** This class is just a workaround for Doxygen and it does not not actually exist. */
|
| 71 |
+
template<typename Derived> struct dense_xpr_base_dispatcher;
|
| 72 |
+
/** This class is just a workaround for Doxygen and it does not not actually exist. */
|
| 73 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
| 74 |
+
struct dense_xpr_base_dispatcher<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
| 75 |
+
: public MatrixBase {};
|
| 76 |
+
/** This class is just a workaround for Doxygen and it does not not actually exist. */
|
| 77 |
+
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
| 78 |
+
struct dense_xpr_base_dispatcher<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
|
| 79 |
+
: public ArrayBase {};
|
| 80 |
+
|
| 81 |
+
} // namespace doxygen
|
| 82 |
+
|
| 83 |
+
/** \class PlainObjectBase
|
| 84 |
+
* \ingroup Core_Module
|
| 85 |
+
* \brief %Dense storage base class for matrices and arrays.
|
| 86 |
+
*
|
| 87 |
+
* This class can be extended with the help of the plugin mechanism described on the page
|
| 88 |
+
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_PLAINOBJECTBASE_PLUGIN.
|
| 89 |
+
*
|
| 90 |
+
* \tparam Derived is the derived type, e.g., a Matrix or Array
|
| 91 |
+
*
|
| 92 |
+
* \sa \ref TopicClassHierarchy
|
| 93 |
+
*/
|
| 94 |
+
template<typename Derived>
|
| 95 |
+
class PlainObjectBase : public doxygen::dense_xpr_base_dispatcher<Derived>
|
| 96 |
+
#else
|
| 97 |
+
template<typename Derived>
|
| 98 |
+
class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
|
| 99 |
+
#endif
|
| 100 |
+
{
|
| 101 |
+
public:
|
| 102 |
+
enum { Options = internal::traits<Derived>::Options };
|
| 103 |
+
typedef typename internal::dense_xpr_base<Derived>::type Base;
|
| 104 |
+
|
| 105 |
+
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
| 106 |
+
typedef typename internal::traits<Derived>::Scalar Scalar;
|
| 107 |
+
|
| 108 |
+
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
|
| 109 |
+
typedef typename NumTraits<Scalar>::Real RealScalar;
|
| 110 |
+
typedef Derived DenseType;
|
| 111 |
+
|
| 112 |
+
using Base::RowsAtCompileTime;
|
| 113 |
+
using Base::ColsAtCompileTime;
|
| 114 |
+
using Base::SizeAtCompileTime;
|
| 115 |
+
using Base::MaxRowsAtCompileTime;
|
| 116 |
+
using Base::MaxColsAtCompileTime;
|
| 117 |
+
using Base::MaxSizeAtCompileTime;
|
| 118 |
+
using Base::IsVectorAtCompileTime;
|
| 119 |
+
using Base::Flags;
|
| 120 |
+
|
| 121 |
+
typedef Eigen::Map<Derived, Unaligned> MapType;
|
| 122 |
+
typedef const Eigen::Map<const Derived, Unaligned> ConstMapType;
|
| 123 |
+
typedef Eigen::Map<Derived, AlignedMax> AlignedMapType;
|
| 124 |
+
typedef const Eigen::Map<const Derived, AlignedMax> ConstAlignedMapType;
|
| 125 |
+
template<typename StrideType> struct StridedMapType { typedef Eigen::Map<Derived, Unaligned, StrideType> type; };
|
| 126 |
+
template<typename StrideType> struct StridedConstMapType { typedef Eigen::Map<const Derived, Unaligned, StrideType> type; };
|
| 127 |
+
template<typename StrideType> struct StridedAlignedMapType { typedef Eigen::Map<Derived, AlignedMax, StrideType> type; };
|
| 128 |
+
template<typename StrideType> struct StridedConstAlignedMapType { typedef Eigen::Map<const Derived, AlignedMax, StrideType> type; };
|
| 129 |
+
|
| 130 |
+
protected:
|
| 131 |
+
DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage;
|
| 132 |
+
|
| 133 |
+
public:
|
| 134 |
+
enum { NeedsToAlign = (SizeAtCompileTime != Dynamic) && (internal::traits<Derived>::Alignment>0) };
|
| 135 |
+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
|
| 136 |
+
|
| 137 |
+
EIGEN_DEVICE_FUNC
|
| 138 |
+
Base& base() { return *static_cast<Base*>(this); }
|
| 139 |
+
EIGEN_DEVICE_FUNC
|
| 140 |
+
const Base& base() const { return *static_cast<const Base*>(this); }
|
| 141 |
+
|
| 142 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 143 |
+
Index rows() const EIGEN_NOEXCEPT { return m_storage.rows(); }
|
| 144 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 145 |
+
Index cols() const EIGEN_NOEXCEPT { return m_storage.cols(); }
|
| 146 |
+
|
| 147 |
+
/** This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,Index) const
|
| 148 |
+
* provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
|
| 149 |
+
*
|
| 150 |
+
* See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details. */
|
| 151 |
+
EIGEN_DEVICE_FUNC
|
| 152 |
+
EIGEN_STRONG_INLINE const Scalar& coeff(Index rowId, Index colId) const
|
| 153 |
+
{
|
| 154 |
+
if(Flags & RowMajorBit)
|
| 155 |
+
return m_storage.data()[colId + rowId * m_storage.cols()];
|
| 156 |
+
else // column-major
|
| 157 |
+
return m_storage.data()[rowId + colId * m_storage.rows()];
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/** This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const
|
| 161 |
+
* provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
|
| 162 |
+
*
|
| 163 |
+
* See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details. */
|
| 164 |
+
EIGEN_DEVICE_FUNC
|
| 165 |
+
EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const
|
| 166 |
+
{
|
| 167 |
+
return m_storage.data()[index];
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/** This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const
|
| 171 |
+
* provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
|
| 172 |
+
*
|
| 173 |
+
* See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const for details. */
|
| 174 |
+
EIGEN_DEVICE_FUNC
|
| 175 |
+
EIGEN_STRONG_INLINE Scalar& coeffRef(Index rowId, Index colId)
|
| 176 |
+
{
|
| 177 |
+
if(Flags & RowMajorBit)
|
| 178 |
+
return m_storage.data()[colId + rowId * m_storage.cols()];
|
| 179 |
+
else // column-major
|
| 180 |
+
return m_storage.data()[rowId + colId * m_storage.rows()];
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/** This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const
|
| 184 |
+
* provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.
|
| 185 |
+
*
|
| 186 |
+
* See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const for details. */
|
| 187 |
+
EIGEN_DEVICE_FUNC
|
| 188 |
+
EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
|
| 189 |
+
{
|
| 190 |
+
return m_storage.data()[index];
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
/** This is the const version of coeffRef(Index,Index) which is thus synonym of coeff(Index,Index).
|
| 194 |
+
* It is provided for convenience. */
|
| 195 |
+
EIGEN_DEVICE_FUNC
|
| 196 |
+
EIGEN_STRONG_INLINE const Scalar& coeffRef(Index rowId, Index colId) const
|
| 197 |
+
{
|
| 198 |
+
if(Flags & RowMajorBit)
|
| 199 |
+
return m_storage.data()[colId + rowId * m_storage.cols()];
|
| 200 |
+
else // column-major
|
| 201 |
+
return m_storage.data()[rowId + colId * m_storage.rows()];
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/** This is the const version of coeffRef(Index) which is thus synonym of coeff(Index).
|
| 205 |
+
* It is provided for convenience. */
|
| 206 |
+
EIGEN_DEVICE_FUNC
|
| 207 |
+
EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const
|
| 208 |
+
{
|
| 209 |
+
return m_storage.data()[index];
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
/** \internal */
|
| 213 |
+
template<int LoadMode>
|
| 214 |
+
EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const
|
| 215 |
+
{
|
| 216 |
+
return internal::ploadt<PacketScalar, LoadMode>
|
| 217 |
+
(m_storage.data() + (Flags & RowMajorBit
|
| 218 |
+
? colId + rowId * m_storage.cols()
|
| 219 |
+
: rowId + colId * m_storage.rows()));
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/** \internal */
|
| 223 |
+
template<int LoadMode>
|
| 224 |
+
EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
|
| 225 |
+
{
|
| 226 |
+
return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/** \internal */
|
| 230 |
+
template<int StoreMode>
|
| 231 |
+
EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar& val)
|
| 232 |
+
{
|
| 233 |
+
internal::pstoret<Scalar, PacketScalar, StoreMode>
|
| 234 |
+
(m_storage.data() + (Flags & RowMajorBit
|
| 235 |
+
? colId + rowId * m_storage.cols()
|
| 236 |
+
: rowId + colId * m_storage.rows()), val);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/** \internal */
|
| 240 |
+
template<int StoreMode>
|
| 241 |
+
EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar& val)
|
| 242 |
+
{
|
| 243 |
+
internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/** \returns a const pointer to the data array of this matrix */
|
| 247 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar *data() const
|
| 248 |
+
{ return m_storage.data(); }
|
| 249 |
+
|
| 250 |
+
/** \returns a pointer to the data array of this matrix */
|
| 251 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *data()
|
| 252 |
+
{ return m_storage.data(); }
|
| 253 |
+
|
| 254 |
+
/** Resizes \c *this to a \a rows x \a cols matrix.
|
| 255 |
+
*
|
| 256 |
+
* This method is intended for dynamic-size matrices, although it is legal to call it on any
|
| 257 |
+
* matrix as long as fixed dimensions are left unchanged. If you only want to change the number
|
| 258 |
+
* of rows and/or of columns, you can use resize(NoChange_t, Index), resize(Index, NoChange_t).
|
| 259 |
+
*
|
| 260 |
+
* If the current number of coefficients of \c *this exactly matches the
|
| 261 |
+
* product \a rows * \a cols, then no memory allocation is performed and
|
| 262 |
+
* the current values are left unchanged. In all other cases, including
|
| 263 |
+
* shrinking, the data is reallocated and all previous values are lost.
|
| 264 |
+
*
|
| 265 |
+
* Example: \include Matrix_resize_int_int.cpp
|
| 266 |
+
* Output: \verbinclude Matrix_resize_int_int.out
|
| 267 |
+
*
|
| 268 |
+
* \sa resize(Index) for vectors, resize(NoChange_t, Index), resize(Index, NoChange_t)
|
| 269 |
+
*/
|
| 270 |
+
EIGEN_DEVICE_FUNC
|
| 271 |
+
EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
|
| 272 |
+
{
|
| 273 |
+
eigen_assert( EIGEN_IMPLIES(RowsAtCompileTime!=Dynamic,rows==RowsAtCompileTime)
|
| 274 |
+
&& EIGEN_IMPLIES(ColsAtCompileTime!=Dynamic,cols==ColsAtCompileTime)
|
| 275 |
+
&& EIGEN_IMPLIES(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic,rows<=MaxRowsAtCompileTime)
|
| 276 |
+
&& EIGEN_IMPLIES(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic,cols<=MaxColsAtCompileTime)
|
| 277 |
+
&& rows>=0 && cols>=0 && "Invalid sizes when resizing a matrix or array.");
|
| 278 |
+
internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(rows, cols);
|
| 279 |
+
#ifdef EIGEN_INITIALIZE_COEFFS
|
| 280 |
+
Index size = rows*cols;
|
| 281 |
+
bool size_changed = size != this->size();
|
| 282 |
+
m_storage.resize(size, rows, cols);
|
| 283 |
+
if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 284 |
+
#else
|
| 285 |
+
m_storage.resize(rows*cols, rows, cols);
|
| 286 |
+
#endif
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
/** Resizes \c *this to a vector of length \a size
|
| 290 |
+
*
|
| 291 |
+
* \only_for_vectors. This method does not work for
|
| 292 |
+
* partially dynamic matrices when the static dimension is anything other
|
| 293 |
+
* than 1. For example it will not work with Matrix<double, 2, Dynamic>.
|
| 294 |
+
*
|
| 295 |
+
* Example: \include Matrix_resize_int.cpp
|
| 296 |
+
* Output: \verbinclude Matrix_resize_int.out
|
| 297 |
+
*
|
| 298 |
+
* \sa resize(Index,Index), resize(NoChange_t, Index), resize(Index, NoChange_t)
|
| 299 |
+
*/
|
| 300 |
+
EIGEN_DEVICE_FUNC
|
| 301 |
+
inline void resize(Index size)
|
| 302 |
+
{
|
| 303 |
+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase)
|
| 304 |
+
eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0);
|
| 305 |
+
#ifdef EIGEN_INITIALIZE_COEFFS
|
| 306 |
+
bool size_changed = size != this->size();
|
| 307 |
+
#endif
|
| 308 |
+
if(RowsAtCompileTime == 1)
|
| 309 |
+
m_storage.resize(size, 1, size);
|
| 310 |
+
else
|
| 311 |
+
m_storage.resize(size, size, 1);
|
| 312 |
+
#ifdef EIGEN_INITIALIZE_COEFFS
|
| 313 |
+
if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 314 |
+
#endif
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
/** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange
|
| 318 |
+
* as in the example below.
|
| 319 |
+
*
|
| 320 |
+
* Example: \include Matrix_resize_NoChange_int.cpp
|
| 321 |
+
* Output: \verbinclude Matrix_resize_NoChange_int.out
|
| 322 |
+
*
|
| 323 |
+
* \sa resize(Index,Index)
|
| 324 |
+
*/
|
| 325 |
+
EIGEN_DEVICE_FUNC
|
| 326 |
+
inline void resize(NoChange_t, Index cols)
|
| 327 |
+
{
|
| 328 |
+
resize(rows(), cols);
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
/** Resizes the matrix, changing only the number of rows. For the parameter of type NoChange_t, just pass the special value \c NoChange
|
| 332 |
+
* as in the example below.
|
| 333 |
+
*
|
| 334 |
+
* Example: \include Matrix_resize_int_NoChange.cpp
|
| 335 |
+
* Output: \verbinclude Matrix_resize_int_NoChange.out
|
| 336 |
+
*
|
| 337 |
+
* \sa resize(Index,Index)
|
| 338 |
+
*/
|
| 339 |
+
EIGEN_DEVICE_FUNC
|
| 340 |
+
inline void resize(Index rows, NoChange_t)
|
| 341 |
+
{
|
| 342 |
+
resize(rows, cols());
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
/** Resizes \c *this to have the same dimensions as \a other.
|
| 346 |
+
* Takes care of doing all the checking that's needed.
|
| 347 |
+
*
|
| 348 |
+
* Note that copying a row-vector into a vector (and conversely) is allowed.
|
| 349 |
+
* The resizing, if any, is then done in the appropriate way so that row-vectors
|
| 350 |
+
* remain row-vectors and vectors remain vectors.
|
| 351 |
+
*/
|
| 352 |
+
template<typename OtherDerived>
|
| 353 |
+
EIGEN_DEVICE_FUNC
|
| 354 |
+
EIGEN_STRONG_INLINE void resizeLike(const EigenBase<OtherDerived>& _other)
|
| 355 |
+
{
|
| 356 |
+
const OtherDerived& other = _other.derived();
|
| 357 |
+
internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.rows(), other.cols());
|
| 358 |
+
const Index othersize = other.rows()*other.cols();
|
| 359 |
+
if(RowsAtCompileTime == 1)
|
| 360 |
+
{
|
| 361 |
+
eigen_assert(other.rows() == 1 || other.cols() == 1);
|
| 362 |
+
resize(1, othersize);
|
| 363 |
+
}
|
| 364 |
+
else if(ColsAtCompileTime == 1)
|
| 365 |
+
{
|
| 366 |
+
eigen_assert(other.rows() == 1 || other.cols() == 1);
|
| 367 |
+
resize(othersize, 1);
|
| 368 |
+
}
|
| 369 |
+
else resize(other.rows(), other.cols());
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
/** Resizes the matrix to \a rows x \a cols while leaving old values untouched.
|
| 373 |
+
*
|
| 374 |
+
* The method is intended for matrices of dynamic size. If you only want to change the number
|
| 375 |
+
* of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or
|
| 376 |
+
* conservativeResize(Index, NoChange_t).
|
| 377 |
+
*
|
| 378 |
+
* Matrices are resized relative to the top-left element. In case values need to be
|
| 379 |
+
* appended to the matrix they will be uninitialized.
|
| 380 |
+
*/
|
| 381 |
+
EIGEN_DEVICE_FUNC
|
| 382 |
+
EIGEN_STRONG_INLINE void conservativeResize(Index rows, Index cols)
|
| 383 |
+
{
|
| 384 |
+
internal::conservative_resize_like_impl<Derived>::run(*this, rows, cols);
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
/** Resizes the matrix to \a rows x \a cols while leaving old values untouched.
|
| 388 |
+
*
|
| 389 |
+
* As opposed to conservativeResize(Index rows, Index cols), this version leaves
|
| 390 |
+
* the number of columns unchanged.
|
| 391 |
+
*
|
| 392 |
+
* In case the matrix is growing, new rows will be uninitialized.
|
| 393 |
+
*/
|
| 394 |
+
EIGEN_DEVICE_FUNC
|
| 395 |
+
EIGEN_STRONG_INLINE void conservativeResize(Index rows, NoChange_t)
|
| 396 |
+
{
|
| 397 |
+
// Note: see the comment in conservativeResize(Index,Index)
|
| 398 |
+
conservativeResize(rows, cols());
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
/** Resizes the matrix to \a rows x \a cols while leaving old values untouched.
|
| 402 |
+
*
|
| 403 |
+
* As opposed to conservativeResize(Index rows, Index cols), this version leaves
|
| 404 |
+
* the number of rows unchanged.
|
| 405 |
+
*
|
| 406 |
+
* In case the matrix is growing, new columns will be uninitialized.
|
| 407 |
+
*/
|
| 408 |
+
EIGEN_DEVICE_FUNC
|
| 409 |
+
EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index cols)
|
| 410 |
+
{
|
| 411 |
+
// Note: see the comment in conservativeResize(Index,Index)
|
| 412 |
+
conservativeResize(rows(), cols);
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/** Resizes the vector to \a size while retaining old values.
|
| 416 |
+
*
|
| 417 |
+
* \only_for_vectors. This method does not work for
|
| 418 |
+
* partially dynamic matrices when the static dimension is anything other
|
| 419 |
+
* than 1. For example it will not work with Matrix<double, 2, Dynamic>.
|
| 420 |
+
*
|
| 421 |
+
* When values are appended, they will be uninitialized.
|
| 422 |
+
*/
|
| 423 |
+
EIGEN_DEVICE_FUNC
|
| 424 |
+
EIGEN_STRONG_INLINE void conservativeResize(Index size)
|
| 425 |
+
{
|
| 426 |
+
internal::conservative_resize_like_impl<Derived>::run(*this, size);
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
/** Resizes the matrix to \a rows x \a cols of \c other, while leaving old values untouched.
|
| 430 |
+
*
|
| 431 |
+
* The method is intended for matrices of dynamic size. If you only want to change the number
|
| 432 |
+
* of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or
|
| 433 |
+
* conservativeResize(Index, NoChange_t).
|
| 434 |
+
*
|
| 435 |
+
* Matrices are resized relative to the top-left element. In case values need to be
|
| 436 |
+
* appended to the matrix they will copied from \c other.
|
| 437 |
+
*/
|
| 438 |
+
template<typename OtherDerived>
|
| 439 |
+
EIGEN_DEVICE_FUNC
|
| 440 |
+
EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase<OtherDerived>& other)
|
| 441 |
+
{
|
| 442 |
+
internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*this, other);
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
/** This is a special case of the templated operator=. Its purpose is to
|
| 446 |
+
* prevent a default operator= from hiding the templated operator=.
|
| 447 |
+
*/
|
| 448 |
+
EIGEN_DEVICE_FUNC
|
| 449 |
+
EIGEN_STRONG_INLINE Derived& operator=(const PlainObjectBase& other)
|
| 450 |
+
{
|
| 451 |
+
return _set(other);
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
/** \sa MatrixBase::lazyAssign() */
|
| 455 |
+
template<typename OtherDerived>
|
| 456 |
+
EIGEN_DEVICE_FUNC
|
| 457 |
+
EIGEN_STRONG_INLINE Derived& lazyAssign(const DenseBase<OtherDerived>& other)
|
| 458 |
+
{
|
| 459 |
+
_resize_to_match(other);
|
| 460 |
+
return Base::lazyAssign(other.derived());
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
template<typename OtherDerived>
|
| 464 |
+
EIGEN_DEVICE_FUNC
|
| 465 |
+
EIGEN_STRONG_INLINE Derived& operator=(const ReturnByValue<OtherDerived>& func)
|
| 466 |
+
{
|
| 467 |
+
resize(func.rows(), func.cols());
|
| 468 |
+
return Base::operator=(func);
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
// Prevent user from trying to instantiate PlainObjectBase objects
|
| 472 |
+
// by making all its constructor protected. See bug 1074.
|
| 473 |
+
protected:
|
| 474 |
+
|
| 475 |
+
EIGEN_DEVICE_FUNC
|
| 476 |
+
EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
|
| 477 |
+
{
|
| 478 |
+
// _check_template_params();
|
| 479 |
+
// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 483 |
+
// FIXME is it still needed ?
|
| 484 |
+
/** \internal */
|
| 485 |
+
EIGEN_DEVICE_FUNC
|
| 486 |
+
explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert)
|
| 487 |
+
: m_storage(internal::constructor_without_unaligned_array_assert())
|
| 488 |
+
{
|
| 489 |
+
// _check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 490 |
+
}
|
| 491 |
+
#endif
|
| 492 |
+
|
| 493 |
+
#if EIGEN_HAS_RVALUE_REFERENCES
|
| 494 |
+
EIGEN_DEVICE_FUNC
|
| 495 |
+
PlainObjectBase(PlainObjectBase&& other) EIGEN_NOEXCEPT
|
| 496 |
+
: m_storage( std::move(other.m_storage) )
|
| 497 |
+
{
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
EIGEN_DEVICE_FUNC
|
| 501 |
+
PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT
|
| 502 |
+
{
|
| 503 |
+
_check_template_params();
|
| 504 |
+
m_storage = std::move(other.m_storage);
|
| 505 |
+
return *this;
|
| 506 |
+
}
|
| 507 |
+
#endif
|
| 508 |
+
|
| 509 |
+
/** Copy constructor */
|
| 510 |
+
EIGEN_DEVICE_FUNC
|
| 511 |
+
EIGEN_STRONG_INLINE PlainObjectBase(const PlainObjectBase& other)
|
| 512 |
+
: Base(), m_storage(other.m_storage) { }
|
| 513 |
+
EIGEN_DEVICE_FUNC
|
| 514 |
+
EIGEN_STRONG_INLINE PlainObjectBase(Index size, Index rows, Index cols)
|
| 515 |
+
: m_storage(size, rows, cols)
|
| 516 |
+
{
|
| 517 |
+
// _check_template_params();
|
| 518 |
+
// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
#if EIGEN_HAS_CXX11
|
| 522 |
+
/** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. \cpp11
|
| 523 |
+
*
|
| 524 |
+
* \only_for_vectors
|
| 525 |
+
*
|
| 526 |
+
* This constructor is for 1D array or vectors with more than 4 coefficients.
|
| 527 |
+
* There exists C++98 analogue constructors for fixed-size array/vector having 1, 2, 3, or 4 coefficients.
|
| 528 |
+
*
|
| 529 |
+
* \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this
|
| 530 |
+
* constructor must match the the fixed number of rows (resp. columns) of \c *this.
|
| 531 |
+
*/
|
| 532 |
+
template <typename... ArgTypes>
|
| 533 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 534 |
+
PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
|
| 535 |
+
: m_storage()
|
| 536 |
+
{
|
| 537 |
+
_check_template_params();
|
| 538 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, sizeof...(args) + 4);
|
| 539 |
+
m_storage.data()[0] = a0;
|
| 540 |
+
m_storage.data()[1] = a1;
|
| 541 |
+
m_storage.data()[2] = a2;
|
| 542 |
+
m_storage.data()[3] = a3;
|
| 543 |
+
Index i = 4;
|
| 544 |
+
auto x = {(m_storage.data()[i++] = args, 0)...};
|
| 545 |
+
static_cast<void>(x);
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
/** \brief Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer
|
| 549 |
+
* lists \cpp11
|
| 550 |
+
*/
|
| 551 |
+
EIGEN_DEVICE_FUNC
|
| 552 |
+
explicit EIGEN_STRONG_INLINE PlainObjectBase(const std::initializer_list<std::initializer_list<Scalar>>& list)
|
| 553 |
+
: m_storage()
|
| 554 |
+
{
|
| 555 |
+
_check_template_params();
|
| 556 |
+
|
| 557 |
+
size_t list_size = 0;
|
| 558 |
+
if (list.begin() != list.end()) {
|
| 559 |
+
list_size = list.begin()->size();
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
// This is to allow syntax like VectorXi {{1, 2, 3, 4}}
|
| 563 |
+
if (ColsAtCompileTime == 1 && list.size() == 1) {
|
| 564 |
+
eigen_assert(list_size == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
|
| 565 |
+
resize(list_size, ColsAtCompileTime);
|
| 566 |
+
std::copy(list.begin()->begin(), list.begin()->end(), m_storage.data());
|
| 567 |
+
} else {
|
| 568 |
+
eigen_assert(list.size() == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
|
| 569 |
+
eigen_assert(list_size == static_cast<size_t>(ColsAtCompileTime) || ColsAtCompileTime == Dynamic);
|
| 570 |
+
resize(list.size(), list_size);
|
| 571 |
+
|
| 572 |
+
Index row_index = 0;
|
| 573 |
+
for (const std::initializer_list<Scalar>& row : list) {
|
| 574 |
+
eigen_assert(list_size == row.size());
|
| 575 |
+
Index col_index = 0;
|
| 576 |
+
for (const Scalar& e : row) {
|
| 577 |
+
coeffRef(row_index, col_index) = e;
|
| 578 |
+
++col_index;
|
| 579 |
+
}
|
| 580 |
+
++row_index;
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
}
|
| 584 |
+
#endif // end EIGEN_HAS_CXX11
|
| 585 |
+
|
| 586 |
+
/** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */
|
| 587 |
+
template<typename OtherDerived>
|
| 588 |
+
EIGEN_DEVICE_FUNC
|
| 589 |
+
EIGEN_STRONG_INLINE PlainObjectBase(const DenseBase<OtherDerived> &other)
|
| 590 |
+
: m_storage()
|
| 591 |
+
{
|
| 592 |
+
_check_template_params();
|
| 593 |
+
resizeLike(other);
|
| 594 |
+
_set_noalias(other);
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
/** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */
|
| 598 |
+
template<typename OtherDerived>
|
| 599 |
+
EIGEN_DEVICE_FUNC
|
| 600 |
+
EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase<OtherDerived> &other)
|
| 601 |
+
: m_storage()
|
| 602 |
+
{
|
| 603 |
+
_check_template_params();
|
| 604 |
+
resizeLike(other);
|
| 605 |
+
*this = other.derived();
|
| 606 |
+
}
|
| 607 |
+
/** \brief Copy constructor with in-place evaluation */
|
| 608 |
+
template<typename OtherDerived>
|
| 609 |
+
EIGEN_DEVICE_FUNC
|
| 610 |
+
EIGEN_STRONG_INLINE PlainObjectBase(const ReturnByValue<OtherDerived>& other)
|
| 611 |
+
{
|
| 612 |
+
_check_template_params();
|
| 613 |
+
// FIXME this does not automatically transpose vectors if necessary
|
| 614 |
+
resize(other.rows(), other.cols());
|
| 615 |
+
other.evalTo(this->derived());
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
public:
|
| 619 |
+
|
| 620 |
+
/** \brief Copies the generic expression \a other into *this.
|
| 621 |
+
* \copydetails DenseBase::operator=(const EigenBase<OtherDerived> &other)
|
| 622 |
+
*/
|
| 623 |
+
template<typename OtherDerived>
|
| 624 |
+
EIGEN_DEVICE_FUNC
|
| 625 |
+
EIGEN_STRONG_INLINE Derived& operator=(const EigenBase<OtherDerived> &other)
|
| 626 |
+
{
|
| 627 |
+
_resize_to_match(other);
|
| 628 |
+
Base::operator=(other.derived());
|
| 629 |
+
return this->derived();
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
/** \name Map
|
| 633 |
+
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
|
| 634 |
+
* while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned
|
| 635 |
+
* \a data pointers.
|
| 636 |
+
*
|
| 637 |
+
* Here is an example using strides:
|
| 638 |
+
* \include Matrix_Map_stride.cpp
|
| 639 |
+
* Output: \verbinclude Matrix_Map_stride.out
|
| 640 |
+
*
|
| 641 |
+
* \see class Map
|
| 642 |
+
*/
|
| 643 |
+
//@{
|
| 644 |
+
static inline ConstMapType Map(const Scalar* data)
|
| 645 |
+
{ return ConstMapType(data); }
|
| 646 |
+
static inline MapType Map(Scalar* data)
|
| 647 |
+
{ return MapType(data); }
|
| 648 |
+
static inline ConstMapType Map(const Scalar* data, Index size)
|
| 649 |
+
{ return ConstMapType(data, size); }
|
| 650 |
+
static inline MapType Map(Scalar* data, Index size)
|
| 651 |
+
{ return MapType(data, size); }
|
| 652 |
+
static inline ConstMapType Map(const Scalar* data, Index rows, Index cols)
|
| 653 |
+
{ return ConstMapType(data, rows, cols); }
|
| 654 |
+
static inline MapType Map(Scalar* data, Index rows, Index cols)
|
| 655 |
+
{ return MapType(data, rows, cols); }
|
| 656 |
+
|
| 657 |
+
static inline ConstAlignedMapType MapAligned(const Scalar* data)
|
| 658 |
+
{ return ConstAlignedMapType(data); }
|
| 659 |
+
static inline AlignedMapType MapAligned(Scalar* data)
|
| 660 |
+
{ return AlignedMapType(data); }
|
| 661 |
+
static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size)
|
| 662 |
+
{ return ConstAlignedMapType(data, size); }
|
| 663 |
+
static inline AlignedMapType MapAligned(Scalar* data, Index size)
|
| 664 |
+
{ return AlignedMapType(data, size); }
|
| 665 |
+
static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols)
|
| 666 |
+
{ return ConstAlignedMapType(data, rows, cols); }
|
| 667 |
+
static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols)
|
| 668 |
+
{ return AlignedMapType(data, rows, cols); }
|
| 669 |
+
|
| 670 |
+
template<int Outer, int Inner>
|
| 671 |
+
static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, const Stride<Outer, Inner>& stride)
|
| 672 |
+
{ return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
|
| 673 |
+
template<int Outer, int Inner>
|
| 674 |
+
static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, const Stride<Outer, Inner>& stride)
|
| 675 |
+
{ return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
|
| 676 |
+
template<int Outer, int Inner>
|
| 677 |
+
static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index size, const Stride<Outer, Inner>& stride)
|
| 678 |
+
{ return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
|
| 679 |
+
template<int Outer, int Inner>
|
| 680 |
+
static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index size, const Stride<Outer, Inner>& stride)
|
| 681 |
+
{ return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
|
| 682 |
+
template<int Outer, int Inner>
|
| 683 |
+
static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
|
| 684 |
+
{ return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
|
| 685 |
+
template<int Outer, int Inner>
|
| 686 |
+
static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
|
| 687 |
+
{ return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
|
| 688 |
+
|
| 689 |
+
template<int Outer, int Inner>
|
| 690 |
+
static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, const Stride<Outer, Inner>& stride)
|
| 691 |
+
{ return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
|
| 692 |
+
template<int Outer, int Inner>
|
| 693 |
+
static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, const Stride<Outer, Inner>& stride)
|
| 694 |
+
{ return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
|
| 695 |
+
template<int Outer, int Inner>
|
| 696 |
+
static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index size, const Stride<Outer, Inner>& stride)
|
| 697 |
+
{ return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
|
| 698 |
+
template<int Outer, int Inner>
|
| 699 |
+
static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index size, const Stride<Outer, Inner>& stride)
|
| 700 |
+
{ return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
|
| 701 |
+
template<int Outer, int Inner>
|
| 702 |
+
static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
|
| 703 |
+
{ return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
|
| 704 |
+
template<int Outer, int Inner>
|
| 705 |
+
static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
|
| 706 |
+
{ return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
|
| 707 |
+
//@}
|
| 708 |
+
|
| 709 |
+
using Base::setConstant;
|
| 710 |
+
EIGEN_DEVICE_FUNC Derived& setConstant(Index size, const Scalar& val);
|
| 711 |
+
EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, Index cols, const Scalar& val);
|
| 712 |
+
EIGEN_DEVICE_FUNC Derived& setConstant(NoChange_t, Index cols, const Scalar& val);
|
| 713 |
+
EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, NoChange_t, const Scalar& val);
|
| 714 |
+
|
| 715 |
+
using Base::setZero;
|
| 716 |
+
EIGEN_DEVICE_FUNC Derived& setZero(Index size);
|
| 717 |
+
EIGEN_DEVICE_FUNC Derived& setZero(Index rows, Index cols);
|
| 718 |
+
EIGEN_DEVICE_FUNC Derived& setZero(NoChange_t, Index cols);
|
| 719 |
+
EIGEN_DEVICE_FUNC Derived& setZero(Index rows, NoChange_t);
|
| 720 |
+
|
| 721 |
+
using Base::setOnes;
|
| 722 |
+
EIGEN_DEVICE_FUNC Derived& setOnes(Index size);
|
| 723 |
+
EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, Index cols);
|
| 724 |
+
EIGEN_DEVICE_FUNC Derived& setOnes(NoChange_t, Index cols);
|
| 725 |
+
EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, NoChange_t);
|
| 726 |
+
|
| 727 |
+
using Base::setRandom;
|
| 728 |
+
Derived& setRandom(Index size);
|
| 729 |
+
Derived& setRandom(Index rows, Index cols);
|
| 730 |
+
Derived& setRandom(NoChange_t, Index cols);
|
| 731 |
+
Derived& setRandom(Index rows, NoChange_t);
|
| 732 |
+
|
| 733 |
+
#ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
|
| 734 |
+
#include EIGEN_PLAINOBJECTBASE_PLUGIN
|
| 735 |
+
#endif
|
| 736 |
+
|
| 737 |
+
protected:
|
| 738 |
+
/** \internal Resizes *this in preparation for assigning \a other to it.
|
| 739 |
+
* Takes care of doing all the checking that's needed.
|
| 740 |
+
*
|
| 741 |
+
* Note that copying a row-vector into a vector (and conversely) is allowed.
|
| 742 |
+
* The resizing, if any, is then done in the appropriate way so that row-vectors
|
| 743 |
+
* remain row-vectors and vectors remain vectors.
|
| 744 |
+
*/
|
| 745 |
+
template<typename OtherDerived>
|
| 746 |
+
EIGEN_DEVICE_FUNC
|
| 747 |
+
EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase<OtherDerived>& other)
|
| 748 |
+
{
|
| 749 |
+
#ifdef EIGEN_NO_AUTOMATIC_RESIZING
|
| 750 |
+
eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size())
|
| 751 |
+
: (rows() == other.rows() && cols() == other.cols())))
|
| 752 |
+
&& "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
|
| 753 |
+
EIGEN_ONLY_USED_FOR_DEBUG(other);
|
| 754 |
+
#else
|
| 755 |
+
resizeLike(other);
|
| 756 |
+
#endif
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
/**
|
| 760 |
+
* \brief Copies the value of the expression \a other into \c *this with automatic resizing.
|
| 761 |
+
*
|
| 762 |
+
* *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
|
| 763 |
+
* it will be initialized.
|
| 764 |
+
*
|
| 765 |
+
* Note that copying a row-vector into a vector (and conversely) is allowed.
|
| 766 |
+
* The resizing, if any, is then done in the appropriate way so that row-vectors
|
| 767 |
+
* remain row-vectors and vectors remain vectors.
|
| 768 |
+
*
|
| 769 |
+
* \sa operator=(const MatrixBase<OtherDerived>&), _set_noalias()
|
| 770 |
+
*
|
| 771 |
+
* \internal
|
| 772 |
+
*/
|
| 773 |
+
// aliasing is dealt once in internal::call_assignment
|
| 774 |
+
// so at this stage we have to assume aliasing... and resising has to be done later.
|
| 775 |
+
template<typename OtherDerived>
|
| 776 |
+
EIGEN_DEVICE_FUNC
|
| 777 |
+
EIGEN_STRONG_INLINE Derived& _set(const DenseBase<OtherDerived>& other)
|
| 778 |
+
{
|
| 779 |
+
internal::call_assignment(this->derived(), other.derived());
|
| 780 |
+
return this->derived();
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
/** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which
|
| 784 |
+
* is the case when creating a new matrix) so one can enforce lazy evaluation.
|
| 785 |
+
*
|
| 786 |
+
* \sa operator=(const MatrixBase<OtherDerived>&), _set()
|
| 787 |
+
*/
|
| 788 |
+
template<typename OtherDerived>
|
| 789 |
+
EIGEN_DEVICE_FUNC
|
| 790 |
+
EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase<OtherDerived>& other)
|
| 791 |
+
{
|
| 792 |
+
// I don't think we need this resize call since the lazyAssign will anyways resize
|
| 793 |
+
// and lazyAssign will be called by the assign selector.
|
| 794 |
+
//_resize_to_match(other);
|
| 795 |
+
// the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because
|
| 796 |
+
// it wouldn't allow to copy a row-vector into a column-vector.
|
| 797 |
+
internal::call_assignment_no_alias(this->derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
|
| 798 |
+
return this->derived();
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
template<typename T0, typename T1>
|
| 802 |
+
EIGEN_DEVICE_FUNC
|
| 803 |
+
EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0)
|
| 804 |
+
{
|
| 805 |
+
const bool t0_is_integer_alike = internal::is_valid_index_type<T0>::value;
|
| 806 |
+
const bool t1_is_integer_alike = internal::is_valid_index_type<T1>::value;
|
| 807 |
+
EIGEN_STATIC_ASSERT(t0_is_integer_alike &&
|
| 808 |
+
t1_is_integer_alike,
|
| 809 |
+
FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
|
| 810 |
+
resize(rows,cols);
|
| 811 |
+
}
|
| 812 |
+
|
| 813 |
+
template<typename T0, typename T1>
|
| 814 |
+
EIGEN_DEVICE_FUNC
|
| 815 |
+
EIGEN_STRONG_INLINE void _init2(const T0& val0, const T1& val1, typename internal::enable_if<Base::SizeAtCompileTime==2,T0>::type* = 0)
|
| 816 |
+
{
|
| 817 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
|
| 818 |
+
m_storage.data()[0] = Scalar(val0);
|
| 819 |
+
m_storage.data()[1] = Scalar(val1);
|
| 820 |
+
}
|
| 821 |
+
|
| 822 |
+
template<typename T0, typename T1>
|
| 823 |
+
EIGEN_DEVICE_FUNC
|
| 824 |
+
EIGEN_STRONG_INLINE void _init2(const Index& val0, const Index& val1,
|
| 825 |
+
typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
|
| 826 |
+
&& (internal::is_same<T0,Index>::value)
|
| 827 |
+
&& (internal::is_same<T1,Index>::value)
|
| 828 |
+
&& Base::SizeAtCompileTime==2,T1>::type* = 0)
|
| 829 |
+
{
|
| 830 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
|
| 831 |
+
m_storage.data()[0] = Scalar(val0);
|
| 832 |
+
m_storage.data()[1] = Scalar(val1);
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
// The argument is convertible to the Index type and we either have a non 1x1 Matrix, or a dynamic-sized Array,
|
| 836 |
+
// then the argument is meant to be the size of the object.
|
| 837 |
+
template<typename T>
|
| 838 |
+
EIGEN_DEVICE_FUNC
|
| 839 |
+
EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if< (Base::SizeAtCompileTime!=1 || !internal::is_convertible<T, Scalar>::value)
|
| 840 |
+
&& ((!internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value || Base::SizeAtCompileTime==Dynamic)),T>::type* = 0)
|
| 841 |
+
{
|
| 842 |
+
// NOTE MSVC 2008 complains if we directly put bool(NumTraits<T>::IsInteger) as the EIGEN_STATIC_ASSERT argument.
|
| 843 |
+
const bool is_integer_alike = internal::is_valid_index_type<T>::value;
|
| 844 |
+
EIGEN_UNUSED_VARIABLE(is_integer_alike);
|
| 845 |
+
EIGEN_STATIC_ASSERT(is_integer_alike,
|
| 846 |
+
FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
|
| 847 |
+
resize(size);
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
// We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type can be implicitly converted)
|
| 851 |
+
template<typename T>
|
| 852 |
+
EIGEN_DEVICE_FUNC
|
| 853 |
+
EIGEN_STRONG_INLINE void _init1(const Scalar& val0, typename internal::enable_if<Base::SizeAtCompileTime==1 && internal::is_convertible<T, Scalar>::value,T>::type* = 0)
|
| 854 |
+
{
|
| 855 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
|
| 856 |
+
m_storage.data()[0] = val0;
|
| 857 |
+
}
|
| 858 |
+
|
| 859 |
+
// We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar type match the index type)
|
| 860 |
+
template<typename T>
|
| 861 |
+
EIGEN_DEVICE_FUNC
|
| 862 |
+
EIGEN_STRONG_INLINE void _init1(const Index& val0,
|
| 863 |
+
typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
|
| 864 |
+
&& (internal::is_same<Index,T>::value)
|
| 865 |
+
&& Base::SizeAtCompileTime==1
|
| 866 |
+
&& internal::is_convertible<T, Scalar>::value,T*>::type* = 0)
|
| 867 |
+
{
|
| 868 |
+
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
|
| 869 |
+
m_storage.data()[0] = Scalar(val0);
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
// Initialize a fixed size matrix from a pointer to raw data
|
| 873 |
+
template<typename T>
|
| 874 |
+
EIGEN_DEVICE_FUNC
|
| 875 |
+
EIGEN_STRONG_INLINE void _init1(const Scalar* data){
|
| 876 |
+
this->_set_noalias(ConstMapType(data));
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
// Initialize an arbitrary matrix from a dense expression
|
| 880 |
+
template<typename T, typename OtherDerived>
|
| 881 |
+
EIGEN_DEVICE_FUNC
|
| 882 |
+
EIGEN_STRONG_INLINE void _init1(const DenseBase<OtherDerived>& other){
|
| 883 |
+
this->_set_noalias(other);
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
// Initialize an arbitrary matrix from an object convertible to the Derived type.
|
| 887 |
+
template<typename T>
|
| 888 |
+
EIGEN_DEVICE_FUNC
|
| 889 |
+
EIGEN_STRONG_INLINE void _init1(const Derived& other){
|
| 890 |
+
this->_set_noalias(other);
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
// Initialize an arbitrary matrix from a generic Eigen expression
|
| 894 |
+
template<typename T, typename OtherDerived>
|
| 895 |
+
EIGEN_DEVICE_FUNC
|
| 896 |
+
EIGEN_STRONG_INLINE void _init1(const EigenBase<OtherDerived>& other){
|
| 897 |
+
this->derived() = other;
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
template<typename T, typename OtherDerived>
|
| 901 |
+
EIGEN_DEVICE_FUNC
|
| 902 |
+
EIGEN_STRONG_INLINE void _init1(const ReturnByValue<OtherDerived>& other)
|
| 903 |
+
{
|
| 904 |
+
resize(other.rows(), other.cols());
|
| 905 |
+
other.evalTo(this->derived());
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
template<typename T, typename OtherDerived, int ColsAtCompileTime>
|
| 909 |
+
EIGEN_DEVICE_FUNC
|
| 910 |
+
EIGEN_STRONG_INLINE void _init1(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
|
| 911 |
+
{
|
| 912 |
+
this->derived() = r;
|
| 913 |
+
}
|
| 914 |
+
|
| 915 |
+
// For fixed-size Array<Scalar,...>
|
| 916 |
+
template<typename T>
|
| 917 |
+
EIGEN_DEVICE_FUNC
|
| 918 |
+
EIGEN_STRONG_INLINE void _init1(const Scalar& val0,
|
| 919 |
+
typename internal::enable_if< Base::SizeAtCompileTime!=Dynamic
|
| 920 |
+
&& Base::SizeAtCompileTime!=1
|
| 921 |
+
&& internal::is_convertible<T, Scalar>::value
|
| 922 |
+
&& internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T>::type* = 0)
|
| 923 |
+
{
|
| 924 |
+
Base::setConstant(val0);
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
// For fixed-size Array<Index,...>
|
| 928 |
+
template<typename T>
|
| 929 |
+
EIGEN_DEVICE_FUNC
|
| 930 |
+
EIGEN_STRONG_INLINE void _init1(const Index& val0,
|
| 931 |
+
typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
|
| 932 |
+
&& (internal::is_same<Index,T>::value)
|
| 933 |
+
&& Base::SizeAtCompileTime!=Dynamic
|
| 934 |
+
&& Base::SizeAtCompileTime!=1
|
| 935 |
+
&& internal::is_convertible<T, Scalar>::value
|
| 936 |
+
&& internal::is_same<typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T*>::type* = 0)
|
| 937 |
+
{
|
| 938 |
+
Base::setConstant(val0);
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
|
| 942 |
+
friend struct internal::matrix_swap_impl;
|
| 943 |
+
|
| 944 |
+
public:
|
| 945 |
+
|
| 946 |
+
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
| 947 |
+
/** \internal
|
| 948 |
+
* \brief Override DenseBase::swap() since for dynamic-sized matrices
|
| 949 |
+
* of same type it is enough to swap the data pointers.
|
| 950 |
+
*/
|
| 951 |
+
template<typename OtherDerived>
|
| 952 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 953 |
+
void swap(DenseBase<OtherDerived> & other)
|
| 954 |
+
{
|
| 955 |
+
enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic };
|
| 956 |
+
internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived());
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
/** \internal
|
| 960 |
+
* \brief const version forwarded to DenseBase::swap
|
| 961 |
+
*/
|
| 962 |
+
template<typename OtherDerived>
|
| 963 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 964 |
+
void swap(DenseBase<OtherDerived> const & other)
|
| 965 |
+
{ Base::swap(other.derived()); }
|
| 966 |
+
|
| 967 |
+
EIGEN_DEVICE_FUNC
|
| 968 |
+
static EIGEN_STRONG_INLINE void _check_template_params()
|
| 969 |
+
{
|
| 970 |
+
EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (int(Options)&RowMajor)==RowMajor)
|
| 971 |
+
&& EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (int(Options)&RowMajor)==0)
|
| 972 |
+
&& ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0))
|
| 973 |
+
&& ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0))
|
| 974 |
+
&& ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0))
|
| 975 |
+
&& ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0))
|
| 976 |
+
&& (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic)
|
| 977 |
+
&& (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic)
|
| 978 |
+
&& (Options & (DontAlign|RowMajor)) == Options),
|
| 979 |
+
INVALID_MATRIX_TEMPLATE_PARAMETERS)
|
| 980 |
+
}
|
| 981 |
+
|
| 982 |
+
enum { IsPlainObjectBase = 1 };
|
| 983 |
+
#endif
|
| 984 |
+
public:
|
| 985 |
+
// These apparently need to be down here for nvcc+icc to prevent duplicate
|
| 986 |
+
// Map symbol.
|
| 987 |
+
template<typename PlainObjectType, int MapOptions, typename StrideType> friend class Eigen::Map;
|
| 988 |
+
friend class Eigen::Map<Derived, Unaligned>;
|
| 989 |
+
friend class Eigen::Map<const Derived, Unaligned>;
|
| 990 |
+
#if EIGEN_MAX_ALIGN_BYTES>0
|
| 991 |
+
// for EIGEN_MAX_ALIGN_BYTES==0, AlignedMax==Unaligned, and many compilers generate warnings for friend-ing a class twice.
|
| 992 |
+
friend class Eigen::Map<Derived, AlignedMax>;
|
| 993 |
+
friend class Eigen::Map<const Derived, AlignedMax>;
|
| 994 |
+
#endif
|
| 995 |
+
};
|
| 996 |
+
|
| 997 |
+
namespace internal {
|
| 998 |
+
|
| 999 |
+
template <typename Derived, typename OtherDerived, bool IsVector>
|
| 1000 |
+
struct conservative_resize_like_impl
|
| 1001 |
+
{
|
| 1002 |
+
#if EIGEN_HAS_TYPE_TRAITS
|
| 1003 |
+
static const bool IsRelocatable = std::is_trivially_copyable<typename Derived::Scalar>::value;
|
| 1004 |
+
#else
|
| 1005 |
+
static const bool IsRelocatable = !NumTraits<typename Derived::Scalar>::RequireInitialization;
|
| 1006 |
+
#endif
|
| 1007 |
+
static void run(DenseBase<Derived>& _this, Index rows, Index cols)
|
| 1008 |
+
{
|
| 1009 |
+
if (_this.rows() == rows && _this.cols() == cols) return;
|
| 1010 |
+
EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
|
| 1011 |
+
|
| 1012 |
+
if ( IsRelocatable
|
| 1013 |
+
&& (( Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows
|
| 1014 |
+
(!Derived::IsRowMajor && _this.rows() == rows) )) // column-major and we change only the number of columns
|
| 1015 |
+
{
|
| 1016 |
+
internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime>::run(rows, cols);
|
| 1017 |
+
_this.derived().m_storage.conservativeResize(rows*cols,rows,cols);
|
| 1018 |
+
}
|
| 1019 |
+
else
|
| 1020 |
+
{
|
| 1021 |
+
// The storage order does not allow us to use reallocation.
|
| 1022 |
+
Derived tmp(rows,cols);
|
| 1023 |
+
const Index common_rows = numext::mini(rows, _this.rows());
|
| 1024 |
+
const Index common_cols = numext::mini(cols, _this.cols());
|
| 1025 |
+
tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
|
| 1026 |
+
_this.derived().swap(tmp);
|
| 1027 |
+
}
|
| 1028 |
+
}
|
| 1029 |
+
|
| 1030 |
+
static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other)
|
| 1031 |
+
{
|
| 1032 |
+
if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
|
| 1033 |
+
|
| 1034 |
+
// Note: Here is space for improvement. Basically, for conservativeResize(Index,Index),
|
| 1035 |
+
// neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the
|
| 1036 |
+
// dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or
|
| 1037 |
+
// conservativeResize(NoChange_t, Index cols). For these methods new static asserts like
|
| 1038 |
+
// EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good.
|
| 1039 |
+
EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
|
| 1040 |
+
EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived)
|
| 1041 |
+
|
| 1042 |
+
if ( IsRelocatable &&
|
| 1043 |
+
(( Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows
|
| 1044 |
+
(!Derived::IsRowMajor && _this.rows() == other.rows()) )) // column-major and we change only the number of columns
|
| 1045 |
+
{
|
| 1046 |
+
const Index new_rows = other.rows() - _this.rows();
|
| 1047 |
+
const Index new_cols = other.cols() - _this.cols();
|
| 1048 |
+
_this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols());
|
| 1049 |
+
if (new_rows>0)
|
| 1050 |
+
_this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
|
| 1051 |
+
else if (new_cols>0)
|
| 1052 |
+
_this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
|
| 1053 |
+
}
|
| 1054 |
+
else
|
| 1055 |
+
{
|
| 1056 |
+
// The storage order does not allow us to use reallocation.
|
| 1057 |
+
Derived tmp(other);
|
| 1058 |
+
const Index common_rows = numext::mini(tmp.rows(), _this.rows());
|
| 1059 |
+
const Index common_cols = numext::mini(tmp.cols(), _this.cols());
|
| 1060 |
+
tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
|
| 1061 |
+
_this.derived().swap(tmp);
|
| 1062 |
+
}
|
| 1063 |
+
}
|
| 1064 |
+
};
|
| 1065 |
+
|
| 1066 |
+
// Here, the specialization for vectors inherits from the general matrix case
|
| 1067 |
+
// to allow calling .conservativeResize(rows,cols) on vectors.
|
| 1068 |
+
template <typename Derived, typename OtherDerived>
|
| 1069 |
+
struct conservative_resize_like_impl<Derived,OtherDerived,true>
|
| 1070 |
+
: conservative_resize_like_impl<Derived,OtherDerived,false>
|
| 1071 |
+
{
|
| 1072 |
+
typedef conservative_resize_like_impl<Derived,OtherDerived,false> Base;
|
| 1073 |
+
using Base::run;
|
| 1074 |
+
using Base::IsRelocatable;
|
| 1075 |
+
|
| 1076 |
+
static void run(DenseBase<Derived>& _this, Index size)
|
| 1077 |
+
{
|
| 1078 |
+
const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size;
|
| 1079 |
+
const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1;
|
| 1080 |
+
if(IsRelocatable)
|
| 1081 |
+
_this.derived().m_storage.conservativeResize(size,new_rows,new_cols);
|
| 1082 |
+
else
|
| 1083 |
+
Base::run(_this.derived(), new_rows, new_cols);
|
| 1084 |
+
}
|
| 1085 |
+
|
| 1086 |
+
static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other)
|
| 1087 |
+
{
|
| 1088 |
+
if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
|
| 1089 |
+
|
| 1090 |
+
const Index num_new_elements = other.size() - _this.size();
|
| 1091 |
+
|
| 1092 |
+
const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows();
|
| 1093 |
+
const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1;
|
| 1094 |
+
if(IsRelocatable)
|
| 1095 |
+
_this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols);
|
| 1096 |
+
else
|
| 1097 |
+
Base::run(_this.derived(), new_rows, new_cols);
|
| 1098 |
+
|
| 1099 |
+
if (num_new_elements > 0)
|
| 1100 |
+
_this.tail(num_new_elements) = other.tail(num_new_elements);
|
| 1101 |
+
}
|
| 1102 |
+
};
|
| 1103 |
+
|
| 1104 |
+
template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
|
| 1105 |
+
struct matrix_swap_impl
|
| 1106 |
+
{
|
| 1107 |
+
EIGEN_DEVICE_FUNC
|
| 1108 |
+
static EIGEN_STRONG_INLINE void run(MatrixTypeA& a, MatrixTypeB& b)
|
| 1109 |
+
{
|
| 1110 |
+
a.base().swap(b);
|
| 1111 |
+
}
|
| 1112 |
+
};
|
| 1113 |
+
|
| 1114 |
+
template<typename MatrixTypeA, typename MatrixTypeB>
|
| 1115 |
+
struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true>
|
| 1116 |
+
{
|
| 1117 |
+
EIGEN_DEVICE_FUNC
|
| 1118 |
+
static inline void run(MatrixTypeA& a, MatrixTypeB& b)
|
| 1119 |
+
{
|
| 1120 |
+
static_cast<typename MatrixTypeA::Base&>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage);
|
| 1121 |
+
}
|
| 1122 |
+
};
|
| 1123 |
+
|
| 1124 |
+
} // end namespace internal
|
| 1125 |
+
|
| 1126 |
+
} // end namespace Eigen
|
| 1127 |
+
|
| 1128 |
+
#endif // EIGEN_DENSESTORAGEBASE_H
|
include/eigen/Eigen/src/Core/Product.h
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_PRODUCT_H
|
| 11 |
+
#define EIGEN_PRODUCT_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
template<typename Lhs, typename Rhs, int Option, typename StorageKind> class ProductImpl;
|
| 16 |
+
|
| 17 |
+
namespace internal {
|
| 18 |
+
|
| 19 |
+
template<typename Lhs, typename Rhs, int Option>
|
| 20 |
+
struct traits<Product<Lhs, Rhs, Option> >
|
| 21 |
+
{
|
| 22 |
+
typedef typename remove_all<Lhs>::type LhsCleaned;
|
| 23 |
+
typedef typename remove_all<Rhs>::type RhsCleaned;
|
| 24 |
+
typedef traits<LhsCleaned> LhsTraits;
|
| 25 |
+
typedef traits<RhsCleaned> RhsTraits;
|
| 26 |
+
|
| 27 |
+
typedef MatrixXpr XprKind;
|
| 28 |
+
|
| 29 |
+
typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
|
| 30 |
+
typedef typename product_promote_storage_type<typename LhsTraits::StorageKind,
|
| 31 |
+
typename RhsTraits::StorageKind,
|
| 32 |
+
internal::product_type<Lhs,Rhs>::ret>::ret StorageKind;
|
| 33 |
+
typedef typename promote_index_type<typename LhsTraits::StorageIndex,
|
| 34 |
+
typename RhsTraits::StorageIndex>::type StorageIndex;
|
| 35 |
+
|
| 36 |
+
enum {
|
| 37 |
+
RowsAtCompileTime = LhsTraits::RowsAtCompileTime,
|
| 38 |
+
ColsAtCompileTime = RhsTraits::ColsAtCompileTime,
|
| 39 |
+
MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime,
|
| 40 |
+
MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime,
|
| 41 |
+
|
| 42 |
+
// FIXME: only needed by GeneralMatrixMatrixTriangular
|
| 43 |
+
InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime),
|
| 44 |
+
|
| 45 |
+
// The storage order is somewhat arbitrary here. The correct one will be determined through the evaluator.
|
| 46 |
+
Flags = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? RowMajorBit
|
| 47 |
+
: (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
|
| 48 |
+
: ( ((LhsTraits::Flags&NoPreferredStorageOrderBit) && (RhsTraits::Flags&RowMajorBit))
|
| 49 |
+
|| ((RhsTraits::Flags&NoPreferredStorageOrderBit) && (LhsTraits::Flags&RowMajorBit)) ) ? RowMajorBit
|
| 50 |
+
: NoPreferredStorageOrderBit
|
| 51 |
+
};
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
} // end namespace internal
|
| 55 |
+
|
| 56 |
+
/** \class Product
|
| 57 |
+
* \ingroup Core_Module
|
| 58 |
+
*
|
| 59 |
+
* \brief Expression of the product of two arbitrary matrices or vectors
|
| 60 |
+
*
|
| 61 |
+
* \tparam _Lhs the type of the left-hand side expression
|
| 62 |
+
* \tparam _Rhs the type of the right-hand side expression
|
| 63 |
+
*
|
| 64 |
+
* This class represents an expression of the product of two arbitrary matrices.
|
| 65 |
+
*
|
| 66 |
+
* The other template parameters are:
|
| 67 |
+
* \tparam Option can be DefaultProduct, AliasFreeProduct, or LazyProduct
|
| 68 |
+
*
|
| 69 |
+
*/
|
| 70 |
+
template<typename _Lhs, typename _Rhs, int Option>
|
| 71 |
+
class Product : public ProductImpl<_Lhs,_Rhs,Option,
|
| 72 |
+
typename internal::product_promote_storage_type<typename internal::traits<_Lhs>::StorageKind,
|
| 73 |
+
typename internal::traits<_Rhs>::StorageKind,
|
| 74 |
+
internal::product_type<_Lhs,_Rhs>::ret>::ret>
|
| 75 |
+
{
|
| 76 |
+
public:
|
| 77 |
+
|
| 78 |
+
typedef _Lhs Lhs;
|
| 79 |
+
typedef _Rhs Rhs;
|
| 80 |
+
|
| 81 |
+
typedef typename ProductImpl<
|
| 82 |
+
Lhs, Rhs, Option,
|
| 83 |
+
typename internal::product_promote_storage_type<typename internal::traits<Lhs>::StorageKind,
|
| 84 |
+
typename internal::traits<Rhs>::StorageKind,
|
| 85 |
+
internal::product_type<Lhs,Rhs>::ret>::ret>::Base Base;
|
| 86 |
+
EIGEN_GENERIC_PUBLIC_INTERFACE(Product)
|
| 87 |
+
|
| 88 |
+
typedef typename internal::ref_selector<Lhs>::type LhsNested;
|
| 89 |
+
typedef typename internal::ref_selector<Rhs>::type RhsNested;
|
| 90 |
+
typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
|
| 91 |
+
typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
|
| 92 |
+
|
| 93 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 94 |
+
Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
|
| 95 |
+
{
|
| 96 |
+
eigen_assert(lhs.cols() == rhs.rows()
|
| 97 |
+
&& "invalid matrix product"
|
| 98 |
+
&& "if you wanted a coeff-wise or a dot product use the respective explicit functions");
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 102 |
+
Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
|
| 103 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
|
| 104 |
+
Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
|
| 105 |
+
|
| 106 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 107 |
+
const LhsNestedCleaned& lhs() const { return m_lhs; }
|
| 108 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 109 |
+
const RhsNestedCleaned& rhs() const { return m_rhs; }
|
| 110 |
+
|
| 111 |
+
protected:
|
| 112 |
+
|
| 113 |
+
LhsNested m_lhs;
|
| 114 |
+
RhsNested m_rhs;
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
namespace internal {
|
| 118 |
+
|
| 119 |
+
template<typename Lhs, typename Rhs, int Option, int ProductTag = internal::product_type<Lhs,Rhs>::ret>
|
| 120 |
+
class dense_product_base
|
| 121 |
+
: public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
|
| 122 |
+
{};
|
| 123 |
+
|
| 124 |
+
/** Conversion to scalar for inner-products */
|
| 125 |
+
template<typename Lhs, typename Rhs, int Option>
|
| 126 |
+
class dense_product_base<Lhs, Rhs, Option, InnerProduct>
|
| 127 |
+
: public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
|
| 128 |
+
{
|
| 129 |
+
typedef Product<Lhs,Rhs,Option> ProductXpr;
|
| 130 |
+
typedef typename internal::dense_xpr_base<ProductXpr>::type Base;
|
| 131 |
+
public:
|
| 132 |
+
using Base::derived;
|
| 133 |
+
typedef typename Base::Scalar Scalar;
|
| 134 |
+
|
| 135 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator const Scalar() const
|
| 136 |
+
{
|
| 137 |
+
return internal::evaluator<ProductXpr>(derived()).coeff(0,0);
|
| 138 |
+
}
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
} // namespace internal
|
| 142 |
+
|
| 143 |
+
// Generic API dispatcher
|
| 144 |
+
template<typename Lhs, typename Rhs, int Option, typename StorageKind>
|
| 145 |
+
class ProductImpl : public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type
|
| 146 |
+
{
|
| 147 |
+
public:
|
| 148 |
+
typedef typename internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type Base;
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
template<typename Lhs, typename Rhs, int Option>
|
| 152 |
+
class ProductImpl<Lhs,Rhs,Option,Dense>
|
| 153 |
+
: public internal::dense_product_base<Lhs,Rhs,Option>
|
| 154 |
+
{
|
| 155 |
+
typedef Product<Lhs, Rhs, Option> Derived;
|
| 156 |
+
|
| 157 |
+
public:
|
| 158 |
+
|
| 159 |
+
typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base;
|
| 160 |
+
EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
|
| 161 |
+
protected:
|
| 162 |
+
enum {
|
| 163 |
+
IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) &&
|
| 164 |
+
(ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic),
|
| 165 |
+
EnableCoeff = IsOneByOne || Option==LazyProduct
|
| 166 |
+
};
|
| 167 |
+
|
| 168 |
+
public:
|
| 169 |
+
|
| 170 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const
|
| 171 |
+
{
|
| 172 |
+
EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
|
| 173 |
+
eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
|
| 174 |
+
|
| 175 |
+
return internal::evaluator<Derived>(derived()).coeff(row,col);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const
|
| 179 |
+
{
|
| 180 |
+
EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
|
| 181 |
+
eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
|
| 182 |
+
|
| 183 |
+
return internal::evaluator<Derived>(derived()).coeff(i);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
};
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 5 |
+
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 6 |
+
// Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
|
| 7 |
+
//
|
| 8 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 9 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 10 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
#ifndef EIGEN_PRODUCTEVALUATORS_H
|
| 14 |
+
#define EIGEN_PRODUCTEVALUATORS_H
|
| 15 |
+
|
| 16 |
+
namespace Eigen {
|
| 17 |
+
|
| 18 |
+
namespace internal {
|
| 19 |
+
|
| 20 |
+
/** \internal
|
| 21 |
+
* Evaluator of a product expression.
|
| 22 |
+
* Since products require special treatments to handle all possible cases,
|
| 23 |
+
* we simply defer the evaluation logic to a product_evaluator class
|
| 24 |
+
* which offers more partial specialization possibilities.
|
| 25 |
+
*
|
| 26 |
+
* \sa class product_evaluator
|
| 27 |
+
*/
|
| 28 |
+
template<typename Lhs, typename Rhs, int Options>
|
| 29 |
+
struct evaluator<Product<Lhs, Rhs, Options> >
|
| 30 |
+
: public product_evaluator<Product<Lhs, Rhs, Options> >
|
| 31 |
+
{
|
| 32 |
+
typedef Product<Lhs, Rhs, Options> XprType;
|
| 33 |
+
typedef product_evaluator<XprType> Base;
|
| 34 |
+
|
| 35 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) : Base(xpr) {}
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
// Catch "scalar * ( A * B )" and transform it to "(A*scalar) * B"
|
| 39 |
+
// TODO we should apply that rule only if that's really helpful
|
| 40 |
+
template<typename Lhs, typename Rhs, typename Scalar1, typename Scalar2, typename Plain1>
|
| 41 |
+
struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
|
| 42 |
+
const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
|
| 43 |
+
const Product<Lhs, Rhs, DefaultProduct> > >
|
| 44 |
+
{
|
| 45 |
+
static const bool value = true;
|
| 46 |
+
};
|
| 47 |
+
template<typename Lhs, typename Rhs, typename Scalar1, typename Scalar2, typename Plain1>
|
| 48 |
+
struct evaluator<CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
|
| 49 |
+
const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
|
| 50 |
+
const Product<Lhs, Rhs, DefaultProduct> > >
|
| 51 |
+
: public evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> >
|
| 52 |
+
{
|
| 53 |
+
typedef CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
|
| 54 |
+
const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
|
| 55 |
+
const Product<Lhs, Rhs, DefaultProduct> > XprType;
|
| 56 |
+
typedef evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> > Base;
|
| 57 |
+
|
| 58 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr)
|
| 59 |
+
: Base(xpr.lhs().functor().m_other * xpr.rhs().lhs() * xpr.rhs().rhs())
|
| 60 |
+
{}
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
template<typename Lhs, typename Rhs, int DiagIndex>
|
| 65 |
+
struct evaluator<Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> >
|
| 66 |
+
: public evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> >
|
| 67 |
+
{
|
| 68 |
+
typedef Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> XprType;
|
| 69 |
+
typedef evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> > Base;
|
| 70 |
+
|
| 71 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr)
|
| 72 |
+
: Base(Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex>(
|
| 73 |
+
Product<Lhs, Rhs, LazyProduct>(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()),
|
| 74 |
+
xpr.index() ))
|
| 75 |
+
{}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
// Helper class to perform a matrix product with the destination at hand.
|
| 80 |
+
// Depending on the sizes of the factors, there are different evaluation strategies
|
| 81 |
+
// as controlled by internal::product_type.
|
| 82 |
+
template< typename Lhs, typename Rhs,
|
| 83 |
+
typename LhsShape = typename evaluator_traits<Lhs>::Shape,
|
| 84 |
+
typename RhsShape = typename evaluator_traits<Rhs>::Shape,
|
| 85 |
+
int ProductType = internal::product_type<Lhs,Rhs>::value>
|
| 86 |
+
struct generic_product_impl;
|
| 87 |
+
|
| 88 |
+
template<typename Lhs, typename Rhs>
|
| 89 |
+
struct evaluator_assume_aliasing<Product<Lhs, Rhs, DefaultProduct> > {
|
| 90 |
+
static const bool value = true;
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
// This is the default evaluator implementation for products:
|
| 94 |
+
// It creates a temporary and call generic_product_impl
|
| 95 |
+
template<typename Lhs, typename Rhs, int Options, int ProductTag, typename LhsShape, typename RhsShape>
|
| 96 |
+
struct product_evaluator<Product<Lhs, Rhs, Options>, ProductTag, LhsShape, RhsShape>
|
| 97 |
+
: public evaluator<typename Product<Lhs, Rhs, Options>::PlainObject>
|
| 98 |
+
{
|
| 99 |
+
typedef Product<Lhs, Rhs, Options> XprType;
|
| 100 |
+
typedef typename XprType::PlainObject PlainObject;
|
| 101 |
+
typedef evaluator<PlainObject> Base;
|
| 102 |
+
enum {
|
| 103 |
+
Flags = Base::Flags | EvalBeforeNestingBit
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 107 |
+
explicit product_evaluator(const XprType& xpr)
|
| 108 |
+
: m_result(xpr.rows(), xpr.cols())
|
| 109 |
+
{
|
| 110 |
+
::new (static_cast<Base*>(this)) Base(m_result);
|
| 111 |
+
|
| 112 |
+
// FIXME shall we handle nested_eval here?,
|
| 113 |
+
// if so, then we must take care at removing the call to nested_eval in the specializations (e.g., in permutation_matrix_product, transposition_matrix_product, etc.)
|
| 114 |
+
// typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested;
|
| 115 |
+
// typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested;
|
| 116 |
+
// typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
|
| 117 |
+
// typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
|
| 118 |
+
//
|
| 119 |
+
// const LhsNested lhs(xpr.lhs());
|
| 120 |
+
// const RhsNested rhs(xpr.rhs());
|
| 121 |
+
//
|
| 122 |
+
// generic_product_impl<LhsNestedCleaned, RhsNestedCleaned>::evalTo(m_result, lhs, rhs);
|
| 123 |
+
|
| 124 |
+
generic_product_impl<Lhs, Rhs, LhsShape, RhsShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
protected:
|
| 128 |
+
PlainObject m_result;
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
// The following three shortcuts are enabled only if the scalar types match exactly.
|
| 132 |
+
// TODO: we could enable them for different scalar types when the product is not vectorized.
|
| 133 |
+
|
| 134 |
+
// Dense = Product
|
| 135 |
+
template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar>
|
| 136 |
+
struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::assign_op<Scalar,Scalar>, Dense2Dense,
|
| 137 |
+
typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
|
| 138 |
+
{
|
| 139 |
+
typedef Product<Lhs,Rhs,Options> SrcXprType;
|
| 140 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 141 |
+
void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
|
| 142 |
+
{
|
| 143 |
+
Index dstRows = src.rows();
|
| 144 |
+
Index dstCols = src.cols();
|
| 145 |
+
if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
|
| 146 |
+
dst.resize(dstRows, dstCols);
|
| 147 |
+
// FIXME shall we handle nested_eval here?
|
| 148 |
+
generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs());
|
| 149 |
+
}
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
// Dense += Product
|
| 153 |
+
template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar>
|
| 154 |
+
struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::add_assign_op<Scalar,Scalar>, Dense2Dense,
|
| 155 |
+
typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
|
| 156 |
+
{
|
| 157 |
+
typedef Product<Lhs,Rhs,Options> SrcXprType;
|
| 158 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 159 |
+
void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<Scalar,Scalar> &)
|
| 160 |
+
{
|
| 161 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
| 162 |
+
// FIXME shall we handle nested_eval here?
|
| 163 |
+
generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs());
|
| 164 |
+
}
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
// Dense -= Product
|
| 168 |
+
template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar>
|
| 169 |
+
struct Assignment<DstXprType, Product<Lhs,Rhs,Options>, internal::sub_assign_op<Scalar,Scalar>, Dense2Dense,
|
| 170 |
+
typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
|
| 171 |
+
{
|
| 172 |
+
typedef Product<Lhs,Rhs,Options> SrcXprType;
|
| 173 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 174 |
+
void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<Scalar,Scalar> &)
|
| 175 |
+
{
|
| 176 |
+
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
| 177 |
+
// FIXME shall we handle nested_eval here?
|
| 178 |
+
generic_product_impl<Lhs, Rhs>::subTo(dst, src.lhs(), src.rhs());
|
| 179 |
+
}
|
| 180 |
+
};
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
// Dense ?= scalar * Product
|
| 184 |
+
// TODO we should apply that rule if that's really helpful
|
| 185 |
+
// for instance, this is not good for inner products
|
| 186 |
+
template< typename DstXprType, typename Lhs, typename Rhs, typename AssignFunc, typename Scalar, typename ScalarBis, typename Plain>
|
| 187 |
+
struct Assignment<DstXprType, CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>, const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>,
|
| 188 |
+
const Product<Lhs,Rhs,DefaultProduct> >, AssignFunc, Dense2Dense>
|
| 189 |
+
{
|
| 190 |
+
typedef CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>,
|
| 191 |
+
const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>,
|
| 192 |
+
const Product<Lhs,Rhs,DefaultProduct> > SrcXprType;
|
| 193 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 194 |
+
void run(DstXprType &dst, const SrcXprType &src, const AssignFunc& func)
|
| 195 |
+
{
|
| 196 |
+
call_assignment_no_alias(dst, (src.lhs().functor().m_other * src.rhs().lhs())*src.rhs().rhs(), func);
|
| 197 |
+
}
|
| 198 |
+
};
|
| 199 |
+
|
| 200 |
+
//----------------------------------------
|
| 201 |
+
// Catch "Dense ?= xpr + Product<>" expression to save one temporary
|
| 202 |
+
// FIXME we could probably enable these rules for any product, i.e., not only Dense and DefaultProduct
|
| 203 |
+
|
| 204 |
+
template<typename OtherXpr, typename Lhs, typename Rhs>
|
| 205 |
+
struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_sum_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr,
|
| 206 |
+
const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > {
|
| 207 |
+
static const bool value = true;
|
| 208 |
+
};
|
| 209 |
+
|
| 210 |
+
template<typename OtherXpr, typename Lhs, typename Rhs>
|
| 211 |
+
struct evaluator_assume_aliasing<CwiseBinaryOp<internal::scalar_difference_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr,
|
| 212 |
+
const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > {
|
| 213 |
+
static const bool value = true;
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
template<typename DstXprType, typename OtherXpr, typename ProductType, typename Func1, typename Func2>
|
| 217 |
+
struct assignment_from_xpr_op_product
|
| 218 |
+
{
|
| 219 |
+
template<typename SrcXprType, typename InitialFunc>
|
| 220 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 221 |
+
void run(DstXprType &dst, const SrcXprType &src, const InitialFunc& /*func*/)
|
| 222 |
+
{
|
| 223 |
+
call_assignment_no_alias(dst, src.lhs(), Func1());
|
| 224 |
+
call_assignment_no_alias(dst, src.rhs(), Func2());
|
| 225 |
+
}
|
| 226 |
+
};
|
| 227 |
+
|
| 228 |
+
#define EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(ASSIGN_OP,BINOP,ASSIGN_OP2) \
|
| 229 |
+
template< typename DstXprType, typename OtherXpr, typename Lhs, typename Rhs, typename DstScalar, typename SrcScalar, typename OtherScalar,typename ProdScalar> \
|
| 230 |
+
struct Assignment<DstXprType, CwiseBinaryOp<internal::BINOP<OtherScalar,ProdScalar>, const OtherXpr, \
|
| 231 |
+
const Product<Lhs,Rhs,DefaultProduct> >, internal::ASSIGN_OP<DstScalar,SrcScalar>, Dense2Dense> \
|
| 232 |
+
: assignment_from_xpr_op_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, internal::ASSIGN_OP<DstScalar,OtherScalar>, internal::ASSIGN_OP2<DstScalar,ProdScalar> > \
|
| 233 |
+
{}
|
| 234 |
+
|
| 235 |
+
EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_sum_op,add_assign_op);
|
| 236 |
+
EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_sum_op,add_assign_op);
|
| 237 |
+
EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_sum_op,sub_assign_op);
|
| 238 |
+
|
| 239 |
+
EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_difference_op,sub_assign_op);
|
| 240 |
+
EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_difference_op,sub_assign_op);
|
| 241 |
+
EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_difference_op,add_assign_op);
|
| 242 |
+
|
| 243 |
+
//----------------------------------------
|
| 244 |
+
|
| 245 |
+
template<typename Lhs, typename Rhs>
|
| 246 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,InnerProduct>
|
| 247 |
+
{
|
| 248 |
+
template<typename Dst>
|
| 249 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 250 |
+
{
|
| 251 |
+
dst.coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum();
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
template<typename Dst>
|
| 255 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 256 |
+
{
|
| 257 |
+
dst.coeffRef(0,0) += (lhs.transpose().cwiseProduct(rhs)).sum();
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
template<typename Dst>
|
| 261 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 262 |
+
{ dst.coeffRef(0,0) -= (lhs.transpose().cwiseProduct(rhs)).sum(); }
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
/***********************************************************************
|
| 267 |
+
* Implementation of outer dense * dense vector product
|
| 268 |
+
***********************************************************************/
|
| 269 |
+
|
| 270 |
+
// Column major result
|
| 271 |
+
template<typename Dst, typename Lhs, typename Rhs, typename Func>
|
| 272 |
+
void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const false_type&)
|
| 273 |
+
{
|
| 274 |
+
evaluator<Rhs> rhsEval(rhs);
|
| 275 |
+
ei_declare_local_nested_eval(Lhs,lhs,Rhs::SizeAtCompileTime,actual_lhs);
|
| 276 |
+
// FIXME if cols is large enough, then it might be useful to make sure that lhs is sequentially stored
|
| 277 |
+
// FIXME not very good if rhs is real and lhs complex while alpha is real too
|
| 278 |
+
const Index cols = dst.cols();
|
| 279 |
+
for (Index j=0; j<cols; ++j)
|
| 280 |
+
func(dst.col(j), rhsEval.coeff(Index(0),j) * actual_lhs);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
// Row major result
|
| 284 |
+
template<typename Dst, typename Lhs, typename Rhs, typename Func>
|
| 285 |
+
void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs &lhs, const Rhs &rhs, const Func& func, const true_type&)
|
| 286 |
+
{
|
| 287 |
+
evaluator<Lhs> lhsEval(lhs);
|
| 288 |
+
ei_declare_local_nested_eval(Rhs,rhs,Lhs::SizeAtCompileTime,actual_rhs);
|
| 289 |
+
// FIXME if rows is large enough, then it might be useful to make sure that rhs is sequentially stored
|
| 290 |
+
// FIXME not very good if lhs is real and rhs complex while alpha is real too
|
| 291 |
+
const Index rows = dst.rows();
|
| 292 |
+
for (Index i=0; i<rows; ++i)
|
| 293 |
+
func(dst.row(i), lhsEval.coeff(i,Index(0)) * actual_rhs);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
template<typename Lhs, typename Rhs>
|
| 297 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,OuterProduct>
|
| 298 |
+
{
|
| 299 |
+
template<typename T> struct is_row_major : internal::conditional<(int(T::Flags)&RowMajorBit), internal::true_type, internal::false_type>::type {};
|
| 300 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 301 |
+
|
| 302 |
+
// TODO it would be nice to be able to exploit our *_assign_op functors for that purpose
|
| 303 |
+
struct set { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() = src; } };
|
| 304 |
+
struct add { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() += src; } };
|
| 305 |
+
struct sub { template<typename Dst, typename Src> EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { dst.const_cast_derived() -= src; } };
|
| 306 |
+
struct adds {
|
| 307 |
+
Scalar m_scale;
|
| 308 |
+
explicit adds(const Scalar& s) : m_scale(s) {}
|
| 309 |
+
template<typename Dst, typename Src> void EIGEN_DEVICE_FUNC operator()(const Dst& dst, const Src& src) const {
|
| 310 |
+
dst.const_cast_derived() += m_scale * src;
|
| 311 |
+
}
|
| 312 |
+
};
|
| 313 |
+
|
| 314 |
+
template<typename Dst>
|
| 315 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 316 |
+
{
|
| 317 |
+
internal::outer_product_selector_run(dst, lhs, rhs, set(), is_row_major<Dst>());
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
template<typename Dst>
|
| 321 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 322 |
+
{
|
| 323 |
+
internal::outer_product_selector_run(dst, lhs, rhs, add(), is_row_major<Dst>());
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
template<typename Dst>
|
| 327 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 328 |
+
{
|
| 329 |
+
internal::outer_product_selector_run(dst, lhs, rhs, sub(), is_row_major<Dst>());
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
template<typename Dst>
|
| 333 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 334 |
+
{
|
| 335 |
+
internal::outer_product_selector_run(dst, lhs, rhs, adds(alpha), is_row_major<Dst>());
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
};
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
// This base class provides default implementations for evalTo, addTo, subTo, in terms of scaleAndAddTo
|
| 342 |
+
template<typename Lhs, typename Rhs, typename Derived>
|
| 343 |
+
struct generic_product_impl_base
|
| 344 |
+
{
|
| 345 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 346 |
+
|
| 347 |
+
template<typename Dst>
|
| 348 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 349 |
+
{ dst.setZero(); scaleAndAddTo(dst, lhs, rhs, Scalar(1)); }
|
| 350 |
+
|
| 351 |
+
template<typename Dst>
|
| 352 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 353 |
+
{ scaleAndAddTo(dst,lhs, rhs, Scalar(1)); }
|
| 354 |
+
|
| 355 |
+
template<typename Dst>
|
| 356 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 357 |
+
{ scaleAndAddTo(dst, lhs, rhs, Scalar(-1)); }
|
| 358 |
+
|
| 359 |
+
template<typename Dst>
|
| 360 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 361 |
+
{ Derived::scaleAndAddTo(dst,lhs,rhs,alpha); }
|
| 362 |
+
|
| 363 |
+
};
|
| 364 |
+
|
| 365 |
+
template<typename Lhs, typename Rhs>
|
| 366 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct>
|
| 367 |
+
: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct> >
|
| 368 |
+
{
|
| 369 |
+
typedef typename nested_eval<Lhs,1>::type LhsNested;
|
| 370 |
+
typedef typename nested_eval<Rhs,1>::type RhsNested;
|
| 371 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 372 |
+
enum { Side = Lhs::IsVectorAtCompileTime ? OnTheLeft : OnTheRight };
|
| 373 |
+
typedef typename internal::remove_all<typename internal::conditional<int(Side)==OnTheRight,LhsNested,RhsNested>::type>::type MatrixType;
|
| 374 |
+
|
| 375 |
+
template<typename Dest>
|
| 376 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 377 |
+
{
|
| 378 |
+
// Fallback to inner product if both the lhs and rhs is a runtime vector.
|
| 379 |
+
if (lhs.rows() == 1 && rhs.cols() == 1) {
|
| 380 |
+
dst.coeffRef(0,0) += alpha * lhs.row(0).conjugate().dot(rhs.col(0));
|
| 381 |
+
return;
|
| 382 |
+
}
|
| 383 |
+
LhsNested actual_lhs(lhs);
|
| 384 |
+
RhsNested actual_rhs(rhs);
|
| 385 |
+
internal::gemv_dense_selector<Side,
|
| 386 |
+
(int(MatrixType::Flags)&RowMajorBit) ? RowMajor : ColMajor,
|
| 387 |
+
bool(internal::blas_traits<MatrixType>::HasUsableDirectAccess)
|
| 388 |
+
>::run(actual_lhs, actual_rhs, dst, alpha);
|
| 389 |
+
}
|
| 390 |
+
};
|
| 391 |
+
|
| 392 |
+
template<typename Lhs, typename Rhs>
|
| 393 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode>
|
| 394 |
+
{
|
| 395 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 396 |
+
|
| 397 |
+
template<typename Dst>
|
| 398 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 399 |
+
{
|
| 400 |
+
// Same as: dst.noalias() = lhs.lazyProduct(rhs);
|
| 401 |
+
// but easier on the compiler side
|
| 402 |
+
call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::assign_op<typename Dst::Scalar,Scalar>());
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
template<typename Dst>
|
| 406 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 407 |
+
{
|
| 408 |
+
// dst.noalias() += lhs.lazyProduct(rhs);
|
| 409 |
+
call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::add_assign_op<typename Dst::Scalar,Scalar>());
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
template<typename Dst>
|
| 413 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs)
|
| 414 |
+
{
|
| 415 |
+
// dst.noalias() -= lhs.lazyProduct(rhs);
|
| 416 |
+
call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::sub_assign_op<typename Dst::Scalar,Scalar>());
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// This is a special evaluation path called from generic_product_impl<...,GemmProduct> in file GeneralMatrixMatrix.h
|
| 420 |
+
// This variant tries to extract scalar multiples from both the LHS and RHS and factor them out. For instance:
|
| 421 |
+
// dst {,+,-}= (s1*A)*(B*s2)
|
| 422 |
+
// will be rewritten as:
|
| 423 |
+
// dst {,+,-}= (s1*s2) * (A.lazyProduct(B))
|
| 424 |
+
// There are at least four benefits of doing so:
|
| 425 |
+
// 1 - huge performance gain for heap-allocated matrix types as it save costly allocations.
|
| 426 |
+
// 2 - it is faster than simply by-passing the heap allocation through stack allocation.
|
| 427 |
+
// 3 - it makes this fallback consistent with the heavy GEMM routine.
|
| 428 |
+
// 4 - it fully by-passes huge stack allocation attempts when multiplying huge fixed-size matrices.
|
| 429 |
+
// (see https://stackoverflow.com/questions/54738495)
|
| 430 |
+
// For small fixed sizes matrices, howver, the gains are less obvious, it is sometimes x2 faster, but sometimes x3 slower,
|
| 431 |
+
// and the behavior depends also a lot on the compiler... This is why this re-writting strategy is currently
|
| 432 |
+
// enabled only when falling back from the main GEMM.
|
| 433 |
+
template<typename Dst, typename Func>
|
| 434 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 435 |
+
void eval_dynamic(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Func &func)
|
| 436 |
+
{
|
| 437 |
+
enum {
|
| 438 |
+
HasScalarFactor = blas_traits<Lhs>::HasScalarFactor || blas_traits<Rhs>::HasScalarFactor,
|
| 439 |
+
ConjLhs = blas_traits<Lhs>::NeedToConjugate,
|
| 440 |
+
ConjRhs = blas_traits<Rhs>::NeedToConjugate
|
| 441 |
+
};
|
| 442 |
+
// FIXME: in c++11 this should be auto, and extractScalarFactor should also return auto
|
| 443 |
+
// this is important for real*complex_mat
|
| 444 |
+
Scalar actualAlpha = combine_scalar_factors<Scalar>(lhs, rhs);
|
| 445 |
+
|
| 446 |
+
eval_dynamic_impl(dst,
|
| 447 |
+
blas_traits<Lhs>::extract(lhs).template conjugateIf<ConjLhs>(),
|
| 448 |
+
blas_traits<Rhs>::extract(rhs).template conjugateIf<ConjRhs>(),
|
| 449 |
+
func,
|
| 450 |
+
actualAlpha,
|
| 451 |
+
typename conditional<HasScalarFactor,true_type,false_type>::type());
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
protected:
|
| 455 |
+
|
| 456 |
+
template<typename Dst, typename LhsT, typename RhsT, typename Func, typename Scalar>
|
| 457 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 458 |
+
void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, const Func &func, const Scalar& s /* == 1 */, false_type)
|
| 459 |
+
{
|
| 460 |
+
EIGEN_UNUSED_VARIABLE(s);
|
| 461 |
+
eigen_internal_assert(s==Scalar(1));
|
| 462 |
+
call_restricted_packet_assignment_no_alias(dst, lhs.lazyProduct(rhs), func);
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
template<typename Dst, typename LhsT, typename RhsT, typename Func, typename Scalar>
|
| 466 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 467 |
+
void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, const Func &func, const Scalar& s, true_type)
|
| 468 |
+
{
|
| 469 |
+
call_restricted_packet_assignment_no_alias(dst, s * lhs.lazyProduct(rhs), func);
|
| 470 |
+
}
|
| 471 |
+
};
|
| 472 |
+
|
| 473 |
+
// This specialization enforces the use of a coefficient-based evaluation strategy
|
| 474 |
+
template<typename Lhs, typename Rhs>
|
| 475 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,LazyCoeffBasedProductMode>
|
| 476 |
+
: generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> {};
|
| 477 |
+
|
| 478 |
+
// Case 2: Evaluate coeff by coeff
|
| 479 |
+
//
|
| 480 |
+
// This is mostly taken from CoeffBasedProduct.h
|
| 481 |
+
// The main difference is that we add an extra argument to the etor_product_*_impl::run() function
|
| 482 |
+
// for the inner dimension of the product, because evaluator object do not know their size.
|
| 483 |
+
|
| 484 |
+
template<int Traversal, int UnrollingIndex, typename Lhs, typename Rhs, typename RetScalar>
|
| 485 |
+
struct etor_product_coeff_impl;
|
| 486 |
+
|
| 487 |
+
template<int StorageOrder, int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 488 |
+
struct etor_product_packet_impl;
|
| 489 |
+
|
| 490 |
+
template<typename Lhs, typename Rhs, int ProductTag>
|
| 491 |
+
struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, DenseShape>
|
| 492 |
+
: evaluator_base<Product<Lhs, Rhs, LazyProduct> >
|
| 493 |
+
{
|
| 494 |
+
typedef Product<Lhs, Rhs, LazyProduct> XprType;
|
| 495 |
+
typedef typename XprType::Scalar Scalar;
|
| 496 |
+
typedef typename XprType::CoeffReturnType CoeffReturnType;
|
| 497 |
+
|
| 498 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 499 |
+
explicit product_evaluator(const XprType& xpr)
|
| 500 |
+
: m_lhs(xpr.lhs()),
|
| 501 |
+
m_rhs(xpr.rhs()),
|
| 502 |
+
m_lhsImpl(m_lhs), // FIXME the creation of the evaluator objects should result in a no-op, but check that!
|
| 503 |
+
m_rhsImpl(m_rhs), // Moreover, they are only useful for the packet path, so we could completely disable them when not needed,
|
| 504 |
+
// or perhaps declare them on the fly on the packet method... We have experiment to check what's best.
|
| 505 |
+
m_innerDim(xpr.lhs().cols())
|
| 506 |
+
{
|
| 507 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost);
|
| 508 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::AddCost);
|
| 509 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
|
| 510 |
+
#if 0
|
| 511 |
+
std::cerr << "LhsOuterStrideBytes= " << LhsOuterStrideBytes << "\n";
|
| 512 |
+
std::cerr << "RhsOuterStrideBytes= " << RhsOuterStrideBytes << "\n";
|
| 513 |
+
std::cerr << "LhsAlignment= " << LhsAlignment << "\n";
|
| 514 |
+
std::cerr << "RhsAlignment= " << RhsAlignment << "\n";
|
| 515 |
+
std::cerr << "CanVectorizeLhs= " << CanVectorizeLhs << "\n";
|
| 516 |
+
std::cerr << "CanVectorizeRhs= " << CanVectorizeRhs << "\n";
|
| 517 |
+
std::cerr << "CanVectorizeInner= " << CanVectorizeInner << "\n";
|
| 518 |
+
std::cerr << "EvalToRowMajor= " << EvalToRowMajor << "\n";
|
| 519 |
+
std::cerr << "Alignment= " << Alignment << "\n";
|
| 520 |
+
std::cerr << "Flags= " << Flags << "\n";
|
| 521 |
+
#endif
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
// Everything below here is taken from CoeffBasedProduct.h
|
| 525 |
+
|
| 526 |
+
typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested;
|
| 527 |
+
typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested;
|
| 528 |
+
|
| 529 |
+
typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
|
| 530 |
+
typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
|
| 531 |
+
|
| 532 |
+
typedef evaluator<LhsNestedCleaned> LhsEtorType;
|
| 533 |
+
typedef evaluator<RhsNestedCleaned> RhsEtorType;
|
| 534 |
+
|
| 535 |
+
enum {
|
| 536 |
+
RowsAtCompileTime = LhsNestedCleaned::RowsAtCompileTime,
|
| 537 |
+
ColsAtCompileTime = RhsNestedCleaned::ColsAtCompileTime,
|
| 538 |
+
InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsNestedCleaned::ColsAtCompileTime, RhsNestedCleaned::RowsAtCompileTime),
|
| 539 |
+
MaxRowsAtCompileTime = LhsNestedCleaned::MaxRowsAtCompileTime,
|
| 540 |
+
MaxColsAtCompileTime = RhsNestedCleaned::MaxColsAtCompileTime
|
| 541 |
+
};
|
| 542 |
+
|
| 543 |
+
typedef typename find_best_packet<Scalar,RowsAtCompileTime>::type LhsVecPacketType;
|
| 544 |
+
typedef typename find_best_packet<Scalar,ColsAtCompileTime>::type RhsVecPacketType;
|
| 545 |
+
|
| 546 |
+
enum {
|
| 547 |
+
|
| 548 |
+
LhsCoeffReadCost = LhsEtorType::CoeffReadCost,
|
| 549 |
+
RhsCoeffReadCost = RhsEtorType::CoeffReadCost,
|
| 550 |
+
CoeffReadCost = InnerSize==0 ? NumTraits<Scalar>::ReadCost
|
| 551 |
+
: InnerSize == Dynamic ? HugeCost
|
| 552 |
+
: InnerSize * (NumTraits<Scalar>::MulCost + int(LhsCoeffReadCost) + int(RhsCoeffReadCost))
|
| 553 |
+
+ (InnerSize - 1) * NumTraits<Scalar>::AddCost,
|
| 554 |
+
|
| 555 |
+
Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT,
|
| 556 |
+
|
| 557 |
+
LhsFlags = LhsEtorType::Flags,
|
| 558 |
+
RhsFlags = RhsEtorType::Flags,
|
| 559 |
+
|
| 560 |
+
LhsRowMajor = LhsFlags & RowMajorBit,
|
| 561 |
+
RhsRowMajor = RhsFlags & RowMajorBit,
|
| 562 |
+
|
| 563 |
+
LhsVecPacketSize = unpacket_traits<LhsVecPacketType>::size,
|
| 564 |
+
RhsVecPacketSize = unpacket_traits<RhsVecPacketType>::size,
|
| 565 |
+
|
| 566 |
+
// Here, we don't care about alignment larger than the usable packet size.
|
| 567 |
+
LhsAlignment = EIGEN_PLAIN_ENUM_MIN(LhsEtorType::Alignment,LhsVecPacketSize*int(sizeof(typename LhsNestedCleaned::Scalar))),
|
| 568 |
+
RhsAlignment = EIGEN_PLAIN_ENUM_MIN(RhsEtorType::Alignment,RhsVecPacketSize*int(sizeof(typename RhsNestedCleaned::Scalar))),
|
| 569 |
+
|
| 570 |
+
SameType = is_same<typename LhsNestedCleaned::Scalar,typename RhsNestedCleaned::Scalar>::value,
|
| 571 |
+
|
| 572 |
+
CanVectorizeRhs = bool(RhsRowMajor) && (RhsFlags & PacketAccessBit) && (ColsAtCompileTime!=1),
|
| 573 |
+
CanVectorizeLhs = (!LhsRowMajor) && (LhsFlags & PacketAccessBit) && (RowsAtCompileTime!=1),
|
| 574 |
+
|
| 575 |
+
EvalToRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
|
| 576 |
+
: (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
|
| 577 |
+
: (bool(RhsRowMajor) && !CanVectorizeLhs),
|
| 578 |
+
|
| 579 |
+
Flags = ((int(LhsFlags) | int(RhsFlags)) & HereditaryBits & ~RowMajorBit)
|
| 580 |
+
| (EvalToRowMajor ? RowMajorBit : 0)
|
| 581 |
+
// TODO enable vectorization for mixed types
|
| 582 |
+
| (SameType && (CanVectorizeLhs || CanVectorizeRhs) ? PacketAccessBit : 0)
|
| 583 |
+
| (XprType::IsVectorAtCompileTime ? LinearAccessBit : 0),
|
| 584 |
+
|
| 585 |
+
LhsOuterStrideBytes = int(LhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename LhsNestedCleaned::Scalar)),
|
| 586 |
+
RhsOuterStrideBytes = int(RhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename RhsNestedCleaned::Scalar)),
|
| 587 |
+
|
| 588 |
+
Alignment = bool(CanVectorizeLhs) ? (LhsOuterStrideBytes<=0 || (int(LhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,LhsAlignment))!=0 ? 0 : LhsAlignment)
|
| 589 |
+
: bool(CanVectorizeRhs) ? (RhsOuterStrideBytes<=0 || (int(RhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,RhsAlignment))!=0 ? 0 : RhsAlignment)
|
| 590 |
+
: 0,
|
| 591 |
+
|
| 592 |
+
/* CanVectorizeInner deserves special explanation. It does not affect the product flags. It is not used outside
|
| 593 |
+
* of Product. If the Product itself is not a packet-access expression, there is still a chance that the inner
|
| 594 |
+
* loop of the product might be vectorized. This is the meaning of CanVectorizeInner. Since it doesn't affect
|
| 595 |
+
* the Flags, it is safe to make this value depend on ActualPacketAccessBit, that doesn't affect the ABI.
|
| 596 |
+
*/
|
| 597 |
+
CanVectorizeInner = SameType
|
| 598 |
+
&& LhsRowMajor
|
| 599 |
+
&& (!RhsRowMajor)
|
| 600 |
+
&& (int(LhsFlags) & int(RhsFlags) & ActualPacketAccessBit)
|
| 601 |
+
&& (int(InnerSize) % packet_traits<Scalar>::size == 0)
|
| 602 |
+
};
|
| 603 |
+
|
| 604 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index row, Index col) const
|
| 605 |
+
{
|
| 606 |
+
return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
/* Allow index-based non-packet access. It is impossible though to allow index-based packed access,
|
| 610 |
+
* which is why we don't set the LinearAccessBit.
|
| 611 |
+
* TODO: this seems possible when the result is a vector
|
| 612 |
+
*/
|
| 613 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 614 |
+
const CoeffReturnType coeff(Index index) const
|
| 615 |
+
{
|
| 616 |
+
const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index;
|
| 617 |
+
const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0;
|
| 618 |
+
return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
template<int LoadMode, typename PacketType>
|
| 622 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 623 |
+
const PacketType packet(Index row, Index col) const
|
| 624 |
+
{
|
| 625 |
+
PacketType res;
|
| 626 |
+
typedef etor_product_packet_impl<bool(int(Flags)&RowMajorBit) ? RowMajor : ColMajor,
|
| 627 |
+
Unroll ? int(InnerSize) : Dynamic,
|
| 628 |
+
LhsEtorType, RhsEtorType, PacketType, LoadMode> PacketImpl;
|
| 629 |
+
PacketImpl::run(row, col, m_lhsImpl, m_rhsImpl, m_innerDim, res);
|
| 630 |
+
return res;
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
template<int LoadMode, typename PacketType>
|
| 634 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 635 |
+
const PacketType packet(Index index) const
|
| 636 |
+
{
|
| 637 |
+
const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index;
|
| 638 |
+
const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0;
|
| 639 |
+
return packet<LoadMode,PacketType>(row,col);
|
| 640 |
+
}
|
| 641 |
+
|
| 642 |
+
protected:
|
| 643 |
+
typename internal::add_const_on_value_type<LhsNested>::type m_lhs;
|
| 644 |
+
typename internal::add_const_on_value_type<RhsNested>::type m_rhs;
|
| 645 |
+
|
| 646 |
+
LhsEtorType m_lhsImpl;
|
| 647 |
+
RhsEtorType m_rhsImpl;
|
| 648 |
+
|
| 649 |
+
// TODO: Get rid of m_innerDim if known at compile time
|
| 650 |
+
Index m_innerDim;
|
| 651 |
+
};
|
| 652 |
+
|
| 653 |
+
template<typename Lhs, typename Rhs>
|
| 654 |
+
struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, LazyCoeffBasedProductMode, DenseShape, DenseShape>
|
| 655 |
+
: product_evaluator<Product<Lhs, Rhs, LazyProduct>, CoeffBasedProductMode, DenseShape, DenseShape>
|
| 656 |
+
{
|
| 657 |
+
typedef Product<Lhs, Rhs, DefaultProduct> XprType;
|
| 658 |
+
typedef Product<Lhs, Rhs, LazyProduct> BaseProduct;
|
| 659 |
+
typedef product_evaluator<BaseProduct, CoeffBasedProductMode, DenseShape, DenseShape> Base;
|
| 660 |
+
enum {
|
| 661 |
+
Flags = Base::Flags | EvalBeforeNestingBit
|
| 662 |
+
};
|
| 663 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 664 |
+
explicit product_evaluator(const XprType& xpr)
|
| 665 |
+
: Base(BaseProduct(xpr.lhs(),xpr.rhs()))
|
| 666 |
+
{}
|
| 667 |
+
};
|
| 668 |
+
|
| 669 |
+
/****************************************
|
| 670 |
+
*** Coeff based product, Packet path ***
|
| 671 |
+
****************************************/
|
| 672 |
+
|
| 673 |
+
template<int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 674 |
+
struct etor_product_packet_impl<RowMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode>
|
| 675 |
+
{
|
| 676 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet &res)
|
| 677 |
+
{
|
| 678 |
+
etor_product_packet_impl<RowMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res);
|
| 679 |
+
res = pmadd(pset1<Packet>(lhs.coeff(row, Index(UnrollingIndex-1))), rhs.template packet<LoadMode,Packet>(Index(UnrollingIndex-1), col), res);
|
| 680 |
+
}
|
| 681 |
+
};
|
| 682 |
+
|
| 683 |
+
template<int UnrollingIndex, typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 684 |
+
struct etor_product_packet_impl<ColMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode>
|
| 685 |
+
{
|
| 686 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet &res)
|
| 687 |
+
{
|
| 688 |
+
etor_product_packet_impl<ColMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res);
|
| 689 |
+
res = pmadd(lhs.template packet<LoadMode,Packet>(row, Index(UnrollingIndex-1)), pset1<Packet>(rhs.coeff(Index(UnrollingIndex-1), col)), res);
|
| 690 |
+
}
|
| 691 |
+
};
|
| 692 |
+
|
| 693 |
+
template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 694 |
+
struct etor_product_packet_impl<RowMajor, 1, Lhs, Rhs, Packet, LoadMode>
|
| 695 |
+
{
|
| 696 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index /*innerDim*/, Packet &res)
|
| 697 |
+
{
|
| 698 |
+
res = pmul(pset1<Packet>(lhs.coeff(row, Index(0))),rhs.template packet<LoadMode,Packet>(Index(0), col));
|
| 699 |
+
}
|
| 700 |
+
};
|
| 701 |
+
|
| 702 |
+
template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 703 |
+
struct etor_product_packet_impl<ColMajor, 1, Lhs, Rhs, Packet, LoadMode>
|
| 704 |
+
{
|
| 705 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index /*innerDim*/, Packet &res)
|
| 706 |
+
{
|
| 707 |
+
res = pmul(lhs.template packet<LoadMode,Packet>(row, Index(0)), pset1<Packet>(rhs.coeff(Index(0), col)));
|
| 708 |
+
}
|
| 709 |
+
};
|
| 710 |
+
|
| 711 |
+
template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 712 |
+
struct etor_product_packet_impl<RowMajor, 0, Lhs, Rhs, Packet, LoadMode>
|
| 713 |
+
{
|
| 714 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, const Rhs& /*rhs*/, Index /*innerDim*/, Packet &res)
|
| 715 |
+
{
|
| 716 |
+
res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
|
| 717 |
+
}
|
| 718 |
+
};
|
| 719 |
+
|
| 720 |
+
template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 721 |
+
struct etor_product_packet_impl<ColMajor, 0, Lhs, Rhs, Packet, LoadMode>
|
| 722 |
+
{
|
| 723 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, const Rhs& /*rhs*/, Index /*innerDim*/, Packet &res)
|
| 724 |
+
{
|
| 725 |
+
res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
|
| 726 |
+
}
|
| 727 |
+
};
|
| 728 |
+
|
| 729 |
+
template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 730 |
+
struct etor_product_packet_impl<RowMajor, Dynamic, Lhs, Rhs, Packet, LoadMode>
|
| 731 |
+
{
|
| 732 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet& res)
|
| 733 |
+
{
|
| 734 |
+
res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
|
| 735 |
+
for(Index i = 0; i < innerDim; ++i)
|
| 736 |
+
res = pmadd(pset1<Packet>(lhs.coeff(row, i)), rhs.template packet<LoadMode,Packet>(i, col), res);
|
| 737 |
+
}
|
| 738 |
+
};
|
| 739 |
+
|
| 740 |
+
template<typename Lhs, typename Rhs, typename Packet, int LoadMode>
|
| 741 |
+
struct etor_product_packet_impl<ColMajor, Dynamic, Lhs, Rhs, Packet, LoadMode>
|
| 742 |
+
{
|
| 743 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, Index innerDim, Packet& res)
|
| 744 |
+
{
|
| 745 |
+
res = pset1<Packet>(typename unpacket_traits<Packet>::type(0));
|
| 746 |
+
for(Index i = 0; i < innerDim; ++i)
|
| 747 |
+
res = pmadd(lhs.template packet<LoadMode,Packet>(row, i), pset1<Packet>(rhs.coeff(i, col)), res);
|
| 748 |
+
}
|
| 749 |
+
};
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
/***************************************************************************
|
| 753 |
+
* Triangular products
|
| 754 |
+
***************************************************************************/
|
| 755 |
+
template<int Mode, bool LhsIsTriangular,
|
| 756 |
+
typename Lhs, bool LhsIsVector,
|
| 757 |
+
typename Rhs, bool RhsIsVector>
|
| 758 |
+
struct triangular_product_impl;
|
| 759 |
+
|
| 760 |
+
template<typename Lhs, typename Rhs, int ProductTag>
|
| 761 |
+
struct generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag>
|
| 762 |
+
: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag> >
|
| 763 |
+
{
|
| 764 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 765 |
+
|
| 766 |
+
template<typename Dest>
|
| 767 |
+
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 768 |
+
{
|
| 769 |
+
triangular_product_impl<Lhs::Mode,true,typename Lhs::MatrixType,false,Rhs, Rhs::ColsAtCompileTime==1>
|
| 770 |
+
::run(dst, lhs.nestedExpression(), rhs, alpha);
|
| 771 |
+
}
|
| 772 |
+
};
|
| 773 |
+
|
| 774 |
+
template<typename Lhs, typename Rhs, int ProductTag>
|
| 775 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag>
|
| 776 |
+
: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag> >
|
| 777 |
+
{
|
| 778 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 779 |
+
|
| 780 |
+
template<typename Dest>
|
| 781 |
+
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 782 |
+
{
|
| 783 |
+
triangular_product_impl<Rhs::Mode,false,Lhs,Lhs::RowsAtCompileTime==1, typename Rhs::MatrixType, false>::run(dst, lhs, rhs.nestedExpression(), alpha);
|
| 784 |
+
}
|
| 785 |
+
};
|
| 786 |
+
|
| 787 |
+
|
| 788 |
+
/***************************************************************************
|
| 789 |
+
* SelfAdjoint products
|
| 790 |
+
***************************************************************************/
|
| 791 |
+
template <typename Lhs, int LhsMode, bool LhsIsVector,
|
| 792 |
+
typename Rhs, int RhsMode, bool RhsIsVector>
|
| 793 |
+
struct selfadjoint_product_impl;
|
| 794 |
+
|
| 795 |
+
template<typename Lhs, typename Rhs, int ProductTag>
|
| 796 |
+
struct generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag>
|
| 797 |
+
: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag> >
|
| 798 |
+
{
|
| 799 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 800 |
+
|
| 801 |
+
template<typename Dest>
|
| 802 |
+
static EIGEN_DEVICE_FUNC
|
| 803 |
+
void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 804 |
+
{
|
| 805 |
+
selfadjoint_product_impl<typename Lhs::MatrixType,Lhs::Mode,false,Rhs,0,Rhs::IsVectorAtCompileTime>::run(dst, lhs.nestedExpression(), rhs, alpha);
|
| 806 |
+
}
|
| 807 |
+
};
|
| 808 |
+
|
| 809 |
+
template<typename Lhs, typename Rhs, int ProductTag>
|
| 810 |
+
struct generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag>
|
| 811 |
+
: generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag> >
|
| 812 |
+
{
|
| 813 |
+
typedef typename Product<Lhs,Rhs>::Scalar Scalar;
|
| 814 |
+
|
| 815 |
+
template<typename Dest>
|
| 816 |
+
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
|
| 817 |
+
{
|
| 818 |
+
selfadjoint_product_impl<Lhs,0,Lhs::IsVectorAtCompileTime,typename Rhs::MatrixType,Rhs::Mode,false>::run(dst, lhs, rhs.nestedExpression(), alpha);
|
| 819 |
+
}
|
| 820 |
+
};
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
/***************************************************************************
|
| 824 |
+
* Diagonal products
|
| 825 |
+
***************************************************************************/
|
| 826 |
+
|
| 827 |
+
template<typename MatrixType, typename DiagonalType, typename Derived, int ProductOrder>
|
| 828 |
+
struct diagonal_product_evaluator_base
|
| 829 |
+
: evaluator_base<Derived>
|
| 830 |
+
{
|
| 831 |
+
typedef typename ScalarBinaryOpTraits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar;
|
| 832 |
+
public:
|
| 833 |
+
enum {
|
| 834 |
+
CoeffReadCost = int(NumTraits<Scalar>::MulCost) + int(evaluator<MatrixType>::CoeffReadCost) + int(evaluator<DiagonalType>::CoeffReadCost),
|
| 835 |
+
|
| 836 |
+
MatrixFlags = evaluator<MatrixType>::Flags,
|
| 837 |
+
DiagFlags = evaluator<DiagonalType>::Flags,
|
| 838 |
+
|
| 839 |
+
_StorageOrder = (Derived::MaxRowsAtCompileTime==1 && Derived::MaxColsAtCompileTime!=1) ? RowMajor
|
| 840 |
+
: (Derived::MaxColsAtCompileTime==1 && Derived::MaxRowsAtCompileTime!=1) ? ColMajor
|
| 841 |
+
: MatrixFlags & RowMajorBit ? RowMajor : ColMajor,
|
| 842 |
+
_SameStorageOrder = _StorageOrder == (MatrixFlags & RowMajorBit ? RowMajor : ColMajor),
|
| 843 |
+
|
| 844 |
+
_ScalarAccessOnDiag = !((int(_StorageOrder) == ColMajor && int(ProductOrder) == OnTheLeft)
|
| 845 |
+
||(int(_StorageOrder) == RowMajor && int(ProductOrder) == OnTheRight)),
|
| 846 |
+
_SameTypes = is_same<typename MatrixType::Scalar, typename DiagonalType::Scalar>::value,
|
| 847 |
+
// FIXME currently we need same types, but in the future the next rule should be the one
|
| 848 |
+
//_Vectorizable = bool(int(MatrixFlags)&PacketAccessBit) && ((!_PacketOnDiag) || (_SameTypes && bool(int(DiagFlags)&PacketAccessBit))),
|
| 849 |
+
_Vectorizable = bool(int(MatrixFlags)&PacketAccessBit)
|
| 850 |
+
&& _SameTypes
|
| 851 |
+
&& (_SameStorageOrder || (MatrixFlags&LinearAccessBit)==LinearAccessBit)
|
| 852 |
+
&& (_ScalarAccessOnDiag || (bool(int(DiagFlags)&PacketAccessBit))),
|
| 853 |
+
_LinearAccessMask = (MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1) ? LinearAccessBit : 0,
|
| 854 |
+
Flags = ((HereditaryBits|_LinearAccessMask) & (unsigned int)(MatrixFlags)) | (_Vectorizable ? PacketAccessBit : 0),
|
| 855 |
+
Alignment = evaluator<MatrixType>::Alignment,
|
| 856 |
+
|
| 857 |
+
AsScalarProduct = (DiagonalType::SizeAtCompileTime==1)
|
| 858 |
+
|| (DiagonalType::SizeAtCompileTime==Dynamic && MatrixType::RowsAtCompileTime==1 && ProductOrder==OnTheLeft)
|
| 859 |
+
|| (DiagonalType::SizeAtCompileTime==Dynamic && MatrixType::ColsAtCompileTime==1 && ProductOrder==OnTheRight)
|
| 860 |
+
};
|
| 861 |
+
|
| 862 |
+
EIGEN_DEVICE_FUNC diagonal_product_evaluator_base(const MatrixType &mat, const DiagonalType &diag)
|
| 863 |
+
: m_diagImpl(diag), m_matImpl(mat)
|
| 864 |
+
{
|
| 865 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost);
|
| 866 |
+
EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index idx) const
|
| 870 |
+
{
|
| 871 |
+
if(AsScalarProduct)
|
| 872 |
+
return m_diagImpl.coeff(0) * m_matImpl.coeff(idx);
|
| 873 |
+
else
|
| 874 |
+
return m_diagImpl.coeff(idx) * m_matImpl.coeff(idx);
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
protected:
|
| 878 |
+
template<int LoadMode,typename PacketType>
|
| 879 |
+
EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::true_type) const
|
| 880 |
+
{
|
| 881 |
+
return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
|
| 882 |
+
internal::pset1<PacketType>(m_diagImpl.coeff(id)));
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
template<int LoadMode,typename PacketType>
|
| 886 |
+
EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::false_type) const
|
| 887 |
+
{
|
| 888 |
+
enum {
|
| 889 |
+
InnerSize = (MatrixType::Flags & RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime,
|
| 890 |
+
DiagonalPacketLoadMode = EIGEN_PLAIN_ENUM_MIN(LoadMode,((InnerSize%16) == 0) ? int(Aligned16) : int(evaluator<DiagonalType>::Alignment)) // FIXME hardcoded 16!!
|
| 891 |
+
};
|
| 892 |
+
return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
|
| 893 |
+
m_diagImpl.template packet<DiagonalPacketLoadMode,PacketType>(id));
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
evaluator<DiagonalType> m_diagImpl;
|
| 897 |
+
evaluator<MatrixType> m_matImpl;
|
| 898 |
+
};
|
| 899 |
+
|
| 900 |
+
// diagonal * dense
|
| 901 |
+
template<typename Lhs, typename Rhs, int ProductKind, int ProductTag>
|
| 902 |
+
struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalShape, DenseShape>
|
| 903 |
+
: diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft>
|
| 904 |
+
{
|
| 905 |
+
typedef diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft> Base;
|
| 906 |
+
using Base::m_diagImpl;
|
| 907 |
+
using Base::m_matImpl;
|
| 908 |
+
using Base::coeff;
|
| 909 |
+
typedef typename Base::Scalar Scalar;
|
| 910 |
+
|
| 911 |
+
typedef Product<Lhs, Rhs, ProductKind> XprType;
|
| 912 |
+
typedef typename XprType::PlainObject PlainObject;
|
| 913 |
+
typedef typename Lhs::DiagonalVectorType DiagonalType;
|
| 914 |
+
|
| 915 |
+
|
| 916 |
+
enum { StorageOrder = Base::_StorageOrder };
|
| 917 |
+
|
| 918 |
+
EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
|
| 919 |
+
: Base(xpr.rhs(), xpr.lhs().diagonal())
|
| 920 |
+
{
|
| 921 |
+
}
|
| 922 |
+
|
| 923 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
|
| 924 |
+
{
|
| 925 |
+
return m_diagImpl.coeff(row) * m_matImpl.coeff(row, col);
|
| 926 |
+
}
|
| 927 |
+
|
| 928 |
+
#ifndef EIGEN_GPUCC
|
| 929 |
+
template<int LoadMode,typename PacketType>
|
| 930 |
+
EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const
|
| 931 |
+
{
|
| 932 |
+
// FIXME: NVCC used to complain about the template keyword, but we have to check whether this is still the case.
|
| 933 |
+
// See also similar calls below.
|
| 934 |
+
return this->template packet_impl<LoadMode,PacketType>(row,col, row,
|
| 935 |
+
typename internal::conditional<int(StorageOrder)==RowMajor, internal::true_type, internal::false_type>::type());
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
template<int LoadMode,typename PacketType>
|
| 939 |
+
EIGEN_STRONG_INLINE PacketType packet(Index idx) const
|
| 940 |
+
{
|
| 941 |
+
return packet<LoadMode,PacketType>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
|
| 942 |
+
}
|
| 943 |
+
#endif
|
| 944 |
+
};
|
| 945 |
+
|
| 946 |
+
// dense * diagonal
|
| 947 |
+
template<typename Lhs, typename Rhs, int ProductKind, int ProductTag>
|
| 948 |
+
struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape, DiagonalShape>
|
| 949 |
+
: diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheRight>
|
| 950 |
+
{
|
| 951 |
+
typedef diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheRight> Base;
|
| 952 |
+
using Base::m_diagImpl;
|
| 953 |
+
using Base::m_matImpl;
|
| 954 |
+
using Base::coeff;
|
| 955 |
+
typedef typename Base::Scalar Scalar;
|
| 956 |
+
|
| 957 |
+
typedef Product<Lhs, Rhs, ProductKind> XprType;
|
| 958 |
+
typedef typename XprType::PlainObject PlainObject;
|
| 959 |
+
|
| 960 |
+
enum { StorageOrder = Base::_StorageOrder };
|
| 961 |
+
|
| 962 |
+
EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
|
| 963 |
+
: Base(xpr.lhs(), xpr.rhs().diagonal())
|
| 964 |
+
{
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
|
| 968 |
+
{
|
| 969 |
+
return m_matImpl.coeff(row, col) * m_diagImpl.coeff(col);
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
#ifndef EIGEN_GPUCC
|
| 973 |
+
template<int LoadMode,typename PacketType>
|
| 974 |
+
EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const
|
| 975 |
+
{
|
| 976 |
+
return this->template packet_impl<LoadMode,PacketType>(row,col, col,
|
| 977 |
+
typename internal::conditional<int(StorageOrder)==ColMajor, internal::true_type, internal::false_type>::type());
|
| 978 |
+
}
|
| 979 |
+
|
| 980 |
+
template<int LoadMode,typename PacketType>
|
| 981 |
+
EIGEN_STRONG_INLINE PacketType packet(Index idx) const
|
| 982 |
+
{
|
| 983 |
+
return packet<LoadMode,PacketType>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
|
| 984 |
+
}
|
| 985 |
+
#endif
|
| 986 |
+
};
|
| 987 |
+
|
| 988 |
+
/***************************************************************************
|
| 989 |
+
* Products with permutation matrices
|
| 990 |
+
***************************************************************************/
|
| 991 |
+
|
| 992 |
+
/** \internal
|
| 993 |
+
* \class permutation_matrix_product
|
| 994 |
+
* Internal helper class implementing the product between a permutation matrix and a matrix.
|
| 995 |
+
* This class is specialized for DenseShape below and for SparseShape in SparseCore/SparsePermutation.h
|
| 996 |
+
*/
|
| 997 |
+
template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape>
|
| 998 |
+
struct permutation_matrix_product;
|
| 999 |
+
|
| 1000 |
+
template<typename ExpressionType, int Side, bool Transposed>
|
| 1001 |
+
struct permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
|
| 1002 |
+
{
|
| 1003 |
+
typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
|
| 1004 |
+
typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
|
| 1005 |
+
|
| 1006 |
+
template<typename Dest, typename PermutationType>
|
| 1007 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Dest& dst, const PermutationType& perm, const ExpressionType& xpr)
|
| 1008 |
+
{
|
| 1009 |
+
MatrixType mat(xpr);
|
| 1010 |
+
const Index n = Side==OnTheLeft ? mat.rows() : mat.cols();
|
| 1011 |
+
// FIXME we need an is_same for expression that is not sensitive to constness. For instance
|
| 1012 |
+
// is_same_xpr<Block<const Matrix>, Block<Matrix> >::value should be true.
|
| 1013 |
+
//if(is_same<MatrixTypeCleaned,Dest>::value && extract_data(dst) == extract_data(mat))
|
| 1014 |
+
if(is_same_dense(dst, mat))
|
| 1015 |
+
{
|
| 1016 |
+
// apply the permutation inplace
|
| 1017 |
+
Matrix<bool,PermutationType::RowsAtCompileTime,1,0,PermutationType::MaxRowsAtCompileTime> mask(perm.size());
|
| 1018 |
+
mask.fill(false);
|
| 1019 |
+
Index r = 0;
|
| 1020 |
+
while(r < perm.size())
|
| 1021 |
+
{
|
| 1022 |
+
// search for the next seed
|
| 1023 |
+
while(r<perm.size() && mask[r]) r++;
|
| 1024 |
+
if(r>=perm.size())
|
| 1025 |
+
break;
|
| 1026 |
+
// we got one, let's follow it until we are back to the seed
|
| 1027 |
+
Index k0 = r++;
|
| 1028 |
+
Index kPrev = k0;
|
| 1029 |
+
mask.coeffRef(k0) = true;
|
| 1030 |
+
for(Index k=perm.indices().coeff(k0); k!=k0; k=perm.indices().coeff(k))
|
| 1031 |
+
{
|
| 1032 |
+
Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>(dst, k)
|
| 1033 |
+
.swap(Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>
|
| 1034 |
+
(dst,((Side==OnTheLeft) ^ Transposed) ? k0 : kPrev));
|
| 1035 |
+
|
| 1036 |
+
mask.coeffRef(k) = true;
|
| 1037 |
+
kPrev = k;
|
| 1038 |
+
}
|
| 1039 |
+
}
|
| 1040 |
+
}
|
| 1041 |
+
else
|
| 1042 |
+
{
|
| 1043 |
+
for(Index i = 0; i < n; ++i)
|
| 1044 |
+
{
|
| 1045 |
+
Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>
|
| 1046 |
+
(dst, ((Side==OnTheLeft) ^ Transposed) ? perm.indices().coeff(i) : i)
|
| 1047 |
+
|
| 1048 |
+
=
|
| 1049 |
+
|
| 1050 |
+
Block<const MatrixTypeCleaned,Side==OnTheLeft ? 1 : MatrixTypeCleaned::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixTypeCleaned::ColsAtCompileTime>
|
| 1051 |
+
(mat, ((Side==OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i);
|
| 1052 |
+
}
|
| 1053 |
+
}
|
| 1054 |
+
}
|
| 1055 |
+
};
|
| 1056 |
+
|
| 1057 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1058 |
+
struct generic_product_impl<Lhs, Rhs, PermutationShape, MatrixShape, ProductTag>
|
| 1059 |
+
{
|
| 1060 |
+
template<typename Dest>
|
| 1061 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
|
| 1062 |
+
{
|
| 1063 |
+
permutation_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs);
|
| 1064 |
+
}
|
| 1065 |
+
};
|
| 1066 |
+
|
| 1067 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1068 |
+
struct generic_product_impl<Lhs, Rhs, MatrixShape, PermutationShape, ProductTag>
|
| 1069 |
+
{
|
| 1070 |
+
template<typename Dest>
|
| 1071 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
|
| 1072 |
+
{
|
| 1073 |
+
permutation_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs);
|
| 1074 |
+
}
|
| 1075 |
+
};
|
| 1076 |
+
|
| 1077 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1078 |
+
struct generic_product_impl<Inverse<Lhs>, Rhs, PermutationShape, MatrixShape, ProductTag>
|
| 1079 |
+
{
|
| 1080 |
+
template<typename Dest>
|
| 1081 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Inverse<Lhs>& lhs, const Rhs& rhs)
|
| 1082 |
+
{
|
| 1083 |
+
permutation_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs);
|
| 1084 |
+
}
|
| 1085 |
+
};
|
| 1086 |
+
|
| 1087 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1088 |
+
struct generic_product_impl<Lhs, Inverse<Rhs>, MatrixShape, PermutationShape, ProductTag>
|
| 1089 |
+
{
|
| 1090 |
+
template<typename Dest>
|
| 1091 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Inverse<Rhs>& rhs)
|
| 1092 |
+
{
|
| 1093 |
+
permutation_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs);
|
| 1094 |
+
}
|
| 1095 |
+
};
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
/***************************************************************************
|
| 1099 |
+
* Products with transpositions matrices
|
| 1100 |
+
***************************************************************************/
|
| 1101 |
+
|
| 1102 |
+
// FIXME could we unify Transpositions and Permutation into a single "shape"??
|
| 1103 |
+
|
| 1104 |
+
/** \internal
|
| 1105 |
+
* \class transposition_matrix_product
|
| 1106 |
+
* Internal helper class implementing the product between a permutation matrix and a matrix.
|
| 1107 |
+
*/
|
| 1108 |
+
template<typename ExpressionType, int Side, bool Transposed, typename ExpressionShape>
|
| 1109 |
+
struct transposition_matrix_product
|
| 1110 |
+
{
|
| 1111 |
+
typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
|
| 1112 |
+
typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
|
| 1113 |
+
|
| 1114 |
+
template<typename Dest, typename TranspositionType>
|
| 1115 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Dest& dst, const TranspositionType& tr, const ExpressionType& xpr)
|
| 1116 |
+
{
|
| 1117 |
+
MatrixType mat(xpr);
|
| 1118 |
+
typedef typename TranspositionType::StorageIndex StorageIndex;
|
| 1119 |
+
const Index size = tr.size();
|
| 1120 |
+
StorageIndex j = 0;
|
| 1121 |
+
|
| 1122 |
+
if(!is_same_dense(dst,mat))
|
| 1123 |
+
dst = mat;
|
| 1124 |
+
|
| 1125 |
+
for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
|
| 1126 |
+
if(Index(j=tr.coeff(k))!=k)
|
| 1127 |
+
{
|
| 1128 |
+
if(Side==OnTheLeft) dst.row(k).swap(dst.row(j));
|
| 1129 |
+
else if(Side==OnTheRight) dst.col(k).swap(dst.col(j));
|
| 1130 |
+
}
|
| 1131 |
+
}
|
| 1132 |
+
};
|
| 1133 |
+
|
| 1134 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1135 |
+
struct generic_product_impl<Lhs, Rhs, TranspositionsShape, MatrixShape, ProductTag>
|
| 1136 |
+
{
|
| 1137 |
+
template<typename Dest>
|
| 1138 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
|
| 1139 |
+
{
|
| 1140 |
+
transposition_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs);
|
| 1141 |
+
}
|
| 1142 |
+
};
|
| 1143 |
+
|
| 1144 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1145 |
+
struct generic_product_impl<Lhs, Rhs, MatrixShape, TranspositionsShape, ProductTag>
|
| 1146 |
+
{
|
| 1147 |
+
template<typename Dest>
|
| 1148 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
|
| 1149 |
+
{
|
| 1150 |
+
transposition_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs);
|
| 1151 |
+
}
|
| 1152 |
+
};
|
| 1153 |
+
|
| 1154 |
+
|
| 1155 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1156 |
+
struct generic_product_impl<Transpose<Lhs>, Rhs, TranspositionsShape, MatrixShape, ProductTag>
|
| 1157 |
+
{
|
| 1158 |
+
template<typename Dest>
|
| 1159 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Transpose<Lhs>& lhs, const Rhs& rhs)
|
| 1160 |
+
{
|
| 1161 |
+
transposition_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs);
|
| 1162 |
+
}
|
| 1163 |
+
};
|
| 1164 |
+
|
| 1165 |
+
template<typename Lhs, typename Rhs, int ProductTag, typename MatrixShape>
|
| 1166 |
+
struct generic_product_impl<Lhs, Transpose<Rhs>, MatrixShape, TranspositionsShape, ProductTag>
|
| 1167 |
+
{
|
| 1168 |
+
template<typename Dest>
|
| 1169 |
+
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Transpose<Rhs>& rhs)
|
| 1170 |
+
{
|
| 1171 |
+
transposition_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs);
|
| 1172 |
+
}
|
| 1173 |
+
};
|
| 1174 |
+
|
| 1175 |
+
} // end namespace internal
|
| 1176 |
+
|
| 1177 |
+
} // end namespace Eigen
|
| 1178 |
+
|
| 1179 |
+
#endif // EIGEN_PRODUCT_EVALUATORS_H
|
include/eigen/E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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
//
|
| 6 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 7 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 8 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 9 |
+
|
| 10 |
+
#ifndef EIGEN_RANDOM_H
|
| 11 |
+
#define EIGEN_RANDOM_H
|
| 12 |
+
|
| 13 |
+
namespace Eigen {
|
| 14 |
+
|
| 15 |
+
namespace internal {
|
| 16 |
+
|
| 17 |
+
template<typename Scalar> struct scalar_random_op {
|
| 18 |
+
EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op)
|
| 19 |
+
inline const Scalar operator() () const { return random<Scalar>(); }
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
template<typename Scalar>
|
| 23 |
+
struct functor_traits<scalar_random_op<Scalar> >
|
| 24 |
+
{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; };
|
| 25 |
+
|
| 26 |
+
} // end namespace internal
|
| 27 |
+
|
| 28 |
+
/** \returns a random matrix expression
|
| 29 |
+
*
|
| 30 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 31 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 32 |
+
*
|
| 33 |
+
* The parameters \a rows and \a cols are the number of rows and of columns of
|
| 34 |
+
* the returned matrix. Must be compatible with this MatrixBase type.
|
| 35 |
+
*
|
| 36 |
+
* \not_reentrant
|
| 37 |
+
*
|
| 38 |
+
* This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
|
| 39 |
+
* it is redundant to pass \a rows and \a cols as arguments, so Random() should be used
|
| 40 |
+
* instead.
|
| 41 |
+
*
|
| 42 |
+
*
|
| 43 |
+
* Example: \include MatrixBase_random_int_int.cpp
|
| 44 |
+
* Output: \verbinclude MatrixBase_random_int_int.out
|
| 45 |
+
*
|
| 46 |
+
* This expression has the "evaluate before nesting" flag so that it will be evaluated into
|
| 47 |
+
* a temporary matrix whenever it is nested in a larger expression. This prevents unexpected
|
| 48 |
+
* behavior with expressions involving random matrices.
|
| 49 |
+
*
|
| 50 |
+
* See DenseBase::NullaryExpr(Index, const CustomNullaryOp&) for an example using C++11 random generators.
|
| 51 |
+
*
|
| 52 |
+
* \sa DenseBase::setRandom(), DenseBase::Random(Index), DenseBase::Random()
|
| 53 |
+
*/
|
| 54 |
+
template<typename Derived>
|
| 55 |
+
inline const typename DenseBase<Derived>::RandomReturnType
|
| 56 |
+
DenseBase<Derived>::Random(Index rows, Index cols)
|
| 57 |
+
{
|
| 58 |
+
return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>());
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/** \returns a random vector expression
|
| 62 |
+
*
|
| 63 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 64 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 65 |
+
*
|
| 66 |
+
* The parameter \a size is the size of the returned vector.
|
| 67 |
+
* Must be compatible with this MatrixBase type.
|
| 68 |
+
*
|
| 69 |
+
* \only_for_vectors
|
| 70 |
+
* \not_reentrant
|
| 71 |
+
*
|
| 72 |
+
* This variant is meant to be used for dynamic-size vector types. For fixed-size types,
|
| 73 |
+
* it is redundant to pass \a size as argument, so Random() should be used
|
| 74 |
+
* instead.
|
| 75 |
+
*
|
| 76 |
+
* Example: \include MatrixBase_random_int.cpp
|
| 77 |
+
* Output: \verbinclude MatrixBase_random_int.out
|
| 78 |
+
*
|
| 79 |
+
* This expression has the "evaluate before nesting" flag so that it will be evaluated into
|
| 80 |
+
* a temporary vector whenever it is nested in a larger expression. This prevents unexpected
|
| 81 |
+
* behavior with expressions involving random matrices.
|
| 82 |
+
*
|
| 83 |
+
* \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random()
|
| 84 |
+
*/
|
| 85 |
+
template<typename Derived>
|
| 86 |
+
inline const typename DenseBase<Derived>::RandomReturnType
|
| 87 |
+
DenseBase<Derived>::Random(Index size)
|
| 88 |
+
{
|
| 89 |
+
return NullaryExpr(size, internal::scalar_random_op<Scalar>());
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/** \returns a fixed-size random matrix or vector expression
|
| 93 |
+
*
|
| 94 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 95 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 96 |
+
*
|
| 97 |
+
* This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
|
| 98 |
+
* need to use the variants taking size arguments.
|
| 99 |
+
*
|
| 100 |
+
* Example: \include MatrixBase_random.cpp
|
| 101 |
+
* Output: \verbinclude MatrixBase_random.out
|
| 102 |
+
*
|
| 103 |
+
* This expression has the "evaluate before nesting" flag so that it will be evaluated into
|
| 104 |
+
* a temporary matrix whenever it is nested in a larger expression. This prevents unexpected
|
| 105 |
+
* behavior with expressions involving random matrices.
|
| 106 |
+
*
|
| 107 |
+
* \not_reentrant
|
| 108 |
+
*
|
| 109 |
+
* \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random(Index)
|
| 110 |
+
*/
|
| 111 |
+
template<typename Derived>
|
| 112 |
+
inline const typename DenseBase<Derived>::RandomReturnType
|
| 113 |
+
DenseBase<Derived>::Random()
|
| 114 |
+
{
|
| 115 |
+
return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>());
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/** Sets all coefficients in this expression to random values.
|
| 119 |
+
*
|
| 120 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 121 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 122 |
+
*
|
| 123 |
+
* \not_reentrant
|
| 124 |
+
*
|
| 125 |
+
* Example: \include MatrixBase_setRandom.cpp
|
| 126 |
+
* Output: \verbinclude MatrixBase_setRandom.out
|
| 127 |
+
*
|
| 128 |
+
* \sa class CwiseNullaryOp, setRandom(Index), setRandom(Index,Index)
|
| 129 |
+
*/
|
| 130 |
+
template<typename Derived>
|
| 131 |
+
EIGEN_DEVICE_FUNC inline Derived& DenseBase<Derived>::setRandom()
|
| 132 |
+
{
|
| 133 |
+
return *this = Random(rows(), cols());
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/** Resizes to the given \a newSize, and sets all coefficients in this expression to random values.
|
| 137 |
+
*
|
| 138 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 139 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 140 |
+
*
|
| 141 |
+
* \only_for_vectors
|
| 142 |
+
* \not_reentrant
|
| 143 |
+
*
|
| 144 |
+
* Example: \include Matrix_setRandom_int.cpp
|
| 145 |
+
* Output: \verbinclude Matrix_setRandom_int.out
|
| 146 |
+
*
|
| 147 |
+
* \sa DenseBase::setRandom(), setRandom(Index,Index), class CwiseNullaryOp, DenseBase::Random()
|
| 148 |
+
*/
|
| 149 |
+
template<typename Derived>
|
| 150 |
+
EIGEN_STRONG_INLINE Derived&
|
| 151 |
+
PlainObjectBase<Derived>::setRandom(Index newSize)
|
| 152 |
+
{
|
| 153 |
+
resize(newSize);
|
| 154 |
+
return setRandom();
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/** Resizes to the given size, and sets all coefficients in this expression to random values.
|
| 158 |
+
*
|
| 159 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 160 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 161 |
+
*
|
| 162 |
+
* \not_reentrant
|
| 163 |
+
*
|
| 164 |
+
* \param rows the new number of rows
|
| 165 |
+
* \param cols the new number of columns
|
| 166 |
+
*
|
| 167 |
+
* Example: \include Matrix_setRandom_int_int.cpp
|
| 168 |
+
* Output: \verbinclude Matrix_setRandom_int_int.out
|
| 169 |
+
*
|
| 170 |
+
* \sa DenseBase::setRandom(), setRandom(Index), class CwiseNullaryOp, DenseBase::Random()
|
| 171 |
+
*/
|
| 172 |
+
template<typename Derived>
|
| 173 |
+
EIGEN_STRONG_INLINE Derived&
|
| 174 |
+
PlainObjectBase<Derived>::setRandom(Index rows, Index cols)
|
| 175 |
+
{
|
| 176 |
+
resize(rows, cols);
|
| 177 |
+
return setRandom();
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/** Resizes to the given size, changing only the number of columns, and sets all
|
| 181 |
+
* coefficients in this expression to random values. For the parameter of type
|
| 182 |
+
* NoChange_t, just pass the special value \c NoChange.
|
| 183 |
+
*
|
| 184 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 185 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 186 |
+
*
|
| 187 |
+
* \not_reentrant
|
| 188 |
+
*
|
| 189 |
+
* \sa DenseBase::setRandom(), setRandom(Index), setRandom(Index, NoChange_t), class CwiseNullaryOp, DenseBase::Random()
|
| 190 |
+
*/
|
| 191 |
+
template<typename Derived>
|
| 192 |
+
EIGEN_STRONG_INLINE Derived&
|
| 193 |
+
PlainObjectBase<Derived>::setRandom(NoChange_t, Index cols)
|
| 194 |
+
{
|
| 195 |
+
return setRandom(rows(), cols);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/** Resizes to the given size, changing only the number of rows, and sets all
|
| 199 |
+
* coefficients in this expression to random values. For the parameter of type
|
| 200 |
+
* NoChange_t, just pass the special value \c NoChange.
|
| 201 |
+
*
|
| 202 |
+
* Numbers are uniformly spread through their whole definition range for integer types,
|
| 203 |
+
* and in the [-1:1] range for floating point scalar types.
|
| 204 |
+
*
|
| 205 |
+
* \not_reentrant
|
| 206 |
+
*
|
| 207 |
+
* \sa DenseBase::setRandom(), setRandom(Index), setRandom(NoChange_t, Index), class CwiseNullaryOp, DenseBase::Random()
|
| 208 |
+
*/
|
| 209 |
+
template<typename Derived>
|
| 210 |
+
EIGEN_STRONG_INLINE Derived&
|
| 211 |
+
PlainObjectBase<Derived>::setRandom(Index rows, NoChange_t)
|
| 212 |
+
{
|
| 213 |
+
return setRandom(rows, cols());
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
} // end namespace Eigen
|
| 217 |
+
|
| 218 |
+
#endif // EIGEN_RANDOM_H
|
include/eigen/Eigen/src/Core/Redux.h
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file is part of Eigen, a lightweight C++ template library
|
| 2 |
+
// for linear algebra.
|
| 3 |
+
//
|
| 4 |
+
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
| 5 |
+
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
| 6 |
+
//
|
| 7 |
+
// This Source Code Form is subject to the terms of the Mozilla
|
| 8 |
+
// Public License v. 2.0. If a copy of the MPL was not distributed
|
| 9 |
+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
| 10 |
+
|
| 11 |
+
#ifndef EIGEN_REDUX_H
|
| 12 |
+
#define EIGEN_REDUX_H
|
| 13 |
+
|
| 14 |
+
namespace Eigen {
|
| 15 |
+
|
| 16 |
+
namespace internal {
|
| 17 |
+
|
| 18 |
+
// TODO
|
| 19 |
+
// * implement other kind of vectorization
|
| 20 |
+
// * factorize code
|
| 21 |
+
|
| 22 |
+
/***************************************************************************
|
| 23 |
+
* Part 1 : the logic deciding a strategy for vectorization and unrolling
|
| 24 |
+
***************************************************************************/
|
| 25 |
+
|
| 26 |
+
template<typename Func, typename Evaluator>
|
| 27 |
+
struct redux_traits
|
| 28 |
+
{
|
| 29 |
+
public:
|
| 30 |
+
typedef typename find_best_packet<typename Evaluator::Scalar,Evaluator::SizeAtCompileTime>::type PacketType;
|
| 31 |
+
enum {
|
| 32 |
+
PacketSize = unpacket_traits<PacketType>::size,
|
| 33 |
+
InnerMaxSize = int(Evaluator::IsRowMajor)
|
| 34 |
+
? Evaluator::MaxColsAtCompileTime
|
| 35 |
+
: Evaluator::MaxRowsAtCompileTime,
|
| 36 |
+
OuterMaxSize = int(Evaluator::IsRowMajor)
|
| 37 |
+
? Evaluator::MaxRowsAtCompileTime
|
| 38 |
+
: Evaluator::MaxColsAtCompileTime,
|
| 39 |
+
SliceVectorizedWork = int(InnerMaxSize)==Dynamic ? Dynamic
|
| 40 |
+
: int(OuterMaxSize)==Dynamic ? (int(InnerMaxSize)>=int(PacketSize) ? Dynamic : 0)
|
| 41 |
+
: (int(InnerMaxSize)/int(PacketSize)) * int(OuterMaxSize)
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
enum {
|
| 45 |
+
MightVectorize = (int(Evaluator::Flags)&ActualPacketAccessBit)
|
| 46 |
+
&& (functor_traits<Func>::PacketAccess),
|
| 47 |
+
MayLinearVectorize = bool(MightVectorize) && (int(Evaluator::Flags)&LinearAccessBit),
|
| 48 |
+
MaySliceVectorize = bool(MightVectorize) && (int(SliceVectorizedWork)==Dynamic || int(SliceVectorizedWork)>=3)
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
public:
|
| 52 |
+
enum {
|
| 53 |
+
Traversal = int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
|
| 54 |
+
: int(MaySliceVectorize) ? int(SliceVectorizedTraversal)
|
| 55 |
+
: int(DefaultTraversal)
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
public:
|
| 59 |
+
enum {
|
| 60 |
+
Cost = Evaluator::SizeAtCompileTime == Dynamic ? HugeCost
|
| 61 |
+
: int(Evaluator::SizeAtCompileTime) * int(Evaluator::CoeffReadCost) + (Evaluator::SizeAtCompileTime-1) * functor_traits<Func>::Cost,
|
| 62 |
+
UnrollingLimit = EIGEN_UNROLLING_LIMIT * (int(Traversal) == int(DefaultTraversal) ? 1 : int(PacketSize))
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
public:
|
| 66 |
+
enum {
|
| 67 |
+
Unrolling = Cost <= UnrollingLimit ? CompleteUnrolling : NoUnrolling
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
#ifdef EIGEN_DEBUG_ASSIGN
|
| 71 |
+
static void debug()
|
| 72 |
+
{
|
| 73 |
+
std::cerr << "Xpr: " << typeid(typename Evaluator::XprType).name() << std::endl;
|
| 74 |
+
std::cerr.setf(std::ios::hex, std::ios::basefield);
|
| 75 |
+
EIGEN_DEBUG_VAR(Evaluator::Flags)
|
| 76 |
+
std::cerr.unsetf(std::ios::hex);
|
| 77 |
+
EIGEN_DEBUG_VAR(InnerMaxSize)
|
| 78 |
+
EIGEN_DEBUG_VAR(OuterMaxSize)
|
| 79 |
+
EIGEN_DEBUG_VAR(SliceVectorizedWork)
|
| 80 |
+
EIGEN_DEBUG_VAR(PacketSize)
|
| 81 |
+
EIGEN_DEBUG_VAR(MightVectorize)
|
| 82 |
+
EIGEN_DEBUG_VAR(MayLinearVectorize)
|
| 83 |
+
EIGEN_DEBUG_VAR(MaySliceVectorize)
|
| 84 |
+
std::cerr << "Traversal" << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl;
|
| 85 |
+
EIGEN_DEBUG_VAR(UnrollingLimit)
|
| 86 |
+
std::cerr << "Unrolling" << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl;
|
| 87 |
+
std::cerr << std::endl;
|
| 88 |
+
}
|
| 89 |
+
#endif
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
/***************************************************************************
|
| 93 |
+
* Part 2 : unrollers
|
| 94 |
+
***************************************************************************/
|
| 95 |
+
|
| 96 |
+
/*** no vectorization ***/
|
| 97 |
+
|
| 98 |
+
template<typename Func, typename Evaluator, int Start, int Length>
|
| 99 |
+
struct redux_novec_unroller
|
| 100 |
+
{
|
| 101 |
+
enum {
|
| 102 |
+
HalfLength = Length/2
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 106 |
+
|
| 107 |
+
EIGEN_DEVICE_FUNC
|
| 108 |
+
static EIGEN_STRONG_INLINE Scalar run(const Evaluator &eval, const Func& func)
|
| 109 |
+
{
|
| 110 |
+
return func(redux_novec_unroller<Func, Evaluator, Start, HalfLength>::run(eval,func),
|
| 111 |
+
redux_novec_unroller<Func, Evaluator, Start+HalfLength, Length-HalfLength>::run(eval,func));
|
| 112 |
+
}
|
| 113 |
+
};
|
| 114 |
+
|
| 115 |
+
template<typename Func, typename Evaluator, int Start>
|
| 116 |
+
struct redux_novec_unroller<Func, Evaluator, Start, 1>
|
| 117 |
+
{
|
| 118 |
+
enum {
|
| 119 |
+
outer = Start / Evaluator::InnerSizeAtCompileTime,
|
| 120 |
+
inner = Start % Evaluator::InnerSizeAtCompileTime
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 124 |
+
|
| 125 |
+
EIGEN_DEVICE_FUNC
|
| 126 |
+
static EIGEN_STRONG_INLINE Scalar run(const Evaluator &eval, const Func&)
|
| 127 |
+
{
|
| 128 |
+
return eval.coeffByOuterInner(outer, inner);
|
| 129 |
+
}
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
// This is actually dead code and will never be called. It is required
|
| 133 |
+
// to prevent false warnings regarding failed inlining though
|
| 134 |
+
// for 0 length run() will never be called at all.
|
| 135 |
+
template<typename Func, typename Evaluator, int Start>
|
| 136 |
+
struct redux_novec_unroller<Func, Evaluator, Start, 0>
|
| 137 |
+
{
|
| 138 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 139 |
+
EIGEN_DEVICE_FUNC
|
| 140 |
+
static EIGEN_STRONG_INLINE Scalar run(const Evaluator&, const Func&) { return Scalar(); }
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
/*** vectorization ***/
|
| 144 |
+
|
| 145 |
+
template<typename Func, typename Evaluator, int Start, int Length>
|
| 146 |
+
struct redux_vec_unroller
|
| 147 |
+
{
|
| 148 |
+
template<typename PacketType>
|
| 149 |
+
EIGEN_DEVICE_FUNC
|
| 150 |
+
static EIGEN_STRONG_INLINE PacketType run(const Evaluator &eval, const Func& func)
|
| 151 |
+
{
|
| 152 |
+
enum {
|
| 153 |
+
PacketSize = unpacket_traits<PacketType>::size,
|
| 154 |
+
HalfLength = Length/2
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
return func.packetOp(
|
| 158 |
+
redux_vec_unroller<Func, Evaluator, Start, HalfLength>::template run<PacketType>(eval,func),
|
| 159 |
+
redux_vec_unroller<Func, Evaluator, Start+HalfLength, Length-HalfLength>::template run<PacketType>(eval,func) );
|
| 160 |
+
}
|
| 161 |
+
};
|
| 162 |
+
|
| 163 |
+
template<typename Func, typename Evaluator, int Start>
|
| 164 |
+
struct redux_vec_unroller<Func, Evaluator, Start, 1>
|
| 165 |
+
{
|
| 166 |
+
template<typename PacketType>
|
| 167 |
+
EIGEN_DEVICE_FUNC
|
| 168 |
+
static EIGEN_STRONG_INLINE PacketType run(const Evaluator &eval, const Func&)
|
| 169 |
+
{
|
| 170 |
+
enum {
|
| 171 |
+
PacketSize = unpacket_traits<PacketType>::size,
|
| 172 |
+
index = Start * PacketSize,
|
| 173 |
+
outer = index / int(Evaluator::InnerSizeAtCompileTime),
|
| 174 |
+
inner = index % int(Evaluator::InnerSizeAtCompileTime),
|
| 175 |
+
alignment = Evaluator::Alignment
|
| 176 |
+
};
|
| 177 |
+
return eval.template packetByOuterInner<alignment,PacketType>(outer, inner);
|
| 178 |
+
}
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
/***************************************************************************
|
| 182 |
+
* Part 3 : implementation of all cases
|
| 183 |
+
***************************************************************************/
|
| 184 |
+
|
| 185 |
+
template<typename Func, typename Evaluator,
|
| 186 |
+
int Traversal = redux_traits<Func, Evaluator>::Traversal,
|
| 187 |
+
int Unrolling = redux_traits<Func, Evaluator>::Unrolling
|
| 188 |
+
>
|
| 189 |
+
struct redux_impl;
|
| 190 |
+
|
| 191 |
+
template<typename Func, typename Evaluator>
|
| 192 |
+
struct redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling>
|
| 193 |
+
{
|
| 194 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 195 |
+
|
| 196 |
+
template<typename XprType>
|
| 197 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
|
| 198 |
+
Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
|
| 199 |
+
{
|
| 200 |
+
eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
|
| 201 |
+
Scalar res;
|
| 202 |
+
res = eval.coeffByOuterInner(0, 0);
|
| 203 |
+
for(Index i = 1; i < xpr.innerSize(); ++i)
|
| 204 |
+
res = func(res, eval.coeffByOuterInner(0, i));
|
| 205 |
+
for(Index i = 1; i < xpr.outerSize(); ++i)
|
| 206 |
+
for(Index j = 0; j < xpr.innerSize(); ++j)
|
| 207 |
+
res = func(res, eval.coeffByOuterInner(i, j));
|
| 208 |
+
return res;
|
| 209 |
+
}
|
| 210 |
+
};
|
| 211 |
+
|
| 212 |
+
template<typename Func, typename Evaluator>
|
| 213 |
+
struct redux_impl<Func,Evaluator, DefaultTraversal, CompleteUnrolling>
|
| 214 |
+
: redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime>
|
| 215 |
+
{
|
| 216 |
+
typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base;
|
| 217 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 218 |
+
template<typename XprType>
|
| 219 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
|
| 220 |
+
Scalar run(const Evaluator &eval, const Func& func, const XprType& /*xpr*/)
|
| 221 |
+
{
|
| 222 |
+
return Base::run(eval,func);
|
| 223 |
+
}
|
| 224 |
+
};
|
| 225 |
+
|
| 226 |
+
template<typename Func, typename Evaluator>
|
| 227 |
+
struct redux_impl<Func, Evaluator, LinearVectorizedTraversal, NoUnrolling>
|
| 228 |
+
{
|
| 229 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 230 |
+
typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar;
|
| 231 |
+
|
| 232 |
+
template<typename XprType>
|
| 233 |
+
static Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
|
| 234 |
+
{
|
| 235 |
+
const Index size = xpr.size();
|
| 236 |
+
|
| 237 |
+
const Index packetSize = redux_traits<Func, Evaluator>::PacketSize;
|
| 238 |
+
const int packetAlignment = unpacket_traits<PacketScalar>::alignment;
|
| 239 |
+
enum {
|
| 240 |
+
alignment0 = (bool(Evaluator::Flags & DirectAccessBit) && bool(packet_traits<Scalar>::AlignedOnScalar)) ? int(packetAlignment) : int(Unaligned),
|
| 241 |
+
alignment = EIGEN_PLAIN_ENUM_MAX(alignment0, Evaluator::Alignment)
|
| 242 |
+
};
|
| 243 |
+
const Index alignedStart = internal::first_default_aligned(xpr);
|
| 244 |
+
const Index alignedSize2 = ((size-alignedStart)/(2*packetSize))*(2*packetSize);
|
| 245 |
+
const Index alignedSize = ((size-alignedStart)/(packetSize))*(packetSize);
|
| 246 |
+
const Index alignedEnd2 = alignedStart + alignedSize2;
|
| 247 |
+
const Index alignedEnd = alignedStart + alignedSize;
|
| 248 |
+
Scalar res;
|
| 249 |
+
if(alignedSize)
|
| 250 |
+
{
|
| 251 |
+
PacketScalar packet_res0 = eval.template packet<alignment,PacketScalar>(alignedStart);
|
| 252 |
+
if(alignedSize>packetSize) // we have at least two packets to partly unroll the loop
|
| 253 |
+
{
|
| 254 |
+
PacketScalar packet_res1 = eval.template packet<alignment,PacketScalar>(alignedStart+packetSize);
|
| 255 |
+
for(Index index = alignedStart + 2*packetSize; index < alignedEnd2; index += 2*packetSize)
|
| 256 |
+
{
|
| 257 |
+
packet_res0 = func.packetOp(packet_res0, eval.template packet<alignment,PacketScalar>(index));
|
| 258 |
+
packet_res1 = func.packetOp(packet_res1, eval.template packet<alignment,PacketScalar>(index+packetSize));
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
packet_res0 = func.packetOp(packet_res0,packet_res1);
|
| 262 |
+
if(alignedEnd>alignedEnd2)
|
| 263 |
+
packet_res0 = func.packetOp(packet_res0, eval.template packet<alignment,PacketScalar>(alignedEnd2));
|
| 264 |
+
}
|
| 265 |
+
res = func.predux(packet_res0);
|
| 266 |
+
|
| 267 |
+
for(Index index = 0; index < alignedStart; ++index)
|
| 268 |
+
res = func(res,eval.coeff(index));
|
| 269 |
+
|
| 270 |
+
for(Index index = alignedEnd; index < size; ++index)
|
| 271 |
+
res = func(res,eval.coeff(index));
|
| 272 |
+
}
|
| 273 |
+
else // too small to vectorize anything.
|
| 274 |
+
// since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize.
|
| 275 |
+
{
|
| 276 |
+
res = eval.coeff(0);
|
| 277 |
+
for(Index index = 1; index < size; ++index)
|
| 278 |
+
res = func(res,eval.coeff(index));
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
return res;
|
| 282 |
+
}
|
| 283 |
+
};
|
| 284 |
+
|
| 285 |
+
// NOTE: for SliceVectorizedTraversal we simply bypass unrolling
|
| 286 |
+
template<typename Func, typename Evaluator, int Unrolling>
|
| 287 |
+
struct redux_impl<Func, Evaluator, SliceVectorizedTraversal, Unrolling>
|
| 288 |
+
{
|
| 289 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 290 |
+
typedef typename redux_traits<Func, Evaluator>::PacketType PacketType;
|
| 291 |
+
|
| 292 |
+
template<typename XprType>
|
| 293 |
+
EIGEN_DEVICE_FUNC static Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
|
| 294 |
+
{
|
| 295 |
+
eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
|
| 296 |
+
const Index innerSize = xpr.innerSize();
|
| 297 |
+
const Index outerSize = xpr.outerSize();
|
| 298 |
+
enum {
|
| 299 |
+
packetSize = redux_traits<Func, Evaluator>::PacketSize
|
| 300 |
+
};
|
| 301 |
+
const Index packetedInnerSize = ((innerSize)/packetSize)*packetSize;
|
| 302 |
+
Scalar res;
|
| 303 |
+
if(packetedInnerSize)
|
| 304 |
+
{
|
| 305 |
+
PacketType packet_res = eval.template packet<Unaligned,PacketType>(0,0);
|
| 306 |
+
for(Index j=0; j<outerSize; ++j)
|
| 307 |
+
for(Index i=(j==0?packetSize:0); i<packetedInnerSize; i+=Index(packetSize))
|
| 308 |
+
packet_res = func.packetOp(packet_res, eval.template packetByOuterInner<Unaligned,PacketType>(j,i));
|
| 309 |
+
|
| 310 |
+
res = func.predux(packet_res);
|
| 311 |
+
for(Index j=0; j<outerSize; ++j)
|
| 312 |
+
for(Index i=packetedInnerSize; i<innerSize; ++i)
|
| 313 |
+
res = func(res, eval.coeffByOuterInner(j,i));
|
| 314 |
+
}
|
| 315 |
+
else // too small to vectorize anything.
|
| 316 |
+
// since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize.
|
| 317 |
+
{
|
| 318 |
+
res = redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling>::run(eval, func, xpr);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
return res;
|
| 322 |
+
}
|
| 323 |
+
};
|
| 324 |
+
|
| 325 |
+
template<typename Func, typename Evaluator>
|
| 326 |
+
struct redux_impl<Func, Evaluator, LinearVectorizedTraversal, CompleteUnrolling>
|
| 327 |
+
{
|
| 328 |
+
typedef typename Evaluator::Scalar Scalar;
|
| 329 |
+
|
| 330 |
+
typedef typename redux_traits<Func, Evaluator>::PacketType PacketType;
|
| 331 |
+
enum {
|
| 332 |
+
PacketSize = redux_traits<Func, Evaluator>::PacketSize,
|
| 333 |
+
Size = Evaluator::SizeAtCompileTime,
|
| 334 |
+
VectorizedSize = (int(Size) / int(PacketSize)) * int(PacketSize)
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
template<typename XprType>
|
| 338 |
+
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE
|
| 339 |
+
Scalar run(const Evaluator &eval, const Func& func, const XprType &xpr)
|
| 340 |
+
{
|
| 341 |
+
EIGEN_ONLY_USED_FOR_DEBUG(xpr)
|
| 342 |
+
eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
|
| 343 |
+
if (VectorizedSize > 0) {
|
| 344 |
+
Scalar res = func.predux(redux_vec_unroller<Func, Evaluator, 0, Size / PacketSize>::template run<PacketType>(eval,func));
|
| 345 |
+
if (VectorizedSize != Size)
|
| 346 |
+
res = func(res,redux_novec_unroller<Func, Evaluator, VectorizedSize, Size-VectorizedSize>::run(eval,func));
|
| 347 |
+
return res;
|
| 348 |
+
}
|
| 349 |
+
else {
|
| 350 |
+
return redux_novec_unroller<Func, Evaluator, 0, Size>::run(eval,func);
|
| 351 |
+
}
|
| 352 |
+
}
|
| 353 |
+
};
|
| 354 |
+
|
| 355 |
+
// evaluator adaptor
|
| 356 |
+
template<typename _XprType>
|
| 357 |
+
class redux_evaluator : public internal::evaluator<_XprType>
|
| 358 |
+
{
|
| 359 |
+
typedef internal::evaluator<_XprType> Base;
|
| 360 |
+
public:
|
| 361 |
+
typedef _XprType XprType;
|
| 362 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 363 |
+
explicit redux_evaluator(const XprType &xpr) : Base(xpr) {}
|
| 364 |
+
|
| 365 |
+
typedef typename XprType::Scalar Scalar;
|
| 366 |
+
typedef typename XprType::CoeffReturnType CoeffReturnType;
|
| 367 |
+
typedef typename XprType::PacketScalar PacketScalar;
|
| 368 |
+
|
| 369 |
+
enum {
|
| 370 |
+
MaxRowsAtCompileTime = XprType::MaxRowsAtCompileTime,
|
| 371 |
+
MaxColsAtCompileTime = XprType::MaxColsAtCompileTime,
|
| 372 |
+
// TODO we should not remove DirectAccessBit and rather find an elegant way to query the alignment offset at runtime from the evaluator
|
| 373 |
+
Flags = Base::Flags & ~DirectAccessBit,
|
| 374 |
+
IsRowMajor = XprType::IsRowMajor,
|
| 375 |
+
SizeAtCompileTime = XprType::SizeAtCompileTime,
|
| 376 |
+
InnerSizeAtCompileTime = XprType::InnerSizeAtCompileTime
|
| 377 |
+
};
|
| 378 |
+
|
| 379 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 380 |
+
CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
|
| 381 |
+
{ return Base::coeff(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); }
|
| 382 |
+
|
| 383 |
+
template<int LoadMode, typename PacketType>
|
| 384 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
| 385 |
+
PacketType packetByOuterInner(Index outer, Index inner) const
|
| 386 |
+
{ return Base::template packet<LoadMode,PacketType>(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); }
|
| 387 |
+
|
| 388 |
+
};
|
| 389 |
+
|
| 390 |
+
} // end namespace internal
|
| 391 |
+
|
| 392 |
+
/***************************************************************************
|
| 393 |
+
* Part 4 : public API
|
| 394 |
+
***************************************************************************/
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
/** \returns the result of a full redux operation on the whole matrix or vector using \a func
|
| 398 |
+
*
|
| 399 |
+
* The template parameter \a BinaryOp is the type of the functor \a func which must be
|
| 400 |
+
* an associative operator. Both current C++98 and C++11 functor styles are handled.
|
| 401 |
+
*
|
| 402 |
+
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
| 403 |
+
*
|
| 404 |
+
* \sa DenseBase::sum(), DenseBase::minCoeff(), DenseBase::maxCoeff(), MatrixBase::colwise(), MatrixBase::rowwise()
|
| 405 |
+
*/
|
| 406 |
+
template<typename Derived>
|
| 407 |
+
template<typename Func>
|
| 408 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 409 |
+
DenseBase<Derived>::redux(const Func& func) const
|
| 410 |
+
{
|
| 411 |
+
eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
|
| 412 |
+
|
| 413 |
+
typedef typename internal::redux_evaluator<Derived> ThisEvaluator;
|
| 414 |
+
ThisEvaluator thisEval(derived());
|
| 415 |
+
|
| 416 |
+
// The initial expression is passed to the reducer as an additional argument instead of
|
| 417 |
+
// passing it as a member of redux_evaluator to help
|
| 418 |
+
return internal::redux_impl<Func, ThisEvaluator>::run(thisEval, func, derived());
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
/** \returns the minimum of all coefficients of \c *this.
|
| 422 |
+
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
| 423 |
+
* NaNPropagation == PropagateFast : undefined
|
| 424 |
+
* NaNPropagation == PropagateNaN : result is NaN
|
| 425 |
+
* NaNPropagation == PropagateNumbers : result is minimum of elements that are not NaN
|
| 426 |
+
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
| 427 |
+
*/
|
| 428 |
+
template<typename Derived>
|
| 429 |
+
template<int NaNPropagation>
|
| 430 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 431 |
+
DenseBase<Derived>::minCoeff() const
|
| 432 |
+
{
|
| 433 |
+
return derived().redux(Eigen::internal::scalar_min_op<Scalar,Scalar, NaNPropagation>());
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
/** \returns the maximum of all coefficients of \c *this.
|
| 437 |
+
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
| 438 |
+
* NaNPropagation == PropagateFast : undefined
|
| 439 |
+
* NaNPropagation == PropagateNaN : result is NaN
|
| 440 |
+
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
| 441 |
+
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
| 442 |
+
*/
|
| 443 |
+
template<typename Derived>
|
| 444 |
+
template<int NaNPropagation>
|
| 445 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 446 |
+
DenseBase<Derived>::maxCoeff() const
|
| 447 |
+
{
|
| 448 |
+
return derived().redux(Eigen::internal::scalar_max_op<Scalar,Scalar, NaNPropagation>());
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
/** \returns the sum of all coefficients of \c *this
|
| 452 |
+
*
|
| 453 |
+
* If \c *this is empty, then the value 0 is returned.
|
| 454 |
+
*
|
| 455 |
+
* \sa trace(), prod(), mean()
|
| 456 |
+
*/
|
| 457 |
+
template<typename Derived>
|
| 458 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 459 |
+
DenseBase<Derived>::sum() const
|
| 460 |
+
{
|
| 461 |
+
if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0))
|
| 462 |
+
return Scalar(0);
|
| 463 |
+
return derived().redux(Eigen::internal::scalar_sum_op<Scalar,Scalar>());
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
/** \returns the mean of all coefficients of *this
|
| 467 |
+
*
|
| 468 |
+
* \sa trace(), prod(), sum()
|
| 469 |
+
*/
|
| 470 |
+
template<typename Derived>
|
| 471 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 472 |
+
DenseBase<Derived>::mean() const
|
| 473 |
+
{
|
| 474 |
+
#ifdef __INTEL_COMPILER
|
| 475 |
+
#pragma warning push
|
| 476 |
+
#pragma warning ( disable : 2259 )
|
| 477 |
+
#endif
|
| 478 |
+
return Scalar(derived().redux(Eigen::internal::scalar_sum_op<Scalar,Scalar>())) / Scalar(this->size());
|
| 479 |
+
#ifdef __INTEL_COMPILER
|
| 480 |
+
#pragma warning pop
|
| 481 |
+
#endif
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
/** \returns the product of all coefficients of *this
|
| 485 |
+
*
|
| 486 |
+
* Example: \include MatrixBase_prod.cpp
|
| 487 |
+
* Output: \verbinclude MatrixBase_prod.out
|
| 488 |
+
*
|
| 489 |
+
* \sa sum(), mean(), trace()
|
| 490 |
+
*/
|
| 491 |
+
template<typename Derived>
|
| 492 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 493 |
+
DenseBase<Derived>::prod() const
|
| 494 |
+
{
|
| 495 |
+
if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0))
|
| 496 |
+
return Scalar(1);
|
| 497 |
+
return derived().redux(Eigen::internal::scalar_product_op<Scalar>());
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
/** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal.
|
| 501 |
+
*
|
| 502 |
+
* \c *this can be any matrix, not necessarily square.
|
| 503 |
+
*
|
| 504 |
+
* \sa diagonal(), sum()
|
| 505 |
+
*/
|
| 506 |
+
template<typename Derived>
|
| 507 |
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
|
| 508 |
+
MatrixBase<Derived>::trace() const
|
| 509 |
+
{
|
| 510 |
+
return derived().diagonal().sum();
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
} // end namespace Eigen
|
| 514 |
+
|
| 515 |
+
#endif // EIGEN_REDUX_H
|