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>;