gonum.org/v1/gonum@v0.14.0/lapack/testlapack/dgetrf.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 testlapack 6 7 import ( 8 "testing" 9 10 "golang.org/x/exp/rand" 11 ) 12 13 type Dgetrfer interface { 14 Dgetrf(m, n int, a []float64, lda int, ipiv []int) bool 15 } 16 17 func DgetrfTest(t *testing.T, impl Dgetrfer) { 18 rnd := rand.New(rand.NewSource(1)) 19 for _, test := range []struct { 20 m, n, lda int 21 }{ 22 {10, 5, 0}, 23 {5, 10, 0}, 24 {10, 10, 0}, 25 {300, 5, 0}, 26 {3, 500, 0}, 27 {4, 5, 0}, 28 {300, 200, 0}, 29 {204, 300, 0}, 30 {1, 3000, 0}, 31 {3000, 1, 0}, 32 {10, 5, 20}, 33 {5, 10, 20}, 34 {10, 10, 20}, 35 {300, 5, 400}, 36 {3, 500, 600}, 37 {200, 200, 300}, 38 {300, 200, 300}, 39 {204, 300, 400}, 40 {1, 3000, 4000}, 41 {3000, 1, 4000}, 42 } { 43 m := test.m 44 n := test.n 45 lda := test.lda 46 if lda == 0 { 47 lda = n 48 } 49 a := make([]float64, m*lda) 50 for i := range a { 51 a[i] = rnd.Float64() 52 } 53 mn := min(m, n) 54 ipiv := make([]int, mn) 55 for i := range ipiv { 56 ipiv[i] = rnd.Int() 57 } 58 59 // Cannot compare the outputs of Dgetrf and Dgetf2 because the pivoting may 60 // happen differently. Instead check that the LPQ factorization is correct. 61 aCopy := make([]float64, len(a)) 62 copy(aCopy, a) 63 ok := impl.Dgetrf(m, n, a, lda, ipiv) 64 checkPLU(t, ok, m, n, lda, ipiv, a, aCopy, 1e-10, false) 65 } 66 }