mirror of
https://github.com/gonum/gonum.git
synced 2025-10-27 09:11:08 +08:00
@@ -809,6 +809,17 @@ func Scale(c float64, dst []float64) {
|
||||
}
|
||||
}
|
||||
|
||||
// ScaleTo multiplies the elements in s by c and stores the result in dst.
|
||||
func ScaleTo(dst []float64, c float64, s []float64) []float64 {
|
||||
if len(dst) != len(s) {
|
||||
panic("floats: lengths of slices do not match")
|
||||
}
|
||||
if len(dst) > 0 {
|
||||
f64.ScalUnitaryTo(dst, c, s)
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -1341,6 +1341,22 @@ func TestScale(t *testing.T) {
|
||||
areSlicesEqual(t, truth, s, "Bad scaling")
|
||||
}
|
||||
|
||||
func TestScaleTo(t *testing.T) {
|
||||
s := []float64{3, 4, 1, 7, 5}
|
||||
sCopy := make([]float64, len(s))
|
||||
copy(sCopy, s)
|
||||
c := 5.0
|
||||
truth := []float64{15, 20, 5, 35, 25}
|
||||
dst := make([]float64, len(s))
|
||||
ScaleTo(dst, c, s)
|
||||
if !Same(dst, truth) {
|
||||
t.Errorf("Scale to does not match. Got %v, want %v", dst, truth)
|
||||
}
|
||||
if !Same(s, sCopy) {
|
||||
t.Errorf("Source modified during call. Got %v, want %v", s, sCopy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpan(t *testing.T) {
|
||||
receiver1 := make([]float64, 5)
|
||||
truth := []float64{1, 2, 3, 4, 5}
|
||||
|
||||
Reference in New Issue
Block a user