class MatrixMultiplication {
def singleThreadedMultiplication(m1:Seq[Array[Double]], m2:Array[Array[Double]] ) ={
val res = Array.fill(m1.length, m2(0).length)(0.0)
for(row <- 0 until m1.length;
col <- 0 until m2(0).length;
i <- 0 until m1(0).length){
res(row)(col) += m1(row)(i) * m2(i)(col)
}
res
}
}
__
object multiplication {
def main(args : Seq[Array[Double]], args2 : Array[Double]) : Unit = {
val matrixmult = new MatrixMultiplication
var b = new Array[Double](4)
b = Array(2,1,2,1)
seq: Seq[Double] = WrappedArray(1, 0, 2, 0)
matrixmult.singleThreadedMultiplication(Seq[Double],b)
}
}
All I need is to know how I can run the single threaded multiplication method since its 1st parameter is Seq[Array[Double]] and I have no idea and I didn’t manage to find any way how to create a seq double array in the second class.
Seqis a trait and there are many subclasses that implement it.ListandArrayBufferfor example. So, you can create anArray[Array[Double]]and pass that tosingleThreadedMultiplication. The appropriate type can be created withval array = Array(Array(1.0,2.0,3.0))and passed tom1orm2insingleThreadedMultiplicationfor example.To run it and use the parameters passed in remove these lines since they are not used.
Then change the call to use the parameters passed in.
This runs but you have an
java.lang.ArrayIndexOutOfBoundsExceptionin thesingleThreadedMultiplicationfunction.