Skip to content

Coordinate Utilities

get_points_in_box(lbs, ubs)

Using a Cartesian product, returns a list of integer points in some region.

Parameters

Iterable[Number]

description

Iterable[Number]

description

Returns

List[List[Number]] description

Examples

get_points_in_box([0,1], [1,2]) [[0, 1], [0, 2], [1, 1], [1, 2]]

Source code in pylattica/core/coordinate_utils.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def get_points_in_box(lbs: Iterable[int], ubs: Iterable[int]) -> List[List[int]]:
    """Using a Cartesian product, returns a list of integer points in some region.

    Parameters
    ----------
    lbs : Iterable[Number]
        _description_
    ubs : Iterable[Number]
        _description_

    Returns
    -------
    List[List[Number]]
        _description_

    Examples
    --------
    >>> get_points_in_box([0,1], [1,2])
    [[0, 1], [0, 2], [1, 1], [1, 2]]
    """
    args = [list(range(lb, ub)) for lb, ub in zip(lbs, ubs)]
    return list(itertools.product(*args))

get_points_in_cube(lb, ub, dim)

Returns the list of all integer separated points in a box of dimension dim with lower bound and upper bounds in each direction specified by lb and ub.

Parameters

int

the lower bound of the cube

int

the uppwer bound of the cube

Returns

List[List[int]] A list of points in the cube

Source code in pylattica/core/coordinate_utils.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def get_points_in_cube(lb: int, ub: int, dim: int) -> List[List[int]]:
    """Returns the list of all integer separated points in a box of dimension
    dim with lower bound and upper bounds in each direction specified by
    lb and ub.

    Parameters
    ----------
    lb : int
        the lower bound of the cube
    ub : int
        the uppwer bound of the cube

    Returns
    -------
    List[List[int]]
        A list of points in the cube
    """
    return get_points_in_box([lb for _ in range(dim)], [ub for _ in range(dim)])