Format EIGEN_STATIC_ASSERT() as a statement macro

This commit is contained in:
Tyler Veness 2024-05-20 23:02:42 +00:00 committed by Rasmus Munk Larsen
parent f78dfe36b0
commit d165c7377f
15 changed files with 114 additions and 110 deletions

View File

@ -2,6 +2,8 @@
Language: Cpp Language: Cpp
BasedOnStyle: Google BasedOnStyle: Google
ColumnLimit: 120 ColumnLimit: 120
StatementMacros:
- EIGEN_STATIC_ASSERT
SortIncludes: false SortIncludes: false
AttributeMacros: AttributeMacros:
- EIGEN_STRONG_INLINE - EIGEN_STRONG_INLINE

View File

@ -253,8 +253,7 @@ struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() {} EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() {}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& m) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& m) : evaluator<PlainObjectBase<XprType>>(m) {}
: evaluator<PlainObjectBase<XprType> >(m) {}
}; };
template <typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols> template <typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
@ -264,8 +263,7 @@ struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() {} EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() {}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& m) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& m) : evaluator<PlainObjectBase<XprType>>(m) {}
: evaluator<PlainObjectBase<XprType> >(m) {}
}; };
// -------------------- Transpose -------------------- // -------------------- Transpose --------------------

View File

@ -243,17 +243,15 @@ struct gemv_static_vector_if<Scalar, Size, Dynamic, true> {
template <typename Scalar, int Size, int MaxSize> template <typename Scalar, int Size, int MaxSize>
struct gemv_static_vector_if<Scalar, Size, MaxSize, true> { struct gemv_static_vector_if<Scalar, Size, MaxSize, true> {
#if EIGEN_MAX_STATIC_ALIGN_BYTES != 0 #if EIGEN_MAX_STATIC_ALIGN_BYTES != 0
internal::plain_array<Scalar, internal::min_size_prefer_fixed(Size, MaxSize), 0, AlignedMax> internal::plain_array<Scalar, internal::min_size_prefer_fixed(Size, MaxSize), 0, AlignedMax> m_data;
m_data;
EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; } EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; }
#else #else
// Some architectures cannot align on the stack, // 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. // => let's manually enforce alignment by allocating more data and return the address of the first aligned element.
internal::plain_array< internal::plain_array<Scalar, internal::min_size_prefer_fixed(Size, MaxSize) + EIGEN_MAX_ALIGN_BYTES, 0> m_data;
Scalar, internal::min_size_prefer_fixed(Size, MaxSize) + EIGEN_MAX_ALIGN_BYTES, 0>
m_data;
EIGEN_STRONG_INLINE Scalar* data() { EIGEN_STRONG_INLINE Scalar* data() {
return reinterpret_cast<Scalar*>((std::uintptr_t(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES - 1))) + EIGEN_MAX_ALIGN_BYTES); return reinterpret_cast<Scalar*>((std::uintptr_t(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES - 1))) +
EIGEN_MAX_ALIGN_BYTES);
} }
#endif #endif
}; };

View File

@ -80,15 +80,12 @@ class Replicate : public internal::dense_xpr_base<Replicate<MatrixType, RowFacto
template <typename OriginalMatrixType> template <typename OriginalMatrixType>
EIGEN_DEVICE_FUNC inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor) EIGEN_DEVICE_FUNC inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
: m_matrix(matrix), : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) {
m_rowFactor(rowFactor),
m_colFactor(colFactor){
EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value), EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value),
THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)} THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const {
return m_matrix.rows() * m_rowFactor.value();
} }
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); } EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
EIGEN_DEVICE_FUNC const MatrixTypeNested_& nestedExpression() const { return m_matrix; } EIGEN_DEVICE_FUNC const MatrixTypeNested_& nestedExpression() const { return m_matrix; }

View File

