Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago