Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:33:07+00:00 2026-06-17T06:33:07+00:00

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
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:33:08+00:00Added an answer on June 17, 2026 at 6:33 am

    Seq is a trait and there are many subclasses that implement it. List and ArrayBuffer for example. So, you can create an Array[Array[Double]] and pass that to singleThreadedMultiplication. The appropriate type can be created with val array = Array(Array(1.0,2.0,3.0)) and passed to m1 or m2 in singleThreadedMultiplication for example.

    object multiplication {
      def main(args : Seq[Array[Double]], args2 : Array[Double]) : Unit = {
        val matrixmult = new MatrixMultiplication
        matrixmult.singleThreadedMultiplication(args, Array(args2)
      }
    }
    

    To run it and use the parameters passed in remove these lines since they are not used.

    var b = new Array[Double](4)
    b = Array(2,1,2,1)
    seq: Seq[Double] = WrappedArray(1, 0, 2, 0)
    

    Then change the call to use the parameters passed in.

    matrixmult.singleThreadedMultiplication(args, Array(args2))
    

    This runs but you have an java.lang.ArrayIndexOutOfBoundsException in the singleThreadedMultiplication function.

    scala> val a = Array(2.0,1.0,2.0,1.0)
    b: Array[Double] = Array(2.0, 1.0, 2.0, 1.0)
    
    scala> val b = Array(Array(1.0,0.0,2.0,0.0))
    c: Array[Array[Double]] = Array(Array(1.0, 0.0, 2.0, 0.0))
    
    scala> multiplication.main(b, a)
    java.lang.ArrayIndexOutOfBoundsException: 1
    at MatrixMultiplication$$anonfun$singleThreadedMultiplication$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcVI$sp$2.apply$mcVI$sp
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class test: def __init__(self, val): self.val = val self.val.lower() Why doesn't lower() operate on
Class Bar inherits from Foo: class Foo(object): def foo_meth_1(self): return 'foometh1' def foo_meth_2(self): return
class MyClass(Object): def __init__(self, x=None): if x: self.x = x def do_something(self): print self.x
class StartAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): print "Hello" start.add_argument('-s', '--start', action=StartAction) I
class A: pass def b(self): print('b') A.b = b a = A() At this
class A attr_accessor :dab .... end Now I have an array of instances of
class A { $props = array('prop1', 'prop2', 'prop3'); } How to convert above defined
class example: def exampleMethod(self): aVar = 'some string' return aVar In this example, how
class object { public: void check() { std::cout<<I am doing ok...<<std::endl; } }; int
class ligne(): def __init__ (self, stops): ##stops = a list of instances of Ligne1Stop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.