func TestPermutation(t *testing.T) { var N int = 15 p := permutation.PermutationAlloc(N) q := permutation.PermutationAlloc(N) rng.EnvSetup() T := rng.DefaultRngType() r := rng.RngAlloc(T) fmt.Printf("initial permutation: ") permutation.PermutationInit(p) permutation.Fprintf(os.Stdout, p, " %u") os.Stdout.Sync() fmt.Printf("\n") fmt.Printf(" random permutation: ") randist.Shuffle(r, p.Slice_(), p.Len()) permutation.Fprintf(os.Stdout, p, " %u") fmt.Printf("\n") fmt.Printf(" inverse permutation: ") permutation.Inverse(q, p) permutation.Fprintf(os.Stdout, q, " %u") fmt.Printf("\n") }
func TestLinalg(t *testing.T) { aData := []float64{0.18, 0.60, 0.57, 0.96, 0.41, 0.24, 0.99, 0.58, 0.14, 0.30, 0.97, 0.66, 0.51, 0.13, 0.19, 0.85} bData := []float64{1.0, 2.0, 3.0, 4.0} m := matrix.ViewArray(aData, 4, 4) b := vector.ViewArray(bData, 4) x := vector.VectorAlloc(4) p := permutation.PermutationAlloc(4) linalg.LUDecomp(m.Matrix(), p) linalg.LUSolve(m.Matrix(), p, b.Vector(), x) fmt.Printf("x = \n") vector.Fprintf(os.Stdout, x, "%g") }
func TestSortVectorIndex(t *testing.T) { var n int = 10000 var k int = 5 v := vector.VectorAlloc(n) p := permutation.PermutationAlloc(n) rng.EnvSetup() T := rng.DefaultRngType() r := rng.RngAlloc(T) for i := 0; i < n; i++ { vector.Set(v, i, rng.Uniform(r)) } sort.SortVectorIndex(p, v) pData := p.Slice_().([]int) for i := 0; i < k; i++ { vpi := vector.Get(v, pData[i]) fmt.Printf("order = %d, value = %g\n", i, vpi) } }