30 #ifndef CORE_DATATYPES_MATRIX_TYPE_CONVERTER_H
31 #define CORE_DATATYPES_MATRIX_TYPE_CONVERTER_H
39 #include <Core/Datatypes/ColumnMatrix.h>
40 #include <Core/Datatypes/DenseColMajMatrix.h>
41 #include <Core/Datatypes/DenseColMajMatrixMultiplication.h>
43 #include <Core/Datatypes/DenseMatrixMultiplication.h>
45 #include <Core/Datatypes/SparseRowMatrixMultiplication.h>
56 template <
class ToType>
57 static ToType*
to(
const MatrixHandle& matrix,
typename boost::enable_if<boost::is_base_of<MatrixBase, ToType> >::type* = 0)
59 return SCI_DATATYPE_CAST<ToType*>(matrix.get_rep());
64 return to<DenseMatrix>(mh);
69 return to<SparseRowMatrix>(mh);
74 return to<ColumnMatrix>(mh);
79 return to<DenseColMajMatrix>(mh);
106 (*m)[i][j] = iget(i, j);
110 template <
typename T>
116 (*cm)[i] = iget(i, 0);
120 template <
typename T>
124 size_type nnz = this->number_of_nonzero_elements();
140 a[
count] = iget(r, c);
144 rows[this->nrows_] =
count;
146 return new SparseRowMatrix(this->nrows_, this->ncols_, sparseData, nnz);
149 template <
typename T>
157 template <
typename T>
165 template <
typename T>
170 if (this->nrows_ == 0)
return dm;
177 nextRow = rows_[r+1];
178 while (count < nextRow)
187 template <
typename T>
192 if (this->nrows_ == 0)
return dm;
198 nextRow = rows_[r+1];
199 while (count < nextRow)
201 dm->
iget(r, columns_[count]) = data_[
count];
208 template <
typename T>
216 for (
int i=0; i<this->nrows_; i++)
219 if (columns_[rows_[i]] == 0)
221 (*cm)[i] = data_[rows_[i]];
232 template <
typename T>
239 template <
typename T>
246 (*dm)[i][0] = data_[i];
251 template <
typename T>
258 dm->
iget(i, 0) = data_[i];
263 template <
typename T>
267 size_type nnz = this->number_of_nonzero_elements();
285 rows[this->nrows_] =
count;
290 template <
typename T>
297 template <
typename T>
302 if (dm == 0)
return (0);
313 v2[i+j*m2] = v1[i*m1+j];
319 template <
typename T>
324 for (
index_type i=0; i<static_cast<index_type>(this->nrows_); i++)
325 (*cm)[i] =
data[i][0];
329 template <
typename T>
333 size_type nnz = this->number_of_nonzero_elements();
338 std::cerr <<
"Could not allocate memory for rows, columns, or non-zero elements buffer "
339 << __FILE__ <<
": " << __LINE__ << std::endl;
359 rows[this->nrows_] =
count;
361 return new SparseRowMatrix(this->nrows_, this->ncols_, sparseData, nnz);
virtual SparseRowMatrix * sparse()
Definition: MatrixTypeConverter.h:122
virtual DenseColMajMatrixGeneric< T > * dense_col_maj()
Definition: MatrixTypeConverter.h:253
boost::shared_array< T > Storage
Definition: SparseRowMatrix.h:74
Definition: DenseMatrix.h:68
LockingHandle< Matrix< double > > MatrixHandle
Definition: MatrixFwd.h:55
virtual ColumnMatrix * column()
Definition: MatrixTypeConverter.h:112
Definition: SparseRowMatrix.h:89
static bool column(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:91
virtual ColumnMatrix * column()
Definition: MatrixTypeConverter.h:321
Definition: DenseColMajMatrix.h:73
Eigen::MatrixXd DenseMatrix
Definition: EigenDenseMatrixTests.cc:33
static DenseColMajMatrix * as_dense_col_maj(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:77
virtual void zero()
slow setters/getter for polymorphic operations
Definition: DenseColMajMatrix.h:330
static bool sparse(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:90
Definition: MatrixTypeConverter.h:85
#define SCISHARE
Definition: share.h:39
bool allocated() const
Definition: SparseRowMatrix.h:112
static DenseMatrix * as_dense(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:62
virtual SparseRowMatrixGeneric< T > * sparse()
Definition: MatrixTypeConverter.h:265
T & iget(index_type r, index_type c)
fast accessors
Definition: DenseColMajMatrix.h:127
ColumnMatrixGeneric< double > ColumnMatrix
Definition: MatrixFwd.h:48
bool nonzero(T d)
Definition: MiscMath.h:58
static SparseRowMatrix * as_sparse(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:67
virtual DenseMatrix * dense()
Convert this matrix to the specified type.
Definition: MatrixTypeConverter.h:167
long long size_type
Definition: Types.h:40
virtual ColumnMatrixGeneric< T > * column()
Definition: MatrixTypeConverter.h:234
dictionary data
Definition: eabLatVolData.py:11
Definition: ColumnMatrix.h:55
virtual T * get_data_pointer() const
Definition: DenseColMajMatrix.h:219
const Rows & rows() const
Definition: SparseRowMatrix.h:114
static bool dense(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:89
virtual SparseRowMatrix * sparse()
Definition: MatrixTypeConverter.h:331
DenseColMajMatrixGeneric< double > DenseColMajMatrix
Definition: MatrixFwd.h:52
static ColumnMatrix * as_column(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:72
virtual DenseMatrix * dense()
Definition: MatrixTypeConverter.h:101
virtual DenseMatrix * dense()
Convert this matrix to the specified type.
Definition: MatrixTypeConverter.h:241
virtual SparseRowMatrixGeneric * sparse()
Definition: MatrixTypeConverter.h:159
virtual ColumnMatrix * column()
Definition: MatrixTypeConverter.h:210
virtual DenseColMajMatrix * dense_col_maj()
Definition: MatrixTypeConverter.h:189
virtual DenseColMajMatrixGeneric * dense_col_maj()
Definition: MatrixTypeConverter.h:151
const Columns & columns() const
Definition: SparseRowMatrix.h:115
SparseRowMatrixGeneric< double > SparseRowMatrix
Definition: MatrixFwd.h:40
virtual void zero()
Definition: ColumnMatrix.h:286
boost::shared_array< index_type > Rows
Definition: SparseRowMatrix.h:72
long long index_type
Definition: Types.h:39
virtual void zero()
slow setters/getter for polymorphic operations
Definition: DenseMatrix.h:500
static ToType * to(const MatrixHandle &matrix, typename boost::enable_if< boost::is_base_of< MatrixBase, ToType > >::type *=0)
Definition: MatrixTypeConverter.h:57
virtual DenseColMajMatrix * dense_col_maj()
Definition: MatrixTypeConverter.h:299
static bool dense_col_maj(const MatrixHandle &mh)
Definition: MatrixTypeConverter.h:92
int count
Definition: readAllFields.py:25
const Storage & data() const
Definition: SparseRowMatrix.h:116
boost::shared_array< index_type > Columns
Definition: SparseRowMatrix.h:73
Definition: MatrixTypeConverter.h:53
DenseMatrixGeneric< double > DenseMatrix
Definition: MatrixFwd.h:44
Definition: MatrixFwd.h:40
virtual DenseMatrix * dense()
Convert this matrix to the specified type.
Definition: MatrixTypeConverter.h:292