Fix std::fill_n reference.

This commit is contained in:
Antonio Sánchez 2025-01-14 00:43:00 +00:00 committed by Charles Schlosser
parent 9836e8d035
commit ad13df7ea4
2 changed files with 17 additions and 11 deletions

View File

@ -78,7 +78,7 @@ template <typename Xpr>
struct eigen_fill_impl<Xpr, /*use_fill*/ true> { struct eigen_fill_impl<Xpr, /*use_fill*/ true> {
using Scalar = typename Xpr::Scalar; using Scalar = typename Xpr::Scalar;
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const Scalar& val) { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const Scalar& val) {
EIGEN_USING_STD(fill_n); using std::fill_n;
fill_n(dst.data(), dst.size(), val); fill_n(dst.data(), dst.size(), val);
} }
template <typename SrcXpr> template <typename SrcXpr>

View File

@ -302,9 +302,10 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
*/ */
inline void setZero() { inline void setZero() {
m_data.clear(); m_data.clear();
std::fill_n(m_outerIndex, m_outerSize + 1, StorageIndex(0)); using std::fill_n;
fill_n(m_outerIndex, m_outerSize + 1, StorageIndex(0));
if (m_innerNonZeros) { if (m_innerNonZeros) {
std::fill_n(m_innerNonZeros, m_outerSize, StorageIndex(0)); fill_n(m_innerNonZeros, m_outerSize, StorageIndex(0));
} }
} }
@ -506,7 +507,7 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
// insert empty outer vectors at indices j, j+1 ... j+num-1 and resize the matrix // insert empty outer vectors at indices j, j+1 ... j+num-1 and resize the matrix
void insertEmptyOuterVectors(Index j, Index num = 1) { void insertEmptyOuterVectors(Index j, Index num = 1) {
EIGEN_USING_STD(fill_n); using std::fill_n;
eigen_assert(num >= 0 && j >= 0 && j < m_outerSize && "Invalid parameters"); eigen_assert(num >= 0 && j >= 0 && j < m_outerSize && "Invalid parameters");
const Index newRows = IsRowMajor ? m_outerSize + num : rows(); const Index newRows = IsRowMajor ? m_outerSize + num : rows();
@ -621,11 +622,13 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
void uncompress() { void uncompress() {
if (!isCompressed()) return; if (!isCompressed()) return;
m_innerNonZeros = internal::conditional_aligned_new_auto<StorageIndex, true>(m_outerSize); m_innerNonZeros = internal::conditional_aligned_new_auto<StorageIndex, true>(m_outerSize);
if (m_outerIndex[m_outerSize] == 0) if (m_outerIndex[m_outerSize] == 0) {
std::fill_n(m_innerNonZeros, m_outerSize, StorageIndex(0)); using std::fill_n;
else fill_n(m_innerNonZeros, m_outerSize, StorageIndex(0));
} else {
for (Index j = 0; j < m_outerSize; j++) m_innerNonZeros[j] = m_outerIndex[j + 1] - m_outerIndex[j]; for (Index j = 0; j < m_outerSize; j++) m_innerNonZeros[j] = m_outerIndex[j + 1] - m_outerIndex[j];
} }
}
/** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerance \a epsilon */ /** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerance \a epsilon */
void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) { void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) {
@ -695,9 +698,10 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
if (outerChange > 0) { if (outerChange > 0) {
StorageIndex lastIdx = m_outerSize == 0 ? StorageIndex(0) : m_outerIndex[m_outerSize]; StorageIndex lastIdx = m_outerSize == 0 ? StorageIndex(0) : m_outerIndex[m_outerSize];
std::fill_n(m_outerIndex + m_outerSize, outerChange + 1, lastIdx); using std::fill_n;
fill_n(m_outerIndex + m_outerSize, outerChange + 1, lastIdx);
if (!isCompressed()) std::fill_n(m_innerNonZeros + m_outerSize, outerChange, StorageIndex(0)); if (!isCompressed()) fill_n(m_innerNonZeros + m_outerSize, outerChange, StorageIndex(0));
} }
} }
m_outerSize = newOuterSize; m_outerSize = newOuterSize;
@ -741,7 +745,8 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize); internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
m_innerNonZeros = 0; m_innerNonZeros = 0;
std::fill_n(m_outerIndex, m_outerSize + 1, StorageIndex(0)); using std::fill_n;
fill_n(m_outerIndex, m_outerSize + 1, StorageIndex(0));
} }
/** \internal /** \internal
@ -843,7 +848,8 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
m_data.squeeze(); m_data.squeeze();
std::iota(m_outerIndex, m_outerIndex + m_outerSize + 1, StorageIndex(0)); std::iota(m_outerIndex, m_outerIndex + m_outerSize + 1, StorageIndex(0));
std::iota(innerIndexPtr(), innerIndexPtr() + m_outerSize, StorageIndex(0)); std::iota(innerIndexPtr(), innerIndexPtr() + m_outerSize, StorageIndex(0));
std::fill_n(valuePtr(), m_outerSize, Scalar(1)); using std::fill_n;
fill_n(valuePtr(), m_outerSize, Scalar(1));
} }
inline SparseMatrix& operator=(const SparseMatrix& other) { inline SparseMatrix& operator=(const SparseMatrix& other) {