From 0f4b2306ecf7f2f04d1af5bec12945eb30218154 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 5 May 2010 17:59:21 +0000 Subject: Tightened what gets specialized: only when the ... Tightened what gets specialized: only when the type parameter appears at top level, or as a type argument to a Java array. For example T, Array[T] cause specialization, but List[T] does not. Resurrected spec-matrix, forgotten among the disabled tests. No review. --- test/disabled/run/spec-matrix.check | 1 - test/disabled/run/spec-matrix.scala | 70 ------------------------------------- test/files/run/spec-matrix.check | 1 + test/files/run/spec-matrix.scala | 70 +++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 test/disabled/run/spec-matrix.check delete mode 100644 test/disabled/run/spec-matrix.scala create mode 100644 test/files/run/spec-matrix.check create mode 100644 test/files/run/spec-matrix.scala (limited to 'test') diff --git a/test/disabled/run/spec-matrix.check b/test/disabled/run/spec-matrix.check deleted file mode 100644 index 72e8ffc0db..0000000000 --- a/test/disabled/run/spec-matrix.check +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/test/disabled/run/spec-matrix.scala b/test/disabled/run/spec-matrix.scala deleted file mode 100644 index 81e3eaf212..0000000000 --- a/test/disabled/run/spec-matrix.scala +++ /dev/null @@ -1,70 +0,0 @@ -/** Test matrix multiplication with specialization. - */ - -class Matrix[@specialized A: ClassManifest](val rows: Int, val cols: Int) { - private val arr: Array[Array[A]] = new Array[Array[A]](rows, cols) - - def apply(i: Int, j: Int): A = { - if (i < 0 || i >= rows || j < 0 || j >= cols) - throw new NoSuchElementException("Indexes out of bounds: " + (i, j)) - - arr(i)(j) - } - - def update(i: Int, j: Int, e: A) { - arr(i)(j) = e - } - - def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] { - var idx = 0; - def hasNext = idx < rows - def next = { - idx += 1 - arr(idx - 1) - } - } -} - -object Test { - def main(args: Array[String]) { - val m = randomMatrix(200, 100) - val n = randomMatrix(100, 200) - - mult(m, n) - println("*") - } - - def randomMatrix(n: Int, m: Int) = { - val r = new util.Random(10) - val x = new Matrix[Int](n, m) - for (i <- 0 until n; j <- 0 until m) - x(i, j) = r.nextInt - x - } - - - def multManifest[@specialized(Int) T](m: Matrix[T], n: Matrix[T])(implicit cm: ClassManifest[T], num: Numeric[T]) { - val p = new Matrix[T](m.rows, n.cols) - import num._ - - for (i <- 0 until m.rows) - for (j <- 0 until n.cols) { - var sum = num.zero - for (k <- 0 until n.rows) - sum += m(i, k) * n(k, j) - p(i, j) = sum - } - } - - def mult(m: Matrix[Int], n: Matrix[Int]) { - val p = new Matrix[Int](m.rows, n.cols) - - for (i <- 0 until m.rows) - for (j <- 0 until n.cols) { - var sum = 0 - for (k <- 0 until n.rows) - sum += m(i, k) * n(k, j) - p(i, j) = sum - } - } -} diff --git a/test/files/run/spec-matrix.check b/test/files/run/spec-matrix.check new file mode 100644 index 0000000000..72e8ffc0db --- /dev/null +++ b/test/files/run/spec-matrix.check @@ -0,0 +1 @@ +* diff --git a/test/files/run/spec-matrix.scala b/test/files/run/spec-matrix.scala new file mode 100644 index 0000000000..81e3eaf212 --- /dev/null +++ b/test/files/run/spec-matrix.scala @@ -0,0 +1,70 @@ +/** Test matrix multiplication with specialization. + */ + +class Matrix[@specialized A: ClassManifest](val rows: Int, val cols: Int) { + private val arr: Array[Array[A]] = new Array[Array[A]](rows, cols) + + def apply(i: Int, j: Int): A = { + if (i < 0 || i >= rows || j < 0 || j >= cols) + throw new NoSuchElementException("Indexes out of bounds: " + (i, j)) + + arr(i)(j) + } + + def update(i: Int, j: Int, e: A) { + arr(i)(j) = e + } + + def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] { + var idx = 0; + def hasNext = idx < rows + def next = { + idx += 1 + arr(idx - 1) + } + } +} + +object Test { + def main(args: Array[String]) { + val m = randomMatrix(200, 100) + val n = randomMatrix(100, 200) + + mult(m, n) + println("*") + } + + def randomMatrix(n: Int, m: Int) = { + val r = new util.Random(10) + val x = new Matrix[Int](n, m) + for (i <- 0 until n; j <- 0 until m) + x(i, j) = r.nextInt + x + } + + + def multManifest[@specialized(Int) T](m: Matrix[T], n: Matrix[T])(implicit cm: ClassManifest[T], num: Numeric[T]) { + val p = new Matrix[T](m.rows, n.cols) + import num._ + + for (i <- 0 until m.rows) + for (j <- 0 until n.cols) { + var sum = num.zero + for (k <- 0 until n.rows) + sum += m(i, k) * n(k, j) + p(i, j) = sum + } + } + + def mult(m: Matrix[Int], n: Matrix[Int]) { + val p = new Matrix[Int](m.rows, n.cols) + + for (i <- 0 until m.rows) + for (j <- 0 until n.cols) { + var sum = 0 + for (k <- 0 until n.rows) + sum += m(i, k) * n(k, j) + p(i, j) = sum + } + } +} -- cgit v1.2.3