mat: add VecDenseCopyOf function

This commit is contained in:
kortschak
2017-08-04 11:25:31 +09:30
committed by Dan Kortschak
parent afe00782c1
commit 785258ce25
3 changed files with 32 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ var (
// Vector is a column vector.
type Vector interface {
Matrix
AtVec(int) float64
Len() int
}
@@ -120,16 +121,29 @@ func (v *VecDense) Reset() {
// CloneVec makes a copy of a into the receiver, overwriting the previous value
// of the receiver.
func (v *VecDense) CloneVec(a *VecDense) {
func (v *VecDense) CloneVec(a Vector) {
if v == a {
return
}
v.n = a.n
v.n = a.Len()
v.mat = blas64.Vector{
Inc: 1,
Data: use(v.mat.Data, v.n),
}
blas64.Copy(v.n, a.mat, v.mat)
if r, ok := a.(RawVectorer); ok {
blas64.Copy(v.n, r.RawVector(), v.mat)
return
}
for i := 0; i < a.Len(); i++ {
v.SetVec(i, a.AtVec(i))
}
}
// VecDenseCopyOf returns a newly allocated copy of the elements of a.
func VecDenseCopyOf(a Vector) *VecDense {
v := &VecDense{}
v.CloneVec(a)
return v
}
func (v *VecDense) RawVector() blas64.Vector {