A robust verification wrapper for NumPy arrays using functional and contract paradigms.
Project description
Verified Numpy
A robust verification wrapper for NumPy arrays using functional and contract paradigms.
Install
uv pip install verified_numpy
Usage
# An example policy. Users can create their own by combining validators.
verify_policy: Final[Validator] = combine((
v_dtype(np.float64),
v_ndim(2),
v_finite,
v_nonempty,
v_row_major_contiguous,
))
# --- Happy Path: Create and use a valid array ---
print("--- Basic Success Case ---")
valid_np_array = np.ascontiguousarray([[1.0, 2.0], [3.0, 4.0]])
va_res = make_verified(valid_np_array, policy=verify_policy)
if va_res.is_ok():
va = va_res.value
print(f"Successfully created VerifiedArray with shape: {va.shape}")
# Use safe, explicit properties
print(f"Array dtype: {va.dtype}, ndim: {va.ndim}")
# Use NumPy functions that work via __array__ protocol
print(f"Sum calculated by NumPy: {np.sum(va)}")
# --- Safe Transformation ---
print("\n--- Safe Transformation via apply_and_verify ---")
centered_res = va.apply_and_verify(lambda arr: arr - arr.mean())
if centered_res.is_ok():
print(f"Centered array:\n{centered_res.value.value}")
else:
print(f"Centering failed: {centered_res.error}")
# --- Operator Error ---
print("\n--- Testing Disabled Operator ---")
try:
# This will fail intentionally, demonstrating the strong contract boundary.
result = va + 1
except TypeError as e:
print(f"Caught expected error: {e}")
# --- Failure Path: Try to create an invalid array ---
print("\n--- Failure Case (Wrong DType) ---")
invalid_np_array = np.array([[1, 2], [3, 4]], dtype=np.int32)
va_res_fail = make_verified(invalid_np_array, policy=verify_policy)
if va_res_fail.is_err():
print(f"Verification failed as expected: {va_res_fail.error}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file verified_numpy-0.1.0.tar.gz.
File metadata
- Download URL: verified_numpy-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f817684aab42e4089a5dd974ada36607d05eba459c5b54cfe576942eeaf485b
|
|
| MD5 |
cbd3b028f56d7c798c4b5c4626bae221
|
|
| BLAKE2b-256 |
d3c03ea371dd8dbe7e73c34de9b46bc88bb69448d361c1e299c5c524e4fb17fb
|
Provenance
The following attestation bundles were made for verified_numpy-0.1.0.tar.gz:
Publisher:
python-publish.yml on J-joon/verified_numpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
verified_numpy-0.1.0.tar.gz -
Subject digest:
9f817684aab42e4089a5dd974ada36607d05eba459c5b54cfe576942eeaf485b - Sigstore transparency entry: 601118304
- Sigstore integration time:
-
Permalink:
J-joon/verified_numpy@d5f39187235fd3b31607049e35bd347b5767dc8d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/J-joon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d5f39187235fd3b31607049e35bd347b5767dc8d -
Trigger Event:
release
-
Statement type:
File details
Details for the file verified_numpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: verified_numpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df9f500305858c6371e0762f290021524d7705aa0ac16382a6315d9a2e9ec863
|
|
| MD5 |
e829b450a282dc471ea9aec0f0ec0a59
|
|
| BLAKE2b-256 |
2458a60e1d097fc0024f797c621f173d05625a7684e6bfdd6be8cac8cb81d13c
|
Provenance
The following attestation bundles were made for verified_numpy-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on J-joon/verified_numpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
verified_numpy-0.1.0-py3-none-any.whl -
Subject digest:
df9f500305858c6371e0762f290021524d7705aa0ac16382a6315d9a2e9ec863 - Sigstore transparency entry: 601118305
- Sigstore integration time:
-
Permalink:
J-joon/verified_numpy@d5f39187235fd3b31607049e35bd347b5767dc8d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/J-joon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d5f39187235fd3b31607049e35bd347b5767dc8d -
Trigger Event:
release
-
Statement type: