10 #include <shogun/lib/config.h> 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;
60 m_operator.sparse_matrix=rows;
68 CSGObject::set_generic<T>();
71 &m_operator.num_vectors,
"sparse_matrix",
72 "The sparse matrix of the linear operator.");
74 "m_operator.num_features",
"Number of features.");
92 REQUIRE(power>0,
"matrix-power is non-positive!\n");
99 Eigen::SparseMatrix<bool> current_power
103 Eigen::SparseMatrix<bool> matrix_power;
118 matrix_power=current_power;
122 matrix_power=matrix_power*current_power;
128 current_power=current_power*current_power;
132 int32_t* outerIndexPtr=
const_cast<int32_t*
>(matrix_power.outerIndexPtr());
133 int32_t* innerIndexPtr=
const_cast<int32_t*
>(matrix_power.innerIndexPtr());
138 matrix_power.rows());
145 SG_SERROR(
"Not supported for complex128_t\n");
152 REQUIRE(m_operator.sparse_matrix,
"Operator not initialized!\n");
154 const int32_t diag_size=m_operator.num_vectors>m_operator.num_features ?
155 m_operator.num_features : m_operator.num_vectors;
159 for (
index_t i=0; i<diag_size; ++i)
162 for (
index_t j=0; j<m_operator[i].num_feat_entries; ++j)
164 if (i==current_row[j].feat_index)
166 diag[i]=current_row[j].
entry;
178 REQUIRE(m_operator.sparse_matrix,
"Operator not initialized!\n");
181 const int32_t diag_size=m_operator.num_vectors>m_operator.num_features ?
182 m_operator.num_features : m_operator.num_vectors;
184 REQUIRE(diag_size==diag.
vlen,
"Dimension mismatch!\n");
186 bool need_sorting=
false;
187 for (
index_t i=0; i<diag_size; ++i)
192 for (
index_t j=0; j<m_operator[i].num_feat_entries; ++j)
194 if (i==current_row[j].feat_index)
196 current_row[j].
entry=diag[i];
205 index_t j=m_operator[i].num_feat_entries;
206 m_operator[i].num_feat_entries=j+1;
208 m_operator[i].features, j, j+1);
209 m_operator[i].features[j].feat_index=i;
210 m_operator[i].features[j].entry=diag[i];
216 m_operator.sort_features();
222 REQUIRE(m_operator.sparse_matrix,
"Operator not initialized!\n");
224 "Number of rows of vector must be equal to the " 225 "number of cols of the operator!\n");
233 #define UNDEFINED(type) \ 235 SGVector<type> CSparseMatrixOperator<type>::apply(SGVector<type> b) const \ 237 SG_SERROR("Not supported for %s\n", #type);\ 255 template class CSparseMatrixOperator<bool>;
256 template class CSparseMatrixOperator<char>;
257 template class CSparseMatrixOperator<int8_t>;
258 template class CSparseMatrixOperator<uint8_t>;
259 template class CSparseMatrixOperator<int16_t>;
260 template class CSparseMatrixOperator<uint16_t>;
261 template class CSparseMatrixOperator<int32_t>;
262 template class CSparseMatrixOperator<uint32_t>;
263 template class CSparseMatrixOperator<int64_t>;
264 template class CSparseMatrixOperator<uint64_t>;
265 template class CSparseMatrixOperator<float32_t>;
266 template class CSparseMatrixOperator<float64_t>;
267 template class CSparseMatrixOperator<floatmax_t>;
268 template class CSparseMatrixOperator<complex128_t>;
template class SGSparseMatrix
virtual const char * get_name() const
SparsityStructure * get_sparsity_structure(int64_t power=1) const
SGSparseMatrix< T > get_matrix_operator() const
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
void add(bool *param, const char *name, const char *description="")
const index_t get_dimension() const
static Eigen::SparseMatrix< T > toEigenSparse(SGSparseMatrix< T > sg_matrix)
virtual void set_diagonal(SGVector< T > diag)
void set_const(T const_elem)
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
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
virtual SGVector< T > apply(SGVector< T > b) const
Abstract base class that represents a matrix linear operator. It provides an interface to computes ma...
virtual SGVector< T > get_diagonal() const