open-standards/eoc/eoc-rs/crates/eoc-quantize/tests/int8_roundtrip.rs
Transaction Science 8180ee8c71 ingest wave D: 3 crates · op-fraud-graph + smart-byte-ilp + eoc-quantize
OpenPay (1 crate, 2487 LOC, 33 tests)
  op-fraud-graph    Graph-based fraud detection. EntityKind (card/email/
                    device/IP/address/phone/BIN+last4/account) with
                    canonicalization + hashed EntityKey + billing↔shipping
                    mismatch detection. Adjacency-list FraudGraph with
                    idempotent upsert + edge-merge. Double-hashing Bloom
                    filter (capacity+FPR-sized). Union-find connected
                    components. PageRank with dangling-sink handling.
                    Louvain community detection. Shared-instrument hub
                    rings. Sliding ring-buffer velocity counters. Synthetic
                    identity heuristics (freshness + heavy-use + mail-drop).
                    Structuring / smurfing / mule-chain DFS. EntityRisk +
                    TransactionRisk + RiskBand combiner.

Smart Byte (1 crate, ~1844 LOC, 44 tests)
  smart-byte-ilp    Interledger Protocol v4. OER codec (length-determinant,
                    var-octet-string, BE u32/u64). Prepare/Fulfill/Reject
                    packet roundtrip with all 19 IL-RFC-27 reject codes.
                    SHA-256 Condition + Fulfillment with constant-time
                    verify. ILP address validator (7 schemes, 1-128 char
                    segments, 1023-byte cap, segment-aligned prefix match).
                    STREAM (15 frame types). BTP. SPSP payment-pointer
                    resolver. Open Payments API. Longest-prefix routing
                    Connector with fixed-point quote conversion + balance +
                    rate-limit checks.

EOC (1 crate, 1921 LOC, 36 tests)
  eoc-quantize      Quantization primitives. int8 (symmetric/asymmetric
                    with zero-inclusion fix), int4 (GPTQ + AWQ group quant),
                    int2 (BitNet), fp8 (E4M3/E5M2), nf4 (QLoRA). GGUF v3
                    header parse. safetensors read sketch. Calibration
                    datasets + per-channel scales. KV-cache quant. Energy
                    tradeoff curves (joules-per-token across schemes).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 16:10:10 -04:00

40 lines
1.2 KiB
Rust

//! Int8 round-trip tolerance test.
use eoc_quantize::int8::{Int8Asymmetric, Int8Symmetric};
use eoc_quantize::scheme::QuantizationScheme;
#[test]
fn symmetric_roundtrip_within_scale() {
let x: Vec<f32> = (0..256).map(|i| (i as f32 - 128.0) * 0.05).collect();
let q = Int8Symmetric::new();
let enc = q.quantize(&x);
let xr = q.dequantize(&enc);
assert_eq!(xr.len(), x.len());
let mut max_err = 0.0_f32;
for (a, b) in x.iter().zip(xr.iter()) {
max_err = max_err.max((a - b).abs());
}
// Symmetric int8 rounding error must be at most ~half a scale unit.
assert!(
max_err <= enc.scale + 1e-5,
"max err {max_err} exceeds scale {}",
enc.scale
);
}
#[test]
fn asymmetric_roundtrip_within_scale() {
let x: Vec<f32> = (0..256).map(|i| 3.0 + i as f32 * 0.01).collect();
let q = Int8Asymmetric::new();
let enc = q.quantize(&x);
let xr = q.dequantize(&enc);
let mut max_err = 0.0_f32;
for (a, b) in x.iter().zip(xr.iter()) {
max_err = max_err.max((a - b).abs());
}
assert!(
max_err <= enc.scale + 1e-5,
"asym max err {max_err} exceeds scale {}",
enc.scale
);
}