@ -1424,8 +1424,7 @@ void BDCSVD<MatrixType, Options>::deflation(Index firstCol, Index lastCol, Index
if ((diag(i) - diag(i - 1)) < epsilon_strict) { if ((diag(i) - diag(i - 1)) < epsilon_strict) {
#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE #ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
std::cout << "deflation 4.4 with i = " << i << " because " << diag(i) << " - " << diag(i - 1) std::cout << "deflation 4.4 with i = " << i << " because " << diag(i) << " - " << diag(i - 1)
<< " == " << (diag(i) - diag(i - 1)) << " < " << " == " << (diag(i) - diag(i - 1)) << " < " << epsilon_strict << "\n";
<< epsilon_strict << "\n";
#endif #endif
eigen_internal_assert(abs(diag(i) - diag(i - 1)) < epsilon_coarse && eigen_internal_assert(abs(diag(i) - diag(i - 1)) < epsilon_coarse &&
" diagonal entries are not properly sorted"); " diagonal entries are not properly sorted");

11
scripts/format.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
# Format files with extensions, excluding plugins because they're partial files that don't contain valid syntax
find . -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cxx' -o -name '*.h' -o -name '*.inc' -not -path '*/plugins/*' \) | xargs -n 1 -P 0 clang-format-17 -i
# Format main headers without extensions
find Eigen -maxdepth 1 -type f | xargs -n 1 -P 0 clang-format-17 -i
find unsupported/Eigen -maxdepth 2 -type f -not -name '*.txt' | xargs -n 1 -P 0 clang-format-17 -i
# Format examples
find doc/examples -type f -name '*.cpp.*' | xargs -n 1 -P 0 clang-format-17 -i

View File

@ -140,7 +140,8 @@ void comparisons(const MatrixType& m) {
// and/or // and/or
VERIFY(((m1.array() < RealScalar(0)).matrix() && (m1.array() > RealScalar(0)).matrix()).count() == 0); VERIFY(((m1.array() < RealScalar(0)).matrix() && (m1.array() > RealScalar(0)).matrix()).count() == 0);
VERIFY(((m1.array() < RealScalar(0)).matrix() || (m1.array() >= RealScalar(0)).matrix()).count() == rows * cols); VERIFY(((m1.array() < RealScalar(0)).matrix() || (m1.array() >= RealScalar(0)).matrix()).count() == rows * cols);
VERIFY(((m1.array() < -mid).matrix() || (m1.array() > mid).matrix()).count() == (m1.cwiseAbs().array() > mid).count()); VERIFY(((m1.array() < -mid).matrix() || (m1.array() > mid).matrix()).count() ==
(m1.cwiseAbs().array() > mid).count());
typedef Matrix<Index, Dynamic, 1> VectorOfIndices; typedef Matrix<Index, Dynamic, 1> VectorOfIndices;

View File

@ -241,16 +241,14 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
template <typename... IndexTypes> template <typename... IndexTypes>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index firstDimension, IndexTypes... otherDimensions) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(Index firstDimension, IndexTypes... otherDimensions)
: m_storage(firstDimension, otherDimensions...) : m_storage(firstDimension, otherDimensions...) {
{
// The number of dimensions used to construct a tensor must be equal to the rank of the tensor. // The number of dimensions used to construct a tensor must be equal to the rank of the tensor.
EIGEN_STATIC_ASSERT(sizeof...(otherDimensions) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE) EIGEN_STATIC_ASSERT(sizeof...(otherDimensions) + 1 == NumIndices, YOU_MADE_A_PROGRAMMING_MISTAKE)
} }
/** Normal Dimension */ /** Normal Dimension */
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Tensor(const array<Index, NumIndices>& dimensions) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Tensor(const array<Index, NumIndices>& dimensions)
: m_storage(internal::array_prod(dimensions), dimensions) : m_storage(internal::array_prod(dimensions), dimensions) {
{
EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
} }

View File

@ -217,12 +217,11 @@ struct DSizes : array<DenseIndex, NumDims> {
template <typename... IndexTypes> template <typename... IndexTypes>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit DSizes(DenseIndex firstDimension, DenseIndex secondDimension, EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit DSizes(DenseIndex firstDimension, DenseIndex secondDimension,
IndexTypes... otherDimensions) IndexTypes... otherDimensions)
: Base({{firstDimension, secondDimension, otherDimensions...}}){EIGEN_STATIC_ASSERT( : Base({{firstDimension, secondDimension, otherDimensions...}}) {
sizeof...(otherDimensions) + 2 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE)} EIGEN_STATIC_ASSERT(sizeof...(otherDimensions) + 2 == NumDims, YOU_MADE_A_PROGRAMMING_MISTAKE)
}
EIGEN_DEVICE_FUNC DSizes EIGEN_DEVICE_FUNC DSizes& operator=(const array<DenseIndex, NumDims>& other) {
&
operator=(const array<DenseIndex, NumDims>& other) {
*static_cast<Base*>(this) = other; *static_cast<Base*>(this) = other;
return *this; return *this;
} }

View File

@ -367,7 +367,8 @@ struct TensorPrinter<Tensor, rank, TensorIOFormatLegacy, std::enable_if_t<rank !
const IndexType total_size = internal::array_prod(tensor.dimensions()); const IndexType total_size = internal::array_prod(tensor.dimensions());
if (total_size > 0) { if (total_size > 0) {
const IndexType first_dim = Eigen::internal::array_get<0>(tensor.dimensions()); const IndexType first_dim = Eigen::internal::array_get<0>(tensor.dimensions());
Map<const Array<Scalar, Dynamic, Dynamic, Tensor::Layout>> matrix(tensor.data(), first_dim, total_size / first_dim); Map<const Array<Scalar, Dynamic, Dynamic, Tensor::Layout>> matrix(tensor.data(), first_dim,
total_size / first_dim);
s << matrix; s << matrix;
return; return;
} }

View File

@ -79,11 +79,11 @@ class TensorMap : public TensorBase<TensorMap<PlainObjectType, Options_, MakePoi
template <typename... IndexTypes> template <typename... IndexTypes>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension, EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, Index firstDimension,
IndexTypes... otherDimensions) IndexTypes... otherDimensions)
: m_data(dataPtr), : m_data(dataPtr), m_dimensions(firstDimension, otherDimensions...) {
m_dimensions(firstDimension, otherDimensions...){
// The number of dimensions used to construct a tensor must be equal to the rank of the tensor. // The number of dimensions used to construct a tensor must be equal to the rank of the tensor.
EIGEN_STATIC_ASSERT((sizeof...(otherDimensions) + 1 == NumIndices || NumIndices == Dynamic), EIGEN_STATIC_ASSERT((sizeof...(otherDimensions) + 1 == NumIndices || NumIndices == Dynamic),
YOU_MADE_A_PROGRAMMING_MISTAKE)} YOU_MADE_A_PROGRAMMING_MISTAKE)
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr, EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorMap(StoragePointerType dataPtr,
const array<Index, NumIndices>& dimensions) const array<Index, NumIndices>& dimensions)