// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-2014 Gael Guennebaud // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef EIGEN_SPARSEASSIGN_H #define EIGEN_SPARSEASSIGN_H namespace Eigen { #ifndef EIGEN_TEST_EVALUATORS template template Derived& SparseMatrixBase::operator=(const EigenBase &other) { other.derived().evalTo(derived()); return derived(); } template template Derived& SparseMatrixBase::operator=(const ReturnByValue& other) { other.evalTo(derived()); return derived(); } template template inline Derived& SparseMatrixBase::operator=(const SparseMatrixBase& other) { return assign(other.derived()); } template inline Derived& SparseMatrixBase::operator=(const Derived& other) { // if (other.isRValue()) // derived().swap(other.const_cast_derived()); // else return assign(other.derived()); } template template inline Derived& SparseMatrixBase::assign(const OtherDerived& other) { const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols(); if ((!transpose) && other.isRValue()) { // eval without temporary derived().resize(other.rows(), other.cols()); derived().setZero(); derived().reserve((std::max)(this->rows(),this->cols())*2); for (Index j=0; j template inline void SparseMatrixBase::assignGeneric(const OtherDerived& other) { //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); eigen_assert(( ((internal::traits::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) || (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) && "the transpose operation is supposed to be handled in SparseMatrix::operator="); enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) }; const Index outerSize = other.outerSize(); //typedef typename internal::conditional, Derived>::type TempType; // thanks to shallow copies, we always eval to a tempary Derived temp(other.rows(), other.cols()); temp.reserve((std::max)(this->rows(),this->cols())*2); for (Index j=0; j // inline Derived& operator=(const SparseSparseProduct& product); // // template // Derived& operator+=(const SparseMatrixBase& other); // template // Derived& operator-=(const SparseMatrixBase& other); // // Derived& operator*=(const Scalar& other); // Derived& operator/=(const Scalar& other); // // template // Derived& operator*=(const SparseMatrixBase& other); #else // EIGEN_TEST_EVALUATORS template template Derived& SparseMatrixBase::operator=(const EigenBase &other) { other.derived().evalTo(derived()); return derived(); } template template Derived& SparseMatrixBase::operator=(const ReturnByValue& other) { other.evalTo(derived()); return derived(); } template template inline Derived& SparseMatrixBase::operator=(const SparseMatrixBase& other) { internal::call_assignment/*_no_alias*/(derived(), other.derived()); return derived(); } template inline Derived& SparseMatrixBase::operator=(const Derived& other) { internal::call_assignment_no_alias(derived(), other.derived()); return derived(); } namespace internal { template<> struct storage_kind_to_evaluator_kind { typedef IteratorBased Kind; }; template<> struct storage_kind_to_shape { typedef SparseShape Shape; }; struct Sparse2Sparse {}; struct Sparse2Dense {}; template<> struct AssignmentKind { typedef Sparse2Sparse Kind; }; template<> struct AssignmentKind { typedef Sparse2Dense Kind; }; template void assign_sparse_to_sparse(DstXprType &dst, const SrcXprType &src) { eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); typedef typename DstXprType::Index Index; typedef typename DstXprType::Scalar Scalar; typedef typename internal::evaluator::type DstEvaluatorType; typedef typename internal::evaluator::type SrcEvaluatorType; SrcEvaluatorType srcEvaluator(src); const bool transpose = (DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit); const Index outerSize = (int(SrcEvaluatorType::Flags) & RowMajorBit) ? src.rows() : src.cols(); if ((!transpose) && src.isRValue()) { // eval without temporary dst.resize(src.rows(), src.cols()); dst.setZero(); dst.reserve((std::max)(src.rows(),src.cols())*2); for (Index j=0; j::SupportedAccessPatterns & OuterRandomAccessPattern)==OuterRandomAccessPattern) || (!((DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit)))) && "the transpose operation is supposed to be handled in SparseMatrix::operator="); enum { Flip = (DstEvaluatorType::Flags & RowMajorBit) != (SrcEvaluatorType::Flags & RowMajorBit) }; const Index outerSize = src.outerSize(); DstXprType temp(src.rows(), src.cols()); temp.reserve((std::max)(src.rows(),src.cols())*2); for (Index j=0; j struct Assignment { static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &/*func*/) { eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); assign_sparse_to_sparse(dst.derived(), src.derived()); } }; // Sparse to Dense assignment template< typename DstXprType, typename SrcXprType, typename Functor, typename Scalar> struct Assignment { static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &/*func*/) { eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); typedef typename SrcXprType::Index Index; dst.setZero(); typename internal::evaluator::type srcEval(src); typename internal::evaluator::type dstEval(dst); for (Index j=0; j::InnerIterator i(srcEval,j); i; ++i) dstEval.coeffRef(i.row(),i.col()) = i.value(); } }; } // end namespace internal #endif // EIGEN_TEST_EVALUATORS } // end namespace Eigen #endif // EIGEN_SPARSEASSIGN_H