mat: move SolveLU* onto LU

This commit is contained in:
kortschak
2017-06-30 14:41:42 +09:30
committed by Dan Kortschak
parent f9e7e06e3e
commit d87e74cea0
3 changed files with 11 additions and 11 deletions

View File

@@ -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
// A * x = b if trans == false
// A^T * x = b if trans == true
// 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
// 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()
br, bc := b.Dims()
if br != n {
@@ -308,16 +308,16 @@ func (m *Dense) SolveLU(lu *LU, trans bool, b Matrix) error {
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
// A * x = b if trans == false
// A^T * x = b if trans == true
// 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
// 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()
bn := b.Len()
if bn != n {

View File

@@ -128,7 +128,7 @@ func TestSolveLU(t *testing.T) {
var lu LU
lu.Factorize(a)
var x Dense
if err := x.SolveLU(&lu, false, b); err != nil {
if err := lu.Solve(&x, false, b); err != nil {
continue
}
var got Dense
@@ -149,13 +149,13 @@ func TestSolveLUCond(t *testing.T) {
lu.Factorize(test)
b := NewDense(m, 2, nil)
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.")
}
bvec := NewVector(m, nil)
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.")
}
}
@@ -176,7 +176,7 @@ func TestSolveLUVec(t *testing.T) {
var lu LU
lu.Factorize(a)
var x Vector
if err := x.SolveLUVec(&lu, false, b); err != nil {
if err := lu.SolveVec(&x, false, b); err != nil {
continue
}
var got Vector

View File

@@ -91,7 +91,7 @@ func (m *Dense) Solve(a, b Matrix) error {
}
var lu LU
lu.Factorize(a)
return m.SolveLU(&lu, false, b)
return lu.Solve(m, false, b)
case ar > ac:
var qr QR
qr.Factorize(a)