mat: Add Scale method for TriDense and Cholesky (#267)

* mat: Add Scale method for TriDense and Cholesky
This commit is contained in:
Brendan Tracey
2017-10-19 07:24:29 -06:00
committed by GitHub
parent 38fbc22caf
commit ac9ad9e533
5 changed files with 173 additions and 0 deletions

View File

@@ -308,6 +308,31 @@ func (c *Cholesky) InverseTo(s *SymDense) error {
return err
}
// Scale multiplies the original matrix A by a positive constant using
// its Cholesky decomposition, storing the result in-place into the receiver.
// That is, if the original Cholesky factorization is
// U^T * U = A
// the updated factorization is
// U'^T * U' = f A = A'
// Scale panics if the constant is non-positive, or if the receiver is non-zero
// and is of a different Size from the input.
func (c *Cholesky) Scale(f float64, orig *Cholesky) {
if !orig.valid() {
panic(badCholesky)
}
if f <= 0 {
panic("cholesky: scaling by a non-positive constant")
}
n := orig.Size()
if c.isZero() {
c.chol = NewTriDense(n, Upper, nil)
} else if c.chol.mat.N != n {
panic(ErrShape)
}
c.chol.ScaleTri(math.Sqrt(f), orig.chol)
c.cond = orig.cond // Scaling by a positive constant does not change the condition number.
}
// SymRankOne performs a rank-1 update of the original matrix A and refactorizes
// its Cholesky factorization, storing the result into the receiver. That is, if
// in the original Cholesky factorization