1 // Copyright 2013 The Gonum Authors. All rights reserved.
2 // Use of this code is governed by a BSD-style
3 // license that can be found in the LICENSE file
11 // Set of examples for all the functions
13 func ExampleAdd_simple() {
14 // Adding three slices together. Note that
15 // the result is stored in the first slice
16 s1 := []float64{1, 2, 3, 4}
17 s2 := []float64{5, 6, 7, 8}
18 s3 := []float64{1, 1, 1, 1}
22 fmt.Println("s1 =", s1)
23 fmt.Println("s2 =", s2)
24 fmt.Println("s3 =", s3)
31 func ExampleAdd_newslice() {
32 // If one wants to store the result in a
33 // new container, just make a new slice
34 s1 := []float64{1, 2, 3, 4}
35 s2 := []float64{5, 6, 7, 8}
36 s3 := []float64{1, 1, 1, 1}
37 dst := make([]float64, len(s1))
42 fmt.Println("dst =", dst)
43 fmt.Println("s1 =", s1)
44 fmt.Println("s2 =", s2)
45 fmt.Println("s3 =", s3)
53 func ExampleAdd_unequallengths() {
54 // If the lengths of the slices are unknown,
56 s1 := []float64{1, 2, 3}
57 s2 := []float64{5, 6, 7, 8}
59 eq := EqualLengths(s1, s2)
63 fmt.Println("Unequal lengths")
69 func ExampleAddConst() {
70 s := []float64{1, -2, 3, -4}
80 func ExampleCumProd() {
81 s := []float64{1, -2, 3, -4}
82 dst := make([]float64, len(s))
86 fmt.Println("dst =", dst)
93 func ExampleCumSum() {
94 s := []float64{1, -2, 3, -4}
95 dst := make([]float64, len(s))
99 fmt.Println("dst =", dst)
100 fmt.Println("s =", s)