mirror of
https://github.com/gonum/gonum.git
synced 2025-10-26 00:30:27 +08:00
Add Dlacpy and tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Gonum LAPACK [](https://travis-ci.org/gonum/lapack) [](https://coveralls.io/r/gonum/lapack)
|
||||
Gonum LAPACK [](https://travis-ci.org/gonum/lapack) [](https://coveralls.io/github/gonum/lapack?branch=master)
|
||||
======
|
||||
|
||||
A collection of packages to provide LAPACK functionality for the Go programming
|
||||
|
||||
@@ -2917,6 +2917,8 @@ func Slacpy(ul blas.Uplo, m int, n int, a []float32, lda int, b []float32, ldb i
|
||||
ul = 'U'
|
||||
case blas.Lower:
|
||||
ul = 'L'
|
||||
case blas.All:
|
||||
ul = 'A'
|
||||
default:
|
||||
panic("lapack: illegal triangle")
|
||||
}
|
||||
@@ -2930,6 +2932,8 @@ func Dlacpy(ul blas.Uplo, m int, n int, a []float64, lda int, b []float64, ldb i
|
||||
ul = 'U'
|
||||
case blas.Lower:
|
||||
ul = 'L'
|
||||
case blas.All:
|
||||
ul = 'A'
|
||||
default:
|
||||
panic("lapack: illegal triangle")
|
||||
}
|
||||
@@ -2943,6 +2947,8 @@ func Clacpy(ul blas.Uplo, m int, n int, a []complex64, lda int, b []complex64, l
|
||||
ul = 'U'
|
||||
case blas.Lower:
|
||||
ul = 'L'
|
||||
case blas.All:
|
||||
ul = 'A'
|
||||
default:
|
||||
panic("lapack: illegal triangle")
|
||||
}
|
||||
@@ -2956,6 +2962,8 @@ func Zlacpy(ul blas.Uplo, m int, n int, a []complex128, lda int, b []complex128,
|
||||
ul = 'U'
|
||||
case blas.Lower:
|
||||
ul = 'L'
|
||||
case blas.All:
|
||||
ul = 'A'
|
||||
default:
|
||||
panic("lapack: illegal triangle")
|
||||
}
|
||||
|
||||
@@ -124,6 +124,12 @@ our %typeConv = (
|
||||
"double_return" => "float64"
|
||||
);
|
||||
|
||||
# allUplo is a list of routines that allow 'A' for their uplo argument.
|
||||
# The list keys are truncated by one character to cover all four numeric types.
|
||||
our %allUplo = (
|
||||
"lacpy" => undef
|
||||
);
|
||||
|
||||
foreach my $line (@lines) {
|
||||
process($line);
|
||||
}
|
||||
@@ -225,7 +231,22 @@ EOH
|
||||
};
|
||||
$var eq "uplo" && do {
|
||||
$var = "ul";
|
||||
my $bp = << "EOH";
|
||||
my $bp;
|
||||
if (exists $allUplo{substr($func, 1)}) {
|
||||
$bp = << "EOH";
|
||||
switch $var {
|
||||
case blas.Upper:
|
||||
$var = 'U'
|
||||
case blas.Lower:
|
||||
$var = 'L'
|
||||
case blas.All:
|
||||
$var = 'A'
|
||||
default:
|
||||
panic("lapack: illegal triangle")
|
||||
}
|
||||
EOH
|
||||
} else {
|
||||
$bp = << "EOH";
|
||||
switch $var {
|
||||
case blas.Upper:
|
||||
$var = 'U'
|
||||
@@ -235,6 +256,7 @@ default:
|
||||
panic("lapack: illegal triangle")
|
||||
}
|
||||
EOH
|
||||
}
|
||||
push @boilerplate, $bp;
|
||||
push @processed, $var." blas.Uplo"; next;
|
||||
};
|
||||
|
||||
@@ -67,6 +67,15 @@ type Implementation struct{}
|
||||
|
||||
var _ lapack.Float64 = Implementation{}
|
||||
|
||||
// Dlacpy copies the elements of A specified by uplo into B. Uplo can specify
|
||||
// a triangular portion with blas.Upper or blas.Lower, or can specify all of the
|
||||
// elemest with blas.All.
|
||||
func (impl Implementation) Dlacpy(uplo blas.Uplo, m, n int, a []float64, lda int, b []float64, ldb int) {
|
||||
checkMatrix(m, n, a, lda)
|
||||
checkMatrix(m, n, b, ldb)
|
||||
clapack.Dlacpy(uplo, m, n, a, lda, b, ldb)
|
||||
}
|
||||
|
||||
// Dlange computes the matrix norm of the general m×n matrix a. The input norm
|
||||
// specifies the norm computed.
|
||||
// lapack.MaxAbs: the maximum absolute value of an element.
|
||||
|
||||
@@ -13,6 +13,10 @@ import (
|
||||
|
||||
var impl = Implementation{}
|
||||
|
||||
func TestDlacpy(t *testing.T) {
|
||||
testlapack.DlacpyTest(t, impl)
|
||||
}
|
||||
|
||||
func TestDlange(t *testing.T) {
|
||||
testlapack.DlangeTest(t, impl)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// calls, as specified in the netlib standard (www.netlib.org).
|
||||
//
|
||||
// The native Go routines are used by default, and the Use function can be used
|
||||
// to set an alternate implementation.
|
||||
// to set an alternative implementation.
|
||||
//
|
||||
// If the type of matrix (General, Symmetric, etc.) is known and fixed, it is
|
||||
// used in the wrapper signature. In many cases, however, the type of the matrix
|
||||
|
||||
40
native/dlacpy.go
Normal file
40
native/dlacpy.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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 native
|
||||
|
||||
import "github.com/gonum/blas"
|
||||
|
||||
// Dlacpy copies the elements of A specified by uplo into B. Uplo can specify
|
||||
// a triangular portion with blas.Upper or blas.Lower, or can specify all of the
|
||||
// elemest with blas.All.
|
||||
func (impl Implementation) Dlacpy(uplo blas.Uplo, m, n int, a []float64, lda int, b []float64, ldb int) {
|
||||
checkMatrix(m, n, a, lda)
|
||||
checkMatrix(m, n, b, ldb)
|
||||
switch uplo {
|
||||
default:
|
||||
panic(badUplo)
|
||||
case blas.Upper:
|
||||
for i := 0; i < m; i++ {
|
||||
for j := i; j < n; j++ {
|
||||
b[i*ldb+j] = a[i*lda+j]
|
||||
}
|
||||
}
|
||||
return
|
||||
case blas.Lower:
|
||||
for i := 0; i < m; i++ {
|
||||
for j := 0; j < min(i, n); j++ {
|
||||
b[i*ldb+j] = a[i*lda+j]
|
||||
}
|
||||
}
|
||||
return
|
||||
case blas.All:
|
||||
for i := 0; i < m; i++ {
|
||||
for j := 0; j < n; j++ {
|
||||
b[i*ldb+j] = a[i*lda+j]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,10 @@ func TestDgetrs(t *testing.T) {
|
||||
testlapack.DgetrsTest(t, impl)
|
||||
}
|
||||
|
||||
func TestDlacpy(t *testing.T) {
|
||||
testlapack.DlacpyTest(t, impl)
|
||||
}
|
||||
|
||||
func TestDlaev2(t *testing.T) {
|
||||
testlapack.Dlaev2Test(t, impl)
|
||||
}
|
||||
|
||||
84
testlapack/dlacpy.go
Normal file
84
testlapack/dlacpy.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package testlapack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/gonum/blas"
|
||||
)
|
||||
|
||||
type Dlacpyer interface {
|
||||
Dlacpy(uplo blas.Uplo, m, n int, a []float64, lda int, b []float64, ldb int)
|
||||
}
|
||||
|
||||
func DlacpyTest(t *testing.T, impl Dlacpyer) {
|
||||
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower, blas.All} {
|
||||
for _, test := range []struct {
|
||||
m, n, lda, ldb int
|
||||
}{
|
||||
{3, 5, 0, 0},
|
||||
{5, 5, 0, 0},
|
||||
{7, 5, 0, 0},
|
||||
|
||||
{3, 5, 10, 12},
|
||||
{5, 5, 10, 12},
|
||||
{7, 5, 10, 12},
|
||||
} {
|
||||
m := test.m
|
||||
n := test.n
|
||||
lda := test.lda
|
||||
if lda == 0 {
|
||||
lda = n
|
||||
}
|
||||
ldb := test.ldb
|
||||
if ldb == 0 {
|
||||
ldb = n
|
||||
}
|
||||
a := make([]float64, m*lda)
|
||||
for i := range a {
|
||||
a[i] = rand.Float64()
|
||||
}
|
||||
b := make([]float64, m*ldb)
|
||||
for i := range b {
|
||||
b[i] = rand.Float64()
|
||||
}
|
||||
impl.Dlacpy(uplo, m, n, a, lda, b, ldb)
|
||||
equal := true
|
||||
switch uplo {
|
||||
case blas.Upper:
|
||||
for i := 0; i < m; i++ {
|
||||
for j := i; j < n; j++ {
|
||||
if b[i*ldb+j] != a[i*lda+j] {
|
||||
equal = false
|
||||
goto DoneCheck
|
||||
}
|
||||
}
|
||||
}
|
||||
case blas.Lower:
|
||||
for i := 0; i < m; i++ {
|
||||
for j := 0; j < min(i, n); j++ {
|
||||
if b[i*ldb+j] != a[i*lda+j] {
|
||||
equal = false
|
||||
goto DoneCheck
|
||||
}
|
||||
}
|
||||
}
|
||||
case blas.All:
|
||||
for i := 0; i < m; i++ {
|
||||
for j := 0; j < n; j++ {
|
||||
if b[i*ldb+j] != a[i*lda+j] {
|
||||
equal = false
|
||||
goto DoneCheck
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DoneCheck:
|
||||
if !equal {
|
||||
fmt.Println(blas.Lower)
|
||||
t.Errorf("Matrices not equal after copy. Uplo = %d, m = %d, n = %d", uplo, m, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user