Commit b394eee
authored
Avoid underflow and overflow in norm() (#975)
* Avoid underflow in norm()
* Perform return-type assertion at last step
* Make _init_zero() take AbstractArray
* Define maxabs_nested() to find maximum of absolute values of entries in nested array
* Remove _norm() and define norm() directly for type stability
* Use maxabs_nested() to define norm() stably without underflow
* Call _init_zero() without qualification by StaticArrays
* Define norm_scaled() and call it inside norm()
* norm(a,p) does not call norm_scaled(a,p) if p == 0, 2, Inf
* Make code more succinct
* Use normInf() instead of maxabs_nested()
* Rename aₘ to scale
* Calculate scale with mapreduce()
* Re-introduce maxabs_nested to avoid type instability
* norm() calls _norm() and _norm_scaled()
* _norm_scaled(Size(a), a, p) does not need to deal with p==2
* Add test for overflow
* Add tests for underflow and overflow for p ≥ 2
* Avoid using iszero(l) and isinf(l) for speedup
* Avoid using iszero(scale) for speedup1 parent 0aefabe commit b394eee
2 files changed
+67
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
228 | 255 | | |
229 | 256 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 257 | + | |
233 | 258 | | |
234 | 259 | | |
235 | 260 | | |
| |||
238 | 263 | | |
239 | 264 | | |
240 | 265 | | |
241 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
242 | 270 | | |
243 | 271 | | |
244 | 272 | | |
| |||
247 | 275 | | |
248 | 276 | | |
249 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
250 | 300 | | |
251 | 301 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 302 | + | |
255 | 303 | | |
256 | 304 | | |
257 | 305 | | |
| |||
265 | 313 | | |
266 | 314 | | |
267 | 315 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
279 | 323 | | |
280 | 324 | | |
281 | 325 | | |
| |||
468 | 512 | | |
469 | 513 | | |
470 | 514 | | |
471 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
239 | 243 | | |
240 | 244 | | |
241 | 245 | | |
| |||
0 commit comments