Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
BracketAdapters.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_BATCHCOMPUTE_BRACKETADAPTER_H
18#define ROOFIT_BATCHCOMPUTE_BRACKETADAPTER_H
19
20#include <ROOT/RSpan.hxx>
21
22#include <vector>
23
24namespace RooBatchCompute {
25
26///Little adapter that gives a bracket operator to types that don't
27///have one. It completely ignores the index and returns a constant.
28template <class T = double>
30 public:
31
32 constexpr BracketAdapter(T payload) noexcept :
33 _payload{payload} { }
34
35 constexpr BracketAdapter(std::span<const T> payload) noexcept :
36 _payload{payload[0]} { }
37
38 constexpr double operator[](std::size_t) const {
39 return _payload;
40 }
41
42 constexpr operator double() const {
43 return _payload;
44 }
45
46 constexpr bool isBatch() const noexcept {
47 return false;
48 }
49
50 private:
51 const T _payload;
52};
53
54
56 public:
57 /// Construct adapter from a fallback value and a batch of values.
58 /// - If `batch.empty()`, always return `payload`.
59 /// - Else, return `batch[i]`.
60 BracketAdapterWithMask(double payload, const std::span<const double>& batch) noexcept :
61 _isBatch(!batch.empty()),
62 _payload(payload),
63 _pointer(batch.empty() ? &_payload : batch.data()),
64 _mask(batch.size() > 1 ? ~static_cast<size_t>(0): 0)
65 {
66 }
67
68 /// Construct adapter from a batch of values.
69 /// - If `batch.size() == 1`, always return the value at `batch[0]`.
70 /// - Else, return `batch[i]`.
71 BracketAdapterWithMask(std::span<const double> batch) :
72 _isBatch(batch.size() > 1),
73 _payload(batch[0]),
74 _pointer(batch.data()),
75 _mask(batch.size() > 1 ? ~static_cast<size_t>(0): 0)
76 {
77 assert(batch.size() > 0);
78 }
79
81 _isBatch(other._isBatch),
82 _payload(other._payload),
83 _pointer(other._isBatch ? other._pointer : &_payload),
84 _mask(other._mask)
85 {
86 }
87
89
90 inline double operator[](std::size_t i) const noexcept {
91 return _pointer[ i & _mask];
92 }
93
94 inline bool isBatch() const noexcept {
95 return _isBatch;
96 }
97
98 private:
99 const bool _isBatch;
100 const double _payload;
101 const double* __restrict const _pointer;
102 const size_t _mask;
103};
104
105}
106
107#endif /* ROOFIT_BATCHCOMPUTE_BRACKETADAPTER_H */
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
const double *__restrict const _pointer
BracketAdapterWithMask(double payload, const std::span< const double > &batch) noexcept
Construct adapter from a fallback value and a batch of values.
BracketAdapterWithMask & operator=(const BracketAdapterWithMask &other)=delete
BracketAdapterWithMask(const BracketAdapterWithMask &other) noexcept
double operator[](std::size_t i) const noexcept
BracketAdapterWithMask(std::span< const double > batch)
Construct adapter from a batch of values.
Little adapter that gives a bracket operator to types that don't have one.
constexpr BracketAdapter(T payload) noexcept
constexpr bool isBatch() const noexcept
constexpr double operator[](std::size_t) const
constexpr BracketAdapter(std::span< const T > payload) noexcept
Namespace for dispatching RooFit computations to various backends.