10 #ifndef EIGEN_SPARSEASSIGN_H 11 #define EIGEN_SPARSEASSIGN_H 15 template<
typename Derived>
16 template<
typename OtherDerived>
17 Derived& SparseMatrixBase<Derived>::operator=(
const EigenBase<OtherDerived> &other)
19 internal::call_assignment_no_alias(derived(), other.derived());
23 template<
typename Derived>
24 template<
typename OtherDerived>
25 Derived& SparseMatrixBase<Derived>::operator=(
const ReturnByValue<OtherDerived>& other)
28 other.evalTo(derived());
32 template<
typename Derived>
33 template<
typename OtherDerived>
34 inline Derived& SparseMatrixBase<Derived>::operator=(
const SparseMatrixBase<OtherDerived>& other)
37 internal::Assignment<Derived,OtherDerived,internal::assign_op<Scalar,typename OtherDerived::Scalar> >
38 ::run(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
42 template<
typename Derived>
43 inline Derived& SparseMatrixBase<Derived>::operator=(
const Derived& other)
45 internal::call_assignment_no_alias(derived(), other.derived());
70 template<
typename DstXprType,
typename SrcXprType>
71 void assign_sparse_to_sparse(DstXprType &dst,
const SrcXprType &src)
73 typedef typename DstXprType::Scalar Scalar;
77 SrcEvaluatorType srcEvaluator(src);
80 const Index outerEvaluationSize = (SrcEvaluatorType::Flags&
RowMajorBit) ? src.rows() : src.cols();
81 if ((!transpose) && src.isRValue())
84 dst.resize(src.rows(), src.cols());
86 dst.reserve((std::max)(src.rows(),src.cols())*2);
87 for (
Index j=0; j<outerEvaluationSize; ++j)
90 for (
typename SrcEvaluatorType::InnerIterator it(srcEvaluator, j); it; ++it)
92 Scalar v = it.value();
93 dst.insertBackByOuterInner(j,it.index()) = v;
102 (!((DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit)))) &&
103 "the transpose operation is supposed to be handled in SparseMatrix::operator=");
105 enum { Flip = (DstEvaluatorType::Flags &
RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit) };
108 DstXprType temp(src.rows(), src.cols());
110 temp.reserve((std::max)(src.rows(),src.cols())*2);
111 for (
Index j=0; j<outerEvaluationSize; ++j)
114 for (
typename SrcEvaluatorType::InnerIterator it(srcEvaluator, j); it; ++it)
116 Scalar v = it.value();
117 temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
122 dst = temp.markAsRValue();
127 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
132 assign_sparse_to_sparse(dst.derived(), src.derived());
137 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
140 static void run(DstXprType &dst,
const SrcXprType &src,
const Functor &
func)
146 Index dstRows = src.rows();
147 Index dstCols = src.cols();
148 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
149 dst.resize(dstRows, dstCols);
153 for (
Index j=0; j<outerEvaluationSize; ++j)
155 func.assignCoeff(dstEval.coeffRef(i.row(),i.col()), i.value());
161 template<
typename DstXprType,
typename DecType,
typename RhsType,
typename Scalar>
167 Index dstRows = src.rows();
168 Index dstCols = src.cols();
169 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
170 dst.resize(dstRows, dstCols);
172 src.dec()._solve_impl(src.rhs(), dst);
180 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
183 typedef typename DstXprType::StorageIndex StorageIndex;
184 typedef typename DstXprType::Scalar Scalar;
187 template<
int Options>
190 Index dstRows = src.rows();
191 Index dstCols = src.cols();
192 if((dst.
rows()!=dstRows) || (dst.
cols()!=dstCols))
193 dst.
resize(dstRows, dstCols);
195 Index size = src.diagonal().size();
197 dst.resizeNonZeros(size);
203 template<
typename DstDerived>
206 dst.diagonal() = src.diagonal();
210 { dst.diagonal() += src.diagonal(); }
213 { dst.diagonal() -= src.diagonal(); }
219 #endif // EIGEN_SPARSEASSIGN_H Definition: NonLinearOptimization.cpp:108
const Scalar * valuePtr() const
Definition: SparseMatrix.h:144
A versatible sparse matrix representation.
Definition: SparseMatrix.h:92
Definition: AssignmentFunctors.h:67
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:88
Definition: CoreEvaluators.h:90
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Definition: Constants.h:521
Index cols() const
Definition: SparseMatrix.h:134
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:61
Definition: Constants.h:512
Definition: CoreEvaluators.h:29
Definition: Constants.h:529
Definition: AssignmentFunctors.h:21
Definition: AssignEvaluator.h:753
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:281
Definition: Constants.h:515
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Index rows() const
Definition: SparseMatrix.h:132
Definition: SparseAssign.h:62
void resize(Index rows, Index cols)
Resizes the matrix to a rows x cols matrix and initializes it to zero.
Definition: SparseMatrix.h:617
The type used to identify a general sparse storage.
Definition: Constants.h:494
void makeCompressed()
Turns the matrix into the compressed format.
Definition: SparseMatrix.h:460
Definition: SparseUtil.h:137
Definition: benchGeometry.cpp:23
const StorageIndex * innerIndexPtr() const
Definition: SparseMatrix.h:153
Definition: BandTriangularSolver.h:13
const StorageIndex * outerIndexPtr() const
Definition: SparseMatrix.h:162
Definition: AssignEvaluator.h:740
Definition: CoreEvaluators.h:23
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
Definition: AssignmentFunctors.h:46
Pseudo expression representing a solving operation.
Definition: Solve.h:62
Definition: ForwardDeclarations.h:17
Definition: SparseAssign.h:61
Definition: SparseAssign.h:176