improve complex digamma edge cases #24
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 391 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.357
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #24"
general
weight: 0.35
oscardssmith
A small tweak to squeeze better performance and accuracy out of digamma in edge cases.
Currently complex
digammaloses accuracy aszapproaches a pole off the real axis, eventually returningInf/NaN(e.g.digamma(-3 + 1e-12*cis(-1.9635))). Real arguments are fine as they were.The problem stems from reflection term in
_cotpi: the denominatorcosh 2πy − cos 2πx, formed as1 − cospi(2x)·sech(2πy), cancels catastrophically near z ∈ ℤ. For |Im z| < 1 this PR now useswhich doesn't have that problem and with
sincospiand cosh πy = √(1 + sinh²πy) it is cheaper than before. Within about √floatmin of the pole at 0 that denominator would underflow, so there is another small fix to account for that.Time for a comparison table again (using mpmath for accuracy checks). 😄 v1.2.2 is this PR.
digamma(::ComplexF64), 200 points per row| region | v1.2.1 | v1.2.2 | SpecialFunctions |
|---|---|---|---|
| near a pole, 10⁻⁴ ≤ R < 10⁻¹ | 3e6 eps · 49 ns | 1.5 eps · 52 ns | 2.2 eps · 83 ns |
| near a pole, 10⁻¹² ≤ R < 10⁻⁴ | 3e15 eps, 93/200 Inf/NaN · 49 ns | 1.8 eps · 51 ns | 1.9 eps · 80 ns |
| near a pole, R < 10⁻¹² (to 10⁻³⁰⁰) | all Inf/NaN · 48 ns | 1.2 eps · 63 ns | 1.2 eps · 60 ns |
| Re z ≤ 0, \|Im z\| < 1 | 8.5 eps · 56 ns | 8.6 eps · 52 ns | 8.5 eps · 87 ns |
| Re z ≤ 0, \|Im z\| ≥ 1 | 1.9 eps · 55 ns | 1.9 eps · 54 ns | 2.8 eps · 94 ns |
| Re z > 0 | 3.3 eps · 30 ns | 3.3 eps · 30 ns | 3.3 eps · 30 ns |
digamma(::ComplexF32), 200 points per row| region | v1.2.1 | v1.2.2 | SpecialFunctions |
|---|---|---|---|
| near a pole, 10⁻⁴ ≤ R < 10⁻¹ | 2e6 eps · 30 ns | 2.0 eps · 26 ns | 0.4 eps · 84 ns |
| near a pole, 10⁻¹² ≤ R < 10⁻⁴ | 6e6 eps, 194/200 Inf/NaN · 30 ns | 1.3 eps · 27 ns | 0.5 eps · 61 ns |
| near a pole, R < 10⁻¹² (to 10⁻³⁷) | all Inf/NaN · 30 ns | 1.2 eps · 34 ns | 0.4 eps · 52 ns |
| Re z ≤ 0, \|Im z\| < 1 | 18 eps · 29 ns | 5.6 eps · 28 ns | 0.5 eps · 87 ns |
| Re z ≤ 0, \|Im z\| ≥ 1 | 2.0 eps · 30 ns | 2.0 eps · 30 ns | 0.4 eps · 94 ns |
| Re z > 0 | 11 eps · 18 ns | 11 eps · 18 ns | 0.5 eps · 31 ns |
digamma(::Complex{BigFloat}), 256-bit precision, 40 points per row| region | v1.2.1 | v1.2.2 | SpecialFunctions |
|---|---|---|---|
| near a pole, 10⁻⁴ ≤ R < 10⁻¹ | 2 bits · 127 µs | 0 · 123 µs | n/a |
| near a pole, 10⁻¹² ≤ R < 10⁻⁴ | 57 bits · 130 µs | 0 · 128 µs | n/a |
| near a pole, R < 10⁻¹² (to 10⁻⁶⁰) | 248 bits, 18/40 Inf/NaN · 133 µs | 0 · 135 µs | n/a |
| Re z ≤ 0, \|Im z\| < 1 | 0 · 128 µs | 0 · 125 µs | n/a |
| Re z ≤ 0, \|Im z\| ≥ 1 | 0 · 128 µs | 0 · 130 µs | n/a |
| Re z > 0 | 0 · 125 µs | 0 · 120 µs | n/a |
Note: SpecialFunctions converts
ComplexF32to Float64 internally, hence the sub-eps Float32 accuracy at ~3x the cost (that's cheating that I don't want to do, if someone puts in F32 they expect F32 performance gains not F64 timings with worse accuracy).New tests were added to prevent future regression in these edge cases too.