Go to the documentation of this file.00001 #ifndef VIENNAMATH_RUNTIME_UNARY_OPERATORS_HPP
00002 #define VIENNAMATH_RUNTIME_UNARY_OPERATORS_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <string>
00021 #include <vector>
00022 #include <math.h>
00023 #include "viennamath/forwards.h"
00024 #include "viennamath/runtime/op_interface.hpp"
00025 #include "viennamath/compiletime/unary_op_tags.hpp"
00026
00031 namespace viennamath
00032 {
00033
00034
00035
00036
00037 template <typename InterfaceType, typename NumericT>
00038 InterfaceType * diff_impl(const InterfaceType * e, op_id<NumericT>, const InterfaceType * diff_var);
00039
00040 template <typename InterfaceType, typename NumericT>
00041 InterfaceType * diff_impl(const InterfaceType * e, op_exp<NumericT>, const InterfaceType * diff_var);
00042
00043 template <typename InterfaceType, typename NumericT>
00044 InterfaceType * diff_impl(const InterfaceType * e, op_sin<NumericT>, const InterfaceType * diff_var);
00045
00046 template <typename InterfaceType, typename NumericT>
00047 InterfaceType * diff_impl(const InterfaceType * e, op_cos<NumericT>, const InterfaceType * diff_var);
00048
00049 template <typename InterfaceType, typename NumericT>
00050 InterfaceType * diff_impl(const InterfaceType * e, op_tan<NumericT>, const InterfaceType * diff_var);
00051
00052 template <typename InterfaceType, typename NumericT>
00053 InterfaceType * diff_impl(const InterfaceType * e, op_fabs<NumericT>, const InterfaceType * diff_var);
00054
00055 template <typename InterfaceType, typename NumericT>
00056 InterfaceType * diff_impl(const InterfaceType * e, op_sqrt<NumericT>, const InterfaceType * diff_var);
00057
00058 template <typename InterfaceType, typename NumericT>
00059 InterfaceType * diff_impl(const InterfaceType * e, op_log<NumericT>, const InterfaceType * diff_var);
00060
00061 template <typename InterfaceType, typename NumericT>
00062 InterfaceType * diff_impl(const InterfaceType * e, op_log10<NumericT>, const InterfaceType * diff_var);
00063
00064
00066 template <typename T>
00067 bool unary_op_equal(T const & lhs, T const & rhs) { return true; }
00068
00069
00070
00071
00072
00078 template <typename UnaryOperation, typename InterfaceType>
00079 class op_unary : public op_interface<InterfaceType>
00080 {
00081 public:
00082 typedef typename InterfaceType::numeric_type numeric_type;
00083
00084 op_unary() {}
00085
00086 op_unary(UnaryOperation const & uo) : unary_op_(uo) {}
00087
00089 UnaryOperation const & op() const { return unary_op_; }
00090
00091
00093 std::string str() const { return unary_op_.str(); }
00094
00096 op_interface<InterfaceType> * clone() const { return new op_unary<UnaryOperation, InterfaceType>(unary_op_); }
00097
00099 numeric_type apply(numeric_type value) const { return unary_op_.apply(value); }
00100
00101
00102
00104 bool is_unary() const { return true; }
00105
00107 InterfaceType * diff(const InterfaceType * e,
00108 const InterfaceType * diff_var) const
00109 {
00110 return diff_impl(e, unary_op_, diff_var);
00111 }
00112
00114 InterfaceType * simplify(const InterfaceType * lhs,
00115 const InterfaceType * rhs) const;
00116
00118 bool can_simplify() const { return unary_op_.can_simplify(); }
00119
00121 bool equal(const op_interface<InterfaceType> * other) const
00122 {
00123 const op_unary<UnaryOperation, InterfaceType> * ptr = dynamic_cast<const op_unary<UnaryOperation, InterfaceType> *>(other);
00124 if (ptr != NULL)
00125 return unary_op_equal(ptr->op(), unary_op_);
00126
00127 return false;
00128 }
00129
00130
00131 private:
00135 UnaryOperation unary_op_;
00136 };
00137
00138
00139 }
00140
00141 #endif