-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,046 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* | ||
* Copyright 2023 quafadas | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package vecxt.plot | ||
|
||
import upickle.default.* | ||
import NamedTupleReadWriter.given | ||
import io.github.jam01.json_schema.* | ||
import io.github.jam01.json_schema.* | ||
import scalatags.JsDom.short.* | ||
|
||
class PlotChecks extends munit.FunSuite: | ||
|
||
test("something") { | ||
|
||
val thePlot = BenchmarkPlotElements.schema ++ | ||
BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++ | ||
(transform = | ||
BenchmarkPlotElements.timeTransform( | ||
List("vecxt.benchmark.AddScalarBenchmark.vecxt_add_vec") | ||
) | ||
) ++ | ||
(vconcat = | ||
List( | ||
BenchmarkPlotElements.layer(3), | ||
BenchmarkPlotElements.layer(1000), | ||
BenchmarkPlotElements.layer(100000) | ||
) | ||
) | ||
|
||
val json = writeJs(thePlot) | ||
|
||
// println(json) | ||
|
||
// assert(json.toString().contains("$schema\":")) | ||
|
||
} | ||
|
||
test("over time plot") { | ||
val plot = BenchmarkPlots.addScalarBenchmarkOverTime | ||
|
||
println(plot) | ||
|
||
assert(plot.contains("data")) | ||
|
||
} | ||
|
||
end PlotChecks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package vecxt.plot | ||
|
||
import scala.NamedTuple.AnyNamedTuple | ||
import scala.annotation.meta.field | ||
import upickle.default.* | ||
import NamedTupleReadWriter.given | ||
|
||
object BenchmarkPlots: | ||
def addScalarBenchmark: String = | ||
val thePlot = BenchmarkPlotElements.schema ++ | ||
BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++ | ||
// BenchmarkPlotElements.fakeData ++ | ||
(transform = | ||
BenchmarkPlotElements.transform(List("AddScalarBenchmark.vecxt_add", "AddScalarBenchmark.vecxt_add_vec")) | ||
) ++ | ||
(vconcat = | ||
List( | ||
BenchmarkPlotElements.layer(10), | ||
BenchmarkPlotElements.layer(1000), | ||
BenchmarkPlotElements.layer(100000) | ||
) | ||
) | ||
write(thePlot) | ||
end addScalarBenchmark | ||
|
||
def addScalarBenchmarkOverTime: String = | ||
val thePlot = BenchmarkPlotElements.schema ++ | ||
// BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++ | ||
BenchmarkPlotElements.fakeData ++ | ||
(transform = BenchmarkPlotElements.timeTransform(List("AddScalarBenchmark.vecxt_add_vec"))) ++ | ||
(vconcat = | ||
List( | ||
BenchmarkPlotElements.timeLayer(10), | ||
BenchmarkPlotElements.timeLayer(1000), | ||
BenchmarkPlotElements.timeLayer(100000) | ||
) | ||
) | ||
write(thePlot) | ||
end addScalarBenchmarkOverTime | ||
|
||
def countTrueBenchmark = | ||
val thePlot = BenchmarkPlotElements.schema ++ | ||
BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++ | ||
(transform = | ||
BenchmarkPlotElements.transform( | ||
List("CountTrueBenchmark.countTrue_loop", "CountTrueBenchmark.countTrue_loop_vec") | ||
) | ||
) ++ | ||
(vconcat = | ||
List( | ||
BenchmarkPlotElements.layer(3), | ||
BenchmarkPlotElements.layer(128), | ||
BenchmarkPlotElements.layer(100000) | ||
) | ||
) | ||
write(thePlot) | ||
end countTrueBenchmark | ||
|
||
end BenchmarkPlots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package vecxt.plot | ||
|
||
import scala.NamedTuple.NamedTuple | ||
import upickle.default.* | ||
import ujson.Value | ||
|
||
object NamedTupleReadWriter: | ||
inline given [N <: Tuple, V <: Tuple, T <: NamedTuple[N, V]]: ReadWriter[T] = | ||
val names = scala.compiletime.constValueTuple[N].toList.asInstanceOf[List[String]] | ||
val readWriters = scala.compiletime.summonAll[Tuple.Map[V, ReadWriter]].toList.asInstanceOf[List[ReadWriter[?]]] | ||
|
||
def toMap(t: T): Map[String, Value] = | ||
val values = t.toTuple.productIterator.toList | ||
(0 until names.length).foldLeft(Map.empty[String, Value]): (map, i) => | ||
val readWriter = readWriters(i).asInstanceOf[ReadWriter[Any]] | ||
map + (names(i) -> transform(values(i))(using readWriter).to(ujson.Value)) | ||
end toMap | ||
|
||
def fromMap(map: Map[String, Value]): T = | ||
val namesAndRWs = names.zip(readWriters) | ||
val valueList = namesAndRWs.map: (name, rw) => | ||
map.get(name) match | ||
case None => throw new Exception(s"Missing field: $name") | ||
case Some(v) => | ||
read(v)(using rw.asInstanceOf[ReadWriter[Any]]) | ||
|
||
val tuple = valueList.foldRight(EmptyTuple: Tuple): (v, tuple) => | ||
v *: tuple | ||
|
||
tuple.asInstanceOf[T] | ||
end fromMap | ||
|
||
summon[ReadWriter[Map[String, Value]]].bimap(toMap, fromMap) | ||
end given | ||
end NamedTupleReadWriter |
Oops, something went wrong.