mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-04 12:15:11 +08:00
Fix sparse iterator and tests.
This commit is contained in:
parent
70410310a4
commit
3918768be1
@ -360,6 +360,7 @@ public:
|
|||||||
|
|
||||||
StorageVal(const StorageIndex& innerIndex, const Scalar& value) : m_innerIndex(innerIndex), m_value(value) {}
|
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(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 const StorageIndex& key() const { return m_innerIndex; }
|
||||||
inline StorageIndex& key() { return m_innerIndex; }
|
inline StorageIndex& key() { return m_innerIndex; }
|
||||||
@ -383,6 +384,9 @@ class StorageRef
|
|||||||
public:
|
public:
|
||||||
using value_type = StorageVal<Scalar, StorageIndex>;
|
using value_type = StorageVal<Scalar, StorageIndex>;
|
||||||
|
|
||||||
|
// StorageRef Needs to be move-able for sort on macos.
|
||||||
|
StorageRef(StorageRef&& other) = default;
|
||||||
|
|
||||||
inline StorageRef& operator=(const StorageRef& other) {
|
inline StorageRef& operator=(const StorageRef& other) {
|
||||||
key() = other.key();
|
key() = other.key();
|
||||||
value() = other.value();
|
value() = other.value();
|
||||||
@ -436,6 +440,7 @@ public:
|
|||||||
CompressedStorageIterator(difference_type index, StorageIndex* innerIndexPtr, Scalar* valuePtr) : m_index(index), m_data(innerIndexPtr, valuePtr) {}
|
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(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(const CompressedStorageIterator& other) : m_index(other.m_index), m_data(other.m_data) {}
|
||||||
|
CompressedStorageIterator(CompressedStorageIterator&& other) = default;
|
||||||
inline CompressedStorageIterator& operator=(const CompressedStorageIterator& other) {
|
inline CompressedStorageIterator& operator=(const CompressedStorageIterator& other) {
|
||||||
m_index = other.m_index;
|
m_index = other.m_index;
|
||||||
m_data = other.m_data;
|
m_data = other.m_data;
|
||||||
|
@ -171,8 +171,10 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
// generate random inner indices with no repeats
|
// generate random inner indices with no repeats
|
||||||
Vector<Index, Dynamic> innerIndices(inner);
|
Vector<Index, Dynamic> innerIndices(inner);
|
||||||
innerIndices.setLinSpaced(inner, 0, inner - 1);
|
innerIndices.setLinSpaced(inner, 0, inner - 1);
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 g(rd());
|
||||||
for (Index j = 0; j < outer; j++) {
|
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<Index>(2, inner / 2);
|
Index nzj = internal::random<Index>(2, inner / 2);
|
||||||
for (Index k = 0; k < nzj; k++) {
|
for (Index k = 0; k < nzj; k++) {
|
||||||
Index i = innerIndices[k];
|
Index i = innerIndices[k];
|
||||||
|
@ -151,7 +151,9 @@ template<typename Scalar,typename StorageIndex> void sparse_vector(int rows, int
|
|||||||
DenseVector refVec1 = DenseVector::Zero(rows);
|
DenseVector refVec1 = DenseVector::Zero(rows);
|
||||||
DenseIndexVector innerIndices(rows);
|
DenseIndexVector innerIndices(rows);
|
||||||
innerIndices.setLinSpaced(0, rows - 1);
|
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<Index>(2, rows / 2);
|
Index nz = internal::random<Index>(2, rows / 2);
|
||||||
for (Index k = 0; k < nz; k++)
|
for (Index k = 0; k < nz; k++)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user