Skip to content

Commit

Permalink
Redo the previous fix a little more carefully
Browse files Browse the repository at this point in the history
Reuse data allocation where possible and properly define dimensions
for the slow case.
  • Loading branch information
kortschak committed Jan 21, 2014
1 parent 322057a commit 1782b1f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mat64/dense.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,32 @@ func (m *Dense) Reset() {
func (m *Dense) Clone(a Matrix) {
r, c := a.Dims()
mat := RawMatrix{
Order: BlasOrder,
Rows: r,
Cols: c,
Data: make([]float64, r*c),
Order: BlasOrder,
Rows: r,
Cols: c,
Stride: c,
}
switch a := a.(type) {
case RawMatrixer:
amat := a.RawMatrix()
mat.Data = make([]float64, r*c)
for i := 0; i < r; i++ {
copy(mat.Data[i*c:(i+1)*c], amat.Data[i*amat.Stride:i*amat.Stride+c])
}
mat.Stride = c
case Vectorer:
mat.Data = use(m.mat.Data, r*c)
for i := 0; i < r; i++ {
a.Row(mat.Data[i*c:(i+1)*c], i)
}
mat.Stride = c
default:
m.mat.Data = mat.Data
mat.Data = use(m.mat.Data, r*c)
m.mat = mat
for i := 0; i < r; i++ {
for j := 0; j < c; j++ {
m.Set(i, j, a.At(i, j))
}
}
return
}
m.mat = mat
}
Expand Down

0 comments on commit 1782b1f

Please sign in to comment.