Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / extern / Eigen2 / Eigen / src / Sparse / SparseCwise.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra. Eigen itself is part of the KDE project.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25
26 #ifndef EIGEN_SPARSE_CWISE_H
27 #define EIGEN_SPARSE_CWISE_H
28
29 /** \internal
30   * convenient macro to defined the return type of a cwise binary operation */
31 #define EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(OP) \
32     CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
33
34 #define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \
35     SparseCwiseBinaryOp< \
36       ei_scalar_product_op< \
37         typename ei_scalar_product_traits< \
38           typename ei_traits<ExpressionType>::Scalar, \
39           typename ei_traits<OtherDerived>::Scalar \
40         >::ReturnType \
41       >, \
42       ExpressionType, \
43       OtherDerived \
44     >
45
46 /** \internal
47   * convenient macro to defined the return type of a cwise unary operation */
48 #define EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(OP) \
49     SparseCwiseUnaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType>
50
51 /** \internal
52   * convenient macro to defined the return type of a cwise comparison to a scalar */
53 /*#define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \
54     CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, \
55         NestByValue<typename ExpressionType::ConstantReturnType> >*/
56
57 template<typename ExpressionType> class SparseCwise
58 {
59   public:
60
61     typedef typename ei_traits<ExpressionType>::Scalar Scalar;
62     typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret,
63         ExpressionType, const ExpressionType&>::ret ExpressionTypeNested;
64     typedef CwiseUnaryOp<ei_scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
65
66     inline SparseCwise(const ExpressionType& matrix) : m_matrix(matrix) {}
67
68     /** \internal */
69     inline const ExpressionType& _expression() const { return m_matrix; }
70
71     template<typename OtherDerived>
72     const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
73     operator*(const SparseMatrixBase<OtherDerived> &other) const;
74
75     template<typename OtherDerived>
76     const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
77     operator*(const MatrixBase<OtherDerived> &other) const;
78
79 //     template<typename OtherDerived>
80 //     const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
81 //     operator/(const SparseMatrixBase<OtherDerived> &other) const;
82 //
83 //     template<typename OtherDerived>
84 //     const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
85 //     operator/(const MatrixBase<OtherDerived> &other) const;
86
87     template<typename OtherDerived>
88     const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
89     min(const SparseMatrixBase<OtherDerived> &other) const;
90
91     template<typename OtherDerived>
92     const EIGEN_SPARSE_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
93     max(const SparseMatrixBase<OtherDerived> &other) const;
94
95     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op)      abs() const;
96     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op)     abs2() const;
97 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op)   square() const;
98 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op)     cube() const;
99 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op)  inverse() const;
100 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op)     sqrt() const;
101 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op)      exp() const;
102 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op)      log() const;
103 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op)      cos() const;
104 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op)      sin() const;
105 //     const EIGEN_SPARSE_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op)      pow(const Scalar& exponent) const;
106
107     template<typename OtherDerived>
108     inline ExpressionType& operator*=(const SparseMatrixBase<OtherDerived> &other);
109
110 //     template<typename OtherDerived>
111 //     inline ExpressionType& operator/=(const SparseMatrixBase<OtherDerived> &other);
112
113     /*
114     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
115     operator<(const MatrixBase<OtherDerived>& other) const;
116
117     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
118     operator<=(const MatrixBase<OtherDerived>& other) const;
119
120     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
121     operator>(const MatrixBase<OtherDerived>& other) const;
122
123     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
124     operator>=(const MatrixBase<OtherDerived>& other) const;
125
126     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
127     operator==(const MatrixBase<OtherDerived>& other) const;
128
129     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
130     operator!=(const MatrixBase<OtherDerived>& other) const;
131
132     // comparisons to a scalar value
133     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
134     operator<(Scalar s) const;
135
136     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
137     operator<=(Scalar s) const;
138
139     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
140     operator>(Scalar s) const;
141
142     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
143     operator>=(Scalar s) const;
144
145     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
146     operator==(Scalar s) const;
147
148     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
149     operator!=(Scalar s) const;
150     */
151
152     // allow to extend SparseCwise outside Eigen
153     #ifdef EIGEN_SPARSE_CWISE_PLUGIN
154     #include EIGEN_SPARSE_CWISE_PLUGIN
155     #endif
156
157   protected:
158     ExpressionTypeNested m_matrix;
159
160   private:
161     SparseCwise& operator=(const SparseCwise&);
162 };
163
164 template<typename Derived>
165 inline const SparseCwise<Derived>
166 SparseMatrixBase<Derived>::cwise() const
167 {
168   return derived();
169 }
170
171 template<typename Derived>
172 inline SparseCwise<Derived>
173 SparseMatrixBase<Derived>::cwise()
174 {
175   return derived();
176 }
177
178 #endif // EIGEN_SPARSE_CWISE_H