Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Gonum LAPACK [![Build Status](https://travis-ci.org/gonum/lapack.svg?branch=master)](https://travis-ci.org/gonum/lapack) [![Coverage Status](https://img.shields.io/coveralls/gonum/lapack.svg)](https://coveralls.io/r/gonum/lapack)
Gonum LAPACK [![Build Status](https://travis-ci.org/gonum/lapack.svg?branch=master)](https://travis-ci.org/gonum/lapack) [![Coverage Status](https://coveralls.io/repos/gonum/lapack/badge.svg?branch=master&service=github)](https://coveralls.io/github/gonum/lapack?branch=master)
======

A collection of packages to provide LAPACK functionality for the Go programming
Expand Down
8 changes: 8 additions & 0 deletions cgo/clapack/clapack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
24 changes: 23 additions & 1 deletion cgo/clapack/genLapack.pl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ package clapack
"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);
}
Expand Down Expand Up @@ -225,7 +231,22 @@ sub processParamToGo {
};
$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'
Expand All @@ -235,6 +256,7 @@ sub processParamToGo {
panic("lapack: illegal triangle")
}
EOH
}
push @boilerplate, $bp;
push @processed, $var." blas.Uplo"; next;
};
Expand Down
9 changes: 9 additions & 0 deletions cgo/lapack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions cgo/lapack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion lapack64/lapack64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions native/dlacpy.go
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions native/lapack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
84 changes: 84 additions & 0 deletions testlapack/dlacpy.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}