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