Logo ROOT  
Reference Guide
BatchHelpers.h
Go to the documentation of this file.
1// Author: Stephan Hageboeck, CERN 25 Feb 2019
2
3/*****************************************************************************
4 * RooFit
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2019, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROOFIT_ROOFITCORE_INC_BATCHHELPERS_H_
18#define ROOFIT_ROOFITCORE_INC_BATCHHELPERS_H_
19
20#include "RooRealProxy.h"
21
22#include <vector>
23#include <RooSpan.h>
24
25class RooArgSet;
26
27namespace BatchHelpers {
28
29constexpr size_t block = 1024;
30
32 const double * __restrict ptr;
33 bool _batch;
34
35 constexpr double operator[](std::size_t i) const {
36 return ptr[i];
37 }
38 constexpr bool batch() const {
39 return _batch;
40 }
41};
42
44 size_t size, nBatches;
45};
46
47size_t findSize(std::vector< RooSpan<const double> > parameters);
48
49EvaluateInfo getInfo(std::vector<const RooRealProxy*> parameters, size_t begin, size_t batchSize);
50EvaluateInfo init(std::vector< RooRealProxy > parameters,
51 std::vector< ArrayWrapper* > wrappers,
52 std::vector< double*> arrays,
53 size_t begin, size_t batchSize );
54
55///Little adapter that gives a bracket operator to types that don't
56///have one. It completely ignores the index and returns a constant.
57template <class T = double>
59 public:
60
61 constexpr BracketAdapter(T payload) noexcept :
62 _payload{payload} { }
63
64 constexpr double operator[](std::size_t) const {
65 return _payload;
66 }
67
68 constexpr operator double() const {
69 return _payload;
70 }
71
72 constexpr bool isBatch() const noexcept {
73 return false;
74 }
75
76 private:
77 const T _payload;
78};
79
80
82 public:
83 BracketAdapterWithMask(double payload, const RooSpan<const double>& batch) noexcept :
84 _isBatch(!batch.empty()),
85 _payload(payload),
86 _pointer(batch.empty() ? &_payload : batch.data()),
87 _mask(batch.empty() ? 0 : ~static_cast<size_t>(0))
88 {
89 }
90
92 _isBatch(other._isBatch),
93 _payload(other._payload),
94 _pointer(other._isBatch ? other._pointer : &_payload),
95 _mask(other._mask)
96 {
97 }
98
100
101 inline double operator[](std::size_t i) const noexcept {
102 return _pointer[ i & _mask];
103 }
104
105 inline bool isBatch() const noexcept {
106 return _isBatch;
107 }
108
109 private:
110 const bool _isBatch;
111 const double _payload;
112 const double* __restrict const _pointer;
113 const size_t _mask;
114};
115
116}
117
118#endif /* ROOFIT_ROOFITCORE_INC_BATCHHELPERS_H_ */
double
Definition: Converters.cxx:921
BracketAdapterWithMask & operator=(const BracketAdapterWithMask &other)=delete
double operator[](std::size_t i) const noexcept
Definition: BatchHelpers.h:101
const double *__restrict const _pointer
Definition: BatchHelpers.h:112
BracketAdapterWithMask(double payload, const RooSpan< const double > &batch) noexcept
Definition: BatchHelpers.h:83
BracketAdapterWithMask(const BracketAdapterWithMask &other) noexcept
Definition: BatchHelpers.h:91
Little adapter that gives a bracket operator to types that don't have one.
Definition: BatchHelpers.h:58
constexpr double operator[](std::size_t) const
Definition: BatchHelpers.h:64
constexpr BracketAdapter(T payload) noexcept
Definition: BatchHelpers.h:61
constexpr bool isBatch() const noexcept
Definition: BatchHelpers.h:72
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
size_t findSize(std::vector< RooSpan< const double > > parameters)
This function returns the minimum size of the non-zero-sized batches.
constexpr size_t block
Definition: BatchHelpers.h:29
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double * > arrays, size_t begin, size_t batchSize)
EvaluateInfo getInfo(std::vector< const RooRealProxy * > parameters, size_t begin, size_t batchSize)
double T(double x)
Definition: ChebyshevPol.h:34
constexpr bool batch() const
Definition: BatchHelpers.h:38
constexpr double operator[](std::size_t i) const
Definition: BatchHelpers.h:35
const double *__restrict ptr
Definition: BatchHelpers.h:32