This struct enables passing computation data around between elements of a computation graph.
The RunContext stores read-only spans to data that has already been computed. This can be data of the observables (which is constant during a fit) or intermediate computation results from evaluating PDFs or formulae for every point in a dataset. The latter may change as fit parameters change.
Instead of storing information about these data inside nodes of the computation graph (requiring a change of their state, possibly violating const-correctness), this information is stored in RunContext::spans using the pointer of the element that produced those results as a key. In this way, one or multiple RunContext instances can be passed around when computations are running, leaving the objects of the computation graph invariant.
The RunContext can provide memory for temporary data, that is, data that can vanish after a fit converges. Using RunContext::makeBatch(), a suitable amount of memory is allocated to store computation results. When intermediate data are cleared, this memory is not freed. In this way, temporary data can be invalidated when fit parameters change, but the memory is only allocated once per fit.
When a RunContext goes out of scope, the memory is freed. That means that in between fit cycles, a RunContext should be cleared using clear(), or single results should be invalidated by removing these from RunContext::spans. The RunContext object should be destroyed only after a fit completes.
Definition at line 31 of file RunContext.h.
Public Member Functions | |
RunContext () | |
Create an empty RunContext that doesn't have access to any computation results. | |
RunContext (const RunContext &)=delete | |
Deleted because copying the owned memory is expensive. | |
RunContext (RunContext &&)=default | |
Move a RunContext. All spans pointing to data retrieved from the original remain valid. | |
void | clear () |
Clear all computation results without freeing memory. | |
RooSpan< const double > | getBatch (const RooAbsReal *owner) const |
Check if there is a span of data corresponding to the object passed as owner. | |
RooSpan< const double > | getBatch (const RooArgProxy &proxy) const |
RooSpan< double > | getWritableBatch (const RooAbsReal *owner) |
Check if there is a writable span of data corresponding to the object passed as owner. | |
RooSpan< double > | makeBatch (const RooAbsReal *owner, std::size_t size) |
Create a writable batch. | |
RooSpan< const double > | operator[] (const RooAbsReal *owner) const |
Retrieve a batch of data corresponding to the element passed as owner . | |
Public Attributes | |
std::vector< double > | logProbabilities |
If evaluation should only occur in a range, the range name can be passed here. | |
std::unordered_map< const RooAbsReal *, std::vector< double > > | ownedMemory |
Memory owned by this struct. It is associated to nodes in the computation graph using their pointers. | |
const char * | rangeName {nullptr} |
std::unordered_map< const RooAbsReal *, RooSpan< const double > > | spans |
Once an object has computed its value(s), the span pointing to the results is registered here. | |
#include <RunContext.h>
|
inline |
Create an empty RunContext that doesn't have access to any computation results.
Definition at line 33 of file RunContext.h.
|
delete |
Deleted because copying the owned memory is expensive.
If needed, it can be implemented, though.
spans
to new location in ownedMemory
after data have been copied!
|
default |
Move a RunContext. All spans pointing to data retrieved from the original remain valid.
|
inline |
Clear all computation results without freeing memory.
Definition at line 49 of file RunContext.h.
RooSpan< const double > RooBatchCompute::RunContext::getBatch | ( | const RooAbsReal * | owner | ) | const |
Check if there is a span of data corresponding to the object passed as owner.
Definition at line 55 of file RunContext.cxx.
RooSpan< const double > RooBatchCompute::RunContext::getBatch | ( | const RooArgProxy & | proxy | ) | const |
RooSpan< double > RooBatchCompute::RunContext::getWritableBatch | ( | const RooAbsReal * | owner | ) |
Check if there is a writable span of data corresponding to the object passed as owner.
The span can be used both for reading and writing.
Definition at line 66 of file RunContext.cxx.
RooSpan< double > RooBatchCompute::RunContext::makeBatch | ( | const RooAbsReal * | owner, |
std::size_t | size | ||
) |
Create a writable batch.
If the RunContext already owns memory for the object owner
, just resize the memory. If it doesn't exist yet, allocate it.
NaN
to help detect such errors.A read-only reference to the memory will be stored in spans
.
owner | RooFit object whose value should be written into the memory. |
size | Requested size of the span. |
Definition at line 87 of file RunContext.cxx.
|
inline |
Retrieve a batch of data corresponding to the element passed as owner
.
Definition at line 44 of file RunContext.h.
std::vector<double> RooBatchCompute::RunContext::logProbabilities |
If evaluation should only occur in a range, the range name can be passed here.
Definition at line 56 of file RunContext.h.
std::unordered_map<const RooAbsReal*, std::vector<double> > RooBatchCompute::RunContext::ownedMemory |
Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
Definition at line 54 of file RunContext.h.
const char* RooBatchCompute::RunContext::rangeName {nullptr} |
Definition at line 55 of file RunContext.h.
std::unordered_map<const RooAbsReal*, RooSpan<const double> > RooBatchCompute::RunContext::spans |
Once an object has computed its value(s), the span pointing to the results is registered here.
Definition at line 52 of file RunContext.h.