antioch-0.4.0
List of all members | Public Member Functions | Private Member Functions
Antioch::SigmaBinConverter< VectorCoeffType > Class Template Reference

#include <sigma_bin_converter.h>

Public Member Functions

 SigmaBinConverter ()
 
 ~SigmaBinConverter ()
 
template<typename VectorStateType >
void y_on_custom_grid (const VectorCoeffType &x_old, const VectorCoeffType &y_old, const VectorStateType &x_new, VectorStateType &y_new) const
 

Private Member Functions

template<typename StateType , typename VUIntType >
StateType custom_bin_value (const StateType &custom_head, const StateType &custom_tail, const VUIntType &index_heads, unsigned int custom_head_index, const VectorCoeffType &list_ref_head_tails, const VectorCoeffType &list_ref_values) const
 

Detailed Description

template<typename VectorCoeffType = std::vector<double>>
class Antioch::SigmaBinConverter< VectorCoeffType >

Definition at line 42 of file sigma_bin_converter.h.

Constructor & Destructor Documentation

template<typename VectorCoeffType >
Antioch::SigmaBinConverter< VectorCoeffType >::SigmaBinConverter ( )
inline

Definition at line 64 of file sigma_bin_converter.h.

65 {
66  return;
67 }
template<typename VectorCoeffType >
Antioch::SigmaBinConverter< VectorCoeffType >::~SigmaBinConverter ( )
inline

Definition at line 71 of file sigma_bin_converter.h.

72 {
73  return;
74 }

Member Function Documentation

template<typename VectorCoeffType >
template<typename StateType , typename VUIntType >
StateType Antioch::SigmaBinConverter< VectorCoeffType >::custom_bin_value ( const StateType &  custom_head,
const StateType &  custom_tail,
const VUIntType &  index_heads,
unsigned int  custom_head_index,
const VectorCoeffType &  list_ref_head_tails,
const VectorCoeffType &  list_ref_values 
) const
inlineprivate

Definition at line 137 of file sigma_bin_converter.h.

References antioch_assert_equal_to, Antioch::constant_clone(), Antioch::custom_clone(), Antioch::disjunction(), Antioch::if_else(), std::max(), Antioch::max(), std::min(), Antioch::min(), and Antioch::zero_clone().

