ochafik/nativelibs4java — Issue #216: [ScalaCLPlugin] scala.Tuple2 cannot be cast to java.lang.Float
Author: frgomes
Created: 2011-12-21 03:22:46+00:00
State: open

The method testCalc1CLArray shown below fails at line 13:

package mytests

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

class Test214 {

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.Test214.calc1(Test214.scala:13)
at mytests.Test214.testCalc1CLArray(Test214.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.