39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
torch = pytest.importorskip("torch")
|
||
|
|
|
||
|
|
import json
|
||
|
|
|
||
|
|
from gpu_feature_parity_contract_v1_1 import deterministic_adversarial_ohlcv # noqa: E402
|
||
|
|
from gpu_feature_engine_v1_2 import supertrend_trace # noqa: E402
|
||
|
|
from gpu_feature_parity_contract_v1_2 import cpu_supertrend_trace # noqa: E402
|
||
|
|
from gpu_supertrend_v1_2_diagnostic import diagnose # noqa: E402
|
||
|
|
|
||
|
|
|
||
|
|
def test_period_10_semantic_diagnostic_has_serializable_cpu_gpu_trace_statistics():
|
||
|
|
ohlcv = deterministic_adversarial_ohlcv(length=96, seed=11)
|
||
|
|
report = diagnose(ohlcv, device=torch.device("cpu"))
|
||
|
|
assert json.dumps(report, allow_nan=False)
|
||
|
|
assert [record["multiplier"] for record in report["records"]] == [2.0, 3.0, 4.0]
|
||
|
|
for record in report["records"]:
|
||
|
|
assert set(record["numeric"]) == {"output", "true_range", "atr", "basic_upper", "basic_lower", "upper", "lower"}
|
||
|
|
assert record["numeric"]["atr"]["first_divergence"] is None
|
||
|
|
assert record["direction"]["exact"]
|
||
|
|
assert record["transitions"]["direction_transition"]["exact"]
|
||
|
|
assert all(item["exact"] for item in record["branch_predicates"].values())
|
||
|
|
|
||
|
|
|
||
|
|
def test_cpu_trace_exposes_the_complete_gpu_trace_surface():
|
||
|
|
ohlcv = deterministic_adversarial_ohlcv(length=96, seed=11)
|
||
|
|
cpu = cpu_supertrend_trace(ohlcv["close"], ohlcv["high"], ohlcv["low"], 10, 3.0)
|
||
|
|
gpu = supertrend_trace(
|
||
|
|
torch.as_tensor(ohlcv["close"], dtype=torch.float64),
|
||
|
|
torch.as_tensor(ohlcv["high"], dtype=torch.float64),
|
||
|
|
torch.as_tensor(ohlcv["low"], dtype=torch.float64),
|
||
|
|
10,
|
||
|
|
3.0,
|
||
|
|
)
|
||
|
|
assert set(cpu) == set(gpu)
|