matrix/mat64: reverse API signatures for matrix extraction
MODIFY
matrix/mat64/gsvd_example_test.go
matrix/mat64/gsvd_example_test.go
@@ -26,8 +26,8 @@ func ExampleGSVD() {
}
var u, v mat64.Dense
- u.UFromGSVD(&gsvd)
- v.VFromGSVD(&gsvd)
+ gsvd.UTo(&u)
+ gsvd.VTo(&v)
s1 := gsvd.ValuesA(nil)
s2 := gsvd.ValuesB(nil)
@@ -38,8 +38,8 @@ func ExampleGSVD() {
s2, mat64.Formatted(&v, mat64.Prefix("\t "), mat64.Excerpt(2)))
var zeroR, q mat64.Dense
- zeroR.ZeroRFromGSVD(&gsvd)
- q.QFromGSVD(&gsvd)
+ gsvd.ZeroRTo(&zeroR)
+ gsvd.QTo(&q)
q.Mul(&zeroR, &q)
fmt.Printf("\nCommon basis vectors\n\n\tQ^T = %.4f\n",
mat64.Formatted(q.T(), mat64.Prefix("\t ")))

MODIFY
matrix/mat64/gsvd_test.go
matrix/mat64/gsvd_test.go
@@ -107,12 +107,12 @@ func TestGSVD(t *testing.T) {
func extractGSVD(gsvd *GSVD) (c, s []float64, s1, s2, zR, u, v, q *Dense) {
var s1m, s2m, zeroR, um, vm, qm Dense
- s1m.SigmaAFromGSVD(gsvd)
- s2m.SigmaBFromGSVD(gsvd)
- zeroR.ZeroRFromGSVD(gsvd)
- um.UFromGSVD(gsvd)
- vm.VFromGSVD(gsvd)
- qm.QFromGSVD(gsvd)
+ gsvd.SigmaATo(&s1m)
+ gsvd.SigmaBTo(&s2m)
+ gsvd.ZeroRTo(&zeroR)
+ gsvd.UTo(&um)
+ gsvd.VTo(&vm)
+ gsvd.QTo(&qm)
c = gsvd.ValuesA(nil)
s = gsvd.ValuesB(nil)
return c, s, &s1m, &s2m, &zeroR, &um, &vm, &qm

MODIFY
matrix/mat64/hogsvd_example_test.go
matrix/mat64/hogsvd_example_test.go
@@ -25,14 +25,14 @@ func ExampleHOGSVD() {
for i, n := range []string{"Africa", "Asia", "Latin America/Caribbean", "Oceania"} {
var u mat64.Dense
- u.UFromHOGSVD(&gsvd, i)
+ gsvd.UTo(&u, i)
s := gsvd.Values(nil, i)
fmt.Printf("%s\n\ts_%d = %.4f\n\n\tU_%[2]d = %.4[4]f\n",
n, i, s, mat64.Formatted(&u, mat64.Prefix("\t ")))
}
var v mat64.Dense
- v.VFromHOGSVD(&gsvd)
+ gsvd.VTo(&v)
fmt.Printf("\nCommon basis vectors\n\n\tV^T = %.4f",
mat64.Formatted(v.T(), mat64.Prefix("\t ")))

MODIFY
matrix/mat64/hogsvd_test.go
matrix/mat64/hogsvd_test.go
@@ -80,10 +80,10 @@ func extractHOGSVD(gsvd *HOGSVD) (u []*Dense, s [][]float64, v *Dense) {
s = make([][]float64, gsvd.Len())
for i := 0; i < gsvd.Len(); i++ {
u[i] = &Dense{}
- u[i].UFromHOGSVD(gsvd, i)
+ gsvd.UTo(u[i], i)
s[i] = gsvd.Values(nil, i)
}
v = &Dense{}
- v.VFromHOGSVD(gsvd)
+ gsvd.VTo(v)
return u, s, v
}

MODIFY
matrix/mat64/lq_test.go
matrix/mat64/lq_test.go
@@ -27,16 +27,16 @@ func TestLQ(t *testing.T) {
var want Dense
want.Clone(a)
- lq := &LQ{}
+ var lq LQ
lq.Factorize(a)
var l, q Dense
- q.QFromLQ(lq)
+ lq.QTo(&q)
if !isOrthonormal(&q, 1e-10) {
t.Errorf("Q is not orthonormal: m = %v, n = %v", m, n)
}
- l.LFromLQ(lq)
+ lq.LTo(&l)
var got Dense
got.Mul(&l, &q)

MODIFY
matrix/mat64/lu.go
matrix/mat64/lu.go
@@ -51,7 +51,7 @@ func (lu *LU) updateCond(norm float64) {
// The LU factorization is computed with pivoting, and so really the decomposition
// is a PLU decomposition where P is a permutation matrix. The individual matrix
// factors can be extracted from the factorization using the Permutation method
-// on Dense, and the LFrom and UFrom methods on TriDense.
+// on Dense, and the LU LTo and UTo methods.
func (lu *LU) Factorize(a Matrix) {
r, c := a.Dims()
if r != c {
@@ -204,30 +204,30 @@ func (lu *LU) RankOne(orig *LU, alpha float64, x, y *Vector) {
lu.updateCond(-1)
}
-// LFromLU extracts the lower triangular matrix from an LU factorization.
-func (t *TriDense) LFromLU(lu *LU) {
+// LTo extracts the lower triangular matrix from an LU factorization.
+func (lu *LU) LTo(dst *TriDense) {
_, n := lu.lu.Dims()
- t.reuseAs(n, false)
+ dst.reuseAs(n, false)
// Extract the lower triangular elements.
for i := 0; i < n; i++ {
for j := 0; j < i; j++ {
- t.mat.Data[i*t.mat.Stride+j] = lu.lu.mat.Data[i*lu.lu.mat.Stride+j]
+ dst.mat.Data[i*dst.mat.Stride+j] = lu.lu.mat.Data[i*lu.lu.mat.Stride+j]
}
}
// Set ones on the diagonal.
for i := 0; i < n; i++ {
- t.mat.Data[i*t.mat.Stride+i] = 1
+ dst.mat.Data[i*dst.mat.Stride+i] = 1
}
}
-// UFromLU extracts the upper triangular matrix from an LU factorization.
-func (t *TriDense) UFromLU(lu *LU) {
+// UTo extracts the upper triangular matrix from an LU factorization.
+func (lu *LU) UTo(dst *TriDense) {
_, n := lu.lu.Dims()
- t.reuseAs(n, true)
+ dst.reuseAs(n, true)
// Extract the upper triangular elements.
for i := 0; i < n; i++ {
for j := i; j < n; j++ {
- t.mat.Data[i*t.mat.Stride+j] = lu.lu.mat.Data[i*lu.lu.mat.Stride+j]
+ dst.mat.Data[i*dst.mat.Stride+j] = lu.lu.mat.Data[i*lu.lu.mat.Stride+j]
}
}
}

MODIFY
matrix/mat64/lu_test.go
matrix/mat64/lu_test.go
@@ -20,12 +20,12 @@ func TestLUD(t *testing.T) {
var want Dense
want.Clone(a)
- lu := &LU{}
+ var lu LU
lu.Factorize(a)
var l, u TriDense
- l.LFromLU(lu)
- u.UFromLU(lu)
+ lu.LTo(&l)
+ lu.UTo(&u)
var p Dense
pivot := lu.Pivot(nil)
p.Permutation(n, pivot)
@@ -93,8 +93,8 @@ func TestLURankOne(t *testing.T) {
// luReconstruct reconstructs the original A matrix from an LU decomposition.
func luReconstruct(lu *LU) *Dense {
var L, U TriDense
- L.LFromLU(lu)
- U.UFromLU(lu)
+ lu.LTo(&L)
+ lu.UTo(&U)
var P Dense
pivot := lu.Pivot(nil)
P.Permutation(len(pivot), pivot)

MODIFY
matrix/mat64/qr_test.go
matrix/mat64/qr_test.go
@@ -30,16 +30,16 @@ func TestQR(t *testing.T) {
var want Dense
want.Clone(a)
- qr := &QR{}
+ var qr QR
qr.Factorize(a)
var q, r Dense
- q.QFromQR(qr)
+ qr.QTo(&q)
if !isOrthonormal(&q, 1e-10) {
t.Errorf("Q is not orthonormal: m = %v, n = %v", m, n)
}
- r.RFromQR(qr)
+ qr.RTo(&r)
var got Dense
got.Mul(&q, &r)

MODIFY
matrix/mat64/svd_test.go
matrix/mat64/svd_test.go
@@ -170,8 +170,8 @@ func TestSVD(t *testing.T) {
func extractSVD(svd *SVD) (s []float64, u, v *Dense) {
var um, vm Dense
- um.UFromSVD(svd)
- vm.VFromSVD(svd)
+ svd.UTo(&um)
+ svd.VTo(&vm)
s = svd.Values(nil)
return s, &um, &vm
}

matrix/mat64: reverse API signatures for matrix extraction