testlapack: review comments for Dlatm1

This commit is contained in:
Vladimir Chalupecky
2017-02-18 23:46:08 +01:00
parent 5cd69473f3
commit 3ead0bc971

View File

@@ -9,30 +9,30 @@ import (
"math/rand" "math/rand"
) )
// Dlatm1 computes the entries of d as specified by mode, cond and rsign. // Dlatm1 computes the entries of dst as specified by mode, cond and rsign.
// //
// mode describes how d will be computed: // mode describes how dst will be computed:
// |mode| == 1: d[0] = 1 and d[1:n] = 1/cond // |mode| == 1: dst[0] = 1 and dst[1:n] = 1/cond
// |mode| == 2: d[:n-1] = 1/cond and d[n-1] = 1 // |mode| == 2: dst[:n-1] = 1/cond and dst[n-1] = 1
// |mode| == 3: d[i] = cond^{-i/(n-1)}, i=0,...,n-1 // |mode| == 3: dst[i] = cond^{-i/(n-1)}, i=0,...,n-1
// |mode| == 4: d[i] = 1 - i*(1-1/cond)/(n-1) // |mode| == 4: dst[i] = 1 - i*(1-1/cond)/(n-1)
// |mode| == 5: d[i] = random number in the range (1/cond, 1) such that // |mode| == 5: dst[i] = random number in the range (1/cond, 1) such that
// their logarithms are uniformly distributed // their logarithms are uniformly distributed
// |mode| == 6: d[i] = random number from the distribution given by dist // |mode| == 6: dst[i] = random number from the distribution given by dist
// If mode is negative, the order of the elements of d will be reversed. // If mode is negative, the order of the elements of dst will be reversed.
// For other values of mode Dlatm1 will panic. // For other values of mode Dlatm1 will panic.
// //
// if rsign is true and mode is not ±6, each entry of d will be multiplied by 1 // If rsign is true and mode is not ±6, each entry of dst will be multiplied by 1
// or -1 with probability 0.5 // or -1 with probability 0.5
// //
// dist specifies the type of distribution to be used when mode == ±6: // dist specifies the type of distribution to be used when mode == ±6:
// dist == 1: Uniform(0,1) // dist == 1: Uniform[0,1)
// dist == 2: Uniform(-1,1) // dist == 2: Uniform[-1,1)
// dist == 3: Normal(0,1) // dist == 3: Normal(0,1)
// For other values of dist Dlatm1 will panic. // For other values of dist Dlatm1 will panic.
// //
// rnd is used as a source of random numbers. // rnd is used as a source of random numbers.
func Dlatm1(mode int, cond float64, rsign bool, dist int, rnd *rand.Rand, d []float64) { func Dlatm1(dst []float64, mode int, cond float64, rsign bool, dist int, rnd *rand.Rand) {
amode := mode amode := mode
if amode < 0 { if amode < 0 {
amode = -amode amode = -amode
@@ -43,76 +43,76 @@ func Dlatm1(mode int, cond float64, rsign bool, dist int, rnd *rand.Rand, d []fl
if cond < 1 { if cond < 1 {
panic("testlapack: cond < 1") panic("testlapack: cond < 1")
} }
if dist != 1 && dist != 2 && dist != 3 { if amode == 6 && (dist < 1 || 3 < dist) {
panic("testlapack: invalid dist") panic("testlapack: invalid dist")
} }
n := len(d) n := len(dst)
if n == 0 { if n == 0 {
return return
} }
switch amode { switch amode {
case 1: case 1:
d[0] = 1 dst[0] = 1
for i := 1; i < n; i++ { for i := 1; i < n; i++ {
d[i] = 1 / cond dst[i] = 1 / cond
} }
case 2: case 2:
for i := 0; i < n-1; i++ { for i := 0; i < n-1; i++ {
d[i] = 1 dst[i] = 1
} }
d[n-1] = 1 / cond dst[n-1] = 1 / cond
case 3: case 3:
d[0] = 1 dst[0] = 1
if n > 1 { if n > 1 {
alpha := math.Pow(cond, -1/float64(n-1)) alpha := math.Pow(cond, -1/float64(n-1))
for i := 1; i < n; i++ { for i := 1; i < n; i++ {
d[i] = math.Pow(alpha, float64(i)) dst[i] = math.Pow(alpha, float64(i))
} }
} }
case 4: case 4:
d[0] = 1 dst[0] = 1
if n > 1 { if n > 1 {
condInv := 1 / cond condInv := 1 / cond
alpha := (1 - condInv) / float64(n-1) alpha := (1 - condInv) / float64(n-1)
for i := 1; i < n; i++ { for i := 1; i < n; i++ {
d[i] = float64(n-i-1)*alpha + condInv dst[i] = float64(n-i-1)*alpha + condInv
} }
} }
case 5: case 5:
alpha := math.Log(1 / cond) alpha := math.Log(1 / cond)
for i := range d { for i := range dst {
d[i] = math.Exp(alpha * rnd.Float64()) dst[i] = math.Exp(alpha * rnd.Float64())
} }
case 6: case 6:
switch dist { switch dist {
case 1: case 1:
for i := range d { for i := range dst {
d[i] = rnd.Float64() dst[i] = rnd.Float64()
} }
case 2: case 2:
for i := range d { for i := range dst {
d[i] = 2*rnd.Float64() - 1 dst[i] = 2*rnd.Float64() - 1
} }
case 3: case 3:
for i := range d { for i := range dst {
d[i] = rnd.NormFloat64() dst[i] = rnd.NormFloat64()
} }
} }
} }
if rsign && mode != -6 && mode != 6 { if rsign && amode != 6 {
for i, v := range d { for i, v := range dst {
if rnd.Float64() < 0.5 { if rnd.Float64() < 0.5 {
d[i] = -v dst[i] = -v
} }
} }
} }
if mode < 0 { if mode < 0 {
for i := 0; i < n/2; i++ { for i := 0; i < n/2; i++ {
d[i], d[n-i-1] = d[n-i-1], d[i] dst[i], dst[n-i-1] = dst[n-i-1], dst[i]
} }
} }
} }