From 3918768be109ec98b8ca0a0449c01da17b7685a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 25 Apr 2023 19:05:49 +0000 Subject: [PATCH] Fix sparse iterator and tests. --- Eigen/src/SparseCore/SparseCompressedBase.h | 5 +++++ test/sparse_basic.cpp | 4 +++- test/sparse_vector.cpp | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index f5047fd4b..c1aa42636 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -360,6 +360,7 @@ public: StorageVal(const StorageIndex& innerIndex, const Scalar& value) : m_innerIndex(innerIndex), m_value(value) {} StorageVal(const StorageVal& other) : m_innerIndex(other.m_innerIndex), m_value(other.m_value) {} + StorageVal(StorageVal&& other) = default; inline const StorageIndex& key() const { return m_innerIndex; } inline StorageIndex& key() { return m_innerIndex; } @@ -382,6 +383,9 @@ class StorageRef { public: using value_type = StorageVal; + + // StorageRef Needs to be move-able for sort on macos. + StorageRef(StorageRef&& other) = default; inline StorageRef& operator=(const StorageRef& other) { key() = other.key(); @@ -436,6 +440,7 @@ public: CompressedStorageIterator(difference_type index, StorageIndex* innerIndexPtr, Scalar* valuePtr) : m_index(index), m_data(innerIndexPtr, valuePtr) {} CompressedStorageIterator(difference_type index, reference data) : m_index(index), m_data(data) {} CompressedStorageIterator(const CompressedStorageIterator& other) : m_index(other.m_index), m_data(other.m_data) {} + CompressedStorageIterator(CompressedStorageIterator&& other) = default; inline CompressedStorageIterator& operator=(const CompressedStorageIterator& other) { m_index = other.m_index; m_data = other.m_data; diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 0eb1e3b7c..ddde617db 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -171,8 +171,10 @@ template void sparse_basic(const SparseMatrixType& re // generate random inner indices with no repeats Vector innerIndices(inner); innerIndices.setLinSpaced(inner, 0, inner - 1); + std::random_device rd; + std::mt19937 g(rd()); for (Index j = 0; j < outer; j++) { - std::random_shuffle(innerIndices.begin(), innerIndices.end()); + std::shuffle(innerIndices.begin(), innerIndices.end(), g); Index nzj = internal::random(2, inner / 2); for (Index k = 0; k < nzj; k++) { Index i = innerIndices[k]; diff --git a/test/sparse_vector.cpp b/test/sparse_vector.cpp index 88cea0948..0f9987950 100644 --- a/test/sparse_vector.cpp +++ b/test/sparse_vector.cpp @@ -151,7 +151,9 @@ template void sparse_vector(int rows, int DenseVector refVec1 = DenseVector::Zero(rows); DenseIndexVector innerIndices(rows); innerIndices.setLinSpaced(0, rows - 1); - std::random_shuffle(innerIndices.begin(), innerIndices.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(innerIndices.begin(), innerIndices.end(), g); Index nz = internal::random(2, rows / 2); for (Index k = 0; k < nz; k++) {