testlapack: add test for Dtrtrs
MODIFY
lapack/gonum/lapack_test.go
lapack/gonum/lapack_test.go
@@ -573,6 +573,11 @@ func TestDtrtri(t *testing.T) {
testlapack.DtrtriTest(t, impl)
}
+func TestDtrtrs(t *testing.T) {
+ t.Parallel()
+ testlapack.DtrtrsTest(t, impl)
+}
+
func TestIladlc(t *testing.T) {
t.Parallel()
testlapack.IladlcTest(t, impl)

MODIFY
lapack/testlapack/general.go
lapack/testlapack/general.go
@@ -110,6 +110,19 @@ func sideToString(side blas.Side) string {
}
}
+func transToString(trans blas.Transpose) string {
+ switch trans {
+ case blas.NoTrans:
+ return "NoTrans"
+ case blas.Trans:
+ return "Trans"
+ case blas.ConjTrans:
+ return "ConjTrans"
+ default:
+ panic("invalid trans")
+ }
+}
+
// nanSlice allocates a new slice of length n filled with NaN.
func nanSlice(n int) []float64 {
s := make([]float64, n)
@@ -1565,3 +1578,191 @@ func dlansb(norm lapack.MatrixNorm, uplo blas.Uplo, n, kd int, ab []float64, lda
}
return value
}
+
+func dlantr(norm lapack.MatrixNorm, uplo blas.Uplo, diag blas.Diag, m, n int, a []float64, lda int, work []float64) float64 {
+ // Quick return if possible.
+ minmn := min(m, n)
+ if minmn == 0 {
+ return 0
+ }
+ switch norm {
+ case lapack.MaxAbs:
+ if diag == blas.Unit {
+ value := 1.0
+ if uplo == blas.Upper {
+ for i := 0; i < m; i++ {
+ for j := i + 1; j < n; j++ {
+ tmp := math.Abs(a[i*lda+j])
+ if math.IsNaN(tmp) {
+ return tmp
+ }
+ if tmp > value {
+ value = tmp
+ }
+ }
+ }
+ return value
+ }
+ for i := 1; i < m; i++ {
+ for j := 0; j < min(i, n); j++ {
+ tmp := math.Abs(a[i*lda+j])
+ if math.IsNaN(tmp) {
+ return tmp
+ }
+ if tmp > value {
+ value = tmp
+ }
+ }
+ }
+ return value
+ }
+ var value float64
+ if uplo == blas.Upper {
+ for i := 0; i < m; i++ {
+ for j := i; j < n; j++ {
+ tmp := math.Abs(a[i*lda+j])
+ if math.IsNaN(tmp) {
+ return tmp
+ }
+ if tmp > value {
+ value = tmp
+ }
+ }
+ }
+ return value
+ }
+ for i := 0; i < m; i++ {
+ for j := 0; j <= min(i, n-1); j++ {
+ tmp := math.Abs(a[i*lda+j])
+ if math.IsNaN(tmp) {
+ return tmp
+ }
+ if tmp > value {
+ value = tmp
+ }
+ }
+ }
+ return value
+ case lapack.MaxColumnSum:
+ if diag == blas.Unit {
+ for i := 0; i < minmn; i++ {
+ work[i] = 1
+ }
+ for i := minmn; i < n; i++ {
+ work[i] = 0
+ }
+ if uplo == blas.Upper {
+ for i := 0; i < m; i++ {
+ for j := i + 1; j < n; j++ {
+ work[j] += math.Abs(a[i*lda+j])
+ }
+ }
+ } else {
+ for i := 1; i < m; i++ {
+ for j := 0; j < min(i, n); j++ {
+ work[j] += math.Abs(a[i*lda+j])
+ }
+ }
+ }
+ } else {
+ for i := 0; i < n; i++ {
+ work[i] = 0
+ }
+ if uplo == blas.Upper {
+ for i := 0; i < m; i++ {
+ for j := i; j < n; j++ {
+ work[j] += math.Abs(a[i*lda+j])
+ }
+ }
+ } else {
+ for i := 0; i < m; i++ {
+ for j := 0; j <= min(i, n-1); j++ {
+ work[j] += math.Abs(a[i*lda+j])
+ }
+ }
+ }
+ }
+ var max float64
+ for _, v := range work[:n] {
+ if math.IsNaN(v) {
+ return math.NaN()
+ }
+ if v > max {
+ max = v
+ }
+ }
+ return max
+ case lapack.MaxRowSum:
+ var maxsum float64
+ if diag == blas.Unit {
+ if uplo == blas.Upper {
+ for i := 0; i < m; i++ {
+ var sum float64
+ if i < minmn {
+ sum = 1
+ }
+ for j := i + 1; j < n; j++ {
+ sum += math.Abs(a[i*lda+j])
+ }
+ if math.IsNaN(sum) {
+ return math.NaN()
+ }
+ if sum > maxsum {
+ maxsum = sum
+ }
+ }
+ return maxsum
+ } else {
+ for i := 0; i < m; i++ {
+ var sum float64
+ if i < minmn {
+ sum = 1
+ }
+ for j := 0; j < min(i, n); j++ {
+ sum += math.Abs(a[i*lda+j])
+ }
+ if math.IsNaN(sum) {
+ return math.NaN()
+ }
+ if sum > maxsum {
+ maxsum = sum
+ }
+ }
+ return maxsum
+ }
+ } else {
+ if uplo == blas.Upper {
+ for i := 0; i < m; i++ {
+ var sum float64
+ for j := i; j < n; j++ {
+ sum += math.Abs(a[i*lda+j])
+ }
+ if math.IsNaN(sum) {
+ return sum
+ }
+ if sum > maxsum {
+ maxsum = sum
+ }
+ }
+ return maxsum
+ } else {
+ for i := 0; i < m; i++ {
+ var sum float64
+ for j := 0; j <= min(i, n-1); j++ {
+ sum += math.Abs(a[i*lda+j])
+ }
+ if math.IsNaN(sum) {
+ return sum
+ }
+ if sum > maxsum {
+ maxsum = sum
+ }
+ }
+ return maxsum
+ }
+ }
+ default:
+ // lapack.Frobenius
+ panic("not implemented")
+ }
+}

testlapack: add test for Dtrtrs