Class Converter
Defined in File converter.h
Inheritance Relationships
Derived Types
public sparsebase::converter::ConverterImpl< ConverterOrderTwo< IDType, NNZType, ValueType > >
(Template Class ConverterImpl)public sparsebase::converter::ConverterImpl< ConverterOrderOne< ValueType > >
(Template Class ConverterImpl)public sparsebase::converter::ConverterImpl< ConverterType >
(Template Class ConverterImpl)
Class Documentation
-
class sparsebase::converter::Converter
Base class for all the converter classes.
Subclassed by sparsebase::converter::ConverterImpl< ConverterOrderTwo< IDType, NNZType, ValueType > >, sparsebase::converter::ConverterImpl< ConverterOrderOne< ValueType > >, sparsebase::converter::ConverterImpl< ConverterType >
Public Functions
-
void RegisterConversionFunction(std::type_index from_type, std::type_index to_type, ConversionFunction conv_func, ConversionCondition edge_condition, bool is_move_conversion = false)
Register a conversion function from one type to another.
Registers a conversion function from one type to another. The conversion will be conditional on
edge_condition
which is a function that returns a boolean based on the source and destination contexts of the conversion.- Parameters
from_type – std::type_index of the source format
to_type – std::type_index of the destination format
conv_func – a conversion function taking an input Format* and a destination context.
edge_condition – an std::function containing a boolean function with two Context* parameters for the source and destination contexts. Returns true if the conversion should happen based on context inputs.
is_move_conversion – whether this conversion is a move conversion.
-
format::Format *Convert(format::Format *source, std::type_index to_type, context::Context *to_context, bool is_move_conversion = false) const
Converts a source format to a destination format.
Converts the source to to_type by automatically selecting and using a registered conversion function
- Parameters
source – a pointer to the source Format instance
to_type – a type_index for the type to convert to (for example: std::typeid(COO<…>) can be used)
to_context – context used for the conversion (see the context namespace for more information)
is_move_conversion – if true the underlying arrays will be moved instead of being copied
- Returns
a pointer to the converted Format instance
-
std::vector<format::Format*> ConvertCached(format::Format *source, std::type_index to_type, context::Context *to_context, bool is_move_conversion = false) const
Converts a source format to a destination format with cached output.
Converts the source to to_type and returns all the formats created during the conversion process.
- Parameters
source – a pointer to the source Format instance
to_type – a type_index for the type to convert to (for example: std::typeid(COO<…>) can be used)
to_context – context used for the conversion (see the context namespace for more information)
is_move_conversion – if true the underlying arrays will be moved instead of being copied
- Returns
a vector of formats, with the last (back) format being the target format, and the ones before it being intermediate ones.
-
format::Format *Convert(format::Format *source, std::type_index to_type, std::vector<context::Context*> to_contexts, bool is_move_conversion = false) const
Converts a source format to a destination format.
Converts the source to to_type by automatically selecting and using a registered conversion function
- Parameters
source – a pointer to the source Format instance
to_type – a type_index for the type to convert to (for example: std::typeid(COO<…>) can be used)
to_contexts – contexts that may be used for the conversion (see the context namespace for more information)
is_move_conversion – if true the underlying arrays will be moved instead of being copied
- Returns
a pointer to the converted Format instance
-
std::vector<format::Format*> ConvertCached(format::Format *source, std::type_index to_type, std::vector<context::Context*> to_context, bool is_move_conversion = false) const
Converts the source to to_type and returns all the formats created during the conversion process.
- Parameters
source – a pointer to the source Format instance
to_type – a type_index for the type to convert to (for example: std::typeid(COO<…>) can be used)
to_contexts – contexts that may be used for the conversion (see the context namespace for more information)
is_move_conversion – if true the underlying arrays will be moved instead of being copied
- Returns
a vector of formats, with the last (back) format being the target format, and the ones before it being intermediate ones.
-
template<typename FormatType>
inline FormatType *Convert(format::Format *source, context::Context *to_context, bool is_move_conversion = false) const Converts a format to another format and returns a cast pointer to the destination format.
An overload of the Convert function where the to_type parameter is provided as a template Usage: Convert<COO<…>>(…) Note that sometimes it might be necessary to use the “template” keyword before the function name in the call.
- Template Parameters
FormatType – the destination format.
- Parameters
source – input format object.
to_context – context to be used for conversion
is_move_conversion – whether this is a move conversion
- Returns
a pointer at
FormatType
object.
-
template<typename FormatType>
inline FormatType *Convert(format::Format *source, std::vector<context::Context*> to_contexts, bool is_move_conversion = false) const Converts a format to another format and returns a cast pointer to the destination format.
An overload of the Convert function where the to_type parameter is provided as a template Usage: Convert<COO<…>>(…) Note that sometimes it might be necessary to use the “template” keyword before the function name in the call.
- Template Parameters
FormatType – the destination format.
- Parameters
source – input format object.
to_contexts – contexts that may be used for the conversion (see the context namespace for more information)
is_move_conversion – whether this is a move conversion
- Returns
a pointer at
FormatType
object.
-
ConversionChain GetConversionChain(std::type_index from_type, context::Context *from_context, std::type_index to_type, const std::vector<context::Context*> &to_contexts, bool is_move_conversion = false) const
Returns a conversion chain needed to convert between two formats.
Takes a single (format, context) input and returns the chain of conversions needed to convert the input to the type
to_type
. The chain is optional, meaning it could be empty if no conversions exist.- Parameters
from_type – type of source format
from_context – context of source format
to_type – format type to convert to
to_contexts – contexts available for conversion
is_move_conversion – whether to find move conversions or normal conversions
- Returns
an optional chain of conversion. If nothing is returned, then no conversions are available. Otherwise, will return a tuple with its second element being the total conversion cost, and its first element a vector of (ConversionFunction, Context) pairs, where the input must be passed through this chain starting from its front to its back to become
to_type
.
-
bool CanConvert(std::type_index from_type, context::Context *from_context, std::type_index to_type, context::Context *to_context, bool is_move_conversion = false) const
Returns true if a conversion from (from_type, from_context) to (to_type, to_context) is possible
- Parameters
from_type – source format type_index
from_context – source context
to_type – destination format type_index
to_context – destination context
is_move_conversion – whether it is a move conversion
- Returns
a boolean indicating whether a conversion is possible
-
bool CanConvert(std::type_index from_type, context::Context *from_context, std::type_index to_type, const std::vector<context::Context*> &to_contexts, bool is_move_conversion = false)
Returns true if a conversion from (from_type, from_context) to (to_type, to_context) is possible
- Parameters
from_type – source format type_index
from_context – source context
to_type – destination format type_index
to_contexts – contexts available for conversion
is_move_conversion – whether it is a move conversion
- Returns
a boolean indicating whether a conversion is possible
-
void ClearConversionFunctions(std::type_index from_type, std::type_index to_type, bool move_conversion = false)
Clears all conversion functions from one format to another.
Removes conversion functions that convert from
from_type
toto_type
from the conversion map- Parameters
from_type – type_index of the original format type
to_type – type_index of the destination format type
move_conversion – whether the conversions to be removed are move conversions or not
-
void ClearConversionFunctions(bool move_conversion = false)
Removes all conversion functions from current converter.
Removes all conversion functions from the current converter in all directions.
Removes all conversion functions from the current converter
- Parameters
move_conversion – whether the conversions to be removed are move conversions or not
-
virtual std::type_index get_converter_type() const = 0
-
virtual void Reset() = 0
-
virtual ~Converter()
Public Static Functions
-
static std::vector<std::vector<format::Format*>> ApplyConversionSchema(const ConversionSchema &cs, const std::vector<format::Format*> &packed_sfs, bool clear_intermediate)
Applies a conversion schema to convert one format to another.
Takes a conversion schema to convert all the formats in
packed_sfs
, carries out the conversions, and returns a chain of converted formats for each format. Chain contains original format, all intermediate formats, and last format in the chain.- Parameters
cs – ConversionSchema containing the an optional chain of conversion functions for every format in
packed_sfs
packed_sfs – formats to convert
clear_intermediate – delete intermediate formats between the starting and destination one.
- Returns
a vector of size
packed_sfs.size()
. Each element is a vector of size >= 1 containing the starting format in the conversion chain, every intermediate format, and the final format. The first format is the original and the last is the output format in each chain.
-
static std::vector<format::Format*> ApplyConversionChain(const ConversionChain &chain, format::Format*, bool clear_intermediate)
Takes a conversion chain and a format and applies that chain on the format to produce some output format.
- Parameters
chain – a conversion chain containing conversion functions and contexts to use for each function.
clear_intermediate – delete intermediate formats between the starting and destination one.
- Returns
a vector of format with the first being the original format, the last being the target format, and the rest being intermediate formats. If a conversion is empty or false, only returns the original format.
-
void RegisterConversionFunction(std::type_index from_type, std::type_index to_type, ConversionFunction conv_func, ConversionCondition edge_condition, bool is_move_conversion = false)