mirror of
https://github.com/gonum/gonum.git
synced 2025-10-29 09:42:38 +08:00
Add dorgqr and tests, update dorg2r tests, and fix cgo dorgqr
This commit is contained in:
@@ -19,13 +19,17 @@ type Dorg2rer interface {
|
||||
|
||||
func Dorg2rTest(t *testing.T, impl Dorg2rer) {
|
||||
for _, test := range []struct {
|
||||
m, n, lda int
|
||||
m, n, k, lda int
|
||||
}{
|
||||
{3, 3, 0},
|
||||
{4, 3, 0},
|
||||
{3, 3, 0, 0},
|
||||
{4, 3, 0, 0},
|
||||
{3, 3, 2, 0},
|
||||
{4, 3, 2, 0},
|
||||
|
||||
{5, 5, 20},
|
||||
{10, 5, 20},
|
||||
{5, 5, 0, 20},
|
||||
{5, 5, 3, 20},
|
||||
{10, 5, 0, 20},
|
||||
{10, 5, 2, 20},
|
||||
} {
|
||||
m := test.m
|
||||
n := test.n
|
||||
@@ -44,7 +48,11 @@ func Dorg2rTest(t *testing.T, impl Dorg2rer) {
|
||||
work = make([]float64, int(work[0]))
|
||||
impl.Dgeqrf(m, n, a, lda, tau, work, len(work))
|
||||
|
||||
q := constructQ("QR", m, n, a, lda, tau)
|
||||
k = test.k
|
||||
if k == 0 {
|
||||
k = n
|
||||
}
|
||||
q := constructQK("QR", m, n, k, a, lda, tau)
|
||||
|
||||
impl.Dorg2r(m, n, k, a, lda, tau, work)
|
||||
|
||||
|
||||
82
testlapack/dorglq.go
Normal file
82
testlapack/dorglq.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright ©2015 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package testlapack
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/gonum/floats"
|
||||
)
|
||||
|
||||
type Dorglqer interface {
|
||||
Dorgl2er
|
||||
Dorglq(m, n, k int, a []float64, lda int, tau, work []float64, lwork int)
|
||||
}
|
||||
|
||||
func DorglqTest(t *testing.T, impl Dorglqer) {
|
||||
// TODO(btracey): Base tests off of nb and nx.
|
||||
for _, test := range []struct{ m, n, k, lda int }{
|
||||
{10, 10, 10, 0},
|
||||
{10, 10, 10, 20},
|
||||
{10, 30, 10, 0},
|
||||
{20, 30, 10, 0},
|
||||
|
||||
{100, 100, 100, 0},
|
||||
{100, 100, 50, 0},
|
||||
{100, 130, 100, 0},
|
||||
{100, 130, 50, 0},
|
||||
{100, 100, 100, 150},
|
||||
{100, 100, 50, 150},
|
||||
{100, 130, 100, 150},
|
||||
{100, 130, 50, 150},
|
||||
|
||||
{200, 200, 200, 0},
|
||||
{200, 200, 150, 0},
|
||||
{200, 230, 200, 0},
|
||||
{200, 230, 150, 0},
|
||||
{200, 200, 200, 250},
|
||||
{200, 200, 150, 250},
|
||||
{200, 230, 200, 250},
|
||||
{200, 230, 150, 250},
|
||||
} {
|
||||
m := test.m
|
||||
n := test.n
|
||||
k := test.k
|
||||
lda := test.lda
|
||||
if lda == 0 {
|
||||
lda = n
|
||||
}
|
||||
a := make([]float64, m*lda)
|
||||
for i := range a {
|
||||
a[i] = rand.Float64()
|
||||
}
|
||||
work := make([]float64, 1)
|
||||
tau := make([]float64, m)
|
||||
for i := range tau {
|
||||
tau[i] = math.NaN()
|
||||
}
|
||||
// Compute LQ factorization.
|
||||
impl.Dgelqf(m, n, a, lda, tau, work, -1)
|
||||
work = make([]float64, int(work[0]))
|
||||
impl.Dgelqf(m, n, a, lda, tau, work, len(work))
|
||||
|
||||
aUnblocked := make([]float64, len(a))
|
||||
copy(aUnblocked, a)
|
||||
for i := range work {
|
||||
work[i] = math.NaN()
|
||||
}
|
||||
impl.Dorgl2(m, n, k, aUnblocked, lda, tau, work)
|
||||
// make sure work isn't used before initialized
|
||||
for i := range work {
|
||||
work[i] = math.NaN()
|
||||
}
|
||||
impl.Dorglq(m, n, k, a, lda, tau, work, len(work))
|
||||
if !floats.EqualApprox(a, aUnblocked, 1e-10) {
|
||||
t.Errorf("Q Mismatch. m = %d, n = %d, k = %d, lda = %d", m, n, k, lda)
|
||||
}
|
||||
}
|
||||
}
|
||||
82
testlapack/dorgqr.go
Normal file
82
testlapack/dorgqr.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright ©2015 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package testlapack
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/gonum/floats"
|
||||
)
|
||||
|
||||
type Dorgqrer interface {
|
||||
Dorg2rer
|
||||
Dorgqr(m, n, k int, a []float64, lda int, tau, work []float64, lwork int)
|
||||
}
|
||||
|
||||
func DorgqrTest(t *testing.T, impl Dorgqrer) {
|
||||
// TODO(btracey): Base tests off of nb and nx.
|
||||
for _, test := range []struct{ m, n, k, lda int }{
|
||||
{10, 10, 10, 0},
|
||||
{10, 10, 10, 20},
|
||||
{30, 10, 10, 0},
|
||||
{30, 20, 10, 0},
|
||||
|
||||
{100, 100, 100, 0},
|
||||
{100, 100, 50, 0},
|
||||
{130, 100, 100, 0},
|
||||
{130, 100, 50, 0},
|
||||
{100, 100, 100, 150},
|
||||
{100, 100, 50, 150},
|
||||
{130, 100, 100, 150},
|
||||
{130, 100, 50, 150},
|
||||
|
||||
{200, 200, 200, 0},
|
||||
{200, 200, 150, 0},
|
||||
{230, 200, 200, 0},
|
||||
{230, 200, 150, 0},
|
||||
{200, 200, 200, 250},
|
||||
{200, 200, 150, 250},
|
||||
{230, 200, 200, 250},
|
||||
{230, 200, 150, 250},
|
||||
} {
|
||||
m := test.m
|
||||
n := test.n
|
||||
k := test.k
|
||||
lda := test.lda
|
||||
if lda == 0 {
|
||||
lda = n
|
||||
}
|
||||
a := make([]float64, m*lda)
|
||||
for i := range a {
|
||||
a[i] = rand.Float64()
|
||||
}
|
||||
work := make([]float64, 1)
|
||||
tau := make([]float64, n)
|
||||
for i := range tau {
|
||||
tau[i] = math.NaN()
|
||||
}
|
||||
// Compute QR factorization.
|
||||
impl.Dgeqrf(m, n, a, lda, tau, work, -1)
|
||||
work = make([]float64, int(work[0]))
|
||||
impl.Dgeqrf(m, n, a, lda, tau, work, len(work))
|
||||
|
||||
aUnblocked := make([]float64, len(a))
|
||||
copy(aUnblocked, a)
|
||||
for i := range work {
|
||||
work[i] = math.NaN()
|
||||
}
|
||||
impl.Dorg2r(m, n, k, aUnblocked, lda, tau, work)
|
||||
// make sure work isn't used before initialized
|
||||
for i := range work {
|
||||
work[i] = math.NaN()
|
||||
}
|
||||
impl.Dorgqr(m, n, k, a, lda, tau, work, len(work))
|
||||
if !floats.EqualApprox(a, aUnblocked, 1e-10) {
|
||||
t.Errorf("Q Mismatch. m = %d, n = %d, k = %d, lda = %d", m, n, k, lda)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,9 +226,15 @@ func constructH(tau []float64, v blas64.General, store lapack.StoreV, direct lap
|
||||
return h
|
||||
}
|
||||
|
||||
// constructQ constructs the Q matrix from the result of dgeqrf and dgeqr2
|
||||
// constructQ constructs the Q matrix from the result of dgeqrf and dgeqr2.
|
||||
func constructQ(kind string, m, n int, a []float64, lda int, tau []float64) blas64.General {
|
||||
k := min(m, n)
|
||||
return constructQK(kind, m, n, k, a, lda, tau)
|
||||
}
|
||||
|
||||
// constructQK constructs the Q matrix from the result of dgeqrf and dgeqr2 using
|
||||
// the first k reflectors.
|
||||
func constructQK(kind string, m, n, k int, a []float64, lda int, tau []float64) blas64.General {
|
||||
var sz int
|
||||
switch kind {
|
||||
case "QR":
|
||||
|
||||
Reference in New Issue
Block a user