Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. def dotProduct(vector: Array[Int], matrix: Array[Array[Int]]): Array[Int] = {
  2. // ignore dimensionality checks for simplicity of example
  3. (0 to (matrix(0).size - 1)).toArray.map( colIdx => {
  4. val colVec: Array[Int] = matrix.map( rowVec => rowVec(colIdx) )
  5. val elemWiseProd: Array[Int] = (vector zip colVec).map( entryTuple => entryTuple._1 * entryTuple._2 )
  6. elemWiseProd.sum
  7. } )
  8. }
  9.  
  10.  
  11. val A = sc.parallelize(Array(Array(7, 5, 4), Array(0, 3, 2), Array(8, 0, 5), Array(-11, 7, -4), Array(-8, 2, -13), Array(5, 0, -2)))
  12.  
  13. val B = sc.broadcast(Array(Array(100, -80, 75, -105, 30, -50), Array(60, -60, 60, -60, 60, -60), Array(-50, 30, -105, 75, -80, 100)))
  14.  
  15. A.map( row => dotProduct(row, B.value) ).collect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement