gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/lapack/gonum/lapack.go (about) 1 // Copyright ©2015 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gonum 6 7 import "gonum.org/v1/gonum/lapack" 8 9 // Implementation is the native Go implementation of LAPACK routines. It 10 // is built on top of calls to the return of blas64.Implementation(), so while 11 // this code is in pure Go, the underlying BLAS implementation may not be. 12 type Implementation struct{} 13 14 var _ lapack.Float64 = Implementation{} 15 16 func abs(a int) int { 17 if a < 0 { 18 return -a 19 } 20 return a 21 } 22 23 const ( 24 // dlamchE is the machine epsilon. For IEEE this is 2^{-53}. 25 dlamchE = 0x1p-53 26 27 // dlamchB is the radix of the machine (the base of the number system). 28 dlamchB = 2 29 30 // dlamchP is base * eps. 31 dlamchP = dlamchB * dlamchE 32 33 // dlamchS is the "safe minimum", that is, the lowest number such that 34 // 1/dlamchS does not overflow, or also the smallest normal number. 35 // For IEEE this is 2^{-1022}. 36 dlamchS = 0x1p-1022 37 38 // Blue's scaling constants 39 // 40 // An n-vector x is well-scaled if 41 // dtsml ≤ |xᵢ| ≤ dtbig for 0 ≤ i < n and n ≤ 1/dlamchP, 42 // where 43 // dtsml = 2^ceil((expmin-1)/2) = 2^ceil((-1021-1)/2) = 2^{-511} = 1.4916681462400413e-154 44 // dtbig = 2^floor((expmax-digits+1)/2) = 2^floor((1024-53+1)/2) = 2^{486} = 1.997919072202235e+146 45 // If any xᵢ is not well-scaled, then multiplying small values by dssml and 46 // large values by dsbig avoids underflow or overflow when computing the sum 47 // of squares \sum_0^{n-1} (xᵢ)². 48 // dssml = 2^{-floor((expmin-digits)/2)} = 2^{-floor((-1021-53)/2)} = 2^537 = 4.4989137945431964e+161 49 // dsbig = 2^{-ceil((expmax+digits-1)/2)} = 2^{-ceil((1024+53-1)/2)} = 2^{-538} = 1.1113793747425387e-162 50 // 51 // References: 52 // - Anderson E. (2017) 53 // Algorithm 978: Safe Scaling in the Level 1 BLAS 54 // ACM Trans Math Softw 44:1--28 55 // https://doi.org/10.1145/3061665 56 // - Blue, James L. (1978) 57 // A Portable Fortran Program to Find the Euclidean Norm of a Vector 58 // ACM Trans Math Softw 4:15--23 59 // https://doi.org/10.1145/355769.355771 60 dtsml = 0x1p-511 61 dtbig = 0x1p486 62 dssml = 0x1p537 63 dsbig = 0x1p-538 64 )