MOAB
4.9.3pre
|
#include <AmbiVector.h>
Classes | |
class | Iterator |
struct | ListEl |
Public Types | |
typedef _Scalar | Scalar |
typedef _StorageIndex | StorageIndex |
typedef NumTraits< Scalar >::Real | RealScalar |
Public Member Functions | |
AmbiVector (Index size) | |
void | init (double estimatedDensity) |
void | init (int mode) |
Index | nonZeros () const |
void | setBounds (Index start, Index end) |
void | setZero () |
void | restart () |
Scalar & | coeffRef (Index i) |
Scalar & | coeff (Index i) |
~AmbiVector () | |
void | resize (Index size) |
StorageIndex | size () const |
Protected Member Functions | |
StorageIndex | convert_index (Index idx) |
void | reallocate (Index size) |
void | reallocateSparse () |
Protected Attributes | |
Scalar * | m_buffer |
Scalar | m_zero |
StorageIndex | m_size |
StorageIndex | m_start |
StorageIndex | m_end |
StorageIndex | m_allocatedSize |
StorageIndex | m_allocatedElements |
StorageIndex | m_mode |
StorageIndex | m_llStart |
StorageIndex | m_llCurrent |
StorageIndex | m_llSize |
Hybrid sparse/dense vector class designed for intensive read-write operations.
See BasicSparseLLT and SparseProduct for usage examples.
Definition at line 23 of file AmbiVector.h.
typedef NumTraits<Scalar>::Real Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::RealScalar |
Definition at line 28 of file AmbiVector.h.
typedef _Scalar Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::Scalar |
Definition at line 26 of file AmbiVector.h.
typedef _StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::StorageIndex |
Definition at line 27 of file AmbiVector.h.
Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::AmbiVector | ( | Index | size | ) | [inline, explicit] |
Definition at line 30 of file AmbiVector.h.
: m_buffer(0), m_zero(0), m_size(0), m_allocatedSize(0), m_allocatedElements(0), m_mode(-1) { resize(size); }
Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::~AmbiVector | ( | ) | [inline] |
Definition at line 52 of file AmbiVector.h.
{ delete[] m_buffer; }
_Scalar & Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::coeff | ( | Index | i | ) |
Definition at line 255 of file AmbiVector.h.
{ if (m_mode==IsDense) return m_buffer[i]; else { ListEl* EIGEN_RESTRICT llElements = reinterpret_cast<ListEl*>(m_buffer); eigen_assert(m_mode==IsSparse); if ((m_llSize==0) || (i<llElements[m_llStart].index)) { return m_zero; } else { Index elid = m_llStart; while (elid >= 0 && llElements[elid].index<i) elid = llElements[elid].next; if (llElements[elid].index==i) return llElements[m_llCurrent].value; else return m_zero; } } }
_Scalar & Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::coeffRef | ( | Index | i | ) |
Definition at line 186 of file AmbiVector.h.
{ if (m_mode==IsDense) return m_buffer[i]; else { ListEl* EIGEN_RESTRICT llElements = reinterpret_cast<ListEl*>(m_buffer); // TODO factorize the following code to reduce code generation eigen_assert(m_mode==IsSparse); if (m_llSize==0) { // this is the first element m_llStart = 0; m_llCurrent = 0; ++m_llSize; llElements[0].value = Scalar(0); llElements[0].index = convert_index(i); llElements[0].next = -1; return llElements[0].value; } else if (i<llElements[m_llStart].index) { // this is going to be the new first element of the list ListEl& el = llElements[m_llSize]; el.value = Scalar(0); el.index = convert_index(i); el.next = m_llStart; m_llStart = m_llSize; ++m_llSize; m_llCurrent = m_llStart; return el.value; } else { StorageIndex nextel = llElements[m_llCurrent].next; eigen_assert(i>=llElements[m_llCurrent].index && "you must call restart() before inserting an element with lower or equal index"); while (nextel >= 0 && llElements[nextel].index<=i) { m_llCurrent = nextel; nextel = llElements[nextel].next; } if (llElements[m_llCurrent].index==i) { // the coefficient already exists and we found it ! return llElements[m_llCurrent].value; } else { if (m_llSize>=m_allocatedElements) { reallocateSparse(); llElements = reinterpret_cast<ListEl*>(m_buffer); } eigen_internal_assert(m_llSize<m_allocatedElements && "internal error: overflow in sparse mode"); // let's insert a new coefficient ListEl& el = llElements[m_llSize]; el.value = Scalar(0); el.index = convert_index(i); el.next = llElements[m_llCurrent].next; llElements[m_llCurrent].next = m_llSize; ++m_llSize; return el.value; } } } }
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::convert_index | ( | Index | idx | ) | [inline, protected] |
Definition at line 64 of file AmbiVector.h.
{
return internal::convert_index<StorageIndex>(idx);
}
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::init | ( | double | estimatedDensity | ) |
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::init | ( | int | mode | ) |
Index Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::nonZeros | ( | ) | const |
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::reallocate | ( | Index | size | ) | [inline, protected] |
Definition at line 69 of file AmbiVector.h.
{ // if the size of the matrix is not too large, let's allocate a bit more than needed such // that we can handle dense vector even in sparse mode. delete[] m_buffer; if (size<1000) { Index allocSize = (size * sizeof(ListEl) + sizeof(Scalar) - 1)/sizeof(Scalar); m_allocatedElements = convert_index((allocSize*sizeof(Scalar))/sizeof(ListEl)); m_buffer = new Scalar[allocSize]; } else { m_allocatedElements = convert_index((size*sizeof(Scalar))/sizeof(ListEl)); m_buffer = new Scalar[size]; } m_size = convert_index(size); m_start = 0; m_end = m_size; }
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::reallocateSparse | ( | ) | [inline, protected] |
Definition at line 90 of file AmbiVector.h.
{ Index copyElements = m_allocatedElements; m_allocatedElements = (std::min)(StorageIndex(m_allocatedElements*1.5),m_size); Index allocSize = m_allocatedElements * sizeof(ListEl); allocSize = (allocSize + sizeof(Scalar) - 1)/sizeof(Scalar); Scalar* newBuffer = new Scalar[allocSize]; memcpy(newBuffer, m_buffer, copyElements * sizeof(ListEl)); delete[] m_buffer; m_buffer = newBuffer; }
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::resize | ( | Index | size | ) | [inline] |
Definition at line 54 of file AmbiVector.h.
{ if (m_allocatedSize < size) reallocate(size); m_size = convert_index(size); }
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::restart | ( | ) |
Must be called whenever we might perform a write access with an index smaller than the previous one.
Don't worry, this function is extremely cheap.
Definition at line 163 of file AmbiVector.h.
{ m_llCurrent = m_llStart; }
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::setBounds | ( | Index | start, |
Index | end | ||
) | [inline] |
Specifies a sub-vector to work on
Definition at line 42 of file AmbiVector.h.
{ m_start = convert_index(start); m_end = convert_index(end); }
void Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::setZero | ( | ) |
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::size | ( | ) | const [inline] |
Definition at line 61 of file AmbiVector.h.
{ return m_size; }
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_allocatedElements [protected] |
Definition at line 118 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_allocatedSize [protected] |
Definition at line 117 of file AmbiVector.h.
Scalar* Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_buffer [protected] |
Definition at line 112 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_end [protected] |
Definition at line 116 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_llCurrent [protected] |
Definition at line 123 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_llSize [protected] |
Definition at line 124 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_llStart [protected] |
Definition at line 122 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_mode [protected] |
Definition at line 119 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_size [protected] |
Definition at line 114 of file AmbiVector.h.
StorageIndex Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_start [protected] |
Definition at line 115 of file AmbiVector.h.
Scalar Eigen::internal::AmbiVector< _Scalar, _StorageIndex >::m_zero [protected] |
Definition at line 113 of file AmbiVector.h.