Qyxo-Zhaenivoth-Guard / source /examples /fast_array_service.py
PureOne's picture
Publish Qyxo-Zhaenivoth Guard v1.0.0 research release
25c6e75 verified
Raw History Blame Contribute Delete
880 Bytes
"""Recommended performance-sensitive interface: already-existing real ndarrays.
This is an integration example, not a benchmark or a production certificate.
"""
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import numpy as np
from qzguard import PreparedBank
x = np.linspace(-1.0, 1.0, 4096, dtype=np.float64)
values = np.column_stack((x, x + 0.25, x - 0.5, 2*x))
bank = PreparedBank(values - 0.01, values + 0.01, backend='filtered')
threshold = np.array([-0.2, 0.05, -0.7, -0.4], dtype=np.float64)
for step in range(3):
lower = np.ones(len(x), dtype=np.float64)
upper = lower * (1.1 + step * 0.05)
result = bank.evaluate(lower, upper, threshold, relation='>=')
assert result.all_guaranteed
print({'step': step, 'backend': result.backend,
'guaranteed': result.guaranteed, 'modes': result.modes})