Template Class FunctionMatcherMixin

Inheritance Relationships

Base Type

Derived Types

Class Documentation

template<typename ReturnType, class PreprocessingImpl = Parameterizable, typename Function = PreprocessFunction<ReturnType>, typename Key = std::vector<std::type_index>, typename KeyHash = TypeIndexVectorHash, typename KeyEqualTo = std::equal_to<std::vector<std::type_index>>>
class sparsebase::utils::FunctionMatcherMixin : public sparsebase::utils::Parameterizable

A mixin that attaches the functionality of matching keys to functions.

This mixin attaches the functionality of matching keys (which, by default, are vectors of type indices) to function pointer objects (by default, their signature is PreprocessFunction).

tparam ReturnType

the return type that will be returned by the preprocessing function implementations

tparam Function

the function signatures that keys will map to. Default is sparsebase::preprocess::PreprocessFunction

tparam Key

the type of the keys used to access function in the inner maps. Default is std::vector<std::type_index>>

tparam KeyHash

the hash function used to has keys.

tparam KeyEqualTo

the function used to evaluate equality of keys

Subclassed by sparsebase::feature::FeaturePreprocessType< IDType * >, sparsebase::feature::FeaturePreprocessType< std::unordered_map< std::type_index, std::any > >, sparsebase::feature::FeaturePreprocessType< FeatureType * >, sparsebase::permute::Permuter< format::FormatOrderOne< ValueType >, format::FormatOrderOne< ValueType > >, sparsebase::permute::Permuter< format::FormatOrderTwo< IDType, NNZType, ValueType >, format::FormatOrderTwo< IDType, NNZType, ValueType > >

Public Functions

inline std::vector<Key> GetAvailableFormats()
bool RegisterFunctionNoOverride(const Key &key_of_function, const Function &func_ptr)

Register a key to a function as long as that key isn’t already registered.

Parameters
  • key_of_function – key used in the map

  • func_ptr – function pointer being registered

Returns

True if the function was registered successfully and false otherwise

void RegisterFunction(const Key &key_of_function, const Function &func_ptr)

Register a key to a function and overrides previous registered function (if any)

Parameters
  • key_of_function – key used in the map

  • func_ptr – function pointer being registered

bool UnregisterFunction(const Key &key_of_function)

Unregister a key from the map if the key was registered to a function.

Parameters

key_of_function – key to unregister

Returns

true if the key was unregistered successfully, and false if it wasn’t already registered to something.

Protected Functions

std::tuple<Function, converter::ConversionSchema> GetFunction(std::vector<format::Format*> packed_formats, Key key, ConversionMap map, std::vector<context::Context*> contexts)

Determines the exact Function and format conversions needed to carry out preprocessing

Return the correct function for the operation and a conversion schema to convert the input formats

Parameters
  • packed_formats – a vector of the input Format* needed for conversion.

  • key – the Key representing the input formats.

  • map – the map between Keys and Functions used to find the needed function.

  • contexts – Contexts available for execution of the preprocessing.

  • key – defines the types of input objects (default is vector of format types)

  • map – the map between keys and functions

Returns

a tuple of a) the Function to use, and b) a converter::ConversionSchemaConditional indicating conversions to be done on input Format objects.

Returns

the function to be executed and the conversion schema the conversions to carry out on inputs

bool CheckIfKeyMatches(ConversionMap map, Key key, std::vector<format::Format*> packed_formats, std::vector<context::Context*> contexts)

Check if a given Key has a function that can be used without any conversions.

Given a conversion map, available execution contexts, input formats, and a key, determines whether the key has a corresponding function and that the available contexts allow that function to be executed.

Parameters
  • map – the map between Keys and Functions used to find the needed function

  • key – the Key representing the input formats.

  • packed_formats – a vector of the input Format* needed for conversion.

  • contexts – Contexts available for execution of the preprocessing

Returns

true if the key has a matching function that can be used with the inputs without any conversions.

template<typename Object, typename ...Objects>
std::vector<Object> PackObjects(Object object, Objects... objects)

A variadic method to pack objects into a vector.

template<typename Object>
std::vector<Object> PackObjects(Object object)

Base case of a variadic method to pack objects into a vector.

template<typename F, typename ...SF>
ReturnType Execute(utils::Parameters *params, std::vector<context::Context*> contexts, bool convert_input, F sf, SF... sfs)

Executes preprocessing on input formats (given variadically)

Determines the function needed to carry out preprocessing on input Format* objects (given variadically), as well as the Format conversions needed on the inputs, executes the preprocessing, and returns the results. Note: this function will delete any intermediary Format objects that were created due to a conversion.

Parameters
  • params – a polymorphic pointer at the object containing hyperparameters needed for preprocessing.

  • contexts – Contexts available for execution of the preprocessing.

  • convert_input – whether or not to convert the input formats if that is needed.

  • sf – a single input Format* (this is templated to allow variadic definition).

  • sfs – a variadic Format* (this is templated to allow variadic definition).

Returns

the output of the preprocessing (of type ReturnType).

template<typename F, typename ...SF>
std::tuple<std::vector<std::vector<format::Format*>>, ReturnType> CachedExecute(utils::Parameters *params, std::vector<context::Context*> contexts, bool convert_input, bool clear_intermediate, F format, SF... formats)

Executes preprocessing on input formats (given variadically)

Determines the function needed to carry out preprocessing on input Format* objects (given variadically), as well as the Format conversions needed on the inputs, executes the preprocessing, and returns:

  • the preprocessing result.

  • pointers at any Format objects that were created due to a conversion. Note: this function will delete any intermediary Format objects that were created due to a conversion.

Parameters
  • PreprocessParams – a polymorphic pointer at the object containing hyperparameters needed for preprocessing.

  • contexts – Contexts available for execution of the preprocessing.

  • convert_input – whether or not to convert the input formats if that is needed

  • sf – a single input Format* (this is templated to allow variadic definition).

  • sfs – a variadic Format* (this is templated to allow variadic definition).

Returns

a tuple containing a) the output of the preprocessing (of type ReturnType), and b) a vector of Format*, where each pointer in the output points at the format that the corresponds Format object from the the input was converted to. If an input Format wasn’t converted, the output pointer will point at nullptr.

Protected Attributes

ConversionMap map_to_function_

Map between Key objects and function pointer Function objects.