Static asserts to check for matching NumDimensions

This commit is contained in:
Tobias Wood 2023-11-20 14:44:06 +00:00 committed by Rasmus Munk Larsen
parent 283dec7f25
commit b2cb49e280

View File

@ -299,6 +299,7 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE Tensor(const TensorBase<OtherDerived, ReadOnlyAccessors>& other) EIGEN_STRONG_INLINE Tensor(const TensorBase<OtherDerived, ReadOnlyAccessors>& other)
{ {
EIGEN_STATIC_ASSERT(OtherDerived::NumDimensions == Base::NumDimensions, Number_of_dimensions_must_match)
typedef TensorAssignOp<Tensor, const OtherDerived> Assign; typedef TensorAssignOp<Tensor, const OtherDerived> Assign;
Assign assign(*this, other.derived()); Assign assign(*this, other.derived());
resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions()); resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions());
@ -309,6 +310,7 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE Tensor(const TensorBase<OtherDerived, WriteAccessors>& other) EIGEN_STRONG_INLINE Tensor(const TensorBase<OtherDerived, WriteAccessors>& other)
{ {
EIGEN_STATIC_ASSERT(OtherDerived::NumDimensions == Base::NumDimensions, Number_of_dimensions_must_match)
typedef TensorAssignOp<Tensor, const OtherDerived> Assign; typedef TensorAssignOp<Tensor, const OtherDerived> Assign;
Assign assign(*this, other.derived()); Assign assign(*this, other.derived());
resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions()); resize(TensorEvaluator<const Assign, DefaultDevice>(assign, DefaultDevice()).dimensions());