mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 15:47:01 +08:00
mat: move SolveLQ* onto LQ
This commit is contained in:
14
mat/lq.go
14
mat/lq.go
@@ -121,7 +121,7 @@ func (lq *LQ) QTo(dst *Dense) *Dense {
|
||||
return dst
|
||||
}
|
||||
|
||||
// SolveLQ 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 LQ factorized
|
||||
// form. If A is singular or near-singular a Condition error is returned. Please
|
||||
// see the documentation for Condition for more information.
|
||||
@@ -129,8 +129,8 @@ func (lq *LQ) QTo(dst *Dense) *Dense {
|
||||
// The minimization problem solved depends on the input parameters.
|
||||
// If trans == false, find the minimum norm solution of A * X = b.
|
||||
// If trans == true, find X such that ||A*X - b||_2 is minimized.
|
||||
// The solution matrix, X, is stored in place into the receiver.
|
||||
func (m *Dense) SolveLQ(lq *LQ, trans bool, b Matrix) error {
|
||||
// The solution matrix, X, is stored in place into m.
|
||||
func (lq *LQ) Solve(m *Dense, trans bool, b Matrix) error {
|
||||
r, c := lq.lq.Dims()
|
||||
br, bc := b.Dims()
|
||||
|
||||
@@ -188,9 +188,9 @@ func (m *Dense) SolveLQ(lq *LQ, trans bool, b Matrix) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SolveLQVec finds a minimum-norm solution to a system of linear equations.
|
||||
// Please see Dense.SolveLQ for the full documentation.
|
||||
func (v *Vector) SolveLQVec(lq *LQ, trans bool, b *Vector) error {
|
||||
// SolveVec finds a minimum-norm solution to a system of linear equations.
|
||||
// Please see LQ.Solve for the full documentation.
|
||||
func (lq *LQ) SolveVec(v *Vector, trans bool, b *Vector) error {
|
||||
if v != b {
|
||||
v.checkOverlap(b.mat)
|
||||
}
|
||||
@@ -202,5 +202,5 @@ func (v *Vector) SolveLQVec(lq *LQ, trans bool, b *Vector) error {
|
||||
} else {
|
||||
v.reuseAs(c)
|
||||
}
|
||||
return v.asDense().SolveLQ(lq, trans, b.asDense())
|
||||
return lq.Solve(v.asDense(), trans, b.asDense())
|
||||
}
|
||||
|
@@ -77,7 +77,7 @@ func TestSolveLQ(t *testing.T) {
|
||||
var x Dense
|
||||
lq := &LQ{}
|
||||
lq.Factorize(a)
|
||||
x.SolveLQ(lq, trans, b)
|
||||
lq.Solve(&x, trans, b)
|
||||
|
||||
// Test that the normal equations hold.
|
||||
// A^T * A * x = A^T * b if !trans
|
||||
@@ -130,7 +130,7 @@ func TestSolveLQVec(t *testing.T) {
|
||||
var x Vector
|
||||
lq := &LQ{}
|
||||
lq.Factorize(a)
|
||||
x.SolveLQVec(lq, trans, b)
|
||||
lq.SolveVec(&x, trans, b)
|
||||
|
||||
// Test that the normal equations hold.
|
||||
// A^T * A * x = A^T * b if !trans
|
||||
@@ -166,13 +166,13 @@ func TestSolveLQCond(t *testing.T) {
|
||||
lq.Factorize(test)
|
||||
b := NewDense(m, 2, nil)
|
||||
var x Dense
|
||||
if err := x.SolveLQ(&lq, false, b); err == nil {
|
||||
if err := lq.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.SolveLQVec(&lq, false, bvec); err == nil {
|
||||
if err := lq.SolveVec(&xvec, false, bvec); err == nil {
|
||||
t.Error("No error for near-singular matrix in matrix solve.")
|
||||
}
|
||||
}
|
||||
|
@@ -99,7 +99,7 @@ func (m *Dense) Solve(a, b Matrix) error {
|
||||
default:
|
||||
var lq LQ
|
||||
lq.Factorize(a)
|
||||
return m.SolveLQ(&lq, false, b)
|
||||
return lq.Solve(m, false, b)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user