mat: Add DiagView methods to types (#711)

* mat: Add DiagView methods to types

Fixes #213
This commit is contained in:
Brendan Tracey
2018-11-29 16:08:30 +00:00
committed by GitHub
parent 4a8f318905
commit b53e0d9ab0
14 changed files with 280 additions and 2 deletions

View File

@@ -296,6 +296,21 @@ func (t *TriDense) isolatedWorkspace(a Triangular) (w *TriDense, restore func())
}
}
// DiagView returns the diagonal as a matrix backed by the original data.
func (t *TriDense) DiagView() Diagonal {
if t.mat.Diag == blas.Unit {
panic("mat: cannot take view of Unit diagonal")
}
n := t.mat.N
return &DiagDense{
mat: blas64.Vector{
Inc: t.mat.Stride + 1,
Data: t.mat.Data[:(n-1)*t.mat.Stride+n],
},
n: n,
}
}
// Copy makes a copy of elements of a into the receiver. It is similar to the
// built-in copy; it copies as much as the overlap between the two matrices and
// returns the number of rows and columns it copied. Only elements within the