utils module

Utility functions for PLAST, including GPU check, distance calculations, and OS page cache warming.

plast.utils.is_gpu_available()

Check if a GPU is available on the system.

Returns:

True if a GPU is available, False otherwise.

Return type:

bool

plast.utils.euclidean(x, y)

Compute the Euclidean distance between two vectors.

Parameters:
  • x (np.ndarray) – First vector.

  • y (np.ndarray) – Second vector.

Returns:

Euclidean distance.

Return type:

float

plast.utils.cosine_similarity_numba(u, v)

copied from https://github.com/pranaychandekar/numba_cosine

Return type:

float

plast.utils.warm_page_cache(files, threshold=0.9, state_dir=None, logger=None)

Warm OS page cache for given files only if not sufficiently cached.

Parameters:
  • files (list[str or Path]) – List of file paths (str or Path). Non-existent files are ignored.

  • threshold (float) – Target cached fraction in [0,1] before skipping warm.

  • state_dir (str or Path, optional) – Directory to place lock/sentinel files (default: $XDG_RUNTIME_DIR or /tmp).

  • logger (Any, optional) – Optional logger with .debug().

Return type:

None

Returns:

None