mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
various work on the Sparse module:
* added some glue to Eigen/Core (SparseBit, ei_eval, Matrix)
* add two new sparse matrix types:
HashMatrix: based on std::map (for random writes)
LinkedVectorMatrix: array of linked vectors
(for outer coherent writes, e.g. to transpose a matrix)
* add a SparseSetter class to easily set/update any kind of matrices, e.g.:
{ SparseSetter<MatrixType,RandomAccessPattern> wrapper(mymatrix);
for (...) wrapper->coeffRef(rand(),rand()) = rand(); }
* automatic shallow copy for RValue
* and a lot of mess !
plus:
* remove the remaining ArrayBit related stuff
* don't use alloca in product for very large memory allocation
This commit is contained in:
@@ -32,11 +32,11 @@ template<typename Scalar> class SparseArray
|
||||
{
|
||||
public:
|
||||
SparseArray()
|
||||
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0)
|
||||
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0), m_isShared(0)
|
||||
{}
|
||||
|
||||
SparseArray(int size)
|
||||
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0)
|
||||
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0), m_isShared(0)
|
||||
{
|
||||
resize(size);
|
||||
}
|
||||
@@ -51,6 +51,28 @@ template<typename Scalar> class SparseArray
|
||||
resize(other.size());
|
||||
memcpy(m_values, other.m_values, m_size * sizeof(Scalar));
|
||||
memcpy(m_indices, other.m_indices, m_size * sizeof(int));
|
||||
m_isShared = 0;
|
||||
}
|
||||
|
||||
void shallowCopy(const SparseArray& other)
|
||||
{
|
||||
delete[] m_values;
|
||||
delete[] m_indices;
|
||||
m_values = other.m_values;
|
||||
m_indices = other.m_indices;
|
||||
m_size = other.m_size;
|
||||
m_allocatedSize = other.m_allocatedSize;
|
||||
m_isShared = false;
|
||||
other.m_isShared = true;
|
||||
}
|
||||
|
||||
~SparseArray()
|
||||
{
|
||||
if (!m_isShared)
|
||||
{
|
||||
delete[] m_values;
|
||||
delete[] m_indices;
|
||||
}
|
||||
}
|
||||
|
||||
void reserve(int size)
|
||||
@@ -117,7 +139,11 @@ template<typename Scalar> class SparseArray
|
||||
Scalar* m_values;
|
||||
int* m_indices;
|
||||
int m_size;
|
||||
int m_allocatedSize;
|
||||
struct {
|
||||
int m_allocatedSize:31;
|
||||
mutable int m_isShared:1;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // EIGEN_SPARSE_ARRAY_H
|
||||
|
||||
Reference in New Issue
Block a user