gonum.org/v1/gonum@v0.14.0/mat/symmetric_example_test.go (about) 1 // Copyright ©2015 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package mat_test 6 7 import ( 8 "fmt" 9 10 "gonum.org/v1/gonum/mat" 11 ) 12 13 func ExampleSymDense_SubsetSym() { 14 n := 5 15 s := mat.NewSymDense(5, nil) 16 count := 1.0 17 for i := 0; i < n; i++ { 18 for j := i; j < n; j++ { 19 s.SetSym(i, j, count) 20 count++ 21 } 22 } 23 fmt.Println("Original matrix:") 24 fmt.Printf("%0.4v\n\n", mat.Formatted(s)) 25 26 // Take the subset {0, 2, 4} 27 var sub mat.SymDense 28 sub.SubsetSym(s, []int{0, 2, 4}) 29 fmt.Println("Subset {0, 2, 4}") 30 fmt.Printf("%0.4v\n\n", mat.Formatted(&sub)) 31 32 // Take the subset {0, 0, 4} 33 sub.SubsetSym(s, []int{0, 0, 4}) 34 fmt.Println("Subset {0, 0, 4}") 35 fmt.Printf("%0.4v\n\n", mat.Formatted(&sub)) 36 37 // Output: 38 // Original matrix: 39 // ⎡ 1 2 3 4 5⎤ 40 // ⎢ 2 6 7 8 9⎥ 41 // ⎢ 3 7 10 11 12⎥ 42 // ⎢ 4 8 11 13 14⎥ 43 // ⎣ 5 9 12 14 15⎦ 44 // 45 // Subset {0, 2, 4} 46 // ⎡ 1 3 5⎤ 47 // ⎢ 3 10 12⎥ 48 // ⎣ 5 12 15⎦ 49 // 50 // Subset {0, 0, 4} 51 // ⎡ 1 1 5⎤ 52 // ⎢ 1 1 5⎥ 53 // ⎣ 5 5 15⎦ 54 }