gorgonia.org/gorgonia@v0.9.17/math_nooptim.go (about) 1 // +build !fastmath 2 3 package gorgonia 4 5 // this file holds the non-hacky version of anything that is in the math_fast.go file 6 7 import ( 8 "math" 9 10 "github.com/chewxy/math32" 11 ) 12 13 // SetOptimizationLevel sets the fast math optimization level. By default, fast math is turned off, 14 // and this function is a no-op. 15 // 16 // Use the `fastmath` build tag to use fast math 17 func SetOptimizationLevel(i int) {} 18 19 func _inversef32(x float32) float32 { return float32(1) / x } 20 func _inversef64(x float64) float64 { return float64(1) / x } 21 22 func _tanhf32(x float32) float32 { return float32(math.Tanh(float64(x))) } 23 func _tanhf64(x float64) float64 { return math.Tanh(x) } 24 25 func _sigmoidf64(x float64) float64 { 26 if x < -709 { 27 return 0 28 } 29 if x > 19 { 30 return 1 31 } 32 33 return 1.0 / (1.0 + math.Exp(-x)) 34 } 35 36 func _sigmoidf32(x float32) float32 { 37 if x < -88 { 38 return 0 39 } 40 if x > 15 { 41 return 1 42 } 43 return float32(1.0 / (1.0 + math.Exp(float64(-x)))) 44 } 45 46 func _inverseSqrtf64(x float64) float64 { 47 return 1 / math.Sqrt(x) 48 } 49 50 func _inverseSqrtf32(x float32) float32 { 51 return 1 / math32.Sqrt(x) 52 }