Utils API

Helper utilities for common operations. The MPI helper is documented separately in Communication API.

Printing

The print functions can print any combination of arguments of different types, including entire vectors. print outputs from the root processor only, so it is the usual choice for program output, while printAll and printAllPlain output from every processor, prefixed with the processor rank or not.

namespace minim

Vector operations

Element-wise arithmetic between vectors and scalars is provided by operator overloads, e.g. a + b, a * 2 and a += b all work as expected for vectors.

The vec namespace contains further vector operations in the style of NumPy, such as vec::dotProduct, vec::sum, vec::norm and vec::slice.

Functions

template<typename T, typename U>
auto operator+(T a, const vector<U> &b)

Element-wise addition of a scalar and a vector.

template<typename T, typename U>
auto operator+(const vector<T> &a, U b)

Element-wise addition of a vector and a scalar.

template<typename T, typename U>
auto operator+(const vector<T> &a, const vector<U> &b)

Element-wise addition of two vectors.

template<typename T, typename U>
auto &operator+=(vector<T> &a, U b)

Add a scalar to each element of the vector.

template<typename T, typename U>
auto &operator+=(vector<T> &a, const vector<U> &b)

Add the elements of another vector to this one.

template<typename T>
auto operator-(const vector<T> &a)

Element-wise negation of a vector.

template<typename T, typename U>
auto operator-(T a, const vector<U> &b)

Element-wise subtraction of a vector from a scalar.

template<typename T, typename U>
auto operator-(const vector<T> &a, U b)

Element-wise subtraction of a scalar from a vector.

template<typename T, typename U>
auto operator-(const vector<T> &a, const vector<U> &b)

Element-wise subtraction of two vectors.

template<typename T, typename U>
auto &operator-=(vector<T> &a, U b)

Subtract a scalar from each element of the vector.

template<typename T, typename U>
auto &operator-=(vector<T> &a, const vector<U> &b)

Subtract the elements of another vector from this one.

template<typename T, typename U>
auto operator*(T a, const vector<U> &b)

Element-wise multiplication of a scalar and a vector.

template<typename T, typename U>
auto operator*(const vector<T> &a, U b)

Element-wise multiplication of a vector and a scalar.

template<typename T, typename U>
auto operator*(const vector<T> &a, const vector<U> &b)

Element-wise multiplication of two vectors.

template<typename T, typename U>
auto &operator*=(vector<T> &a, U b)

Multiply each element of the vector by a scalar.

template<typename T, typename U>
auto &operator*=(vector<T> &a, const vector<U> &b)

Multiply the elements of this vector by those of another.

template<typename T, typename U>
auto operator/(T a, const vector<U> &b)

Element-wise division of a scalar by a vector.

template<typename T, typename U>
auto operator/(const vector<T> &a, U b)

Element-wise division of a vector by a scalar.

template<typename T, typename U>
auto operator/(const vector<T> &a, const vector<U> &b)

Element-wise division of two vectors.

template<typename T, typename U>
auto &operator/=(vector<T> &a, U b)

Divide each element of the vector by a scalar.

template<typename T, typename U>
auto &operator/=(vector<T> &a, const vector<U> &b)

Divide the elements of this vector by those of another.

namespace vec

Vector operations and helpers, in the style of NumPy.

Functions

template<typename T>
bool any(const vector<T> &a)

Whether any element is truthy.

template<typename T>
bool all(const vector<T> &a)

Whether all elements are truthy.

template<typename T>
bool isIn(const vector<T> &vec, T value)

Whether the vector contains the given value.

template<typename T>
void insert_unique(vector<T> &vec, T value)

Insert a value into a vector if not already present.

Ranges

The range classes provide iterators over a multi-dimensional grid, optionally with a halo. RangeX yields the grid indices at each position, while RangeI yields the flat index, e.g.:

for (auto x : RangeX({nx, ny}, halo)) {
  // x is the vector of grid indices, including the halo
}

RangeX

class RangeX

A range over a multi-dimensional grid, yielding the grid indices.

Public Functions

inline RangeX(std::vector<int> xSize)

Construct a range over a grid of the given size.

inline RangeX(std::vector<int> xSize, int halo)

Construct a range over a grid with a halo of the given width.

inline RangeX(std::vector<int> xSize, std::vector<int> xHalo)

Construct a range over a grid with the given halo widths.

RangeI

class RangeI

A range over a multi-dimensional grid, yielding the flat index.

Public Functions

inline RangeI(std::vector<int> xSize)

Construct a range over a grid of the given size.

inline RangeI(std::vector<int> xSize, int halo)

Construct a range over a grid with a halo of the given width.

inline RangeI(std::vector<int> xSize, std::vector<int> xHalo)

Construct a range over a grid with the given halo widths.