ComPPare 1.0.0
Loading...
Searching...
No Matches
comppare::InputContext< Inputs >::OutputContext< OutputSpecs > Class Template Reference

OutputContext class template to hold output parameters and manage implementations. More...

#include <comppare.hpp>

Classes

struct  Impl
 Internal container representing one registered implementation. More...
 

Public Member Functions

template<typename... Ins>
 OutputContext (Ins &&...ins)
 Construct a new OutputContext.
 
 OutputContext (const OutputContext &other)=delete
 Deleted copy constructor.
 
OutputContextoperator= (const OutputContext &other)=delete
 Deleted copy assignment operator.
 
 OutputContext (OutputContext &&other)=delete
 Deleted move constructor.
 
OutputContextoperator= (OutputContext &&other)=delete
 Deleted move assignment operator.
 
template<typename F >
requires std::invocable<F, const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...>
Implset_reference (std::string name, F &&f)
 Set a reference implementation.
 
template<typename F >
requires std::invocable<F, const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...>
Impladd (std::string name, F &&f)
 Add a new implementation to the comparison framework.
 
const OutPtr get_reference_output () const
 Get the reference output by pointer.
 
const OutPtr get_output (const size_t idx) const
 Get the output for a specific implementation by pointer.
 
const OutPtr get_output (const std::string_view name) const
 Get the output for a specific implementation by name.
 
void get_reference_output (outtype_t< OutputSpecs > *...outs) const
 Copies the reference output into provided pointer to variables.
 
void get_output (const size_t idx, outtype_t< OutputSpecs > *...outs) const
 Copies the outputs of a specific implementation by index into provided pointer to variables.
 
void get_output (const std::string_view name, outtype_t< OutputSpecs > *...outs) const
 Copies the outputs of a specific implementation by name into provided pointer to variables.
 
void run (int argc=0, char **argv=nullptr)
 Runs the comparison for all added implementations.
 

Private Types

template<typename S >
using outtype_t = typename outspec< S >::outtype_t
 Extracts the value type from a outspec.
 
template<typename S >
using pol_t = typename outspec< S >::policy_t
 Extracts the policy type from a outspec.
 
using Func = std::function< void(const std::decay_t< Inputs > &..., outtype_t< OutputSpecs > &...)>
 Alias for the function signature of a user-provided implementation.
 
using InTup = std::tuple< std::decay_t< Inputs >... >
 Tuple type holding all input arguments.
 
using OutTup = std::tuple< outtype_t< OutputSpecs >... >
 Tuple type holding all output values (one element per outspec).
 
using PolicyTup = std::tuple< pol_t< OutputSpecs >... >
 Tuple type holding the error/policy object associated with each output outspec.
 
using OutPtr = std::shared_ptr< OutTup >
 Shared pointer to an output tuple.
 

Private Member Functions

void register_plugin (const std::shared_ptr< plugin::Plugin< InTup, OutTup > > &p)
 Register a plugin for the output context.
 
void print_header () const
 Print the header for the output table.
 
void compute_errors (PolicyTup &errs, const OutTup &test, const OutTup &ref)
 Compute the error metrics for each output specification.
 
bool any_fail (const PolicyTup &errs) const
 Check if any of the error policies indicate a failure.
 
void print_metrics (const PolicyTup &errs) const
 Print the metrics for each output specification.
 
OutPtr get_output_by_index_ (const size_t idx) const
 Get the output by index.
 
OutPtr get_output_by_name_ (const std::string_view name) const
 Get the output by implementation name.
 
void unpack_output_ (const OutTup &outtup, outtype_t< OutputSpecs > *...outs) const
 Unpack the output tuple into the provided output pointers.
 

Static Private Member Functions

template<std::size_t I>
static constexpr std::size_t spec_metric_count ()
 Get the implementation details for a specific implementation index.
 
template<std::size_t I>
static constexpr std::string_view spec_metric_name (std::size_t m)
 Get the name of a specific metric for a specific implementation index.
 

Private Attributes

InTup inputs_
 Tuple instance storing all current input arguments.
 
std::vector< OutPtroutputs_
 Storage for reference and comparison outputs.
 
PolicyTup policies_ref_
 Tuple of policy objects for the reference outputs.
 
std::shared_ptr< plugin::Plugin< InTup, OutTup > > plugin_
 Shared pointer to the plugin instance.
 
std::vector< Implimpls_
 Vector to hold all implementations.
 

Static Private Attributes

static constexpr size_t NUM_OUT = sizeof...(OutputSpecs)
 Number of output specifications.
 
static constexpr int PRINT_COL_WIDTH = 20
 Set the width of the print columns.
 

Detailed Description

template<typename... Inputs>
template<OutSpec... OutputSpecs>
class comppare::InputContext< Inputs >::OutputContext< OutputSpecs >

OutputContext class template to hold output parameters and manage implementations.

Template Parameters
OutputSpecs

Member Typedef Documentation

◆ Func

template<typename... Inputs>
template<OutSpec... OutputSpecs>
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::Func = std::function<void(const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...)>
private

Alias for the function signature of a user-provided implementation.

