Created
December 26, 2011 00:55
-
-
Save piotrga/1520175 to your computer and use it in GitHub Desktop.
singleThreadedMultiplicationFAST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inline def singleThreadedMultiplicationFAST(m1:Seq[Array[Double]], m2:Array[Array[Double]] ) ={ | |
val res = Array.ofDim[Double](m1.length, m2(0).length) | |
val M1_COLS = m1(0).length | |
val M1_ROWS = m1.length | |
val M2_COLS = m2(0).length | |
var col, i = 0 | |
var sum = 0.0 | |
var row = 0 | |
while(row < M1_ROWS){ col = 0 | |
while(col < M2_COLS){ i = 0; sum = 0 | |
while(i<M1_COLS){ | |
// calculating the sum in a variable seems to be faster than updating the array all the time | |
sum += m1(row)(i) * m2(i)(col) | |
i+=1 | |
} | |
res(row)(col) = sum | |
col += 1 | |
}; row += 1 | |
} | |
res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment