Commit 98b4048
authored
Fix sfd nan at large negative x from log(0) (#347)
sfd(x) computes the Fermi-Dirac entropy -f*log(f) - (1-f)*log(1-f).
For x <= -39, expm1(x) rounds to -1.0 in float64, so f -> 1.0 and
1-f -> 0.0, producing log(0) -> nan and RuntimeWarnings (divide by zero
in log, invalid value in multiply). The physical entropy limit there is
0 (x*log(x) -> 0 as x -> 0).
Mask the f=0/1 boundaries to 0 instead of computing the log. Interior
values are unchanged. This was a real numerical bug, not just noise:
test_band and other tests consumed nan-valued entropy from sfd.
Add a regression test covering x in [-100, 100] asserting finiteness and
the vanishing boundary. Drop the NaN-tolerating filter in
test_sfd_properties since sfd no longer returns nan.1 parent dbd7391 commit 98b4048
2 files changed
Lines changed: 35 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
168 | 187 | | |
169 | 188 | | |
170 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
151 | 162 | | |
152 | 163 | | |
153 | 164 | | |
| |||
0 commit comments