mat: move SolveQR* onto QR

This commit is contained in:
kortschak
2017-06-30 14:46:34 +09:30
committed by Dan Kortschak
parent d87e74cea0
commit bba47c3605
3 changed files with 14 additions and 14 deletions

View File

@@ -117,7 +117,7 @@ func (qr *QR) QTo(dst *Dense) *Dense {
return dst
}
// SolveQR finds a minimum-norm solution to a system of linear equations defined
// Solve finds a minimum-norm solution to a system of linear equations defined
// by the matrices A and b, where A is an m×n matrix represented in its QR factorized
// form. If A is singular or near-singular a Condition error is returned. Please
// see the documentation for Condition for more information.
@@ -125,8 +125,8 @@ func (qr *QR) QTo(dst *Dense) *Dense {
// The minimization problem solved depends on the input parameters.
// If trans == false, find X such that ||A*X - b||_2 is minimized.
// If trans == true, find the minimum norm solution of A^T * X = b.
// The solution matrix, X, is stored in place into the receiver.
func (m *Dense) SolveQR(qr *QR, trans bool, b Matrix) error {
// The solution matrix, X, is stored in place into m.
func (qr *QR) Solve(m *Dense, trans bool, b Matrix) error {
r, c := qr.qr.Dims()
br, bc := b.Dims()
@@ -184,9 +184,9 @@ func (m *Dense) SolveQR(qr *QR, trans bool, b Matrix) error {
return nil
}
// SolveQRVec finds a minimum-norm solution to a system of linear equations.
// Please see Dense.SolveQR for the full documentation.
func (v *Vector) SolveQRVec(qr *QR, trans bool, b *Vector) error {
// SolveVec finds a minimum-norm solution to a system of linear equations.
// Please see QR.Solve for the full documentation.
func (qr *QR) SolveVec(v *Vector, trans bool, b *Vector) error {
if v != b {
v.checkOverlap(b.mat)
}
@@ -198,5 +198,5 @@ func (v *Vector) SolveQRVec(qr *QR, trans bool, b *Vector) error {
} else {
v.reuseAs(c)
}
return v.asDense().SolveQR(qr, trans, b.asDense())
return qr.Solve(v.asDense(), trans, b.asDense())
}

View File

@@ -101,9 +101,9 @@ func TestSolveQR(t *testing.T) {
}
}
var x Dense
qr := &QR{}
var qr QR
qr.Factorize(a)
x.SolveQR(qr, trans, b)
qr.Solve(&x, trans, b)
// Test that the normal equations hold.
// A^T * A * x = A^T * b if !trans
@@ -154,9 +154,9 @@ func TestSolveQRVec(t *testing.T) {
b.SetVec(i, rand.Float64())
}
var x Vector
qr := &QR{}
var qr QR
qr.Factorize(a)
x.SolveQRVec(qr, trans, b)
qr.SolveVec(&x, trans, b)
// Test that the normal equations hold.
// A^T * A * x = A^T * b if !trans
@@ -192,13 +192,13 @@ func TestSolveQRCond(t *testing.T) {
qr.Factorize(test)
b := NewDense(m, 2, nil)
var x Dense
if err := x.SolveQR(&qr, false, b); err == nil {
if err := qr.Solve(&x, false, b); err == nil {
t.Error("No error for near-singular matrix in matrix solve.")
}
bvec := NewVector(m, nil)
var xvec Vector
if err := xvec.SolveQRVec(&qr, false, bvec); err == nil {
if err := qr.SolveVec(&xvec, false, bvec); err == nil {
t.Error("No error for near-singular matrix in matrix solve.")
}
}

View File

@@ -95,7 +95,7 @@ func (m *Dense) Solve(a, b Matrix) error {
case ar > ac:
var qr QR
qr.Factorize(a)
return m.SolveQR(&qr, false, b)
return qr.Solve(m, false, b)
default:
var lq LQ
lq.Factorize(a)