Skip to content

Commit f119650

Browse files
ci: apply reviewed Stage C backend fix
1 parent a09891c commit f119650

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: PR126 Stage C reviewed fix
2+
3+
on:
4+
push:
5+
branches: [agent/panel-p1-stage-c-covariance]
6+
paths:
7+
- '.github/workflows/pr126-stage-c-fix.yml'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
patch:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: agent/panel-p1-stage-c-covariance
19+
fetch-depth: 0
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
- name: Remove HC leverage host-vector transfer
24+
run: |
25+
python - <<'PY'
26+
from pathlib import Path
27+
28+
path = Path('statgpu/panel/_covariance.py')
29+
text = path.read_text(encoding='utf-8')
30+
old = ''' leverage_np = np.asarray(_to_numpy(leverage), dtype=np.float64).ravel()
31+
tol = 256.0 * np.finfo(np.float64).eps
32+
if leverage_np.size and float(np.min(leverage_np)) < -tol:
33+
raise ValueError("HC2/HC3 leverage is materially negative")
34+
if leverage_np.size and float(np.max(leverage_np)) > 1.0 + tol:
35+
raise ValueError("HC2/HC3 leverage is materially greater than one")
36+
leverage_np = np.clip(leverage_np, 0.0, 1.0)
37+
denominator_np = 1.0 - leverage_np
38+
if denominator_np.size and float(np.min(denominator_np)) <= tol:
39+
raise ValueError("HC2/HC3 covariance is undefined when leverage is numerically one")
40+
denominator = xp_asarray(
41+
denominator_np,
42+
dtype=xp.float64,
43+
xp=xp,
44+
ref_arr=X,
45+
)
46+
'''
47+
new = ''' leverage_min = _to_float_scalar(xp.min(leverage))
48+
leverage_max = _to_float_scalar(xp.max(leverage))
49+
tol = 256.0 * np.finfo(np.float64).eps
50+
if leverage_min < -tol:
51+
raise ValueError("HC2/HC3 leverage is materially negative")
52+
if leverage_max > 1.0 + tol:
53+
raise ValueError("HC2/HC3 leverage is materially greater than one")
54+
if _is_torch(xp):
55+
leverage = xp.clamp(leverage, min=0.0, max=1.0)
56+
else:
57+
leverage = xp.clip(leverage, 0.0, 1.0)
58+
denominator = 1.0 - leverage
59+
denominator_min = _to_float_scalar(xp.min(denominator))
60+
if denominator_min <= tol:
61+
raise ValueError("HC2/HC3 covariance is undefined when leverage is numerically one")
62+
'''
63+
if old not in text:
64+
raise SystemExit('expected HC leverage block not found')
65+
text = text.replace(old, new, 1)
66+
text = text.replace(
67+
'"leverage_min": float(leverage_np.min()) if leverage_np.size else None,\n "leverage_max": float(leverage_np.max()) if leverage_np.size else None,',
68+
'"leverage_min": float(leverage_min),\n "leverage_max": float(leverage_max),',
69+
1,
70+
)
71+
path.write_text(text, encoding='utf-8')
72+
PY
73+
python -m compileall -q statgpu/panel/_covariance.py
74+
git diff --check
75+
- name: Commit reviewed fix
76+
run: |
77+
git config user.name 'github-actions[bot]'
78+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
79+
git add statgpu/panel/_covariance.py
80+
git commit -m 'fix: keep HC leverage backend-native'
81+
git push origin HEAD:agent/panel-p1-stage-c-covariance

0 commit comments

Comments
 (0)