mirror of
https://github.com/gonum/gonum.git
synced 2025-10-09 00:50:16 +08:00
mat: move SolveLU* onto LU
This commit is contained in:
12
mat/lu.go
12
mat/lu.go
@@ -265,16 +265,16 @@ func (m *Dense) Permutation(r int, swaps []int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SolveLU solves a system of linear equations using the LU decomposition of a matrix.
|
// Solve solves a system of linear equations using the LU decomposition of a matrix.
|
||||||
// It computes
|
// It computes
|
||||||
// A * x = b if trans == false
|
// A * x = b if trans == false
|
||||||
// A^T * x = b if trans == true
|
// A^T * x = b if trans == true
|
||||||
// In both cases, A is represented in LU factorized form, and the matrix x is
|
// In both cases, A is represented in LU factorized form, and the matrix x is
|
||||||
// stored into the receiver.
|
// stored into m.
|
||||||
//
|
//
|
||||||
// If A is singular or near-singular a Condition error is returned. Please see
|
// If A is singular or near-singular a Condition error is returned. Please see
|
||||||
// the documentation for Condition for more information.
|
// the documentation for Condition for more information.
|
||||||
func (m *Dense) SolveLU(lu *LU, trans bool, b Matrix) error {
|
func (lu *LU) Solve(m *Dense, trans bool, b Matrix) error {
|
||||||
_, n := lu.lu.Dims()
|
_, n := lu.lu.Dims()
|
||||||
br, bc := b.Dims()
|
br, bc := b.Dims()
|
||||||
if br != n {
|
if br != n {
|
||||||
@@ -308,16 +308,16 @@ func (m *Dense) SolveLU(lu *LU, trans bool, b Matrix) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SolveLUVec solves a system of linear equations using the LU decomposition of a matrix.
|
// SolveVec solves a system of linear equations using the LU decomposition of a matrix.
|
||||||
// It computes
|
// It computes
|
||||||
// A * x = b if trans == false
|
// A * x = b if trans == false
|
||||||
// A^T * x = b if trans == true
|
// A^T * x = b if trans == true
|
||||||
// In both cases, A is represented in LU factorized form, and the matrix x is
|
// In both cases, A is represented in LU factorized form, and the matrix x is
|
||||||
// stored into the receiver.
|
// stored into v.
|
||||||
//
|
//
|
||||||
// If A is singular or near-singular a Condition error is returned. Please see
|
// If A is singular or near-singular a Condition error is returned. Please see
|
||||||
// the documentation for Condition for more information.
|
// the documentation for Condition for more information.
|
||||||
func (v *Vector) SolveLUVec(lu *LU, trans bool, b *Vector) error {
|
func (lu *LU) SolveVec(v *Vector, trans bool, b *Vector) error {
|
||||||
_, n := lu.lu.Dims()
|
_, n := lu.lu.Dims()
|
||||||
bn := b.Len()
|
bn := b.Len()
|
||||||
if bn != n {
|
if bn != n {
|
||||||
|
@@ -128,7 +128,7 @@ func TestSolveLU(t *testing.T) {
|
|||||||
var lu LU
|
var lu LU
|
||||||
lu.Factorize(a)
|
lu.Factorize(a)
|
||||||
var x Dense
|
var x Dense
|
||||||
if err := x.SolveLU(&lu, false, b); err != nil {
|
if err := lu.Solve(&x, false, b); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var got Dense
|
var got Dense
|
||||||
@@ -149,13 +149,13 @@ func TestSolveLUCond(t *testing.T) {
|
|||||||
lu.Factorize(test)
|
lu.Factorize(test)
|
||||||
b := NewDense(m, 2, nil)
|
b := NewDense(m, 2, nil)
|
||||||
var x Dense
|
var x Dense
|
||||||
if err := x.SolveLU(&lu, false, b); err == nil {
|
if err := lu.Solve(&x, false, b); err == nil {
|
||||||
t.Error("No error for near-singular matrix in matrix solve.")
|
t.Error("No error for near-singular matrix in matrix solve.")
|
||||||
}
|
}
|
||||||
|
|
||||||
bvec := NewVector(m, nil)
|
bvec := NewVector(m, nil)
|
||||||
var xvec Vector
|
var xvec Vector
|
||||||
if err := xvec.SolveLUVec(&lu, false, bvec); err == nil {
|
if err := lu.SolveVec(&xvec, false, bvec); err == nil {
|
||||||
t.Error("No error for near-singular matrix in matrix solve.")
|
t.Error("No error for near-singular matrix in matrix solve.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ func TestSolveLUVec(t *testing.T) {
|
|||||||
var lu LU
|
var lu LU
|
||||||
lu.Factorize(a)
|
lu.Factorize(a)
|
||||||
var x Vector
|
var x Vector
|
||||||
if err := x.SolveLUVec(&lu, false, b); err != nil {
|
if err := lu.SolveVec(&x, false, b); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var got Vector
|
var got Vector
|
||||||
|
@@ -91,7 +91,7 @@ func (m *Dense) Solve(a, b Matrix) error {
|
|||||||
}
|
}
|
||||||
var lu LU
|
var lu LU
|
||||||
lu.Factorize(a)
|
lu.Factorize(a)
|
||||||
return m.SolveLU(&lu, false, b)
|
return lu.Solve(m, false, b)
|
||||||
case ar > ac:
|
case ar > ac:
|
||||||
var qr QR
|
var qr QR
|
||||||
qr.Factorize(a)
|
qr.Factorize(a)
|
||||||
|
Reference in New Issue
Block a user