|
template<long NDims, typename Rng > |
std::vector< std::vector< long > > | ndim_size (const Rng &rng) |
| Calculates the size of a multidimensional range. More...
|
|
template<typename Rng > |
std::vector< std::vector< long > > | ndim_size (const Rng &rng) |
| Calculates the size of a multidimensional range. More...
|
|
template<long NDims, typename Rng , typename ValT = ndim_type_t<Rng, NDims>> |
Rng & | ndim_resize (Rng &vec, const std::vector< std::vector< long >> &vec_size, ValT val=ValT{}) |
| Resizes a multidimensional range to the given size. More...
|
|
template<long NDims, typename Rng , typename ValT = ndim_type_t<Rng, NDims>> |
Rng & | ndim_pad (Rng &vec, ValT val=ValT{}) |
| Pads a mutlidimensional range to a rectangular size. More...
|
|
template<long NDims, typename Rng > |
std::vector< long > | shape (const Rng &rng) |
| Calculates the shape of a multidimensional range. More...
|
|
template<typename Rng > |
std::vector< long > | shape (const Rng &rng) |
| Calculates the shape of a multidimensional range. More...
|
|
template<long NDims, typename Rng > |
auto | flat_view (Rng &rng) |
| Makes a flat view out of a multidimensional range. More...
|
|
template<long N, typename Rng > |
auto | reshaped_view (Rng &rng, std::vector< long > shape) |
| Makes a view of a multidimensional range with a specific shape. More...
|
|
template<long NDims, typename Rng , typename Gen > |
void | generate (Rng &&rng, Gen &&gen, long gendims=std::numeric_limits< long >::max()) |
| Fill a multidimensional range with values generated by a nullary function. More...
|
|
template<long NDims, typename Rng , typename Prng = std::mt19937&, typename Dist = std::uniform_real_distribution<double>> |
void | random_fill (Rng &&rng, Dist &&dist=Dist{0, 1}, Prng &&prng=utility::random_generator, long gendims=std::numeric_limits< long >::max()) |
| Fill a multidimensional range with random values. More...
|
|
template<typename Tuple > |
bool | same_size (Tuple &&rngs) |
| Utility function which checks that all the ranges in a tuple have the same size. More...
|
|
template<long NDims, typename Rng , typename Gen >
void generate |
( |
Rng && |
rng, |
|
|
Gen && |
gen, |
|
|
long |
gendims = std::numeric_limits<long>::max() |
|
) |
| |
Fill a multidimensional range with values generated by a nullary function.
If the vector is multidimensional, the generator will be used only up to the given dimension and the rest of the dimensions will be constant.
Example:
struct gen {
int i = 0;
int operator()() { return i++; };
};
std::vector<std::vector<std::vector<int>>> data = {{{-1, -1, -1}, {-1}}, {{-1}, {-1, -1}}};
data = {{{-1, -1, -1}, {-1}}, {{}, {}}, {{-1}, {-1, -1}}};
- Parameters
-
rng | The range to be filled. |
gen | The generator to be used. |
gendims | The generator will be used only for this number of dimension. The rest of the dimensions will be filled by the last generated value. Use std::numeric_limits<long>::max() to fill all the dimensions using the generator. |
- Template Parameters
-
NDims | The number of dimensions to which will the fill routine recurse. Elements after this dimension are considered to be units (even if they are ranges). If omitted, it defaults to ndims<Rng> - ndims<gen()>. |
Definition at line 628 of file ndim.hpp.
template<long NDims, typename Rng , typename ValT = ndim_type_t<Rng, NDims>>
Rng& ndim_pad |
( |
Rng & |
vec, |
|
|
ValT |
val = ValT{} |
|
) |
| |
Pads a mutlidimensional range to a rectangular size.
The range has to support .resize()
method up to the given dimension.
Example:
std::vector<std::vector<int>> v1 = {{1, 2}, {3, 4, 5}, {}};
std::vector<std::list<std::vector<int>>> v2 = {{{1}, {2, 3}}, {{4, 5, 6}}};
ndim_pad<2>(vec, {-1, -2, -3, -4});
- Parameters
-
vec | The range to be padded. |
val | The value to pad with. |
- Template Parameters
-
NDims | The number of dimensions to be considered. If omitted, it defaults to ndims<Rng> - ndims<ValT>. |
- Returns
- The reference to the given vector after padding.
Definition at line 309 of file ndim.hpp.
template<long NDims, typename Rng , typename ValT = ndim_type_t<Rng, NDims>>
Rng& ndim_resize |
( |
Rng & |
vec, |
|
|
const std::vector< std::vector< long >> & |
vec_size, |
|
|
ValT |
val = ValT{} |
|
) |
| |
Resizes a multidimensional range to the given size.
i-th element of the given size vector are the sizes of the ranges in the i-th dimension. See ndim_size. The range has to support .resize()
method up to the given dimension.
Example:
std::vector<std::vector<int>> vec;
- Parameters
-
vec | The range to be resized. |
vec_size | The requested size created by ndim_size. |
val | The value to pad with. |
- Template Parameters
-
NDims | The number of dimensions to be considered. If omitted, it defaults to ndims<Rng> - ndims<ValT>. |
- Returns
- The reference to the given vector after resizing.
Definition at line 262 of file ndim.hpp.
template<long NDims, typename Rng >
std::vector<std::vector<long> > ndim_size |
( |
const Rng & |
rng | ) |
|
Calculates the size of a multidimensional range.
i-th element of the resulting vector are the sizes of the ranges in the i-th dimension.
Example:
std::vector<std::list<int>> rng{{1, 2, 3}, {1}, {5, 6}, {7}};
std::vector<std::vector<long>> rng_size = ndim_size<2>(rng);
rng_size = ndim_size<1>(rng);
- Parameters
-
rng | The multidimensional range whose size shall be calculated. |
- Template Parameters
-
NDims | The number of dimensions that should be considered. |
- Returns
- The sizes of the given range.
Definition at line 191 of file ndim.hpp.
template<long NDims, typename Rng , typename Prng = std::mt19937&, typename Dist = std::uniform_real_distribution<double>>
void random_fill |
( |
Rng && |
rng, |
|
|
Dist && |
dist = Dist{0, 1} , |
|
|
Prng && |
prng = utility::random_generator , |
|
|
long |
gendims = std::numeric_limits<long>::max() |
|
) |
| |
Fill a multidimensional range with random values.
If the range is multidimensional, the random generator will be used only up to the given dimension and the rest of the dimensions will be constant.
Note: This function internally uses utility::generate().
Example:
std::mt19937 gen = ...;
std::uniform_int_distribution dist = ...;
std::vector<std::vector<std::vector<int>>> data = {{{0, 0, 0}, {0}}, {{0}, {0, 0}}};
- Parameters
-
rng | The range to be filled. |
dist | The distribution to be used. |
prng | The random generator to be used. |
gendims | The random generator will be used only for this number of dimension. The rest of the dimensions will be filled by the last generated value. Use std::numeric_limits<long>::max() to randomly fill all the dimensions. |
- Template Parameters
-
NDims | The number of dimensions to which will the fill routine recurse. Elements after this dimension are considered to be units (even if they are ranges). If omitted, it defaults to ndims<Rng> - ndims<dist(prng)>. |
Definition at line 682 of file ndim.hpp.