46 m_operator=
SGSparseMatrix<T>(orig.m_operator.num_vectors, orig.m_operator.num_features);
48 vector* rows=SG_MALLOC(vector, m_operator.num_features);
49 for (
index_t i=0; i<m_operator.num_vectors; ++i)
51 entry* features=SG_MALLOC(entry, orig.m_operator[i].num_feat_entries);
52 for (
index_t j=0; j<orig.m_operator[i].num_feat_entries; ++j)
54 features[j].feat_index=orig.m_operator[i].features[j].feat_index;
55 features[j].entry=orig.m_operator[i].features[j].entry;
57 rows[i].features=features;
58 rows[i].num_feat_entries=m_operator[i].num_feat_entries;
62 SG_SGCDEBUG(
"%s deep copy created (%p)\n", this->get_name(),
this);
68 CSGObject::set_generic<T>();
70 this->m_parameters->add_vector(&m_operator.sparse_matrix,
71 &m_operator.num_vectors,
"sparse_matrix",
72 "The sparse matrix of the linear operator.");
73 this->m_parameters->add(&m_operator.num_features,
74 "m_operator.num_features",
"Number of features.");
93 REQUIRE(power>0,
"matrix-power is non-positive!\n");
100 Eigen::SparseMatrix<bool> current_power
104 Eigen::SparseMatrix<bool> matrix_power;
119 matrix_power=current_power;
123 matrix_power=matrix_power*current_power;
129 current_power=current_power*current_power;
133 int32_t* outerIndexPtr=
const_cast<int32_t*
>(matrix_power.outerIndexPtr());
134 int32_t* innerIndexPtr=
const_cast<int32_t*
>(matrix_power.innerIndexPtr());
139 matrix_power.rows());
149 #endif // HAVE_EIGEN3
155 SG_SERROR(
"Not supported for complex128_t\n");
162 REQUIRE(m_operator.sparse_matrix,
"Operator not initialized!\n");
164 const int32_t diag_size=m_operator.num_vectors>m_operator.num_features ?
165 m_operator.num_features : m_operator.num_vectors;
169 for (
index_t i=0; i<diag_size; ++i)
172 for (
index_t j=0; j<m_operator[i].num_feat_entries; ++j)
174 if (i==current_row[j].feat_index)
176 diag[i]=current_row[j].
entry;
188 REQUIRE(m_operator.sparse_matrix,
"Operator not initialized!\n");
191 const int32_t diag_size=m_operator.num_vectors>m_operator.num_features ?
192 m_operator.num_features : m_operator.num_vectors;
194 REQUIRE(diag_size==diag.
vlen,
"Dimension mismatch!\n");
196 bool need_sorting=
false;
197 for (
index_t i=0; i<diag_size; ++i)
202 for (
index_t j=0; j<m_operator[i].num_feat_entries; ++j)
204 if (i==current_row[j].feat_index)
206 current_row[j].
entry=diag[i];
215 index_t j=m_operator[i].num_feat_entries;
216 m_operator[i].num_feat_entries=j+1;
218 m_operator[i].features, j, j+1);
219 m_operator[i].features[j].feat_index=i;
220 m_operator[i].features[j].entry=diag[i];
226 m_operator.sort_features();
232 REQUIRE(m_operator.sparse_matrix,
"Operator not initialized!\n");
234 "Number of rows of vector must be equal to the "
235 "number of cols of the operator!\n");
243 #define UNDEFINED(type) \
245 SGVector<type> CSparseMatrixOperator<type>::apply(SGVector<type> b) const \
247 SG_SERROR("Not supported for %s\n", #type);\
265 template class CSparseMatrixOperator<bool>;
266 template class CSparseMatrixOperator<char>;
267 template class CSparseMatrixOperator<int8_t>;
268 template class CSparseMatrixOperator<uint8_t>;
269 template class CSparseMatrixOperator<int16_t>;
270 template class CSparseMatrixOperator<uint16_t>;
271 template class CSparseMatrixOperator<int32_t>;
272 template class CSparseMatrixOperator<uint32_t>;
273 template class CSparseMatrixOperator<int64_t>;
274 template class CSparseMatrixOperator<uint64_t>;
275 template class CSparseMatrixOperator<float32_t>;
276 template class CSparseMatrixOperator<float64_t>;
277 template class CSparseMatrixOperator<floatmax_t>;
278 template class CSparseMatrixOperator<complex128_t>;
SparsityStructure * get_sparsity_structure(int64_t power=1) const
template class SGSparseMatrix
SGSparseMatrix< T > get_matrix_operator() const
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
virtual SGVector< T > get_diagonal() const
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
virtual SGVector< T > apply(SGVector< T > b) const
static Eigen::SparseMatrix< T > toEigenSparse(SGSparseMatrix< T > sg_matrix)
virtual void set_diagonal(SGVector< T > diag)
void set_const(T const_elem)
const index_t get_dimension() const
Struct that represents the sparsity structure of the Sparse Matrix in CRS. Implementation has been ad...
all of classes and functions are contained in the shogun namespace
Class that represents a sparse-matrix linear operator. It computes matrix-vector product in its appl...
template class SGSparseVectorEntry
Abstract base class that represents a matrix linear operator. It provides an interface to computes ma...