| 69 | |
| 70 | template<typename DstXprType, typename SrcXprType> |
| 71 | void assign_sparse_to_sparse(DstXprType &dst, const SrcXprType &src) |
| 72 | { |
| 73 | typedef typename DstXprType::Scalar Scalar; |
| 74 | typedef internal::evaluator<DstXprType> DstEvaluatorType; |
| 75 | typedef internal::evaluator<SrcXprType> SrcEvaluatorType; |
| 76 | |
| 77 | SrcEvaluatorType srcEvaluator(src); |
| 78 | |
| 79 | const bool transpose = (DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit); |
| 80 | const Index outerEvaluationSize = (SrcEvaluatorType::Flags&RowMajorBit) ? src.rows() : src.cols(); |
| 81 | if ((!transpose) && src.isRValue()) |
| 82 | { |
| 83 | // eval without temporary |
| 84 | dst.resize(src.rows(), src.cols()); |
| 85 | dst.setZero(); |
| 86 | dst.reserve((std::max)(src.rows(),src.cols())*2); |
| 87 | for (Index j=0; j<outerEvaluationSize; ++j) |
| 88 | { |
| 89 | dst.startVec(j); |
| 90 | for (typename SrcEvaluatorType::InnerIterator it(srcEvaluator, j); it; ++it) |
| 91 | { |
| 92 | Scalar v = it.value(); |
| 93 | dst.insertBackByOuterInner(j,it.index()) = v; |
| 94 | } |
| 95 | } |
| 96 | dst.finalize(); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | // eval through a temporary |
| 101 | eigen_assert(( ((internal::traits<DstXprType>::SupportedAccessPatterns & OuterRandomAccessPattern)==OuterRandomAccessPattern) || |
| 102 | (!((DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit)))) && |
| 103 | "the transpose operation is supposed to be handled in SparseMatrix::operator="); |
| 104 | |
| 105 | enum { Flip = (DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit) }; |
| 106 | |
| 107 | |
| 108 | DstXprType temp(src.rows(), src.cols()); |
| 109 | |
| 110 | temp.reserve((std::max)(src.rows(),src.cols())*2); |
| 111 | for (Index j=0; j<outerEvaluationSize; ++j) |
| 112 | { |
| 113 | temp.startVec(j); |
| 114 | for (typename SrcEvaluatorType::InnerIterator it(srcEvaluator, j); it; ++it) |
| 115 | { |
| 116 | Scalar v = it.value(); |
| 117 | temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v; |
| 118 | } |
| 119 | } |
| 120 | temp.finalize(); |
| 121 | |
| 122 | dst = temp.markAsRValue(); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Generic Sparse to Sparse assignment |
| 127 | template< typename DstXprType, typename SrcXprType, typename Functor> |