Refactor code to use constexpr for data() functions.
diff --git a/Eigen/src/Core/ArrayWrapper.h b/Eigen/src/Core/ArrayWrapper.h index b45395d..b636d88 100644 --- a/Eigen/src/Core/ArrayWrapper.h +++ b/Eigen/src/Core/ArrayWrapper.h
@@ -65,8 +65,8 @@ return m_expression.innerStride(); } - EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } - EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_expression.data(); } + EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); } EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { return m_expression.coeffRef(rowId, colId); @@ -144,8 +144,8 @@ return m_expression.innerStride(); } - EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } - EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_expression.data(); } + EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_expression.data(); } EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { return m_expression.derived().coeffRef(rowId, colId);
diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 9b16ed2..709264c 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h
@@ -278,7 +278,7 @@ #ifdef EIGEN_PARSED_BY_DOXYGEN /** \sa MapBase::data() */ - EIGEN_DEVICE_FUNC inline const Scalar* data() const; + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const; EIGEN_DEVICE_FUNC inline Index innerStride() const; EIGEN_DEVICE_FUNC inline Index outerStride() const; #endif
diff --git a/Eigen/src/Core/DenseStorage.h b/Eigen/src/Core/DenseStorage.h index f616939..49c4099 100644 --- a/Eigen/src/Core/DenseStorage.h +++ b/Eigen/src/Core/DenseStorage.h
@@ -258,8 +258,8 @@ m_cols = cols; eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size."); } - EIGEN_DEVICE_FUNC const T* data() const { return nullptr; } - EIGEN_DEVICE_FUNC T* data() { return nullptr; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return nullptr; } + EIGEN_DEVICE_FUNC constexpr T* data() { return nullptr; } }; template <typename T, int Rows_, int Options_> @@ -288,8 +288,8 @@ m_cols = cols; eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size."); } - EIGEN_DEVICE_FUNC const T* data() const { return nullptr; } - EIGEN_DEVICE_FUNC T* data() { return nullptr; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return nullptr; } + EIGEN_DEVICE_FUNC constexpr T* data() { return nullptr; } }; template <typename T, int Cols_, int Options_> @@ -318,8 +318,8 @@ m_rows = rows; eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size."); } - EIGEN_DEVICE_FUNC const T* data() const { return nullptr; } - EIGEN_DEVICE_FUNC T* data() { return nullptr; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return nullptr; } + EIGEN_DEVICE_FUNC constexpr T* data() { return nullptr; } }; // dynamic-size matrix with fixed-size storage @@ -507,8 +507,8 @@ m_rows = rows; m_cols = cols; } - EIGEN_DEVICE_FUNC const T* data() const { return m_data; } - EIGEN_DEVICE_FUNC T* data() { return m_data; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data; } }; // matrix with dynamic width and fixed height (so that matrix has dynamic size). @@ -574,8 +574,8 @@ } m_cols = cols; } - EIGEN_DEVICE_FUNC const T* data() const { return m_data; } - EIGEN_DEVICE_FUNC T* data() { return m_data; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data; } }; // matrix with dynamic height and fixed width (so that matrix has dynamic size). @@ -641,8 +641,8 @@ } m_rows = rows; } - EIGEN_DEVICE_FUNC const T* data() const { return m_data; } - EIGEN_DEVICE_FUNC T* data() { return m_data; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data; } }; } // end namespace Eigen
diff --git a/Eigen/src/Core/GeneralProduct.h b/Eigen/src/Core/GeneralProduct.h index b7ae44f..dc12481 100644 --- a/Eigen/src/Core/GeneralProduct.h +++ b/Eigen/src/Core/GeneralProduct.h
@@ -229,7 +229,7 @@ template <typename Scalar, int Size, int MaxSize> struct gemv_static_vector_if<Scalar, Size, MaxSize, false> { - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { + EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr Scalar* data() { eigen_internal_assert(false && "should never be called"); return 0; } @@ -237,19 +237,19 @@ template <typename Scalar, int Size> struct gemv_static_vector_if<Scalar, Size, Dynamic, true> { - EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { return 0; } + EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr Scalar* data() { return 0; } }; template <typename Scalar, int Size, int MaxSize> struct gemv_static_vector_if<Scalar, Size, MaxSize, true> { #if EIGEN_MAX_STATIC_ALIGN_BYTES != 0 internal::plain_array<Scalar, internal::min_size_prefer_fixed(Size, MaxSize), 0, AlignedMax> m_data; - EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; } + EIGEN_STRONG_INLINE constexpr Scalar* data() { return m_data.array; } #else // Some architectures cannot align on the stack, // => let's manually enforce alignment by allocating more data and return the address of the first aligned element. internal::plain_array<Scalar, internal::min_size_prefer_fixed(Size, MaxSize) + EIGEN_MAX_ALIGN_BYTES, 0> m_data; - EIGEN_STRONG_INLINE Scalar* data() { + EIGEN_STRONG_INLINE constexpr Scalar* data() { return reinterpret_cast<Scalar*>((std::uintptr_t(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES - 1))) + EIGEN_MAX_ALIGN_BYTES); }
diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index da95b5c..1e83fdf 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h
@@ -94,7 +94,7 @@ * * \sa innerStride(), outerStride() */ - EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; } + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_data; } /** \copydoc PlainObjectBase::coeff(Index,Index) const */ EIGEN_DEVICE_FUNC inline const Scalar& coeff(Index rowId, Index colId) const { @@ -233,8 +233,8 @@ typedef std::conditional_t<internal::is_lvalue<Derived>::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue; - EIGEN_DEVICE_FUNC inline const Scalar* data() const { return this->m_data; } - EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return this->m_data; } + EIGEN_DEVICE_FUNC constexpr ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error
diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index df90318..62195f4 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h
@@ -270,10 +270,10 @@ } /** \returns a const pointer to the data array of this matrix */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar* data() const { return m_storage.data(); } + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_storage.data(); } /** \returns a pointer to the data array of this matrix */ - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar* data() { return m_storage.data(); } + EIGEN_DEVICE_FUNC constexpr Scalar* data() { return m_storage.data(); } /** Resizes \c *this to a \a rows x \a cols matrix. *
diff --git a/Eigen/src/Core/Reshaped.h b/Eigen/src/Core/Reshaped.h index b881dd6..4b34e16 100644 --- a/Eigen/src/Core/Reshaped.h +++ b/Eigen/src/Core/Reshaped.h
@@ -173,7 +173,7 @@ #ifdef EIGEN_PARSED_BY_DOXYGEN /** \sa MapBase::data() */ - EIGEN_DEVICE_FUNC inline const Scalar* data() const; + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const; EIGEN_DEVICE_FUNC inline Index innerStride() const; EIGEN_DEVICE_FUNC inline Index outerStride() const; #endif
diff --git a/Eigen/src/Core/Stride.h b/Eigen/src/Core/Stride.h index a8fdeaf..14b025c 100644 --- a/Eigen/src/Core/Stride.h +++ b/Eigen/src/Core/Stride.h
@@ -70,6 +70,13 @@ /** Copy constructor */ EIGEN_DEVICE_FUNC Stride(const Stride& other) : m_outer(other.outer()), m_inner(other.inner()) {} + /** Copy assignment operator */ + EIGEN_DEVICE_FUNC Stride& operator=(const Stride& other) { + m_outer.setValue(other.outer()); + m_inner.setValue(other.inner()); + return *this; + } + /** \returns the outer stride */ EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outer() const { return m_outer.value(); } /** \returns the inner stride */
diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 1cc7a28..89e3d95 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h
@@ -119,10 +119,12 @@ typedef std::conditional_t<internal::is_lvalue<MatrixType>::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue; - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ScalarWithConstIfNotLvalue* data() { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr ScalarWithConstIfNotLvalue* data() { return derived().nestedExpression().data(); } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar* data() const { return derived().nestedExpression().data(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const Scalar* data() const { + return derived().nestedExpression().data(); + } // FIXME: shall we keep the const version of coeffRef? EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeffRef(Index rowId, Index colId) const {
diff --git a/Eigen/src/Core/util/BlasUtil.h b/Eigen/src/Core/util/BlasUtil.h index c2994b2..19d9917 100644 --- a/Eigen/src/Core/util/BlasUtil.h +++ b/Eigen/src/Core/util/BlasUtil.h
@@ -241,7 +241,7 @@ EIGEN_DEVICE_FUNC const Index stride() const { return m_stride; } EIGEN_DEVICE_FUNC const Index incr() const { return 1; } - EIGEN_DEVICE_FUNC const Scalar* data() const { return m_data; } + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_data; } EIGEN_DEVICE_FUNC Index firstAligned(Index size) const { if (std::uintptr_t(m_data) % sizeof(Scalar)) { @@ -430,7 +430,7 @@ EIGEN_DEVICE_FUNC const Index stride() const { return m_stride; } EIGEN_DEVICE_FUNC const Index incr() const { return m_incr.value(); } - EIGEN_DEVICE_FUNC Scalar* data() const { return m_data; } + EIGEN_DEVICE_FUNC constexpr Scalar* data() const { return m_data; } protected: Scalar* EIGEN_RESTRICT m_data;
diff --git a/Eigen/src/Core/util/MaxSizeVector.h b/Eigen/src/Core/util/MaxSizeVector.h index 2f1e3d3..54b556d 100644 --- a/Eigen/src/Core/util/MaxSizeVector.h +++ b/Eigen/src/Core/util/MaxSizeVector.h
@@ -116,17 +116,17 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool empty() const { return size_ == 0; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* data() { return data_; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* data() { return data_; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T* data() const { return data_; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* data() const { return data_; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* begin() { return data_; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* begin() { return data_; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* end() { return data_ + size_; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr T* end() { return data_ + size_; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T* begin() const { return data_; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* begin() const { return data_; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T* end() const { return data_ + size_; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const T* end() const { return data_ + size_; } private: size_t reserve_;
diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index fd3fc58..b1a9f21 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h
@@ -588,9 +588,9 @@ EIGEN_DEVICE_FUNC inline Transform inverse(TransformTraits traits = (TransformTraits)Mode) const; /** \returns a const pointer to the column major internal matrix */ - EIGEN_DEVICE_FUNC const Scalar* data() const { return m_matrix.data(); } + EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_matrix.data(); } /** \returns a non-const pointer to the column major internal matrix */ - EIGEN_DEVICE_FUNC Scalar* data() { return m_matrix.data(); } + EIGEN_DEVICE_FUNC constexpr Scalar* data() { return m_matrix.data(); } /** \returns \c *this with scalar type casted to \a NewScalarType *
diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 24ebb7c..16ee8da 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h
@@ -202,9 +202,9 @@ inline StorageIndex* innerNonZeroPtr() { return m_innerNonZeros; } /** \internal */ - inline Storage& data() { return m_data; } + constexpr Storage& data() { return m_data; } /** \internal */ - inline const Storage& data() const { return m_data; } + constexpr const Storage& data() const { return m_data; } /** \returns the value of the matrix at position \a i, \a j * This function returns Scalar(0) if the element is an explicit \em zero */
diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index 6b1816b..58ebb1b 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h
@@ -90,9 +90,9 @@ inline StorageIndex* innerNonZeroPtr() { return 0; } /** \internal */ - inline Storage& data() { return m_data; } + constexpr Storage& data() { return m_data; } /** \internal */ - inline const Storage& data() const { return m_data; } + constexpr const Storage& data() const { return m_data; } inline Scalar coeff(Index row, Index col) const { eigen_assert(IsColVector ? (col == 0 && row >= 0 && row < m_size) : (row == 0 && col >= 0 && col < m_size));