Class ReorderBase
Defined in File reorder_base.h
Class Documentation
-
class sparsebase::bases::ReorderBase
A class containing the interface for reordering and permuting data.
The class contains all the functionalities needed for reordering. That includes a function generate reordering permutations from data, functions to permute data using a permutation vector, and a function to inverse the permutation of data. In the upcoming release, ReorderBase will include functions to extract feeatures from permutation vectors and permuted data.
Public Static Functions
-
template<template<typename, typename, typename> typename Reordering, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline AutoIDType *Reorder(typename Reordering<AutoIDType, AutoNNZType, AutoValueType>::ParamsType params, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_input) Generates a permutation array from a FormatOrderTwo object using the Reordering class
Reordering
.- Template Parameters
Reordering – a reordering class defining a reordering algorithm. For a full list of available reordering algorithms, please check here.
- Parameters
params – a struct containing the parameters specific for the reordering algorithm
Reordering
. Please check the documentation of each reordering for the specifications of its parameters.format – FormatOrderTwo object to be used to generate permutation array.
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
- Returns
the permutation array.
-
template<template<typename, typename, typename> typename Reordering, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline std::pair<std::vector<format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType>*>, AutoIDType*> ReorderCached(typename Reordering<AutoIDType, AutoNNZType, AutoValueType>::ParamsType params, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts) Generates a permutation array from a FormatOrderTwo object using the Reordering class
Reordering
with cached output.- Template Parameters
Reordering – a reordering class defining a reordering algorithm. For a full list of available reordering algorithms, please check: xxx
- Parameters
params – a struct containing the parameters specific for the reordering algorithm
Reordering
. Please check the documentation of each reordering for the specifications of its parameters.format – FormatOrderTwo object to be used to generate permutation array.
contexts – vector of contexts that can be used for permutation.
- Returns
An std::pair with the second element being the permutation array, and the first being a vector of all the formats generated by converting the input (if such conversions were needed to execute the permutation).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType> *Permute2D(AutoIDType *ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_input, bool convert_output = false) Permute a two-dimensional format row- and column-wise using a single permutation array for both axes.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
order – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
The permuted format. By default, the function returns a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline std::pair<std::vector<format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType>*>, ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType>*> Permute2DCached(AutoIDType *ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_output = false) Permute a two-dimensional format row- and column-wise using a single permutation array for both axes with cached output.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
ordering – Permutation array to use when permuting rows and columns.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
An std::pair with the second element being the permuted format, and the first being a vector of all the formats generated by converting the input (if such conversions were needed to execute the permutation). By default, the permuted object is returned as a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline std::pair<std::vector<format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType>*>, ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType>*> Permute2DRowColumnWiseCached(AutoIDType *row_ordering, AutoIDType *col_ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_output = false) Permute a two-dimensional format row- and column-wise using a permutation array for each axis with cached output.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
row_ordering – Permutation array to use when permuting rows.
col_ordering – Permutation array to use when permuting col.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
An std::pair with the second element being the permuted format, and the first being a vector of all the formats generated by converting the input (if such conversions were needed to execute the permutation). By default, the permuted object is returned as a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType> *Permute2DRowColumnWise(AutoIDType *row_ordering, AutoIDType *col_ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_input, bool convert_output = false) Permute a two-dimensional format row- and column-wise using a permutation array for each axis.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
order – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
The permuted format. By default, the function returns a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType> *Permute2DRowWise(AutoIDType *ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_input, bool convert_output = false) Permute a two-dimensional format row-wise using a permutation array.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
order – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
The permuted format. By default, the function returns a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename RelativeReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline std::pair<std::vector<format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType>*>, RelativeReturnFormatType<AutoIDType, AutoNNZType, AutoValueType>*> Permute2DRowWiseCached(AutoIDType *ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_output = false) Permute a two-dimensional format row-wise using a permutation array with cached output.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
ordering – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
An std::pair with the second element being the permuted format, and the first being a vector of all the formats generated by converting the input (if such conversions were needed to execute the permutation). By default, the permuted object is returned as a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType> *Permute2DColWise(AutoIDType *ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_input, bool convert_output = false) Permute a two-dimensional format column-wise using a permutation array.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
order – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
The permuted format. By default, the function returns a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename, typename, typename> typename ReturnFormatType = format::FormatOrderTwo, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline std::pair<std::vector<format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType>*>, ReturnFormatType<AutoIDType, AutoNNZType, AutoValueType>*> Permute2DColWiseCached(AutoIDType *ordering, format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, std::vector<context::Context*> contexts, bool convert_output = false) Permute a two-dimensional format column-wise using a permutation array with cached output.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderTwo. Defines the return pointer type. Default is FormatOrderTwo.
- Parameters
ordering – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
An std::pair with the second element being the permuted format, and the first being a vector of all the formats generated by converting the input (if such conversions were needed to execute the permutation). By default, the permuted object is returned as a pointer at a generic FormatOrderTwo object. However, if the user passes a concrete FormatOrderTwo class as the templated parameter
ReturnFormatType
, e.g. format::CSR, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename> typename ReturnFormatType = format::FormatOrderOne, typename AutoIDType, typename AutoValueType>
static inline ReturnFormatType<AutoValueType> *Permute1D(AutoIDType *ordering, format::FormatOrderOne<AutoValueType> *format, std::vector<context::Context*> context, bool convert_inputs, bool convert_output = false) Permute a one-dimensional format using a permutation array.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderOne. Defines the return pointer type. Default is FormatOrderOne.
- Parameters
order – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
The permuted format. By default, the function returns a pointer at a generic FormatOrderOne object. However, if the user passes a concrete FormatOrderOne class as the templated parameter
ReturnFormatType
, e.g. format::Array, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<template<typename> typename ReturnFormatType = format::FormatOrderOne, typename AutoIDType, typename AutoValueType>
static inline std::pair<std::vector<format::FormatOrderOne<AutoValueType>*>, ReturnFormatType<AutoValueType>*> Permute1DCached(AutoIDType *ordering, format::FormatOrderOne<AutoValueType> *format, std::vector<context::Context*> context, bool convert_output = false) Permute a one-dimensional format using a permutation array with cached output.
- Template Parameters
ReturnFormatType – a child class of type FormatOrderOne. Defines the return pointer type. Default is FormatOrderOne.
- Parameters
order – Permutation array.
format – object to be permuted.
contexts – vector of contexts that can be used for permutation.
convert_output – if true, the returned object will be converted to
ReturnFormatType
. Otherwise, the returned object will be cast toReturnFormatType
, and if the cast fails, an exception of typesparsebase::utils::TypeException
.
- Returns
An std::pair with the second element being the permuted format, and the first being a vector of all the formats generated by converting the input (if such conversions were needed to execute the permutation). By default, the permuted object is returned as a pointer at a generic FormatOrderOne object. However, if the user passes a FormatOrderOne class as the templated parameter
ReturnFormatType
, e.g. format::Array, then ifconvert_output
is true, the returned format will be converted to that type. If not, the returned object will only be cast to that type (if casting fails, an exception of type utils::TypeException will be thrown).
-
template<typename AutoIDType, typename AutoNumType>
static inline AutoIDType *InversePermutation(AutoIDType *perm, AutoNumType length) Takes a permutation array and its length and inverses it.
Takes a permutation array and its length and inverses it. If a format
A
was permuted withperm
into objectB
, then permutingB
with the inverse permutation returns its order toA
.- Parameters
perm – a permutation array of length
length
length – the length of the permutation array
- Returns
a permutation array of length
length
that is the inverse ofperm
, i.e. can be used to reverse a permutation done byperm
.
-
template<typename FloatType, typename AutoIDType, typename AutoNNZType, typename AutoValueType>
static inline sparsebase::format::Array<FloatType> *Heatmap(format::FormatOrderTwo<AutoIDType, AutoNNZType, AutoValueType> *format, format::FormatOrderOne<AutoIDType> *permutation_r, format::FormatOrderOne<AutoIDType> *permutation_c, int num_parts, std::vector<context::Context*> contexts, bool convert_input) Calculates density of non-zeros of a 2D format on a num_parts * num_parts grid
Splits the input 2D matrix into a grid of size num_parts * num_parts containing an equal number of rows and columns, and calculates the density of non-zeros in each cell in the grid relative to the total number of non-zeros in the matrix, given that the matrix was reordered according to a permutation matrix. Returns the densities as a dense array (FormatOrderOne) of size num_parts * num_parts where the density at cell [i][j] in the 2D grid is located at index [i*num_parts+j] in the grid. The density values sum up to 1.
- Template Parameters
FloatType – type used to represent the densities of non-zeros.
- Parameters
format – the 2D matrix to calculate densities for.
permutation – the permutation array containing the reordering of rows and columns.
num_parts – number of parts to split rows/columns over
contexts – vector of contexts that can be used for permutation.
convert_input – whether or not to convert the input format if that is needed.
- Returns
a format::Array containing the densities of the cells in the num_parts * num_parts 2D grid.
-
template<template<typename, typename, typename> typename Reordering, typename AutoIDType, typename AutoNNZType, typename AutoValueType>