mirror of
https://github.com/gonum/gonum.git
synced 2025-10-20 05:54:41 +08:00
mat: Add Scale method for TriDense and Cholesky (#267)
* mat: Add Scale method for TriDense and Cholesky
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user