Version 10.06

This commit is contained in:
mkazhdan
2019-01-27 00:45:07 -05:00
parent 7c0b908693
commit c19d3188c9
17 changed files with 668 additions and 279 deletions
+59 -5
View File
@@ -31,9 +31,11 @@ DAMAGE.
#include "SparseMatrixInterface.h"
#include "Array.h"
template< class T , class IndexType=int > class SparseMatrix : public SparseMatrixInterface< T , ConstPointer( MatrixEntry< T , IndexType > ) >
template< class T , class IndexType , size_t MaxRowSize=0 > class SparseMatrix;
template< class T , class IndexType > class SparseMatrix< T , IndexType , 0 > : public SparseMatrixInterface< T , ConstPointer( MatrixEntry< T , IndexType > ) >
{
template< class T2 , class IndexType2 > friend class SparseMatrix;
template< class T2 , class IndexType2 , size_t MaxRowSize2 > friend class SparseMatrix;
Pointer( Pointer( MatrixEntry< T , IndexType > ) ) _entries;
public:
static void Swap( SparseMatrix& M1 , SparseMatrix& M2 )
@@ -52,17 +54,17 @@ public:
SparseMatrix( const SparseMatrix& M );
SparseMatrix( SparseMatrix&& M );
template< class T2 , class IndexType2 >
SparseMatrix( const SparseMatrix< T2 , IndexType2 >& M );
SparseMatrix( const SparseMatrix< T2 , IndexType2 , 0 >& M );
~SparseMatrix();
SparseMatrix& operator = ( SparseMatrix&& M );
SparseMatrix< T , IndexType >& operator = ( const SparseMatrix< T , IndexType >& M );
template< class T2 , class IndexType2 >
SparseMatrix< T , IndexType >& operator = ( const SparseMatrix< T2 , IndexType2 >& M );
SparseMatrix< T , IndexType , 0 >& operator = ( const SparseMatrix< T2 , IndexType2 , 0 >& M );
template< class T2 > void operator()( const T2* in , T2* out ) const;
template< class T2 , class IndexType2 >
SparseMatrix< T , IndexType >& copy( const SparseMatrix< T2 , IndexType2 >& M );
SparseMatrix< T , IndexType , 0 >& copy( const SparseMatrix< T2 , IndexType2 , 0 >& M );
inline ConstPointer( MatrixEntry< T , IndexType > ) begin( size_t row ) const { return _entries[row]; }
inline ConstPointer( MatrixEntry< T , IndexType > ) end ( size_t row ) const { return _entries[row] + (unsigned long long)rowSizes[row]; }
@@ -100,5 +102,57 @@ public:
template< class const_iterator >
static SparseMatrix Transpose( const SparseMatrixInterface< T , const_iterator >& At , size_t outRows , T (*TransposeFunction)( const T& )=NULL );
};
template< class T , class IndexType , size_t MaxRowSize > class SparseMatrix : public SparseMatrixInterface< T , ConstPointer( MatrixEntry< T , IndexType > ) >
{
template< class T2 , class IndexType2 > friend class _SparseMatrix;
Pointer( MatrixEntry< T , IndexType > ) _entries;
size_t _rowNum;
Pointer( size_t ) _rowSizes;
size_t _maxRows;
public:
static void Swap( SparseMatrix& M1 , SparseMatrix& M2 )
{
std::swap( M1._rowNum , M2._rowNum );
std::swap( M1._rowSizes , M2._rowSizes );
std::swap( M1._entries , M2._entries );
}
typedef SparseMatrixInterface< T , ConstPointer( MatrixEntry< T , IndexType > ) > Interface;
typedef ConstPointer( MatrixEntry< T , IndexType > ) RowIterator;
SparseMatrix( void );
SparseMatrix( const SparseMatrix& M );
SparseMatrix( SparseMatrix&& M );
template< class T2 , class IndexType2 >
SparseMatrix( const SparseMatrix< T2 , IndexType2 , MaxRowSize >& M );
SparseMatrix& operator = ( SparseMatrix&& M );
SparseMatrix< T , IndexType , MaxRowSize >& operator = ( const SparseMatrix< T , IndexType , MaxRowSize >& M );
template< class T2 , class IndexType2 >
SparseMatrix< T , IndexType , MaxRowSize >& operator = ( const SparseMatrix< T2 , IndexType2 , MaxRowSize >& M );
~SparseMatrix( void );
template< class T2 > void operator()( const T2* in , T2* out ) const;
inline ConstPointer( MatrixEntry< T , IndexType > ) begin( size_t row ) const { return _entries + MaxRowSize * row; }
inline ConstPointer( MatrixEntry< T , IndexType > ) end ( size_t row ) const { return _entries + MaxRowSize * row + (unsigned long long)_rowSizes[row]; }
inline size_t rows ( void ) const { return _rowNum; }
inline size_t rowSize ( size_t idx ) const { return _rowSizes[idx]; }
SparseMatrix( size_t rowNum );
void resize ( size_t rowNum );
void setRowSize( size_t row , size_t rowSize );
void resetRowSize( size_t row , size_t rowSize );
inline Pointer( MatrixEntry< T , IndexType > ) operator[] ( size_t idx ) { return _entries + MaxRowSize * idx; }
inline ConstPointer( MatrixEntry< T , IndexType > ) operator[] ( size_t idx ) const { return _entries + MaxRowSize * idx; }
// With copy move, these should be well-behaved from a memory perspective
SparseMatrix operator * ( T s ) const;
SparseMatrix operator / ( T s ) const;
SparseMatrix& operator *= ( T s );
SparseMatrix& operator /= ( T s );
Pointer( T ) operator * ( const Pointer( T ) in ) const;
};
#include "SparseMatrix.inl"
#endif /* __SPARSEMATRIX_HPP */