Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
make output row slice indexing more efficient
Browse files Browse the repository at this point in the history
By taking a slice once, we can avoid doing some extra math on each loop.
  • Loading branch information
jonlawlor committed Jan 1, 2015
1 parent 2bce680 commit 256229d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions mat64/dense_arithmetic.go
Expand Up @@ -508,34 +508,38 @@ func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) {
if aTrans {
if bTrans {
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for c := 0; c < bc; c++ {
w.mat.Data[r*w.mat.Stride+c] = blasEngine.Ddot(ac, a.Col(row, r), 1, b.Row(col, c), 1)
dataTmp[c] = blasEngine.Ddot(ac, a.Col(row, r), 1, b.Row(col, c), 1)
}
}
*m = w
return
}
// TODO(jonlawlor): determine if (b*a)' is more efficient
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for c := 0; c < bc; c++ {
w.mat.Data[r*w.mat.Stride+c] = blasEngine.Ddot(ac, a.Col(row, r), 1, b.Col(col, c), 1)
dataTmp[c] = blasEngine.Ddot(ac, a.Col(row, r), 1, b.Col(col, c), 1)
}
}
*m = w
return
}
if bTrans {
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for c := 0; c < bc; c++ {
w.mat.Data[r*w.mat.Stride+c] = blasEngine.Ddot(ac, a.Row(row, r), 1, b.Row(col, c), 1)
dataTmp[c] = blasEngine.Ddot(ac, a.Row(row, r), 1, b.Row(col, c), 1)
}
}
*m = w
return
}
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for c := 0; c < bc; c++ {
w.mat.Data[r*w.mat.Stride+c] = blasEngine.Ddot(ac, a.Row(row, r), 1, b.Col(col, c), 1)
dataTmp[c] = blasEngine.Ddot(ac, a.Row(row, r), 1, b.Col(col, c), 1)
}
}
*m = w
Expand All @@ -547,6 +551,7 @@ func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) {
if aTrans {
if bTrans {
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for i := range row {
row[i] = a.At(i, r)
}
Expand All @@ -555,14 +560,15 @@ func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) {
for i, e := range row {
v += e * b.At(c, i)
}
w.mat.Data[r*w.mat.Stride+c] = v
dataTmp[c] = v
}
}
*m = w
return
}

for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for i := range row {
row[i] = a.At(i, r)
}
Expand All @@ -571,14 +577,15 @@ func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) {
for i, e := range row {
v += e * b.At(i, c)
}
w.mat.Data[r*w.mat.Stride+c] = v
dataTmp[c] = v
}
}
*m = w
return
}
if bTrans {
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for i := range row {
row[i] = a.At(r, i)
}
Expand All @@ -587,13 +594,14 @@ func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) {
for i, e := range row {
v += e * b.At(c, i)
}
w.mat.Data[r*w.mat.Stride+c] = v
dataTmp[c] = v
}
}
*m = w
return
}
for r := 0; r < ar; r++ {
dataTmp := w.mat.Data[r*w.mat.Stride : r*w.mat.Stride+bc]
for i := range row {
row[i] = a.At(r, i)
}
Expand All @@ -602,7 +610,7 @@ func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool) {
for i, e := range row {
v += e * b.At(i, c)
}
w.mat.Data[r*w.mat.Stride+c] = v
dataTmp[c] = v
}
}
*m = w
Expand Down

0 comments on commit 256229d

Please sign in to comment.