mirror of
https://github.com/gonum/gonum.git
synced 2025-10-13 02:43:59 +08:00
Changed Linspace and Logspace to Span and LogSpan, fixed capitalization issues with BenchmarkLogsumexp
This commit is contained in:
30
sliceops.go
30
sliceops.go
@@ -143,25 +143,13 @@ func FindFirst(s []float64, f func(float64) bool, k int) (inds []int, err error)
|
||||
return inds, InsufficientElements{}
|
||||
}
|
||||
|
||||
// Linspace returns a set of N equally spaced points between l and u, where N
|
||||
// is equal to the length of the destination. The first element of the destination
|
||||
// is l, the final element of the destination is u. Will panic if the destination has
|
||||
// length < 2
|
||||
func Linspace(dst []float64, l, u float64) {
|
||||
n := len(dst)
|
||||
step := (u - l) / float64(n-1)
|
||||
for i := range dst {
|
||||
dst[i] = l + step*float64(i)
|
||||
}
|
||||
}
|
||||
|
||||
// Logspace returns a set of N equally spaced points in log space between l and u, where N
|
||||
// LogSpan returns a set of N equally spaced points in log space between l and u, where N
|
||||
// is equal to the length of the destination. The first element of the destination
|
||||
// is l, the final element of the destination is u. Will panic if the destination has
|
||||
// length < 2. Note that this call will return NaNs if l or u are negative, and
|
||||
// zeros if l or u is zero.
|
||||
func Logspace(dst []float64, l, u float64) {
|
||||
Linspace(dst, math.Log(l), math.Log(u))
|
||||
func LogSpan(dst []float64, l, u float64) {
|
||||
Span(dst, math.Log(l), math.Log(u))
|
||||
Apply(dst, math.Exp)
|
||||
}
|
||||
|
||||
@@ -276,6 +264,18 @@ func Scale(s []float64, c float64) {
|
||||
}
|
||||
}
|
||||
|
||||
// Span returns a set of N equally spaced points between l and u, where N
|
||||
// is equal to the length of the destination. The first element of the destination
|
||||
// is l, the final element of the destination is u. Will panic if the destination has
|
||||
// length < 2
|
||||
func Span(dst []float64, l, u float64) {
|
||||
n := len(dst)
|
||||
step := (u - l) / float64(n-1)
|
||||
for i := range dst {
|
||||
dst[i] = l + step*float64(i)
|
||||
}
|
||||
}
|
||||
|
||||
// Sub subtracts, element-wise, the first argument from the second. Assumes
|
||||
// the lengths of s and t match (can be tested with EqLen)
|
||||
func Sub(s, t []float64) {
|
||||
|
Reference in New Issue
Block a user