Skip to content
Snippets Groups Projects

Few more new features for LHCbMath

Merged Vanya Belyaev requested to merge vanya-lhcbmath9 into master
  1. Extend operations with polynomials
  2. Allow change/extend/shrink domain for Bernstein polynomials
  3. Allow math-ooperations for (Bernstein) polynomials with different domains
  4. Collect interpolation functions into separate header file
  5. Add Neville interpolation algorithm
  6. Add few more signatures for interpolation functions
  7. Add optional range for splines/interpolations
  8. Reduce code duplication
  9. Add more protection for invalid covariances in math-operations for ValueWithError objects

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 ) ;
  • const auto ny = std::distance(  ybegin, yend );

    is much less verbose, and thus easier to read (at least for me ;-) (and the lost information isn't relevant IMHO)

  • 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 ; } ) ;
    • I suspect you want:

      [] ( const auto& i ) { return i.first; }

      to avoid copying the pair. And note that this returns i.first by value, not reference...

  • Author Developer

    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...

  • Author Developer

    @graven This is exactly that reflex(?) does not like :-)

  • Author Developer

    @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
  • 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 ...

    • Author Developer

      counting number of lines and occurances of this cconstruction , I see no obvious gain :-) It is almost the same.

    • 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 and select2nd 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> ()
  • Re reflex: I thought that only I/O still needed dictionaries, and that for the rest one could just get cling (i.e. clang) to parse the header... hence we should be able to considerably reduce the entries in dictionaries....

  • @graven I think the dictionaries are also needed for the python bindings?

  • Marco Cattaneo Status changed to merged

    Status changed to merged

  • Marco Cattaneo mentioned in commit 366e0980

    mentioned in commit 366e0980

  • @cattanem : I was under the impression the python bindings relied entirely on cling, and thus that it is sufficient to get cling to parse the headers. But @clemenci surely knows the real answer!

  • @graven is correct: dictionaries are needed only for I/O. See GAUDI-1098.

  • Gerhard Raven mentioned in merge request !174 (merged)

    mentioned in merge request !174 (merged)

  • Marco Cattaneo mentioned in commit 96cfa093

    mentioned in commit 96cfa093

  • Marco Cattaneo Mentioned in commit 366e0980

    Mentioned in commit 366e0980

  • Marco Cattaneo Mentioned in commit 96cfa093

    Mentioned in commit 96cfa093

  • Please register or sign in to reply
    Loading