Skip to content

Instantly share code, notes, and snippets.

@piotrga
Created December 26, 2011 00:55
Show Gist options
  • Save piotrga/1520175 to your computer and use it in GitHub Desktop.
Save piotrga/1520175 to your computer and use it in GitHub Desktop.
singleThreadedMultiplicationFAST
@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