mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 19:59:05 +08:00
Added support for tensor maps of rank 0.
This commit is contained in:
parent
3785c69294
commit
ce19e38c1f
@ -52,6 +52,12 @@ template<typename PlainObjectType, int Options_> class TensorMap : public Tensor
|
|||||||
CoordAccess = true,
|
CoordAccess = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr) : m_data(dataPtr), m_dimensions() {
|
||||||
|
// The number of dimensions used to construct a tensor must be equal to the rank of the tensor.
|
||||||
|
EIGEN_STATIC_ASSERT((0 == NumIndices || NumIndices == Dynamic), YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
||||||
template<typename... IndexTypes> EIGEN_DEVICE_FUNC
|
template<typename... IndexTypes> EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
|
EIGEN_STRONG_INLINE TensorMap(PointerArgType dataPtr, Index firstDimension, IndexTypes... otherDimensions) : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
|
||||||
@ -121,11 +127,18 @@ template<typename PlainObjectType, int Options_> class TensorMap : public Tensor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE const Scalar& operator()() const
|
||||||
|
{
|
||||||
|
EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||||
|
return m_data[0];
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
||||||
template<typename... IndexTypes> EIGEN_DEVICE_FUNC
|
template<typename... IndexTypes> EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) const
|
EIGEN_STRONG_INLINE const Scalar& operator()(Index firstIndex, IndexTypes... otherIndices) const
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(otherIndices) + 1 == NumIndices, "Number of indices used to access a tensor coefficient must be equal to the rank of the tensor.");
|
EIGEN_STATIC_ASSERT(sizeof...(otherIndices) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||||
if (PlainObjectType::Options&RowMajor) {
|
if (PlainObjectType::Options&RowMajor) {
|
||||||
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, otherIndices...}});
|
const Index index = m_dimensions.IndexOfRowMajor(array<Index, NumIndices>{{firstIndex, otherIndices...}});
|
||||||
return m_data[index];
|
return m_data[index];
|
||||||
@ -200,6 +213,13 @@ template<typename PlainObjectType, int Options_> class TensorMap : public Tensor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE Scalar& operator()()
|
||||||
|
{
|
||||||
|
EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||||
|
return m_data[0];
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
#ifdef EIGEN_HAS_VARIADIC_TEMPLATES
|
||||||
template<typename... IndexTypes> EIGEN_DEVICE_FUNC
|
template<typename... IndexTypes> EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
|
EIGEN_STRONG_INLINE Scalar& operator()(Index firstIndex, IndexTypes... otherIndices)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user