mat: replace untranspose with untransposeExtract
* mat: replace untranspose with untransposeExtract
This leaves one remaining use in TriDense but that case is a bit more complicated
MODIFY
mat/dense.go
mat/dense.go
@@ -389,10 +389,10 @@ func (m *Dense) CloneFrom(a Matrix) {
}
m.capRows, m.capCols = r, c
- aU, trans := untranspose(a)
+ aU, trans := untransposeExtract(a)
switch aU := aU.(type) {
- case RawMatrixer:
- amat := aU.RawMatrix()
+ case *Dense:
+ amat := aU.mat
mat.Data = make([]float64, r*c)
if trans {
for i := 0; i < r; i++ {
@@ -442,10 +442,10 @@ func (m *Dense) Copy(a Matrix) (r, c int) {
return 0, 0
}
- aU, trans := untranspose(a)
+ aU, trans := untransposeExtract(a)
switch aU := aU.(type) {
- case RawMatrixer:
- amat := aU.RawMatrix()
+ case *Dense:
+ amat := aU.mat
if trans {
if amat.Stride != 1 {
m.checkOverlap(amat)

MODIFY
mat/dense_arithmetic.go
mat/dense_arithmetic.go
@@ -21,13 +21,13 @@ func (m *Dense) Add(a, b Matrix) {
panic(ErrShape)
}
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
m.reuseAs(ar, ac)
- if arm, ok := a.(RawMatrixer); ok {
- if brm, ok := b.(RawMatrixer); ok {
- amat, bmat := arm.RawMatrix(), brm.RawMatrix()
+ if arm, ok := a.(*Dense); ok {
+ if brm, ok := b.(*Dense); ok {
+ amat, bmat := arm.mat, brm.mat
if m != aU {
m.checkOverlap(amat)
}
@@ -70,13 +70,13 @@ func (m *Dense) Sub(a, b Matrix) {
panic(ErrShape)
}
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
m.reuseAs(ar, ac)
- if arm, ok := a.(RawMatrixer); ok {
- if brm, ok := b.(RawMatrixer); ok {
- amat, bmat := arm.RawMatrix(), brm.RawMatrix()
+ if arm, ok := a.(*Dense); ok {
+ if brm, ok := b.(*Dense); ok {
+ amat, bmat := arm.mat, brm.mat
if m != aU {
m.checkOverlap(amat)
}
@@ -120,13 +120,13 @@ func (m *Dense) MulElem(a, b Matrix) {
panic(ErrShape)
}
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
m.reuseAs(ar, ac)
- if arm, ok := a.(RawMatrixer); ok {
- if brm, ok := b.(RawMatrixer); ok {
- amat, bmat := arm.RawMatrix(), brm.RawMatrix()
+ if arm, ok := a.(*Dense); ok {
+ if brm, ok := b.(*Dense); ok {
+ amat, bmat := arm.mat, brm.mat
if m != aU {
m.checkOverlap(amat)
}
@@ -170,13 +170,13 @@ func (m *Dense) DivElem(a, b Matrix) {
panic(ErrShape)
}
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
m.reuseAs(ar, ac)
- if arm, ok := a.(RawMatrixer); ok {
- if brm, ok := b.(RawMatrixer); ok {
- amat, bmat := arm.RawMatrix(), brm.RawMatrix()
+ if arm, ok := a.(*Dense); ok {
+ if brm, ok := b.(*Dense); ok {
+ amat, bmat := arm.mat, brm.mat
if m != aU {
m.checkOverlap(amat)
}
@@ -221,11 +221,11 @@ func (m *Dense) Inverse(a Matrix) error {
panic(ErrSquare)
}
m.reuseAs(a.Dims())
- aU, aTrans := untranspose(a)
+ aU, aTrans := untransposeExtract(a)
switch rm := aU.(type) {
- case RawMatrixer:
+ case *Dense:
if m != aU || aTrans {
- if m == aU || m.checkOverlap(rm.RawMatrix()) {
+ if m == aU || m.checkOverlap(rm.mat) {
tmp := getWorkspace(r, c, false)
tmp.Copy(a)
m.Copy(tmp)
@@ -681,9 +681,9 @@ func (m *Dense) Scale(f float64, a Matrix) {
m.reuseAs(ar, ac)
- aU, aTrans := untranspose(a)
- if rm, ok := aU.(RawMatrixer); ok {
- amat := rm.RawMatrix()
+ aU, aTrans := untransposeExtract(a)
+ if rm, ok := aU.(*Dense); ok {
+ amat := rm.mat
if m == aU || m.checkOverlap(amat) {
var restore func()
m, restore = m.isolatedWorkspace(a)
@@ -721,9 +721,9 @@ func (m *Dense) Apply(fn func(i, j int, v float64) float64, a Matrix) {
m.reuseAs(ar, ac)
- aU, aTrans := untranspose(a)
- if rm, ok := aU.(RawMatrixer); ok {
- amat := rm.RawMatrix()
+ aU, aTrans := untransposeExtract(a)
+ if rm, ok := aU.(*Dense); ok {
+ amat := rm.mat
if m == aU || m.checkOverlap(amat) {
var restore func()
m, restore = m.isolatedWorkspace(a)
@@ -767,26 +767,26 @@ func (m *Dense) RankOne(a Matrix, alpha float64, x, y Vector) {
}
if a != m {
- aU, _ := untranspose(a)
- if rm, ok := aU.(RawMatrixer); ok {
+ aU, _ := untransposeExtract(a)
+ if rm, ok := aU.(*Dense); ok {
m.checkOverlap(rm.RawMatrix())
}
}
var xmat, ymat blas64.Vector
fast := true
- xU, _ := untranspose(x)
- if rv, ok := xU.(RawVectorer); ok {
+ xU, _ := untransposeExtract(x)
+ if rv, ok := xU.(*VecDense); ok {
r, c := xU.Dims()
- xmat = rv.RawVector()
+ xmat = rv.mat
m.checkOverlap(generalFromVector(xmat, r, c))
} else {
fast = false
}
- yU, _ := untranspose(y)
- if rv, ok := yU.(RawVectorer); ok {
+ yU, _ := untransposeExtract(y)
+ if rv, ok := yU.(*VecDense); ok {
r, c := yU.Dims()
- ymat = rv.RawVector()
+ ymat = rv.mat
m.checkOverlap(generalFromVector(ymat, r, c))
} else {
fast = false
@@ -840,18 +840,18 @@ func (m *Dense) Outer(alpha float64, x, y Vector) {
var xmat, ymat blas64.Vector
fast := true
- xU, _ := untranspose(x)
- if rv, ok := xU.(RawVectorer); ok {
+ xU, _ := untransposeExtract(x)
+ if rv, ok := xU.(*VecDense); ok {
r, c := xU.Dims()
- xmat = rv.RawVector()
+ xmat = rv.mat
m.checkOverlap(generalFromVector(xmat, r, c))
} else {
fast = false
}
- yU, _ := untranspose(y)
- if rv, ok := yU.(RawVectorer); ok {
+ yU, _ := untransposeExtract(y)
+ if rv, ok := yU.(*VecDense); ok {
r, c := yU.Dims()
- ymat = rv.RawVector()
+ ymat = rv.mat
m.checkOverlap(generalFromVector(ymat, r, c))
} else {
fast = false

MODIFY
mat/symmetric.go
mat/symmetric.go
@@ -280,10 +280,10 @@ func (s *SymDense) SymRankOne(a Symmetric, alpha float64, x Vector) {
s.CopySym(a)
}
- xU, _ := untranspose(x)
- if rv, ok := xU.(RawVectorer); ok {
+ xU, _ := untransposeExtract(x)
+ if rv, ok := xU.(*VecDense); ok {
r, c := xU.Dims()
- xmat := rv.RawVector()
+ xmat := rv.mat
s.checkOverlap(generalFromVector(xmat, r, c))
blas64.Syr(alpha, xmat, s.mat)
return
@@ -305,10 +305,10 @@ func (s *SymDense) SymRankK(a Symmetric, alpha float64, x Matrix) {
if r != n {
panic(ErrShape)
}
- xMat, aTrans := untranspose(x)
+ xMat, aTrans := untransposeExtract(x)
var g blas64.General
- if rm, ok := xMat.(RawMatrixer); ok {
- g = rm.RawMatrix()
+ if rm, ok := xMat.(*Dense); ok {
+ g = rm.mat
} else {
g = DenseCopyOf(x).mat
aTrans = false
@@ -394,18 +394,18 @@ func (s *SymDense) RankTwo(a Symmetric, alpha float64, x, y Vector) {
var xmat, ymat blas64.Vector
fast := true
- xU, _ := untranspose(x)
- if rv, ok := xU.(RawVectorer); ok {
+ xU, _ := untransposeExtract(x)
+ if rv, ok := xU.(*VecDense); ok {
r, c := xU.Dims()
- xmat = rv.RawVector()
+ xmat = rv.mat
s.checkOverlap(generalFromVector(xmat, r, c))
} else {
fast = false
}
- yU, _ := untranspose(y)
- if rv, ok := yU.(RawVectorer); ok {
+ yU, _ := untransposeExtract(y)
+ if rv, ok := yU.(*VecDense); ok {
r, c := yU.Dims()
- ymat = rv.RawVector()
+ ymat = rv.mat
s.checkOverlap(generalFromVector(ymat, r, c))
} else {
fast = false

MODIFY
mat/vector.go
mat/vector.go
@@ -291,18 +291,18 @@ func (v *VecDense) AddScaledVec(a Vector, alpha float64, b Vector) {
var amat, bmat blas64.Vector
fast := true
- aU, _ := untranspose(a)
- if rv, ok := aU.(RawVectorer); ok {
- amat = rv.RawVector()
+ aU, _ := untransposeExtract(a)
+ if rv, ok := aU.(*VecDense); ok {
+ amat = rv.mat
if v != a {
v.checkOverlap(amat)
}
} else {
fast = false
}
- bU, _ := untranspose(b)
- if rv, ok := bU.(RawVectorer); ok {
- bmat = rv.RawVector()
+ bU, _ := untransposeExtract(b)
+ if rv, ok := bU.(*VecDense); ok {
+ bmat = rv.mat
if v != b {
v.checkOverlap(bmat)
}
@@ -355,13 +355,13 @@ func (v *VecDense) AddVec(a, b Vector) {
v.reuseAs(ar)
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
- if arv, ok := aU.(RawVectorer); ok {
- if brv, ok := bU.(RawVectorer); ok {
- amat := arv.RawVector()
- bmat := brv.RawVector()
+ if arv, ok := aU.(*VecDense); ok {
+ if brv, ok := bU.(*VecDense); ok {
+ amat := arv.mat
+ bmat := brv.mat
if v != a {
v.checkOverlap(amat)
@@ -398,13 +398,13 @@ func (v *VecDense) SubVec(a, b Vector) {
v.reuseAs(ar)
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
- if arv, ok := aU.(RawVectorer); ok {
- if brv, ok := bU.(RawVectorer); ok {
- amat := arv.RawVector()
- bmat := brv.RawVector()
+ if arv, ok := aU.(*VecDense); ok {
+ if brv, ok := bU.(*VecDense); ok {
+ amat := arv.mat
+ bmat := brv.mat
if v != a {
v.checkOverlap(amat)
@@ -442,13 +442,13 @@ func (v *VecDense) MulElemVec(a, b Vector) {
v.reuseAs(ar)
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
- if arv, ok := aU.(RawVectorer); ok {
- if brv, ok := bU.(RawVectorer); ok {
- amat := arv.RawVector()
- bmat := brv.RawVector()
+ if arv, ok := aU.(*VecDense); ok {
+ if brv, ok := bU.(*VecDense); ok {
+ amat := arv.mat
+ bmat := brv.mat
if v != a {
v.checkOverlap(amat)
@@ -491,13 +491,13 @@ func (v *VecDense) DivElemVec(a, b Vector) {
v.reuseAs(ar)
- aU, _ := untranspose(a)
- bU, _ := untranspose(b)
+ aU, _ := untransposeExtract(a)
+ bU, _ := untransposeExtract(b)
- if arv, ok := aU.(RawVectorer); ok {
- if brv, ok := bU.(RawVectorer); ok {
- amat := arv.RawVector()
- bmat := brv.RawVector()
+ if arv, ok := aU.(*VecDense); ok {
+ if brv, ok := bU.(*VecDense); ok {
+ amat := arv.mat
+ bmat := brv.mat
if v != a {
v.checkOverlap(amat)
@@ -537,12 +537,12 @@ func (v *VecDense) MulVec(a Matrix, b Vector) {
panic(ErrShape)
}
- aU, trans := untranspose(a)
+ aU, trans := untransposeExtract(a)
var bmat blas64.Vector
fast := true
- bU, _ := untranspose(b)
- if rv, ok := bU.(RawVectorer); ok {
- bmat = rv.RawVector()
+ bU, _ := untransposeExtract(b)
+ if rv, ok := bU.(*VecDense); ok {
+ bmat = rv.mat
if v != b {
v.checkOverlap(bmat)
}
@@ -571,8 +571,8 @@ func (v *VecDense) MulVec(a Matrix, b Vector) {
// {1,n} x {n,1}
if fast {
- if rv, ok := aU.(RawVectorer); ok {
- amat := rv.RawVector()
+ if rv, ok := aU.(*VecDense); ok {
+ amat := rv.mat
if v != aU {
v.checkOverlap(amat)
}
@@ -593,18 +593,18 @@ func (v *VecDense) MulVec(a Matrix, b Vector) {
}
v.setVec(0, sum)
return
- case RawSymmetricer:
+ case *SymDense:
if fast {
- amat := aU.RawSymmetric()
+ amat := aU.mat
// We don't know that a is a *SymDense, so make
// a temporary SymDense to check overlap.
(&SymDense{mat: amat}).checkOverlap(v.asGeneral())
blas64.Symv(1, amat, bmat, 0, v.mat)
return
}
- case RawTriangular:
+ case *TriDense:
v.CopyVec(b)
- amat := aU.RawTriangular()
+ amat := aU.mat
// We don't know that a is a *TriDense, so make
// a temporary TriDense to check overlap.
(&TriDense{mat: amat}).checkOverlap(v.asGeneral())
@@ -613,9 +613,9 @@ func (v *VecDense) MulVec(a Matrix, b Vector) {
ta = blas.Trans
}
blas64.Trmv(ta, amat, v.mat)
- case RawMatrixer:
+ case *Dense:
if fast {
- amat := aU.RawMatrix()
+ amat := aU.mat
// We don't know that a is a *Dense, so make
// a temporary Dense to check overlap.
(&Dense{mat: amat}).checkOverlap(v.asGeneral())

mat: replace untranspose with untransposeExtract (#1036)

* mat: replace untranspose with untransposeExtract

This leaves one remaining use in TriDense but that case is a bit more complicated