Few more new features for LHCbMath
- Extend operations with polynomials
- Allow change/extend/shrink domain for Bernstein polynomials
- Allow math-ooperations for (Bernstein) polynomials with different domains
- Collect interpolation functions into separate header file
- Add Neville interpolation algorithm
- Add few more signatures for interpolation functions
- Add optional range for splines/interpolations
- Reduce code duplication
- Add more protection for invalid covariances in math-operations for ValueWithError objects
Merge request reports
Activity
- Kernel/LHCbMath/LHCbMath/Interpolation.h 0 → 100644
425 Gaudi::Math::Interpolation::lagrange 426 ( XITERATOR xbegin , 427 XITERATOR xend , 428 YITERATOR ybegin , 429 YITERATOR yend , 430 const double x , 431 RESULT result , 432 XADAPTER xvalue , // adaptor to get y-value 433 YADAPTER yvalue ) // adaptor to get x-value 434 { 435 /// 1)special case no data 436 if ( xbegin == xend || ybegin == yend ) { return result ; } // RETURN 437 const typename std::iterator_traits<XITERATOR>::difference_type nx = std::distance ( xbegin , xend ) ; 438 /// 2) special case: constant function 439 if ( 1 == nx ) { return result + yvalue ( *ybegin ) ; } // RETURN 440 const typename std::iterator_traits<XITERATOR>::difference_type ny = std::distance ( ybegin , yend ) ; - Kernel/LHCbMath/src/Interpolation.cpp 0 → 100644
145 */ 146 // ============================================================================ 147 std::pair<double,double> 148 Gaudi::Math::Interpolation::lagrange2 149 ( const Gaudi::Math::Interpolation::DATA& data , 150 const double x , 151 const unsigned int iy ) 152 { 153 const double r = lagrange ( data.begin () , 154 data.end () , 155 data.begin () , 156 data.end () , 157 x , 158 0.0 , 159 [] ( auto i ) { return i.first ; } , 160 [] ( auto i ) { return i.second ; } ) ; for the zeroth there were many auto in the code, and C++ part compiles nicely. But when I've tried to build the dictionaries for the derived (non-templated) functions, I've got problems form included headers with lambdas and autos.. It loosk like dictionary-buiding machinery puts some constraints.
I've replaced all autos with the exact types and everything is fine now. Probably is would be enough to replace only part of autos... but since it works, it does nto matter too much...@graven Sorry - I mean reflex does not like when such construction appears in header files.. For this *.cpp file it is fine. I've reshuffles lines several times between *.h and * .cpp, cleaning *.h from stuff that Refles does not like..
Edited by Vanya Belyaev- Kernel/LHCbMath/src/Interpolation.cpp 0 → 100644
214 * (e.g. >20) due to bad numerical stability 215 * @author Vanya BELYAEV Ivan.Belyaev@itep.ru 216 * @date 2016-07-23 217 */ 218 // ============================================================================ 219 double Gaudi::Math::Interpolation::neville 220 ( const Gaudi::Math::Interpolation::DATA& data , const double x ) 221 { 222 return neville ( data.begin () , 223 data.end () , 224 data.begin () , 225 data.end () , 226 x , 227 [] ( const std::pair<double,double>& i ) { return i.first ; } , 228 [] ( const std::pair<double,double>& i ) { return i.second ; } ); 229 } given the repeat occurrences, why not add
namespace { template <typename F, typename S> constexpr struct select1st_t { F& operator()(std::pair<F,S>& p) const { return p.first; } const F& operator()( const std::pair<F,S>& p ) const { return p.first; } F& operator() (std::pair<F,S>&& ) const = delete; // avoid returning a dangling reference } select1st {}; }
to the top of the file, and then use
select1st
instead of repeating the lambda ...If you also count all other occurrences in other bits of code throughout LHCb, I'm sure there is a gain if we put
select1st
andselect2nd
in a common header file (and the presence 3rd operator() = delete has the advantage of refusing to compile in case of a silly mistake -- could even make it do the right thing by returning a value instead of a reference in that case ;-)
556 539 const GaudiMath::Interpolation::Type& type , 557 540 const bool null , 558 541 const double scale , 559 const double shift ) 542 const double shift , 543 const unsigned int begin , 544 const unsigned int end ) 560 545 : std::unary_function<double,Gaudi::Math::ValueWithError> () please note that
std::unary_function
has been deprecated in C++11, and will be removed in C++17... (see eg. http://en.cppreference.com/w/cpp/utility/functional/unary_function)
@graven I think the dictionaries are also needed for the python bindings?
mentioned in commit 366e0980
@graven is correct: dictionaries are needed only for I/O. See GAUDI-1098.
mentioned in merge request !174 (merged)
mentioned in commit 96cfa093
Mentioned in commit 366e0980
Mentioned in commit 96cfa093