Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ScalaCLPlugin] scala.Tuple2 cannot be cast to java.lang.Float #13

Open
ochafik opened this issue Mar 16, 2015 · 0 comments
Open

[ScalaCLPlugin] scala.Tuple2 cannot be cast to java.lang.Float #13

ochafik opened this issue Mar 16, 2015 · 0 comments

Comments

@ochafik
Copy link
Member

ochafik commented Mar 16, 2015

From @frgomes on December 21, 2011 3:22

The method testCalc1CLArray shown below fails at line 13:

package mytests

import scalacl._
import org.junit.{Assert, Test, Ignore}

class Test216 {

  private implicit val context = Context.best

  // Using IndexedSeq

  def calc1(vx : IndexedSeq[Float], vy : IndexedSeq[Float], mx : Float, my : Float) : Float = {
(vx zip vy).par.map( { case (x,y) => { (x - mx) * (y - my) } } ).sum  // line 13
  }

  @Test
  def testCalc1Array() : Unit = {
val a = Array[Float]( 1.0F,  2.0F,  3.0F)
val b = Array[Float](10.0F, 20.0F, 30.0F)

val f = calc1(a, b, 2.0F, 20.0F)
println(f)
  }

  @Test
  def testCalc1CLArray() : Unit = {
val a = Array[Float]( 1.0F,  2.0F,  3.0F)
val b = Array[Float](10.0F, 20.0F, 30.0F)

val f = calc1(a.cl, b.cl, 2.0F, 20.0F) // line 30
println(f)
  }


  // Using CLArray

  def calc2(vx : CLArray[Float], vy : CLArray[Float], mx : Float, my : Float) : Float = {
(vx zip vy).par.map( { case (x,y) => { (x - mx) * (y - my) } } ).sum
  }

  @Test
  def testCalc2CLArray() : Unit = {
val a = Array[Float]( 1.0F,  2.0F,  3.0F)
val b = Array[Float](10.0F, 20.0F, 30.0F)

val f = calc2(a.cl, b.cl, 2.0F, 20.0F)
println(f)
  }

}

java.lang.ClassCastException: scala.Tuple2 cannot be cast to java.lang.Float
    at scala.runtime.BoxesRunTime.unboxToFloat(Unknown Source)
    at scala.runtime.ScalaRunTime$.array_update(ScalaRunTime.scala:72)
    at scala.Array$.slowcopy(Array.scala:63)
    at scala.Array$.copy(Array.scala:89)
    at scala.collection.mutable.ResizableArray$class.copyToArray(ResizableArray.scala:76)
    at scala.collection.mutable.ArrayBuffer.copyToArray(ArrayBuffer.scala:44)
    at scala.collection.TraversableOnce$class.copyToArray(TraversableOnce.scala:226)
    at scala.collection.mutable.ArrayBuffer.copyToArray(ArrayBuffer.scala:44)
    at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:234)
    at scala.collection.mutable.ArrayBuffer.toArray(ArrayBuffer.scala:44)
    at scalacl.CLArray$.fromSeq(CLArray.scala:31)
    at scalacl.CLArray$$anonfun$newBuilder$1.apply(CLArray.scala:46)
    at scalacl.CLArray$$anonfun$newBuilder$1.apply(CLArray.scala:46)
    at scala.collection.mutable.Builder$$anon$1.result(Builder.scala:103)
    at scala.collection.IndexedSeqOptimized$class.zip(IndexedSeqOptimized.scala:86)
    at scalacl.CLArray.zip(CLArray.scala:86)
    at mytests.Test216.calc1(Test216.scala:13)
    at mytests.Test216.testCalc1CLArray(Test216.scala:30)

Some diagnotics:

I have other methods which:

  1. do not employ ScalaCL objects explicitly but are called with ScalaCL objects.
  2. employ method zip() but ScalaCL objects are explicitly employed

So, looks like it is a problem in the way zip() is implemented when non-ScalaCL objects are involved.

Copied from original issue: nativelibs4java/nativelibs4java#216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant