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