mat: add VecDense and RawVectorer cases to untransposeExtract (#1186)

* mat: add VecDense.SetRawVector
* mat: add VecDense and RawVectorer cases to untransposeExtract
* mat: add comments to VecDense.{RawVector,SetRawVector}
This commit is contained in:
Vladimír Chalupecký
2019-11-28 00:24:04 +01:00
committed by GitHub
parent 7df05ce3f8
commit af3666d0f9
2 changed files with 15 additions and 1 deletions

View File

@@ -244,7 +244,7 @@ func untranspose(a Matrix) (Matrix, bool) {
func untransposeExtract(a Matrix) (Matrix, bool) { func untransposeExtract(a Matrix) (Matrix, bool) {
ut, trans := untranspose(a) ut, trans := untranspose(a)
switch m := ut.(type) { switch m := ut.(type) {
case *DiagDense, *SymBandDense, *TriBandDense, *BandDense, *TriDense, *SymDense, *Dense: case *DiagDense, *SymBandDense, *TriBandDense, *BandDense, *TriDense, *SymDense, *Dense, *VecDense:
return m, trans return m, trans
// TODO(btracey): Add here if we ever have an equivalent of RawDiagDense. // TODO(btracey): Add here if we ever have an equivalent of RawDiagDense.
case RawSymBander: case RawSymBander:
@@ -287,6 +287,10 @@ func untransposeExtract(a Matrix) (Matrix, bool) {
var d Dense var d Dense
d.SetRawMatrix(m.RawMatrix()) d.SetRawMatrix(m.RawMatrix())
return &d, trans return &d, trans
case RawVectorer:
var v VecDense
v.SetRawVector(m.RawVector())
return &v, trans
default: default:
return ut, trans return ut, trans
} }

View File

@@ -215,10 +215,20 @@ func VecDenseCopyOf(a Vector) *VecDense {
return v return v
} }
// RawVector returns the underlying blas64.Vector used by the receiver.
// Changes to elements in the receiver following the call will be reflected
// in returned blas64.Vector.
func (v *VecDense) RawVector() blas64.Vector { func (v *VecDense) RawVector() blas64.Vector {
return v.mat return v.mat
} }
// SetRawVector sets the underlying blas64.Vector used by the receiver.
// Changes to elements in the receiver following the call will be reflected
// in the input.
func (v *VecDense) SetRawVector(a blas64.Vector) {
v.mat = a
}
// CopyVec makes a copy of elements of a into the receiver. It is similar to the // CopyVec 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 vectors and // built-in copy; it copies as much as the overlap between the two vectors and
// returns the number of elements it copied. // returns the number of elements it copied.