Skip to content

range

thkit.range

Functions:

  • range_inclusive

    Generate evenly spaced points including the endpoint (within tolerance).

  • composite_range

    A custom parser to allow define composite ranges. This is needed for defining input parameters in YAML files.

  • composite_index

    Allow define composite index ranges.

  • composite_strain_points

    Generate composite spacing points from multiple ranges with tolerance-based uniqueness.

  • chunk_list

    Yield successive n-sized chunks from input_list.

range_inclusive(start: float, end: float, step: float, tol: float = 1e-06) -> list[float]

Generate evenly spaced points including the endpoint (within tolerance).

composite_range(list_inputs: list[float | str], tol=1e-06) -> list[float]

A custom parser to allow define composite ranges. This is needed for defining input parameters in YAML files.

Parameters:

  • list_inputs (list[int | float | str]) –

    Accepts numbers or strings with special form 'start:end[:step]' (inclusive).

  • tol (float, default: 1e-06 ) –

    Tolerance for including the endpoint.

Examples: ["-3.1:-1", 0.1, 2, "3.1:5.2", "6.0:10.1:0.5"]

composite_index(list_inputs: list[float | str]) -> list[int]

Allow define composite index ranges.

Parameters:

  • list_inputs (list[int | str]) –

    Accepts ints or strings with special form 'start:end[:step]' (inclusive).

Examples: [1, 2, "3:5", "7:10:2"] -> [1, 2, 3, 4, 5, 7, 9, 10]

composite_strain_points(list_inputs: list[int | float | str], tol=1e-06) -> list[float]

Generate composite spacing points from multiple ranges with tolerance-based uniqueness.

Notes
  • np.round(np.array(all_points) / tol).astype(int) is a trick to avoid floating point issues when comparing points with a certain tolerance.

chunk_list(input_list: list, chunk_size: int) -> Generator

Yield successive n-sized chunks from input_list.

Parameters:

  • input_list (list) –

    Input list to be chunked.

  • chunk_size (int) –

    Chunk size (number of elements per chunk).