mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 15:47:01 +08:00
mat: implement helper routines for type extraction and update Trace to use an interface (#932)
* Implement helper routines for type extraction and update Trace to use an interface. Updates #929.
This commit is contained in:
@@ -217,6 +217,18 @@ func (t *TriDense) RawTriangular() blas64.Triangular {
|
||||
return t.mat
|
||||
}
|
||||
|
||||
// SetRawTriangular sets the underlying blas64.Triangular used by the receiver.
|
||||
// Changes to elements in the receiver following the call will be reflected
|
||||
// in the input.
|
||||
//
|
||||
// The supplied Triangular must not use blas.Unit storage format.
|
||||
func (t *TriDense) SetRawTriangular(mat blas64.Triangular) {
|
||||
if mat.Diag == blas.Unit {
|
||||
panic("mat: cannot set TriDense with Unit storage format")
|
||||
}
|
||||
t.mat = mat
|
||||
}
|
||||
|
||||
// Reset zeros the dimensions of the matrix so that it can be reused as the
|
||||
// receiver of a dimensionally restricted operation.
|
||||
//
|
||||
@@ -513,6 +525,16 @@ func (t *TriDense) ScaleTri(f float64, a Triangular) {
|
||||
}
|
||||
}
|
||||
|
||||
// Trace returns the trace of the matrix.
|
||||
func (t *TriDense) Trace() float64 {
|
||||
// TODO(btracey): could use internal asm sum routine.
|
||||
var v float64
|
||||
for i := 0; i < t.mat.N; i++ {
|
||||
v += t.mat.Data[i*t.mat.Stride+i]
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// copySymIntoTriangle copies a symmetric matrix into a TriDense
|
||||
func copySymIntoTriangle(t *TriDense, s Symmetric) {
|
||||
n, upper := t.Triangle()
|
||||
|
Reference in New Issue
Block a user