00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. Eigen itself is part of the KDE project. 00003 // 00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> 00005 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com> 00006 // 00007 // Eigen is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 3 of the License, or (at your option) any later version. 00011 // 00012 // Alternatively, you can redistribute it and/or 00013 // modify it under the terms of the GNU General Public License as 00014 // published by the Free Software Foundation; either version 2 of 00015 // the License, or (at your option) any later version. 00016 // 00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY 00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License and a copy of the GNU General Public License along with 00024 // Eigen. If not, see <http://www.gnu.org/licenses/>. 00025 00026 #ifndef EIGEN_SPARSE_CWISE_H 00027 #define EIGEN_SPARSE_CWISE_H 00028 00031 #define EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(OP) \ 00032 CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived> 00033 00034 #define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \ 00035 SparseCwiseBinaryOp< \ 00036 ei_scalar_product_op< \ 00037 typename ei_scalar_product_traits< \ 00038 typename ei_traits<ExpressionType>::Scalar, \ 00039 typename ei_traits<OtherDerived>::Scalar \ 00040 >::ReturnType \ 00041 >, \ 00042 ExpressionType, \ 00043 OtherDerived \ 00044 > 00045 00048 #define EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(OP) \ 00049 SparseCwiseUnaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType> 00050 00053 /*#define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \ 00054 CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, \ 00055 NestByValue<typename ExpressionType::ConstantReturnType> >*/ 00056 00057 template<typename ExpressionType> class SparseCwise 00058 { 00059 public: 00060 00061 typedef typename ei_traits<ExpressionType>::Scalar Scalar; 00062 typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret, 00063 ExpressionType, const ExpressionType&>::ret ExpressionTypeNested; 00064 typedef CwiseUnaryOp<ei_scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType; 00065 00066 inline SparseCwise(const ExpressionType& matrix) : m_matrix(matrix) {} 00067 00069 inline const ExpressionType& _expression() const { return m_matrix; } 00070 00071 template<typename OtherDerived> 00072 const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE 00073 operator*(const SparseMatrixBase<OtherDerived> &other) const; 00074 00075 template<typename OtherDerived> 00076 const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE 00077 operator*(const MatrixBase<OtherDerived> &other) const; 00078 00079 // template<typename OtherDerived> 00080 // const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op) 00081 // operator/(const SparseMatrixBase<OtherDerived> &other) const; 00082 // 00083 // template<typename OtherDerived> 00084 // const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op) 00085 // operator/(const MatrixBase<OtherDerived> &other) const; 00086 00087 template<typename OtherDerived> 00088 const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op) 00089 min(const SparseMatrixBase<OtherDerived> &other) const; 00090 00091 template<typename OtherDerived> 00092 const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op) 00093 max(const SparseMatrixBase<OtherDerived> &other) const; 00094 00095 const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op) abs() const; 00096 const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op) abs2() const; 00097 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op) square() const; 00098 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op) cube() const; 00099 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op) inverse() const; 00100 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op) sqrt() const; 00101 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op) exp() const; 00102 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op) log() const; 00103 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op) cos() const; 00104 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op) sin() const; 00105 // const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op) pow(const Scalar& exponent) const; 00106 00107 template<typename OtherDerived> 00108 inline ExpressionType& operator*=(const SparseMatrixBase<OtherDerived> &other); 00109 00110 // template<typename OtherDerived> 00111 // inline ExpressionType& operator/=(const SparseMatrixBase<OtherDerived> &other); 00112 00113 /* 00114 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less) 00115 operator<(const MatrixBase<OtherDerived>& other) const; 00116 00117 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal) 00118 operator<=(const MatrixBase<OtherDerived>& other) const; 00119 00120 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater) 00121 operator>(const MatrixBase<OtherDerived>& other) const; 00122 00123 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal) 00124 operator>=(const MatrixBase<OtherDerived>& other) const; 00125 00126 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to) 00127 operator==(const MatrixBase<OtherDerived>& other) const; 00128 00129 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to) 00130 operator!=(const MatrixBase<OtherDerived>& other) const; 00131 00132 // comparisons to a scalar value 00133 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less) 00134 operator<(Scalar s) const; 00135 00136 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal) 00137 operator<=(Scalar s) const; 00138 00139 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater) 00140 operator>(Scalar s) const; 00141 00142 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal) 00143 operator>=(Scalar s) const; 00144 00145 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to) 00146 operator==(Scalar s) const; 00147 00148 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to) 00149 operator!=(Scalar s) const; 00150 */ 00151 00152 // allow to extend SparseCwise outside Eigen 00153 #ifdef EIGEN_SPARSE_CWISE_PLUGIN 00154 #include EIGEN_SPARSE_CWISE_PLUGIN 00155 #endif 00156 00157 protected: 00158 ExpressionTypeNested m_matrix; 00159 00160 private: 00161 SparseCwise& operator=(const SparseCwise&); 00162 }; 00163 00164 template<typename Derived> 00165 inline const SparseCwise<Derived> 00166 SparseMatrixBase<Derived>::cwise() const 00167 { 00168 return derived(); 00169 } 00170 00171 template<typename Derived> 00172 inline SparseCwise<Derived> 00173 SparseMatrixBase<Derived>::cwise() 00174 { 00175 return derived(); 00176 } 00177 00178 #endif // EIGEN_SPARSE_CWISE_H