Skip to content

Commit

Permalink
updated to newer Scala 3 syntax with fewer braces
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Läufer <[email protected]>
  • Loading branch information
klaeufer committed Sep 30, 2023
1 parent 63283a6 commit a417d2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Integration:
// begin-integrate
def integrateSequential(a: Double, b: Double, rectangles: Int, f: Fx): Double =
val interval = (b - a) / rectangles
val fxValues = (1 until rectangles).view map { n => f(a + n * interval) }
val fxValues = (1 until rectangles).view.map { n => f(a + n * interval) }
interval * (f(a) / 2 + f(b) / 2 + fxValues.sum)
// end-integrate

Expand All @@ -26,10 +26,10 @@ object Integration:
require { rectangles % grainSize == 0 } // can relax this later
val workers = rectangles / grainSize
val interval = (b - a) / workers
val fullIntegration = (0 until workers).view map { n =>
val c = a + n * interval
integrateSequential(c, c + interval, grainSize, f)
}
val fullIntegration = (0 until workers).view.map:
n =>
val c = a + n * interval
integrateSequential(c, c + interval, grainSize, f)
fullIntegration.sum
// end-integrateParallelGranular

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ object Main:
// begin-timedRun
def timedRun(rectangles: Int, n: Int, how: String,
integrationStrategy: (Double, Double, Int, Fx) => Double): Unit =
timeThis(how) {
timeThis(how):
print("Computing area " + how + "; now timing " + n + " iterations")
val area: Double = (1 to n).map { _ => integrationStrategy(0, 10, rectangles, sqr) }.head
println("; area = " + area)
}

// end-timedRun
end Main

0 comments on commit a417d2b

Please sign in to comment.