utils

Utilities used by recursivenodes.

recursivenodes.utils.coord_map(x, origin, image)[source]

Map coordinates from one reference d-simplex to another.

Parameters
  • x (ndarray) – 2D array of coordinates of shape (num_points, coordinate_dimension)

  • origin (str) – Current domain of x, one of ['unit', 'biunit', 'equilateral', 'barycentric'].

  • image (str) – Desired domain of mapped coordinates.

Returns

2D array of coordinates in the new domain, shape (num_points, new_coordinated_dimension).

Return type

ndarray

See also

The domain optional argument” for formal definitions of the domains.

recursivenodes.utils.multiindex_equal(d, k)[source]

A generator for \(d\)-tuple multi-indices whose sum is \(k\).

Parameters
  • d (int) – The length of the tuples

  • k (int) – The sum of the entries in the tuples

Yields

tuple – tuples of length d whose entries sum to k, in lexicographic order.

Example

>>> for i in multiindex_equal(3, 2): print(i)
(0, 0, 2)
(0, 1, 1)
(0, 2, 0)
(1, 0, 1)
(1, 1, 0)
(2, 0, 0)
recursivenodes.utils.multiindex_to_lex(alpha)[source]

Get the lexicographic index of \(\boldsymbol{\alpha}\) among all multiindices with the same length and sum.

Parameters

alpha (tuple) – A tuple of non-negative indices

Returns

The index of \(\boldsymbol{\alpha}\) in a lexicographically sorted list of multiindices with the same length and sum.

Return type

int

Example

>>> multiindex_to_lex((1, 0, 1))
3
recursivenodes.utils.multiindex_up_to(d, k)[source]

A generator for \(d\)-tuple multi-indices whose sum is at most \(k\).

Parameters
  • d (int) – The length of the tuples

  • k (int) – The maximum sum of the entries in the tuples

Yields

tuple – tuples of length d whose entries sum to k, in lexicographic order.

Example

>>> for i in multiindex_up_to(3, 2): print(i)
(0, 0, 0)
(0, 0, 1)
(0, 0, 2)
(0, 1, 0)
(0, 1, 1)
(0, 2, 0)
(1, 0, 0)
(1, 0, 1)
(1, 1, 0)
(2, 0, 0)
recursivenodes.utils.npolys(d, k)[source]

The number of polynomials up to a degree \(k\) in \(d\) dimensions.

Parameters
  • d (int) – The dimension of the space.

  • k (int) – The polynomial degree.

Returns

\(\binom{k+d}{d}\).

Return type

int

Example

>>> npolys(3, 2)
10