Bayeux  3.4.1
Core Foundation library for SuperNEMO
i_unary_function.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_I_UNARY_FUNCTION_H
4 #define MYGSL_I_UNARY_FUNCTION_H 1
5 
6 // Standard library:
7 #include <iostream>
8 #include <limits>
9 #include <functional>
10 #include <string>
11 #include <vector>
12 #include <map>
13 
14 // Third party:
15 // - Boost:
16 #include <boost/cstdint.hpp>
17 // - Bayeux/datatools:
18 #include <datatools/handle.h>
20 #include <datatools/i_tree_dump.h>
21 #include <datatools/properties.h>
22 
23 // This project:
24 #include <mygsl/ioutils.h>
25 #include <mygsl/interval.h>
27 
28 namespace mygsl {
29 
30  // // Forward class declaration:
31  // class i_unary_function;
32 
33  // //! Alias for a handle to an unary function object
34  // typedef datatools::handle<i_unary_function> unary_function_handle_type;
35 
36  // //! Alias for a handle to a const unary function object
37  // typedef datatools::handle<const i_unary_function> const_unary_function_handle_type;
38 
39  // //! Alias for dictionary of handles to unary function objects
40  // // typedef std::map<std::string, unary_function_handle_type> unary_function_dict_type;
41  // typedef std::map<std::string, unary_function_handle_type> unary_function_dict_type;
42 
45  : public std::unary_function<double,double>
47  {
48  public:
49 
51  static const double DEFAULT_EPSILON;
52 
54  static const double AUTO_EPSILON;
55 
58  wo_none = 0,
59  wo_data_index = 0x1,
60  wo_skip_nan = 0x2,
61  wo_skip_inf = 0x4,
62  wo_skip_onzd = 0x8,
63  wo_skip_odod = 0x10,
64  wo_append = 0x20,
66  };
67 
69  i_unary_function(double epsilon_ = 0.0);
70 
72  virtual ~i_unary_function();
73 
75  virtual bool has_explicit_domain_of_definition() const;
76 
78  virtual bool is_in_domain_of_definition(double x_) const;
79 
81  virtual double eval(double x_) const;
82 
84  double evaluate(double x_) const;
85 
87  virtual double eval_no_check(double x_) const;
88 
90  virtual double get_non_zero_domain_min() const;
91 
93  bool has_non_zero_domain_min() const;
94 
96  virtual double get_non_zero_domain_max() const;
97 
99  bool has_non_zero_domain_max() const;
100 
102  bool is_in_non_zero_domain(double x_) const;
103 
105  bool is_in_zero_domain(double x_) const;
106 
108  bool has_zero_domain() const;
109 
111  double operator() (double x_) const;
112 
114  void write_ascii(std::ostream & fout_,
115  double min_, double max_, unsigned int nsamples_,
116  int x_precision_ = 16,
117  int fx_precision_ = 16,
118  uint32_t options_ = wo_default) const;
119 
121  void write_ascii_with_units(std::ostream & fout_,
122  double min_, double max_, unsigned int nsamples_,
123  double x_unit_,
124  double fx_unit_,
125  int x_precision_ = 16,
126  int fx_precision_ = 16,
127  uint32_t options_ = wo_default) const;
128 
130  void write_ascii_file(const std::string & filename_,
131  double min_, double max_, unsigned int nsamples_,
132  int x_precision_ = 16,
133  int fx_precision_ = 16,
134  uint32_t options_ = wo_default) const;
135 
137  void write_ascii_file_with_units(const std::string & filename_,
138  double min_, double max_, unsigned int nsamples_,
139  const std::string & x_unit_label_,
140  const std::string & fx_unit_label_,
141  int x_precision_ = 16,
142  int fx_precision_ = 16,
143  uint32_t options_ = wo_default) const;
144 
146  static double g_function(double x_, void * functor_);
147 
149  void set_epsilon(double);
150 
152  double get_epsilon() const;
153 
155  void initialize_simple();
156 
158  void initialize_standalone(const datatools::properties & config_);
159 
164  virtual void initialize(const datatools::properties & config_,
165  const unary_function_dict_type & functors_);
166 
168  virtual void reset();
169 
171  virtual bool is_initialized() const;
172 
174  virtual void tree_dump(std::ostream & out_ = std::clog,
175  const std::string & title_ = "",
176  const std::string & indent_ = "",
177  bool inherit_ = false) const;
178 
179  protected:
180 
182  virtual double _eval(double x_) const = 0;
183 
184  void _base_initialize(const datatools::properties & config_,
185  const unary_function_dict_type & functors_);
186 
187  void _base_reset();
188 
189  void _compute_auto_epsilon();
190 
192  void _set_defaults();
193 
194  private :
195 
196  double _epsilon_;
197 
198  // Factory stuff :
200 
201  };
202 
203 } // namespace mygsl
204 
205 // Registration macros:
206 #define MYGSL_UNARY_FUNCTOR_REGISTRATION_INTERFACE(UnaryFunctorClass) \
207  private: \
208  DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_INTERFACE(::mygsl::i_unary_function, UnaryFunctorClass ) \
209 
210 
211 #define MYGSL_UNARY_FUNCTOR_REGISTRATION_IMPLEMENT(UnaryFunctorClass,UnaryFunctorClassId) \
212  DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_IMPLEMENTATION(::mygsl::i_unary_function, UnaryFunctorClass , UnaryFunctorClassId ) \
213 
214 
215 #endif // MYGSL_I_UNARY_FUNCTION_H
216 
217 // Local Variables: --
218 // mode: c++ --
219 // c-file-style: "gnu" --
220 // tab-width: 2 --
221 // End: --
bool has_zero_domain() const
Check if the functor has an explicit zero domain.
void write_ascii(std::ostream &fout_, double min_, double max_, unsigned int nsamples_, int x_precision_=16, int fx_precision_=16, uint32_t options_=wo_default) const
Write the (x,y=f(x)) value pairs in an ASCII stream :
Definition: i_unary_function.h:65
virtual ~i_unary_function()
Destructor.
write_options_type
Options for writing sampled function in an ASCII stream.
Definition: i_unary_function.h:57
double operator()(double x_) const
Standard C++ functor interface.
static const double AUTO_EPSILON
Value for automatic computation of the error.
Definition: i_unary_function.h:54
virtual double _eval(double x_) const =0
The function evaluation abstract method.
virtual double eval_no_check(double x_) const
The function evaluation method with any value check.
Do not print (x,y=f(x)) pairs if y is a NaN.
Definition: i_unary_function.h:60
Do not print (x,y=f(x)) pairs if y is a +/-infinity.
Definition: i_unary_function.h:61
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
void write_ascii_with_units(std::ostream &fout_, double min_, double max_, unsigned int nsamples_, double x_unit_, double fx_unit_, int x_precision_=16, int fx_precision_=16, uint32_t options_=wo_default) const
Write the (x,y=f(x)) value pairs in an ASCII stream :
Do not print (x,y=f(x)) pairs if x lies out of domain of definition.
Definition: i_unary_function.h:63
static const double DEFAULT_EPSILON
Default error.
Definition: i_unary_function.h:51
void set_epsilon(double)
Set the precision.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart printing.
double get_epsilon() const
Return the precision.
void initialize_standalone(const datatools::properties &config_)
Initialization from a container of parameters.
Append to an existing file.
Definition: i_unary_function.h:64
static double g_function(double x_, void *functor_)
A generic static function to feed the GSL gsl_function interface:
void _base_initialize(const datatools::properties &config_, const unary_function_dict_type &functors_)
virtual double get_non_zero_domain_max() const
The maximum bound of the non-zero domain (default is plus infinity)
i_unary_function(double epsilon_=0.0)
Constructor.
virtual void reset()
Reset the functor.
void initialize_simple()
Simple initialization.
Definition: i_unary_function.h:58
virtual double get_non_zero_domain_min() const
The minimum bound of the non-zero domain (default is minus infinity)
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
double evaluate(double x_) const
The function evaluation method.
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
bool is_in_zero_domain(double x_) const
Check if a value is in the zero domain.
Do not print (x,y=f(x)) pairs if x lies out of the non-zero domain.
Definition: i_unary_function.h:62
virtual bool is_initialized() const
Check initialization status.
std::map< std::string, unary_function_handle_type > unary_function_dict_type
Alias for dictionary of handles to unary function objects.
Definition: unary_function_utils.h:30
virtual void initialize(const datatools::properties &config_, const unary_function_dict_type &functors_)
void write_ascii_file(const std::string &filename_, double min_, double max_, unsigned int nsamples_, int x_precision_=16, int fx_precision_=16, uint32_t options_=wo_default) const
Write the (x,y=f(x)) value pairs in an ASCII file (typical Gnuplot input) :
void _set_defaults()
Set defaults attributes.
Store as a data index for Gnuplot (2 blank lines at the end)
Definition: i_unary_function.h:59
bool has_non_zero_domain_min() const
Check the minimum bound of the non-zero domain.
virtual bool is_in_domain_of_definition(double x_) const
Check if a value is in the domain of definition of the function (default: true)
void write_ascii_file_with_units(const std::string &filename_, double min_, double max_, unsigned int nsamples_, const std::string &x_unit_label_, const std::string &fx_unit_label_, int x_precision_=16, int fx_precision_=16, uint32_t options_=wo_default) const
Write the (x,y=f(x)) value pairs in an ASCII file (typical Gnuplot input) :
#define DATATOOLS_FACTORY_SYSTEM_REGISTER_INTERFACE(BaseType)
Declaration of a system (allocator/functor) factory register as a static member of a base class and s...
Definition: factory_macros.h:52
virtual bool has_explicit_domain_of_definition() const
Check if the function has an explicit domain of definition (default: false)
virtual double eval(double x_) const
The function evaluation method.
bool is_in_non_zero_domain(double x_) const
Check if a value is in the non-zero domain.
bool has_non_zero_domain_max() const
Check the maximum bound of the non-zero domain.
A dictionary of arbitrary properties.
Definition: properties.h:125