aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/src/SparseExtra
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-02-13 18:57:41 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-02-13 18:57:41 +0100
commitfc202bab398ed9b78ef8452f8e4ef35e233965f6 (patch)
treef0f427ee115aa8579b0d43a49c2ad762b1b0f57c /unsupported/Eigen/src/SparseExtra
parentfe513199808654bfa5080fe16bda7dcdafbd57c6 (diff)
Index refactoring: StorageIndex must be used for storage only (and locally when it make sense). In all other cases use the global Index type.
Diffstat (limited to 'unsupported/Eigen/src/SparseExtra')
-rw-r--r--unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h98
-rw-r--r--unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h50
-rw-r--r--unsupported/Eigen/src/SparseExtra/RandomSetter.h8
3 files changed, 78 insertions, 78 deletions
diff --git a/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h b/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h
index d92fd0ef1..8a7e0e57f 100644
--- a/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h
+++ b/unsupported/Eigen/src/SparseExtra/BlockSparseMatrix.h
@@ -535,7 +535,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \brief Set the number of rows and columns blocks
*/
- inline void resize(StorageIndex brow, StorageIndex bcol)
+ inline void resize(Index brow, Index bcol)
{
m_innerBSize = IsColMajor ? brow : bcol;
m_outerBSize = IsColMajor ? bcol : brow;
@@ -546,7 +546,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
*
* Call this only for fixed-size blocks
*/
- inline void setBlockSize(StorageIndex blockSize)
+ inline void setBlockSize(Index blockSize)
{
m_blockSize = blockSize;
}
@@ -593,7 +593,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
* is computed in setBlockLayout() for variable-size blocks
* \sa setBlockSize()
*/
- inline void reserve(const StorageIndex nonzerosblocks)
+ inline void reserve(const Index nonzerosblocks)
{
eigen_assert((m_innerBSize != 0 && m_outerBSize != 0) &&
"TRYING TO RESERVE ZERO-SIZE MATRICES, CALL resize() first");
@@ -735,7 +735,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \returns the number of rows
*/
- inline StorageIndex rows() const
+ inline Index rows() const
{
// return blockRows();
return (IsColMajor ? innerSize() : outerSize());
@@ -744,39 +744,39 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \returns the number of cols
*/
- inline StorageIndex cols() const
+ inline Index cols() const
{
// return blockCols();
return (IsColMajor ? outerSize() : innerSize());
}
- inline StorageIndex innerSize() const
+ inline Index innerSize() const
{
if(m_blockSize == Dynamic) return m_innerOffset[m_innerBSize];
else return (m_innerBSize * m_blockSize) ;
}
- inline StorageIndex outerSize() const
+ inline Index outerSize() const
{
if(m_blockSize == Dynamic) return m_outerOffset[m_outerBSize];
else return (m_outerBSize * m_blockSize) ;
}
/** \returns the number of rows grouped by blocks */
- inline StorageIndex blockRows() const
+ inline Index blockRows() const
{
return (IsColMajor ? m_innerBSize : m_outerBSize);
}
/** \returns the number of columns grouped by blocks */
- inline StorageIndex blockCols() const
+ inline Index blockCols() const
{
return (IsColMajor ? m_outerBSize : m_innerBSize);
}
- inline StorageIndex outerBlocks() const { return m_outerBSize; }
- inline StorageIndex innerBlocks() const { return m_innerBSize; }
+ inline Index outerBlocks() const { return m_outerBSize; }
+ inline Index innerBlocks() const { return m_innerBSize; }
/** \returns the block index where outer belongs to */
- inline StorageIndex outerToBlock(StorageIndex outer) const
+ inline Index outerToBlock(Index outer) const
{
eigen_assert(outer < outerSize() && "OUTER INDEX OUT OF BOUNDS");
@@ -788,7 +788,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
return b_outer - 1;
}
/** \returns the block index where inner belongs to */
- inline StorageIndex innerToBlock(StorageIndex inner) const
+ inline Index innerToBlock(Index inner) const
{
eigen_assert(inner < innerSize() && "OUTER INDEX OUT OF BOUNDS");
@@ -803,7 +803,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
*\returns a reference to the (i,j) block as an Eigen Dense Matrix
*/
- Ref<BlockScalar> coeffRef(StorageIndex brow, StorageIndex bcol)
+ Ref<BlockScalar> coeffRef(Index brow, Index bcol)
{
eigen_assert(brow < blockRows() && "BLOCK ROW INDEX OUT OF BOUNDS");
eigen_assert(bcol < blockCols() && "BLOCK nzblocksFlagCOLUMN OUT OF BOUNDS");
@@ -829,7 +829,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \returns the value of the (i,j) block as an Eigen Dense Matrix
*/
- Map<const BlockScalar> coeff(StorageIndex brow, StorageIndex bcol) const
+ Map<const BlockScalar> coeff(Index brow, Index bcol) const
{
eigen_assert(brow < blockRows() && "BLOCK ROW INDEX OUT OF BOUNDS");
eigen_assert(bcol < blockCols() && "BLOCK COLUMN OUT OF BOUNDS");
@@ -857,9 +857,9 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
}
/** \returns the number of nonzero blocks */
- inline StorageIndex nonZerosBlocks() const { return m_nonzerosblocks; }
+ inline Index nonZerosBlocks() const { return m_nonzerosblocks; }
/** \returns the total number of nonzero elements, including eventual explicit zeros in blocks */
- inline StorageIndex nonZeros() const { return m_nonzeros; }
+ inline Index nonZeros() const { return m_nonzeros; }
inline BlockScalarReturnType *valuePtr() {return static_cast<BlockScalarReturnType *>(m_values);}
// inline Scalar *valuePtr(){ return m_values; }
@@ -873,7 +873,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \returns the starting index of the bi row block
*/
- inline StorageIndex blockRowsIndex(StorageIndex bi) const
+ inline Index blockRowsIndex(Index bi) const
{
return IsColMajor ? blockInnerIndex(bi) : blockOuterIndex(bi);
}
@@ -881,26 +881,26 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \returns the starting index of the bj col block
*/
- inline StorageIndex blockColsIndex(Index bj) const
+ inline Index blockColsIndex(Index bj) const
{
return IsColMajor ? blockOuterIndex(bj) : blockInnerIndex(bj);
}
- inline StorageIndex blockOuterIndex(Index bj) const
+ inline Index blockOuterIndex(Index bj) const
{
return (m_blockSize == Dynamic) ? m_outerOffset[bj] : (bj * m_blockSize);
}
- inline StorageIndex blockInnerIndex(Index bi) const
+ inline Index blockInnerIndex(Index bi) const
{
return (m_blockSize == Dynamic) ? m_innerOffset[bi] : (bi * m_blockSize);
}
// Not needed ???
- inline StorageIndex blockInnerSize(Index bi) const
+ inline Index blockInnerSize(Index bi) const
{
return (m_blockSize == Dynamic) ? (m_innerOffset[bi+1] - m_innerOffset[bi]) : m_blockSize;
}
- inline StorageIndex blockOuterSize(Index bj) const
+ inline Index blockOuterSize(Index bj) const
{
return (m_blockSize == Dynamic) ? (m_outerOffset[bj+1]- m_outerOffset[bj]) : m_blockSize;
}
@@ -933,7 +933,7 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
/**
* \returns the starting position of the block <id> in the array of values
*/
- StorageIndex blockPtr(Index id) const
+ Index blockPtr(Index id) const
{
if(m_blockSize == Dynamic) return m_blockPtr[id];
else return id * m_blockSize * m_blockSize;
@@ -955,17 +955,17 @@ class BlockSparseMatrix : public SparseMatrixBase<BlockSparseMatrix<_Scalar,_Blo
// Insert a block at a particular location... need to make a room for that
Map<BlockScalar> insert(Index brow, Index bcol);
- StorageIndex m_innerBSize; // Number of block rows
- StorageIndex m_outerBSize; // Number of block columns
+ Index m_innerBSize; // Number of block rows
+ Index m_outerBSize; // Number of block columns
StorageIndex *m_innerOffset; // Starting index of each inner block (size m_innerBSize+1)
StorageIndex *m_outerOffset; // Starting index of each outer block (size m_outerBSize+1)
- StorageIndex m_nonzerosblocks; // Total nonzeros blocks (lower than m_innerBSize x m_outerBSize)
- StorageIndex m_nonzeros; // Total nonzeros elements
+ Index m_nonzerosblocks; // Total nonzeros blocks (lower than m_innerBSize x m_outerBSize)
+ Index m_nonzeros; // Total nonzeros elements
Scalar *m_values; //Values stored block column after block column (size m_nonzeros)
StorageIndex *m_blockPtr; // Pointer to the beginning of each block in m_values, size m_nonzeroblocks ... null for fixed-size blocks
StorageIndex *m_indices; //Inner block indices, size m_nonzerosblocks ... OK
StorageIndex *m_outerIndex; // Starting pointer of each block column in m_indices (size m_outerBSize)... OK
- StorageIndex m_blockSize; // Size of a block for fixed-size blocks, otherwise -1
+ Index m_blockSize; // Size of a block for fixed-size blocks, otherwise -1
};
template<typename _Scalar, int _BlockAtCompileTime, int _Options, typename _StorageIndex>
@@ -977,7 +977,7 @@ class BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, _StorageIndex>::
Flags = _Options
};
- BlockInnerIterator(const BlockSparseMatrix& mat, const StorageIndex outer)
+ BlockInnerIterator(const BlockSparseMatrix& mat, const Index outer)
: m_mat(mat),m_outer(outer),
m_id(mat.m_outerIndex[outer]),
m_end(mat.m_outerIndex[outer+1])
@@ -997,23 +997,23 @@ class BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, _StorageIndex>::
rows(),cols());
}
// Block inner index
- inline StorageIndex index() const {return m_mat.m_indices[m_id]; }
- inline StorageIndex outer() const { return m_outer; }
+ inline Index index() const {return m_mat.m_indices[m_id]; }
+ inline Index outer() const { return m_outer; }
// block row index
- inline StorageIndex row() const {return index(); }
+ inline Index row() const {return index(); }
// block column index
- inline StorageIndex col() const {return outer(); }
+ inline Index col() const {return outer(); }
// FIXME Number of rows in the current block
- inline StorageIndex rows() const { return (m_mat.m_blockSize==Dynamic) ? (m_mat.m_innerOffset[index()+1] - m_mat.m_innerOffset[index()]) : m_mat.m_blockSize; }
+ inline Index rows() const { return (m_mat.m_blockSize==Dynamic) ? (m_mat.m_innerOffset[index()+1] - m_mat.m_innerOffset[index()]) : m_mat.m_blockSize; }
// Number of columns in the current block ...
- inline StorageIndex cols() const { return (m_mat.m_blockSize==Dynamic) ? (m_mat.m_outerOffset[m_outer+1]-m_mat.m_outerOffset[m_outer]) : m_mat.m_blockSize;}
+ inline Index cols() const { return (m_mat.m_blockSize==Dynamic) ? (m_mat.m_outerOffset[m_outer+1]-m_mat.m_outerOffset[m_outer]) : m_mat.m_blockSize;}
inline operator bool() const { return (m_id < m_end); }
protected:
const BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, StorageIndex>& m_mat;
- const StorageIndex m_outer;
- StorageIndex m_id;
- StorageIndex m_end;
+ const Index m_outer;
+ Index m_id;
+ Index m_end;
};
template<typename _Scalar, int _BlockAtCompileTime, int _Options, typename _StorageIndex>
@@ -1055,23 +1055,23 @@ class BlockSparseMatrix<_Scalar, _BlockAtCompileTime, _Options, _StorageIndex>::
{
return itb.valueRef().coeff(m_id - m_start, m_offset);
}
- inline StorageIndex index() const { return m_id; }
- inline StorageIndex outer() const {return m_outer; }
- inline StorageIndex col() const {return outer(); }
- inline StorageIndex row() const { return index();}
+ inline Index index() const { return m_id; }
+ inline Index outer() const {return m_outer; }
+ inline Index col() const {return outer(); }
+ inline Index row() const { return index();}
inline operator bool() const
{
return itb;
}
protected:
const BlockSparseMatrix& m_mat;
- const StorageIndex m_outer;
- const StorageIndex m_outerB;
+ const Index m_outer;
+ const Index m_outerB;
BlockInnerIterator itb; // Iterator through the blocks
- const StorageIndex m_offset; // Position of this column in the block
- StorageIndex m_start; // starting inner index of this block
- StorageIndex m_id; // current inner index in the block
- StorageIndex m_end; // starting inner index of the next block
+ const Index m_offset; // Position of this column in the block
+ Index m_start; // starting inner index of this block
+ Index m_id; // current inner index in the block
+ Index m_end; // starting inner index of the next block
};
} // end namespace Eigen
diff --git a/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h b/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h
index bedb1dec5..e1284c782 100644
--- a/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h
+++ b/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h
@@ -33,11 +33,11 @@ namespace Eigen {
*/
namespace internal {
-template<typename _Scalar, int _Options, typename _Index>
-struct traits<DynamicSparseMatrix<_Scalar, _Options, _Index> >
+template<typename _Scalar, int _Options, typename _StorageIndex>
+struct traits<DynamicSparseMatrix<_Scalar, _Options, _StorageIndex> >
{
typedef _Scalar Scalar;
- typedef _Index StorageIndex;
+ typedef _StorageIndex StorageIndex;
typedef Sparse StorageKind;
typedef MatrixXpr XprKind;
enum {
@@ -52,9 +52,9 @@ struct traits<DynamicSparseMatrix<_Scalar, _Options, _Index> >
};
}
-template<typename _Scalar, int _Options, typename _Index>
+template<typename _Scalar, int _Options, typename _StorageIndex>
class DynamicSparseMatrix
- : public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Options, _Index> >
+ : public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Options, _StorageIndex> >
{
public:
EIGEN_SPARSE_PUBLIC_INTERFACE(DynamicSparseMatrix)
@@ -72,16 +72,16 @@ template<typename _Scalar, int _Options, typename _Index>
typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0), StorageIndex> TransposedSparseMatrix;
- StorageIndex m_innerSize;
+ Index m_innerSize;
std::vector<internal::CompressedStorage<Scalar,StorageIndex> > m_data;
public:
- inline StorageIndex rows() const { return IsRowMajor ? outerSize() : m_innerSize; }
- inline StorageIndex cols() const { return IsRowMajor ? m_innerSize : outerSize(); }
- inline StorageIndex innerSize() const { return m_innerSize; }
- inline StorageIndex outerSize() const { return convert_index(m_data.size()); }
- inline StorageIndex innerNonZeros(Index j) const { return m_data[j].size(); }
+ inline Index rows() const { return IsRowMajor ? outerSize() : m_innerSize; }
+ inline Index cols() const { return IsRowMajor ? m_innerSize : outerSize(); }
+ inline Index innerSize() const { return m_innerSize; }
+ inline Index outerSize() const { return convert_index(m_data.size()); }
+ inline Index innerNonZeros(Index j) const { return m_data[j].size(); }
std::vector<internal::CompressedStorage<Scalar,StorageIndex> >& _data() { return m_data; }
const std::vector<internal::CompressedStorage<Scalar,StorageIndex> >& _data() const { return m_data; }
@@ -117,11 +117,11 @@ template<typename _Scalar, int _Options, typename _Index>
}
/** \returns the number of non zero coefficients */
- StorageIndex nonZeros() const
+ Index nonZeros() const
{
- StorageIndex res = 0;
+ Index res = 0;
for (Index j=0; j<outerSize(); ++j)
- res += convert_index(m_data[j].size());
+ res += m_data[j].size();
return res;
}
@@ -320,10 +320,10 @@ template<typename _Scalar, int _Options, typename _Index>
# endif
};
-template<typename Scalar, int _Options, typename _Index>
-class DynamicSparseMatrix<Scalar,_Options,_Index>::InnerIterator : public SparseVector<Scalar,_Options,_Index>::InnerIterator
+template<typename Scalar, int _Options, typename _StorageIndex>
+class DynamicSparseMatrix<Scalar,_Options,_StorageIndex>::InnerIterator : public SparseVector<Scalar,_Options,_StorageIndex>::InnerIterator
{
- typedef typename SparseVector<Scalar,_Options,_Index>::InnerIterator Base;
+ typedef typename SparseVector<Scalar,_Options,_StorageIndex>::InnerIterator Base;
public:
InnerIterator(const DynamicSparseMatrix& mat, Index outer)
: Base(mat.m_data[outer]), m_outer(outer)
@@ -337,10 +337,10 @@ class DynamicSparseMatrix<Scalar,_Options,_Index>::InnerIterator : public Sparse
const Index m_outer;
};
-template<typename Scalar, int _Options, typename _Index>
-class DynamicSparseMatrix<Scalar,_Options,_Index>::ReverseInnerIterator : public SparseVector<Scalar,_Options,_Index>::ReverseInnerIterator
+template<typename Scalar, int _Options, typename _StorageIndex>
+class DynamicSparseMatrix<Scalar,_Options,_StorageIndex>::ReverseInnerIterator : public SparseVector<Scalar,_Options,_StorageIndex>::ReverseInnerIterator
{
- typedef typename SparseVector<Scalar,_Options,_Index>::ReverseInnerIterator Base;
+ typedef typename SparseVector<Scalar,_Options,_StorageIndex>::ReverseInnerIterator Base;
public:
ReverseInnerIterator(const DynamicSparseMatrix& mat, Index outer)
: Base(mat.m_data[outer]), m_outer(outer)
@@ -356,13 +356,13 @@ class DynamicSparseMatrix<Scalar,_Options,_Index>::ReverseInnerIterator : public
namespace internal {
-template<typename _Scalar, int _Options, typename _Index>
-struct evaluator<DynamicSparseMatrix<_Scalar,_Options,_Index> >
- : evaluator_base<DynamicSparseMatrix<_Scalar,_Options,_Index> >
+template<typename _Scalar, int _Options, typename _StorageIndex>
+struct evaluator<DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> >
+ : evaluator_base<DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> >
{
typedef _Scalar Scalar;
- typedef _Index Index;
- typedef DynamicSparseMatrix<_Scalar,_Options,_Index> SparseMatrixType;
+ typedef _StorageIndex Index;
+ typedef DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> SparseMatrixType;
typedef typename SparseMatrixType::InnerIterator InnerIterator;
typedef typename SparseMatrixType::ReverseInnerIterator ReverseInnerIterator;
diff --git a/unsupported/Eigen/src/SparseExtra/RandomSetter.h b/unsupported/Eigen/src/SparseExtra/RandomSetter.h
index 807ba9d94..0b71ed3ad 100644
--- a/unsupported/Eigen/src/SparseExtra/RandomSetter.h
+++ b/unsupported/Eigen/src/SparseExtra/RandomSetter.h
@@ -292,10 +292,10 @@ class RandomSetter
/** \returns a reference to the coefficient at given coordinates \a row, \a col */
Scalar& operator() (Index row, Index col)
{
- const StorageIndex outer = internal::convert_index<StorageIndex>(SetterRowMajor ? row : col);
- const StorageIndex inner = internal::convert_index<StorageIndex>(SetterRowMajor ? col : row);
- const StorageIndex outerMajor = outer >> OuterPacketBits; // index of the packet/map
- const StorageIndex outerMinor = outer & OuterPacketMask; // index of the inner vector in the packet
+ const Index outer = SetterRowMajor ? row : col;
+ const Index inner = SetterRowMajor ? col : row;
+ const Index outerMajor = outer >> OuterPacketBits; // index of the packet/map
+ const Index outerMinor = outer & OuterPacketMask; // index of the inner vector in the packet
const KeyType key = (KeyType(outerMinor)<<m_keyBitsOffset) | inner;
return m_hashmaps[outerMajor][key].value;
}