SparseCwiseUnaryOp.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H
00011 #define EIGEN_SPARSE_CWISE_UNARY_OP_H
00012 
00013 namespace Eigen { 
00014 
00015 template<typename UnaryOp, typename MatrixType>
00016 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>
00017   : public SparseMatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
00018 {
00019   public:
00020 
00021     class InnerIterator;
00022     class ReverseInnerIterator;
00023 
00024     typedef CwiseUnaryOp<UnaryOp, MatrixType> Derived;
00025     EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00026 
00027   protected:
00028     typedef typename internal::traits<Derived>::_XprTypeNested _MatrixTypeNested;
00029     typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00030     typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
00031 };
00032 
00033 template<typename UnaryOp, typename MatrixType>
00034 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator
00035     : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator
00036 {
00037     typedef typename CwiseUnaryOpImpl::Scalar Scalar;
00038     typedef typename CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator Base;
00039   public:
00040 
00041     EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, typename CwiseUnaryOpImpl::Index outer)
00042       : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00043     {}
00044 
00045     EIGEN_STRONG_INLINE InnerIterator& operator++()
00046     { Base::operator++(); return *this; }
00047 
00048     EIGEN_STRONG_INLINE typename CwiseUnaryOpImpl::Scalar value() const { return m_functor(Base::value()); }
00049 
00050   protected:
00051     const UnaryOp m_functor;
00052   private:
00053     typename CwiseUnaryOpImpl::Scalar& valueRef();
00054 };
00055 
00056 template<typename UnaryOp, typename MatrixType>
00057 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::ReverseInnerIterator
00058     : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator
00059 {
00060     typedef typename CwiseUnaryOpImpl::Scalar Scalar;
00061     typedef typename CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
00062   public:
00063 
00064     EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryOpImpl& unaryOp, typename CwiseUnaryOpImpl::Index outer)
00065       : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00066     {}
00067 
00068     EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
00069     { Base::operator--(); return *this; }
00070 
00071     EIGEN_STRONG_INLINE typename CwiseUnaryOpImpl::Scalar value() const { return m_functor(Base::value()); }
00072 
00073   protected:
00074     const UnaryOp m_functor;
00075   private:
00076     typename CwiseUnaryOpImpl::Scalar& valueRef();
00077 };
00078 
00079 template<typename ViewOp, typename MatrixType>
00080 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
00081   : public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
00082 {
00083   public:
00084 
00085     class InnerIterator;
00086     class ReverseInnerIterator;
00087 
00088     typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00089     EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00090 
00091   protected:
00092     typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested;
00093     typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00094     typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
00095 };
00096 
00097 template<typename ViewOp, typename MatrixType>
00098 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
00099     : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator
00100 {
00101     typedef typename CwiseUnaryViewImpl::Scalar Scalar;
00102     typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator Base;
00103   public:
00104 
00105     EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer)
00106       : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00107     {}
00108 
00109     EIGEN_STRONG_INLINE InnerIterator& operator++()
00110     { Base::operator++(); return *this; }
00111 
00112     EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); }
00113     EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); }
00114 
00115   protected:
00116     const ViewOp m_functor;
00117 };
00118 
00119 template<typename ViewOp, typename MatrixType>
00120 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::ReverseInnerIterator
00121     : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator
00122 {
00123     typedef typename CwiseUnaryViewImpl::Scalar Scalar;
00124     typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
00125   public:
00126 
00127     EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer)
00128       : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00129     {}
00130 
00131     EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
00132     { Base::operator--(); return *this; }
00133 
00134     EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); }
00135     EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); }
00136 
00137   protected:
00138     const ViewOp m_functor;
00139 };
00140 
00141 template<typename Derived>
00142 EIGEN_STRONG_INLINE Derived&
00143 SparseMatrixBase<Derived>::operator*=(const Scalar& other)
00144 {
00145   for (Index j=0; j<outerSize(); ++j)
00146     for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00147       i.valueRef() *= other;
00148   return derived();
00149 }
00150 
00151 template<typename Derived>
00152 EIGEN_STRONG_INLINE Derived&
00153 SparseMatrixBase<Derived>::operator/=(const Scalar& other)
00154 {
00155   for (Index j=0; j<outerSize(); ++j)
00156     for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00157       i.valueRef() /= other;
00158   return derived();
00159 }
00160 
00161 } // end namespace Eigen
00162 
00163 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:12:04