landlab.graph.sort.intpair

class IntPairCollection[source]

Bases: Collection

Collection of pairs of int, that ignores ordering of pairs.

Examples

>>> from landlab.graph.sort.intpair import IntPairCollection
>>> pairs = IntPairCollection([(0, 1), (2, 3), (1, 2), (4, 5)])
>>> (0, 1) in pairs
True
>>> (1, 0) in pairs
True
>>> (2, 4) in pairs
False
>>> pairs.contains_pairs([(1, 0), (5, 4), (4, 5), (3, 200)])
array([ True, True, True, False])
>>> pairs.contains_pairs([(1, 0, 2), (5, 4, -1), (-1, 4, 5), (3, 2, 1)])
array([[ True, False],
       [ True, False],
       [False, False],
       [ True,  True]])
>>> pairs.contains_pairs(
...     [(1, 0, 2), (5, 4, -1), (-1, 4, 5), (3, 2, 1)], wraparound=True
... )
array([[ True, False,  True],
       [ True,  True, False],
       [False, False, False],
       [ True,  True, False]])
__init__(pairs, sorter=None, sorted=False)[source]
Parameters:
__new__(**kwargs)
contains_pairs(pairs, wraparound=False)[source]
class IntPairMapping[source]

Bases: Mapping, IntPairCollection

Mapping of pairs of int, that ignores ordering of pairs.

Examples

>>> from landlab.graph.sort.intpair import IntPairMapping
>>> pairs = IntPairMapping([(0, 1), (2, 3), (1, 2), (4, 5)], values=[1, 2, 3, 4])
>>> pairs[(1, 0)]
1
>>> pairs[(0, 1)]
1
>>> pairs[(2, 4)]
Traceback (most recent call last):
KeyError: (2, 4)
>>> pairs.get_items([(1, 0), (5, 4), (4, 5), (3, 200)])
array([ 1, 4, 4, -1])
>>> pairs.get_items([(1, 0, 2), (5, 4, -1), (-1, 4, 5), (3, 2, 1)])
array([[ 1, -1],
       [ 4, -1],
       [-1, -1],
       [ 2,  3]])
>>> pairs.get_items([(1, 0, 2), (5, 4, -1), (-1, 4, 5), (3, 2, 1)], wraparound=True)
array([[ 1, -1,  3],
       [ 4,  4, -1],
       [-1, -1, -1],
       [ 2,  3, -1]])
__init__(pairs, values, sorter=None, sorted=False)[source]
Parameters:
Return type:

None

__new__(**kwargs)
contains_pairs(pairs, wraparound=False)
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
get_items(keys, out=None, wraparound=False)[source]
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
values() an object providing a view on D's values
map_pairs_to_values(mapping, pairs, out=None, sorter=None, sorted=False)[source]

Return the values for integer pairs from a mapping.

Parameters:
  • mapping (tuple of ndarray of int) – Integer pair to value mapping as (pairs, values) where pairs is ndarray of shape (M, 2) and values an array of length M.

  • pairs (ndarray of int of shape (N, 2)) – Integer pairs to get the values of.

  • out (ndarray of bool, size (N,), optional) – Buffer to place the result. If not provided, a new array will be allocated.

  • sorter (ndarray of int, size (M,), optional) – Array of indices that sorts the src, as would be returned by argsort. If not provided, src is assumed to already be sorted.

  • sorted (bool, optional) – Indicate if the mapping key pairs are already sorted.

Returns:

Array of values of the given integer pairs.

Return type:

ndarray of int

Examples

>>> from landlab.graph.sort.intpair import map_pairs_to_values
>>> keys = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1]]
>>> values = [0, 10, 20, 30, 40]
>>> pairs = [[1, 1], [3, 1]]
>>> map_pairs_to_values((keys, values), pairs)
array([10, 30])
map_rolling_pairs_to_values(mapping, pairs, out=None, sorter=None, sorted=False, size_of_row=None, wraparound=True)[source]
pair_isin(src, pairs, out=None, sorter=None, sorted=False)[source]