Class AsyCost

Nested Relationships

Nested Types

Class Documentation

class AsyCost

Represents a symbolic asymptotic cost as a polynomial in the sizes of index spaces. A cost is a sum of terms, each of which is a rational multiplier times a product of space sizes raised to non-negative integer powers. Spaces are identified by IndexSpace; AsyCost orders and prints them using IndexSpace’s own ordering and base_key(), and never consults an IndexSpaceRegistry.

Examples (with I, A denoting two index spaces):

  • AsyCost({{I, 2}, {A, 4}}) represents $I^2 A^4$.

  • AsyCost({{I, 2}, {A, 4}}, rational{1, 2}) halves the numeric value above when extents are substituted.

Public Types

using ExponentMap = container::map<IndexSpace, std::size_t>
using ExtentMap = container::map<IndexSpace, std::size_t>

Public Functions

AsyCost()

Default construct to zero cost.

explicit AsyCost(ExponentMap exponents, rational prefactor = 1)
Parameters:
  • exponents – Map from index space to its exponent in this term. Zero exponents may be supplied; they are dropped.

  • prefactor – Rational multiplier; defaults to 1.

AsyCost(AsyCost const&) = default
AsyCost(AsyCost&&) = default
AsyCost &operator=(AsyCost const&) = default
AsyCost &operator=(AsyCost&&) = default
double ops(ExtentMap const &extents = {}) const

Substitute each space in this cost by an extent and evaluate.

Parameters:

extents – Map from index space to extent (size). A space appearing in this cost but absent from extents falls back to its IndexSpace::approximate_size(). Defaults to empty, in which case every space uses its approximate_size().

Returns:

Numerical value of the cost.

std::wstring to_latex() const
Returns:

A LaTeX rendering of the whole cost: its terms joined by +, most expensive first. The zero cost renders as 0.

std::string text() const
Returns:

A plain-text rendering of the whole cost: its terms joined by +, most expensive first. The zero cost renders as 0.

AsyCost &operator+=(AsyCost const&)
AsyCost &operator-=(AsyCost const&)

Public Static Functions

static AsyCost const &max()
Returns:

The infinitely scaling cost.

static AsyCost const &zero()
Returns:

The zero cost.

Friends

friend AsyCost operator+(AsyCost const &lhs, AsyCost const &rhs)
friend AsyCost operator*(AsyCost const &lhs, rational scale)
friend AsyCost operator*(rational scale, AsyCost const &lhs)
friend bool operator<(AsyCost const &lhs, AsyCost const &rhs)
friend bool operator==(AsyCost const &lhs, AsyCost const &rhs)
friend bool operator<=(AsyCost const &lhs, AsyCost const &rhs)
friend bool operator>=(AsyCost const &lhs, AsyCost const &rhs)