The function must take all input arguments by const reference, and all output arguments by non-const reference. The framework invokes this function to compare multiple implementations on the same input.

Example signature:

void f(const In1&, const In2&, ..., Out1&, Out2&...);

◆ InTup

template<typename... Inputs>
template<OutSpec... OutputSpecs>
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::InTup = std::tuple<std::decay_t<Inputs>...>
private

Tuple type holding all input arguments.

◆ OutPtr

template<typename... Inputs>
template<OutSpec... OutputSpecs>
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::OutPtr = std::shared_ptr<OutTup>
private

Shared pointer to an output tuple.

Used to manage lifetime of output results across multiple implementations.

◆ OutTup

template<typename... Inputs>
template<OutSpec... OutputSpecs>
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::OutTup = std::tuple<outtype_t<OutputSpecs>...>
private

Tuple type holding all output values (one element per outspec).

◆ outtype_t

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<typename S >
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::outtype_t = typename outspec<S>::outtype_t
private

Extracts the value type from a outspec.

Template Parameters
SThe output outspec type.

◆ pol_t

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<typename S >
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::pol_t = typename outspec<S>::policy_t
private

Extracts the policy type from a outspec.

Template Parameters
SThe output outspec type.

◆ PolicyTup

template<typename... Inputs>
template<OutSpec... OutputSpecs>
using comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::PolicyTup = std::tuple<pol_t<OutputSpecs>...>
private

Tuple type holding the error/policy object associated with each output outspec.

Constructor & Destructor Documentation

◆ OutputContext() [1/3]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<typename... Ins>
comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::OutputContext ( Ins &&...  ins)
inlineexplicit

Construct a new OutputContext.

Template Parameters
InsThe types of the input arguments
Parameters
insThe input arguments

This constructor initializes the OutputContext with the provided input arguments. The inputs are perfectly forwarded to allow for move and copy semantics.

◆ OutputContext() [2/3]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::OutputContext ( const OutputContext< OutputSpecs > &  other)
delete

Deleted copy constructor.

◆ OutputContext() [3/3]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::OutputContext ( OutputContext< OutputSpecs > &&  other)
delete

Deleted move constructor.

Member Function Documentation

◆ add()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<typename F >
requires std::invocable<F, const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...>
Impl & comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::add ( std::string  name,
F &&  f 
)
inline

Add a new implementation to the comparison framework.

Template Parameters
FThe type of the function
Parameters
nameThe name of the implementation
fThe function to execute
Returns
The implementation instance

This function adds a new implementation to the comparison framework. The function will be run and compared against the reference implementation.

◆ any_fail()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
bool comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::any_fail ( const PolicyTup errs) const
inlineprivate

Check if any of the error policies indicate a failure.

Parameters
errsThe tuple of error policies to check.
Returns
true if any policy indicates a failure, false otherwise.

◆ compute_errors()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::compute_errors ( PolicyTup errs,
const OutTup test,
const OutTup ref 
)
inlineprivate

Compute the error metrics for each output specification.

Parameters
errsThe tuple of error policies.
testThe test output.
refThe reference output.

◆ get_output() [1/4]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
const OutPtr comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_output ( const size_t  idx) const
inline

Get the output for a specific implementation by pointer.

Parameters
idxThe index of the implementation
Returns
A shared pointer to the output of the implementation

This function returns a shared pointer to the output of the implementation at the specified index.

◆ get_output() [2/4]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_output ( const size_t  idx,
outtype_t< OutputSpecs > *...  outs 
) const
inline

Copies the outputs of a specific implementation by index into provided pointer to variables.

Parameters
outsOne pointer per output element. Each pointer must point to writable storage of the corresponding output type.

Internally, this looks up the output tuple at the specified index, and unpacks its elements into the provided pointers. This allows callers to access values without dealing with std::tuple directly.

◆ get_output() [3/4]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
const OutPtr comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_output ( const std::string_view  name) const
inline

Get the output for a specific implementation by name.

Parameters
nameThe name of the implementation
Returns
A shared pointer to the output of the implementation

This function returns a shared pointer to the output of the implementation with the specified name.

◆ get_output() [4/4]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_output ( const std::string_view  name,
outtype_t< OutputSpecs > *...  outs 
) const
inline

Copies the outputs of a specific implementation by name into provided pointer to variables.

Parameters
outsOne pointer per output element. Each pointer must point to writable storage of the corresponding output type.

Internally, this looks up the output tuple at the specified name, and unpacks its elements into the provided pointers. This allows callers to access values without dealing with std::tuple directly.

◆ get_output_by_index_()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
OutPtr comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_output_by_index_ ( const size_t  idx) const
inlineprivate

Get the output by index.

Parameters
idxThe index of the output.
Returns
Shared pointer to the output tuple.

◆ get_output_by_name_()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
OutPtr comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_output_by_name_ ( const std::string_view  name) const
inlineprivate

Get the output by implementation name.

Parameters
nameThe name of the implementation.
Returns
Shared pointer to the output tuple.

◆ get_reference_output() [1/2]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
const OutPtr comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_reference_output ( ) const
inline

Get the reference output by pointer.

