Skip to content

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

Open
@ochafik

Description

@ochafik

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions