vertebrae.utils.validation
Validation helpers for dense and sparse embeddings.
Functions
|
Validate a dense 2D numeric array. |
|
Validate dense 2D numeric output from an extractor. |
|
Validate dense or sparse numeric 2D embeddings. |
|
Validate a scipy sparse numeric matrix. |
|
Convert a sparse matrix to dense after checking memory size. |
|
Estimate bytes required to represent a matrix densely. |
|
Return whether value is a scipy sparse matrix. |
|
Return a scipy sparse matrix/array format without deprecated APIs. |
|
Validate an exact, one-dimensional row selection. |
|
L2-normalize dense or sparse rows without densifying sparse input. |
Module Contents
- vertebrae.utils.validation.ensure_2d_numeric_array(value, name)[source]
Validate a dense 2D numeric array.
- Parameters:
value (Any) – Array-like value to validate.
name (str) – Human-readable name used in error messages.
- Returns:
A NumPy array with numeric, finite values.
- Raises:
ValueError – If value is sparse, non-2D, non-numeric, or non-finite.
- Return type:
numpy.ndarray
- vertebrae.utils.validation.ensure_dense_numeric_2d(value, name)[source]
Validate dense 2D numeric output from an extractor.
- Parameters:
value (Any) – Array-like value to validate.
name (str) – Human-readable name used in error messages.
- Returns:
A dense numeric NumPy array.
- Raises:
ValueError – If value is sparse or invalid.
- Return type:
numpy.ndarray
- vertebrae.utils.validation.ensure_numeric_matrix(value, name, allow_sparse=True)[source]
Validate dense or sparse numeric 2D embeddings.
- Parameters:
value (Any) – Dense array-like object or scipy sparse matrix.
name (str) – Human-readable name used in error messages.
allow_sparse (bool) – Whether sparse matrices are accepted.
- Returns:
A NumPy array for dense input, or a CSR matrix for sparse input.
- Raises:
ValueError – If the matrix is not 2D, numeric, finite, or sparse is disallowed.
- Return type:
Any
- vertebrae.utils.validation.ensure_sparse_numeric_2d(value, name)[source]
Validate a scipy sparse numeric matrix.
- Parameters:
value (Any) – Sparse matrix to validate.
name (str) – Human-readable name used in error messages.
- Returns:
A CSR matrix that preserves the input dtype.
- Raises:
ValueError – If the sparse matrix is non-2D, non-numeric, or non-finite.
- Return type:
Any
- vertebrae.utils.validation.sparse_to_dense(value, name, max_dense_bytes)[source]
Convert a sparse matrix to dense after checking memory size.
- Parameters:
value (Any) – Sparse matrix to densify.
name (str) – Human-readable name used in error messages.
max_dense_bytes (int) – Maximum allowed dense allocation size.
- Returns:
A dense numeric NumPy array.
- Raises:
ValueError – If the dense representation would exceed max_dense_bytes.
- Return type:
numpy.ndarray
- vertebrae.utils.validation.estimate_dense_nbytes(value)[source]
Estimate bytes required to represent a matrix densely.
- Parameters:
value (Any)
- Return type:
int
- vertebrae.utils.validation.is_sparse_matrix(value)[source]
Return whether value is a scipy sparse matrix.
- Parameters:
value (Any)
- Return type:
bool
- vertebrae.utils.validation.sparse_storage_format(value)[source]
Return a scipy sparse matrix/array format without deprecated APIs.
- Parameters:
value (Any)
- Return type:
str
- vertebrae.utils.validation.validate_row_indices(value, size, name='indices')[source]
Validate an exact, one-dimensional row selection.
NumPy’s
dtype=intcoercion silently truncates floats and accepts booleans. Dataset subsetting is identity-bearing, so those coercions are not safe here.- Parameters:
value (Any)
size (int)
name (str)
- Return type:
numpy.ndarray