Returns
A shared pointer to the reference output tuple

This function returns a shared pointer to the output of the reference implementation.

◆ get_reference_output() [2/2]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::get_reference_output ( outtype_t< OutputSpecs > *...  outs) const
inline

Copies the reference output into provided pointer to variables.

Parameters
outsOne pointer per output element. Each pointer must point to writable storage of the corresponding output type.

Internally, this looks up the output tuple at index 0 (the reference), and unpacks its elements into the provided pointers. This allows callers to access values without dealing with std::tuple directly.

◆ operator=() [1/2]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
OutputContext & comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::operator= ( const OutputContext< OutputSpecs > &  other)
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<typename... Inputs>
template<OutSpec... OutputSpecs>
OutputContext & comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::operator= ( OutputContext< OutputSpecs > &&  other)
delete

Deleted move assignment operator.

◆ print_header()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::print_header ( ) const
inlineprivate

Print the header for the output table.

This includes the framework title, number of implementations, warmup iterations, and benchmark iterations. It also prints the column headers for the output table. The metric headers are printed dynamically based on the number of output specs.

◆ print_metrics()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::print_metrics ( const PolicyTup errs) const
inlineprivate

Print the metrics for each output specification.

Parameters
errsThe tuple of error policies containing the metrics to print.

◆ register_plugin()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::register_plugin ( const std::shared_ptr< plugin::Plugin< InTup, OutTup > > &  p)
inlineprivate

Register a plugin for the output context.

Parameters
pThe shared pointer to the plugin to register.

◆ run()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::run ( int  argc = 0,
char **  argv = nullptr 
)
inline

Runs the comparison for all added implementations.

Parameters
argcNumber of command line arguments
argvArray of command line arguments

◆ set_reference()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<typename F >
requires std::invocable<F, const std::decay_t<Inputs> &..., outtype_t<OutputSpecs> &...>
Impl & comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::set_reference ( std::string  name,
F &&  f 
)
inline

Set a reference implementation.

Template Parameters
FThe type of the function
Parameters
nameThe name of the implementation
fThe function to execute
Returns
The implementation instance

This function sets a reference implementation to the comparison framework. The reference implementation is always the first one added and is used as the baseline for comparison.

◆ spec_metric_count()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<std::size_t I>
static constexpr std::size_t comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::spec_metric_count ( )
inlinestaticconstexprprivate

Get the implementation details for a specific implementation index.

Template Parameters
IThe implementation index.
Returns
std::size_t The number of metrics for the implementation.

◆ spec_metric_name()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
template<std::size_t I>
static constexpr std::string_view comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::spec_metric_name ( std::size_t  m)
inlinestaticconstexprprivate

Get the name of a specific metric for a specific implementation index.

Template Parameters
IThe implementation index.
Parameters
mThe metric index of the output policy.
Returns
std::string_view The name of the metric.

◆ unpack_output_()

template<typename... Inputs>
template<OutSpec... OutputSpecs>
void comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::unpack_output_ ( const OutTup outtup,
outtype_t< OutputSpecs > *...  outs 
) const
inlineprivate

Unpack the output tuple into the provided output pointers.

Parameters
outtupThe output tuple to unpack.
outsThe output pointers to fill.

Member Data Documentation

◆ impls_

template<typename... Inputs>
template<OutSpec... OutputSpecs>
std::vector<Impl> comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::impls_
private

Vector to hold all implementations.

This vector is used to store all the different implementations of the operation being benchmarked.

◆ inputs_

template<typename... Inputs>
template<OutSpec... OutputSpecs>
InTup comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::inputs_
private

Tuple instance storing all current input arguments.

◆ NUM_OUT

template<typename... Inputs>
template<OutSpec... OutputSpecs>
constexpr size_t comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::NUM_OUT = sizeof...(OutputSpecs)
staticconstexprprivate

Number of output specifications.

This is equal to the number of outputs of a function.

See also
https://en.cppreference.com/w/cpp/language/sizeof....html

◆ outputs_

template<typename... Inputs>
template<OutSpec... OutputSpecs>
std::vector<OutPtr> comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::outputs_
private

Storage for reference and comparison outputs.

Each implementation’s outputs are stored here as shared pointer to tuples. The first implementation is treated as the reference.

◆ plugin_

template<typename... Inputs>
template<OutSpec... OutputSpecs>
std::shared_ptr<plugin::Plugin<InTup, OutTup> > comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::plugin_
private

Shared pointer to the plugin instance.

This pointer is used to store the plugin instance and ensure only one plugin is registered. It is shared across all implementations within the output context.

◆ policies_ref_

template<typename... Inputs>
template<OutSpec... OutputSpecs>
PolicyTup comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::policies_ref_
private

Tuple of policy objects for the reference outputs.

Each policy governs how the corresponding output is validated

◆ PRINT_COL_WIDTH

template<typename... Inputs>
template<OutSpec... OutputSpecs>
constexpr int comppare::InputContext< Inputs >::OutputContext< OutputSpecs >::PRINT_COL_WIDTH = 20
staticconstexprprivate

Set the width of the print columns.


The documentation for this class was generated from the following file: