Skip to content

Commit

Permalink
Add explicit implicit RandBasis-s, update method call name
Browse files Browse the repository at this point in the history
  • Loading branch information
bwignall committed Jul 1, 2024
1 parent 9dd67b5 commit 43c74ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

package breeze.benchmark

import breeze.stats.distributions.RandBasis
import com.google.caliper.Benchmark
import com.google.caliper.runner.CaliperMain

/**
* Extend this to create an actual benchmarking class.
*/
trait BreezeBenchmark {
implicit val randBasis: RandBasis = RandBasis.mt0

/**
* Sugar to run 'f' for 'reps' number of times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import breeze.macros._
object DenseMatrixBenchmark extends MyRunner(classOf[DenseMatrixBenchmark])

trait BuildsRandomMatrices {
private val uniform = Uniform(0, 1)
private val uniform = Uniform(0, 1)(RandBasis.mt0)
def randomMatrix(m: Int, n: Int, transpose: Boolean = false): DenseMatrix[Double] = {
if (!transpose) {
DenseMatrix.rand[Double](m, n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import breeze.macros._
object DenseVectorBenchmark extends MyRunner(classOf[DenseVectorBenchmark])

trait BuildsRandomVectors {
private val uniform = Uniform(0, 1)
private val uniform = Uniform(0, 1)(RandBasis.mt0)
def randomArray(size: Int, offset: Int = 0, stride: Int = 1): DenseVector[Double] = {
require(offset >= 0)
require(stride >= 1)
val result = new DenseVector(new Array[Double](offset + stride * size), offset, stride, size)
var i = 0
while (i < size) {
result.unsafeUpdate(i, uniform.draw())
result.update(i, uniform.draw())
i += 1
}
result
Expand Down Expand Up @@ -83,7 +83,7 @@ class DenseVectorBenchmark extends BreezeBenchmark with BuildsRandomVectors {

def timeValueAt(reps: Int) = valueAtBench(reps, 1024 * 8, 1)
def timeValueAtStride4(reps: Int) = valueAtBench(reps, 1024 * 8, 4)

def updateBench(reps: Int, size: Int, stride: Int) =
runWith(reps, { randomArray(size, stride = stride) })(arr => {
var i = 0
Expand All @@ -101,7 +101,7 @@ class DenseVectorBenchmark extends BreezeBenchmark with BuildsRandomVectors {
runWith(reps, { randomArray(size, stride = stride) })(arr => {
var i = 0
while (i < arr.size) {
arr.unsafeUpdate(i, i.toDouble)
arr.update(i, i.toDouble)
i += 1
}
arr
Expand Down

0 comments on commit 43c74ac

Please sign in to comment.