rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rexlib::type_rule_interpreter Class Reference

Interpreter of a typing rule lowered to a descriptor. More...

#include <rexlib/core/operation/type_rule/type_rule_interpreter.hpp>

Public Member Functions

 type_rule_interpreter (const type_rule_descriptor &rule) noexcept
 Construct an interpreter of a rule.
 
void check_instance (const operation_descriptor &descriptor, span< const numerical_type > operation_data_types) const
 Check the data types an operation instance supplies.
 
void deduce (const operation_descriptor &descriptor, span< const numerical_type > operation_data_types, span< operand_specification > canonical_outputs, span< const operand_specification > inputs) const
 Compute the data types of the outputs the inputs call for.
 
void accept (const operation_descriptor &descriptor, span< const numerical_type > operation_data_types, span< const operand_specification > user_outputs, span< const operand_specification > inputs) const
 Decide whether outputs supplied in advance have admissible data types.
 
type_rule_resolution resolve (span< const numerical_type > operation_data_types, span< const numerical_type > output_types, span< const numerical_type > input_types) const noexcept
 Resolve the rule against concrete operand data types.
 
REXLIB_NORETURN void throw_error (const operation_descriptor &descriptor, const type_rule_resolution &resolution) const
 Turn a failed resolution into an exception.
 

Detailed Description

Interpreter of a typing rule lowered to a descriptor.

Deduces the data types of the outputs of an operation from the data types of its inputs, and decides whether outputs supplied in advance have admissible data types. Shapes are left alone.

Each call takes the data types the operation instance supplies, in the order the pivots reading them are declared.

deduce resolves the rule's pivots from the input types, checks every input against its slot and evaluates the output slots. resolve binds the rule's free pivots from the outputs as well and checks every operand, which admits the looser outputs a converting operation needs. It reports a rejection as a type_rule_resolution, and throw_error turns that into an exception. accept does both.

See also
operand_type_rule

Constructor & Destructor Documentation

◆ type_rule_interpreter()

rexlib::type_rule_interpreter::type_rule_interpreter ( const type_rule_descriptor &  rule)
explicitnoexcept

Construct an interpreter of a rule.

Parameters
ruleThe rule. It must outlive the interpreter, which type_rule_descriptor_of guarantees by holding it in static storage.

Member Function Documentation

◆ accept()

void rexlib::type_rule_interpreter::accept ( const operation_descriptor &  descriptor,
span< const numerical_type >  operation_data_types,
span< const operand_specification >  user_outputs,
span< const operand_specification >  inputs 
) const

Decide whether outputs supplied in advance have admissible data types.

Parameters
descriptorDescription of the operation, used to name the operation and its operands when reporting a rejection.
operation_data_typesThe data types the operation supplies.
user_outputsThe outputs supplied in advance, one per output slot.
inputsThe inputs, one per input slot.
Exceptions
std::invalid_argumentWhen the inputs or an output are not admissible.

◆ check_instance()

void rexlib::type_rule_interpreter::check_instance ( const operation_descriptor &  descriptor,
span< const numerical_type >  operation_data_types 
) const

Check the data types an operation instance supplies.

Parameters
descriptorDescription of the operation, used to name it when reporting a rejection.
operation_data_typesThe data types the operation supplies.
Exceptions
std::invalid_argumentWhen there are not as many as the rule reads, or one lies outside the domain of its pivot.

◆ deduce()

void rexlib::type_rule_interpreter::deduce ( const operation_descriptor &  descriptor,
span< const numerical_type >  operation_data_types,
span< operand_specification >  canonical_outputs,
span< const operand_specification >  inputs 
) const

Compute the data types of the outputs the inputs call for.

A data type the inputs do not determine is left as numerical_type::unknown.

Parameters
descriptorDescription of the operation, used to name the operation and its operands when reporting a rejection.
operation_data_typesThe data types the operation supplies.
canonical_outputsThe outputs, one per output slot. Only their data types are set.
inputsThe inputs, one per input slot.
Exceptions
std::invalid_argumentWhen the inputs are not admissible.

◆ resolve()

type_rule_resolution rexlib::type_rule_interpreter::resolve ( span< const numerical_type >  operation_data_types,
span< const numerical_type >  output_types,
span< const numerical_type >  input_types 
) const
noexcept

Resolve the rule against concrete operand data types.

Parameters
operation_data_typesThe data types the operation supplies.
output_typesThe data type of every output.
input_typesThe data type of every input.
Returns
type_rule_resolution The resolved pivots, or the reason the operands are not admissible.

◆ throw_error()

REXLIB_NORETURN void rexlib::type_rule_interpreter::throw_error ( const operation_descriptor &  descriptor,
const type_rule_resolution &  resolution 
) const

Turn a failed resolution into an exception.

Parameters
descriptorDescription of the operation, used to name the operation and its operands.
resolutionA failed resolution of this rule.
Exceptions
std::invalid_argumentAlways.

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