Question: Hi , this is my matrix multiplication program in scala i am trying to execute on data bricks, / / Define small matrices M and

Hi, this is my matrix multiplication program in scala i am trying to execute on data bricks,
// Define small matrices M and N
val M = Array(Array(1.0,2.0), Array(3.0,4.0))
val N = Array(Array(5.0,6.0), Array(7.0,8.0))
// Convert small matrices to RDDs
val MRDDSmall = sc.parallelize(M.zipWithIndex.flatMap {
case (row, i)=>
row.zipWithIndex.map {
case (value, j)=>
((i.toInt, j.toInt), value)
}
})
val NRDDSmall = sc.parallelize(N.zipWithIndex.flatMap {
case (row, i)=>
row.zipWithIndex.map {
case (value, j)=>
((i.toInt, j.toInt), value)
}
})
// Function to perform matrix multiplication of RDDs
def COOMatrixMultiply(M: RDD[((Int, Int), Double)], N: RDD[((Int, Int), Double)]): RDD[((Int, Int), Double)]={
val MJoined = M.map {
case ((i, k), value)=>(k,(i, value))
}
val NJoined = N.map {
case ((k, j), value)=>(k,(j, value))
}
MJoined.join(NJoined).map {
case (_,((i, Mvalue),(_, Nvalue)))=>((i, j), Mvalue * Nvalue)
}.reduceByKey(_+_)
}
// Perform matrix multiplication
val R_RDD_Small = COOMatrixMultiply(MRDDSmall, NRDDSmall)
// Print the result
R_RDD_Small.collect().foreach(println)
but this is the errors i am facing:
command-1035103480973730:9: error: not found: value Mvalue
case (_,((i, Mvalue),(_, Nvalue)))=>((i, j), Mvalue * Nvalue)
^
command-1035103480973730:9: error: not found: value Nvalue
case (_,((i, Mvalue),(_, Nvalue)))=>((i, j), Mvalue * Nvalue)
^
command-1035103480973730:9: error: not found: value j
case (_,((i, Mvalue),(_, Nvalue)))=>((i, j), Mvalue * Nvalue)
^
command-1035103480973730:9: error: not found: value Mvalue
case (_,((i, Mvalue),(_, Nvalue)))=>((i, j), Mvalue * Nvalue)
^
command-1035103480973730:9: error: not found: value Nvalue
case (_,((i, Mvalue),(_, Nvalue)))=>((i, j), Mvalue * Nvalue)
can you please help me fix this so that the code runs on data bricks. I am not able to run this on data bricks. i have very little knowledge in scala and would like to have help.
Thank you so much

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!