141  {
142 
143  using std::min;
144  using Antioch::min;
145  using std::max;
146  using Antioch::max;
147 
148  antioch_assert_equal_to(list_ref_head_tails.size(),list_ref_values.size());
149 
150  StateType surf = Antioch::zero_clone(custom_head);
151 
152  typedef typename Antioch::value_type<VUIntType>::type UIntType;
153 
154  UIntType start_head = index_heads[custom_head_index];
155 
156  UIntType value_head = Antioch::if_else(start_head > (typename Antioch::value_type<typename Antioch::value_type<VUIntType>::type>::type)0,
157  (UIntType)(start_head - Antioch::constant_clone(start_head,1)),
158  (UIntType)(index_heads[index_heads.size() - 1])); // right stairs, value never used
159 
160  UIntType ref_end_tail = min((UIntType)(start_head + Antioch::constant_clone(start_head,1)) ,
161  (UIntType)(Antioch::constant_clone(start_head,list_ref_head_tails.size() - 1)));
162 
163  // if StateType is vectorized, it takes care of it here
164  StateType ref_head = Antioch::custom_clone(custom_head,list_ref_head_tails,start_head);
165  StateType ref_tail = Antioch::custom_clone(custom_head,list_ref_head_tails,ref_end_tail);
166  StateType ref_value = Antioch::custom_clone(custom_head,list_ref_values,value_head);
167 
168  // head from custom head to ref head
169  // super not efficient, everything is calculated every time...
170  surf += Antioch::if_else(Antioch::constant_clone(custom_head,list_ref_head_tails[0]) > custom_head ||
171  Antioch::constant_clone(custom_head,list_ref_head_tails[list_ref_head_tails.size() - 1]) < custom_head, // custom is outside ref
172  Antioch::zero_clone(surf),
173  (StateType)
174  Antioch::if_else(ref_head < custom_tail, // custom is within ref bin
175  (StateType)(ref_value * (ref_head - custom_head)),
176  (StateType)(ref_value * (custom_tail - custom_head)))
177  );
178 
179  //body from ref head to ref last tail
180  while(Antioch::disjunction(ref_tail < custom_tail && // ref is below tail (<=> start_head < index_heads[custom_head_index + 1])
181  start_head < Antioch::constant_clone(start_head,list_ref_head_tails.size() - 1))) // ref is still defined
182  {
183  ref_end_tail = min((UIntType)(start_head + Antioch::constant_clone(start_head,1)) ,
184  (UIntType)(Antioch::constant_clone(start_head,list_ref_head_tails.size() - 1)));
185 
186  ref_head = Antioch::custom_clone(custom_head,list_ref_head_tails,start_head);
187  ref_tail = Antioch::custom_clone(custom_head,list_ref_head_tails,ref_end_tail);
188  ref_value = Antioch::custom_clone(custom_head,list_ref_values,start_head);
189 
190  surf += Antioch::if_else(ref_tail < custom_tail && start_head < Antioch::constant_clone(start_head,list_ref_head_tails.size()),
191  (StateType)((ref_tail - ref_head) * ref_value),
192  Antioch::zero_clone(surf));
193 
194  start_head += Antioch::if_else(ref_tail < custom_tail && start_head < Antioch::constant_clone(start_head,list_ref_head_tails.size()),
195  Antioch::constant_clone(start_head,1),
196  Antioch::zero_clone(start_head));
197  }
198 
199  ref_end_tail = min((UIntType)(start_head + Antioch::constant_clone(start_head,1)) ,
200  (UIntType)(Antioch::constant_clone(start_head,list_ref_head_tails.size() - 1)));
201 
202  ref_head = Antioch::custom_clone(custom_head,list_ref_head_tails,start_head);
203  ref_tail = Antioch::custom_clone(custom_head,list_ref_head_tails,ref_end_tail);
204  ref_value = Antioch::custom_clone(custom_head,list_ref_values,start_head);
205 
206  // tail from ref_head to custom_tail
207  // super not efficient, everything is calculated every time...
208  surf += Antioch::if_else(
209  Antioch::constant_clone(custom_tail,list_ref_head_tails[list_ref_head_tails.size() - 1]) < custom_tail || // custom is outside ref
210  Antioch::constant_clone(custom_tail,list_ref_head_tails.front()) > custom_tail || // custom is outside ref
211  ref_head > custom_tail, // custom is fully inside ref bin (already taken into account in head)
212  Antioch::zero_clone(surf),
213  (StateType)(ref_value * (custom_tail - ref_head)));
214 
215  return surf / (custom_tail - custom_head);
216  }
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
#define antioch_assert_equal_to(expr1, expr2)
T custom_clone(const T &, const VectorScalar &values, unsigned int indexes)
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type min(const T &in)
Definition: eigen_utils.h:98
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
max(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
enable_if_c< is_eigen< T1 >::value &&is_eigen< T2 >::value, typename state_type< T1 >::type >::type if_else(const Condition &condition, const T1 &if_true, const T2 &if_false)
Definition: eigen_utils.h:250
typename _Scalar int _Rows int _Cols int _Options int _MaxRows int _MaxCols inline min(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
Definition: eigen_utils.h:145
bool disjunction(const bool &vec)
template<typename VectorCoeffType >
template<typename VectorStateType >
void Antioch::SigmaBinConverter< VectorCoeffType >::y_on_custom_grid ( const VectorCoeffType &  x_old,
const VectorCoeffType &  y_old,
const VectorStateType &  x_new,
VectorStateType &  y_new 
) const
inline

Definition at line 79 of file sigma_bin_converter.h.

References antioch_assert_equal_to, antioch_assert_not_equal_to, Antioch::conjunction(), Antioch::constant_clone(), Antioch::eval_index(), Antioch::if_else(), Antioch::init_constant(), and Antioch::zero_clone().

Referenced by k_photo(), tester(), and vectester().

81 {
82 // data consistency
83  antioch_assert_not_equal_to(x_custom.size(),0);
84  antioch_assert_equal_to(y_custom.size(),x_custom.size());
85  antioch_assert_not_equal_to(x_old.size(),0);
86  antioch_assert_equal_to(x_old.size(),y_old.size());
87 
88 
89 // first meta-prog needed stuff
91  unsigned int>::type UIntType;
92  typedef typename Antioch::rebind<VectorStateType,UIntType>::type VUIntType;
93 
94 // find all the indexes of old that are just after all
95 // the custom values
96 // todo: better way to build the indexes container?
97  UIntType example;
98  Antioch::zero_clone(example,x_custom[0]);
99 // two levels needed to obtain correct fixed-sized vexcl vector
100 // within eigen vector (VIntType = Eigen<vexcl<unsigned int> >):
101 // Eigen => can't initialize in constructor VUIntType
102 // vexcl => fixed size accessible only within constructor
103  VUIntType ihead(x_custom.size());
104  Antioch::init_constant(ihead,example);
105 
106  UIntType unfound = Antioch::constant_clone(example,x_old.size()-1);
107 
108  for(unsigned int ic = 0; ic < x_custom.size(); ic++)
109  {
110  UIntType ihigh = Antioch::constant_clone(example,x_old.size()-1);
111  for (unsigned int i = 0; i != x_old.size() - 1; ++i)
112  {
113  UIntType icus = Antioch::constant_clone(example,ic);
114 
115  ihigh = Antioch::if_else (Antioch::eval_index(x_custom,icus) < x_old[i] && ihigh == unfound,
116  Antioch::constant_clone(example,i),
117  ihigh);
118 
119  if(Antioch::conjunction(ihigh != unfound))break; // once we found everyone, don't waste time
120  }
121  ihead[ic] = ihigh;
122  }
123 
124  // bin
125  for(unsigned int ic = 0; ic < x_custom.size() - 1; ic++) // right stairs, last one = 0
126  {
127  y_custom[ic] = this->custom_bin_value(x_custom[ic], x_custom[ic + 1],ihead, ic, x_old, y_old);
128  }
129 
130  return;
131 
132 }
#define antioch_assert_equal_to(expr1, expr2)
StateType custom_bin_value(const StateType &custom_head, const StateType &custom_tail, const VUIntType &index_heads, unsigned int custom_head_index, const VectorCoeffType &list_ref_head_tails, const VectorCoeffType &list_ref_values) const
#define antioch_assert_not_equal_to(expr1, expr2)
bool conjunction(const bool &vec)
enable_if_c< is_eigen< typename value_type< VectorT >::type >::value, typename value_type< VectorT >::type >::type eval_index(const VectorT &vec, const _Matrix< _UIntT, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &index)
Definition: eigen_utils.h:268
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
enable_if_c< is_eigen< T1 >::value &&is_eigen< T2 >::value, typename state_type< T1 >::type >::type if_else(const Condition &condition, const T1 &if_true, const T2 &if_false)
Definition: eigen_utils.h:250
void init_constant(Vector &output, const Scalar &example)
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
Definition: eigen_utils.h:145

The documentation for this class was generated from the following file:

Generated on Thu Jul 7 2016 11:09:50 for antioch-0.4.0 by  doxygen 1.8.8