This page is no longer maintained — Please continue to the home page at

problem getting specialized method to be used

No replies
Matthew Pocock 3
Joined: 2010-07-30,
User offline. Last seen 42 years 45 weeks ago.
I'm having real trouble getting a specialized version of a def to be used. I have 3 different factory methods for making instances of one of the matrix types in scalala.
def apply[@specialized(Int, Long, Float, Double) V: Scalar: ClassManifest: DefaultArrayValue](domain: TableDomain): CCSMatrix[V]def apply[R, @specialized(Int, Long, Float, Double) V](rows: R*)(implicit rl : LiteralRow[R, V], scalar: Scalar[V]): CCSMatrix[V] def zeros[@specialized(Int, Long, Float, Double) V](rows: Int, cols: Int)(implicit s: Scalar[V]): CCSMatrix[V]
The first and third of these seem to behave just fine. When you invoke them from code, it runs one of the specialized defs and returns the right implementation. E.g.
val m3 = CCSMatrix.apply[Double](TableDomain(3,3)) // scalala.tensor.sparse.CCSMatrix$mcD$spval z3 = CCSMatrix.zeros[Double](3,3) // scalala.tensor.sparse.CCSMatrix$mcD$sp
However, the 2nd one refuses to behave itself.
val mSq = CCSMatrix.apply((1.0, 2.0), (3.0, 4.0)) // scala.tensor.sparse.CCSMatrix
In the bytecode, you can see that it's pulled in all the 'right' implicits. We can even fill them in manually with the exact same ones as the compiler injects above:
val mSq = CCSMatrix.apply[(Double, Double), Double]((1.0, 2.0),(3.0, 4.0))(LiteralRow.tuple2, Scalar.scalarD)
Still no joy. Yet, when I look in the bytecode I can see, plain as day, the specialized versions for this apply() are present, and both the tuple2 and scalarD are the specialized versions of those type classes. Yet, at the call-site, it's using the non-specialized version.
At one point I thought it could have been R* confusing things, but when I wrote a version that uses R, still no joy. I'm stuck over how to debug this further. I'm really not sure why it is failing to bind to the specialized version of apply() here, particularly as it seems to work in the other two cases.
This is with scala 2.9.0-1.
Dr Matthew PocockVisitor, School of Computing Science, Newcastle Universitymailto: turingatemyhamster [at] gmail [dot] com gchat: turingatemyhamster [at] gmail [dot] commsn: matthew_pocock [at] yahoo [dot] co [dot] uk drdozertel: (0191) 2566550mob: +447535664143

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland