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 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H
00026 #define EIGEN_SPARSE_CWISE_UNARY_OP_H
00027 
00028 // template<typename UnaryOp, typename MatrixType>
00029 // struct internal::traits<SparseCwiseUnaryOp<UnaryOp, MatrixType> > : internal::traits<MatrixType>
00030 // {
00031 //   typedef typename internal::result_of<
00032 //                      UnaryOp(typename MatrixType::Scalar)
00033 //                    >::type Scalar;
00034 //   typedef typename MatrixType::Nested MatrixTypeNested;
00035 //   typedef typename internal::remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00036 //   enum {
00037 //     CoeffReadCost = _MatrixTypeNested::CoeffReadCost + internal::functor_traits<UnaryOp>::Cost
00038 //   };
00039 // };
00040 
00041 template<typename UnaryOp, typename MatrixType>
00042 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>
00043   : public SparseMatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
00044 {
00045   public:
00046 
00047     class InnerIterator;
00048 //     typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
00049 
00050     typedef CwiseUnaryOp<UnaryOp, MatrixType> Derived;
00051     EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00052 };
00053 
00054 template<typename UnaryOp, typename MatrixType>
00055 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator
00056 {
00057     typedef typename CwiseUnaryOpImpl::Scalar Scalar;
00058     typedef typename internal::traits<Derived>::_XprTypeNested _MatrixTypeNested;
00059     typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00060     typedef typename MatrixType::Index Index;
00061   public:
00062 
00063     EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, Index outer)
00064       : m_iter(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00065     {}
00066 
00067     EIGEN_STRONG_INLINE InnerIterator& operator++()
00068     { ++m_iter; return *this; }
00069 
00070     EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); }
00071 
00072     EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
00073     EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
00074     EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
00075 
00076     EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
00077 
00078   protected:
00079     MatrixTypeIterator m_iter;
00080     const UnaryOp m_functor;
00081 };
00082 
00083 template<typename ViewOp, typename MatrixType>
00084 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
00085   : public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
00086 {
00087   public:
00088 
00089     class InnerIterator;
00090 //     typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
00091 
00092     typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00093     EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00094 };
00095 
00096 template<typename ViewOp, typename MatrixType>
00097 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
00098 {
00099     typedef typename CwiseUnaryViewImpl::Scalar Scalar;
00100     typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested;
00101     typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00102     typedef typename MatrixType::Index Index;
00103   public:
00104 
00105     EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryView, Index outer)
00106       : m_iter(unaryView.derived().nestedExpression(),outer), m_functor(unaryView.derived().functor())
00107     {}
00108 
00109     EIGEN_STRONG_INLINE InnerIterator& operator++()
00110     { ++m_iter; return *this; }
00111 
00112     EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); }
00113     EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(m_iter.valueRef()); }
00114 
00115     EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
00116     EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
00117     EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
00118 
00119     EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
00120 
00121   protected:
00122     MatrixTypeIterator m_iter;
00123     const ViewOp m_functor;
00124 };
00125 
00126 template<typename Derived>
00127 EIGEN_STRONG_INLINE Derived&
00128 SparseMatrixBase<Derived>::operator*=(const Scalar& other)
00129 {
00130   for (Index j=0; j<outerSize(); ++j)
00131     for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00132       i.valueRef() *= other;
00133   return derived();
00134 }
00135 
00136 template<typename Derived>
00137 EIGEN_STRONG_INLINE Derived&
00138 SparseMatrixBase<Derived>::operator/=(const Scalar& other)
00139 {
00140   for (Index j=0; j<outerSize(); ++j)
00141     for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00142       i.valueRef() /= other;
00143   return derived();
00144 }
00145 
00146 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:48