Skip to content

Commit 483b58a

Browse files
Re domain specific module (#62)
* setup domain specific module * . * . * . * fix boolean suite * int array mean and var * update variance to accept different modes * . * DRY a little * scenarios * fmt * . * . * . * . * start reporting * . * fixy * . * . * . * . * . * . * welfords algorithm * . * . * . * . * . * Add BegBin * . * . * pareto plot * . * . * . * [autofix.ci] apply automated fixes * . * . * . * [autofix.ci] apply automated fixes * . * . * scenarr is now a monoid * [autofix.ci] apply automated fixes * oep * . * . * [autofix.ci] apply automated fixes * fix * . * . * . * . * . * . * poisson * . * . * . * . * stats * . * . * [autofix.ci] apply automated fixes * . * . * . * . * [autofix.ci] apply automated fixes * . * . * [autofix.ci] apply automated fixes * . --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 05ae3f3 commit 483b58a

157 files changed

Lines changed: 10232 additions & 425 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ vecxt/
4545
│ ├── src-jvm/ # JVM-specific tests
4646
│ ├── src-js/ # Js-specific tests
4747
│ └── src-native/ # Scala Native-specific tests
48+
├── vecxt_re/ # Domain specific library for reinsurance calculations
49+
│ ├── src/ # Cross-platform shared source code
50+
│ ├── src-jvm/ # JVM-specific implementations (SIMD Vector API)
51+
│ ├── src-js/ # JavaScript-specific implementations
52+
│ ├── src-js-native/ # JavaScript / native shared (DRY) implementations
53+
│ ├── src-native/ # Scala Native-specific implementations
54+
│ └── test/ # Cross-platform test suite (munit)
55+
│ ├── src/ # Shared test source files
56+
│ ├── src-jvm/ # JVM-specific tests
57+
│ ├── src-js/ # Js-specific tests
58+
│ └── src-native/ # Scala Native-specific tests
4859
├── vecxt/ # Main source directory and core published module
4960
│ ├── src/ # Cross-platform shared source code
5061
│ ├── src-jvm/ # JVM-specific implementations (SIMD Vector API)
@@ -81,4 +92,8 @@ Follow styleguide.md for coding conventions
8192
Use inline methods where possible to avoid dispatch overhead where possible.
8293

8394
## GitHub Actions CI
84-
The project uses GitHub Actions for CI/CD
95+
The project uses GitHub Actions for CI/CD
96+
97+
## Vecxt Re
98+
99+
Contains a bunch of domain specific code for reinsurance calculations, structures, and various reinsurance contract types. It will often rely on Vecxt. You should view the principles as the same - correctness above all else - performance matters. It also aims to eexpose a consistent cross platform API.

.github/workflows/autofix.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'autofix.ci'
2+
on:
3+
pull_request:
4+
jobs:
5+
autofix:
6+
if: github.event.pull_request.draft == false
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- uses: actions/setup-java@v4
12+
with:
13+
distribution: 'temurin'
14+
java-version: 25
15+
16+
- name: Run autoformat
17+
run: ./mill mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources
18+
19+
- uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ jobs:
6868
- name: Test
6969
run: ./mill vecxtensions.${{ matrix.project }}.test
7070

71+
- name: Test
72+
run: ./mill vecxt_re.${{ matrix.project }}.test
73+
7174
- name: Laws Test
7275
if: matrix.project == 'jvm'
7376
run: ./mill laws.${{ matrix.project }}.test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ weights2.csv
3838
biases1.csv
3939
biases2.csv
4040
.DS_Store
41+
42+
.venv/
43+
experiments/src/bhd.scala

.vscode/launch.json

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,35 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
52
"version": "0.2.0",
63
"configurations": [
74
{
85
"type": "scala",
96
"request": "launch",
10-
"name": "test Suite",
11-
"buildTarget": "vecxt.jvm.test",
12-
"testClass": "vecxt.LongArraysSuite",
13-
"jvmOptions": [
14-
"--add-modules=jdk.incubator.vector"
15-
],
16-
"args": [
17-
"-oD"
18-
]
7+
"name": "plotIndex",
8+
"mainClass": "experiments.plotIndex",
9+
"buildTarget": "file:///Users/simon/Code/vecxt/experiments",
10+
"args": [],
11+
"jvmOptions": [],
12+
"env": {}
1913
},
2014
{
2115
"type": "scala",
2216
"request": "launch",
23-
"name": "debug test",
24-
"buildTarget": "vecxt.jvm.test",
25-
"testClass": "vecxt.MatrixAdditionTest",
26-
"jvmOptions": [
27-
"--add-modules=jdk.incubator.vector"
28-
],
29-
"args": [
30-
"-oD"
31-
],
32-
"env": {},
33-
"internalConsoleOptions": "openOnSessionStart",
34-
"preLaunchTask": "",
35-
"postDebugTask": ""
17+
"name": "readXl",
18+
"mainClass": "experiments.readXl",
19+
"buildTarget": "file:///Users/simon/Code/vecxt/experiments",
20+
"args": [],
21+
"jvmOptions": [],
22+
"env": {}
3623
},
3724
{
3825
"type": "scala",
39-
"request": "attach",
40-
"name": "Attach debugger",
41-
// name of the module that is being debugging
42-
"buildTarget": "vecxt.jvm.test",
43-
// Host of the jvm to connect to
44-
"hostName": "localhost",
45-
// Port to connect to
46-
"port": 5005
26+
"request": "launch",
27+
"name": "pricingFun",
28+
"mainClass": "experiments.pricingFun",
29+
"buildTarget": "file:///Users/simon/Code/vecxt/experiments",
30+
"args": [],
31+
"jvmOptions": [],
32+
"env": {}
4733
}
4834
]
4935
}

.vscode/mcp.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"servers": {
33
"vecxt-metals": {
4-
"url": "http://localhost:51891/sse",
5-
"type": "sse"
4+
"url": "http://localhost:51891/mcp",
5+
"type": "http"
66
}
77
}
88
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"label": "compiledClassesAndSemanticDbFiles",
66
"type": "shell",
7-
"command": "./mill __.compiledClassesAndSemanticDbFiles",
7+
"command": "./mill __.jvm.compiledClassesAndSemanticDbFiles",
88
"runOptions": {
99
"runOn": "folderOpen"
1010
},

benchmark/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object `package` extends JmhModule with ScalaModule:
99
def scalaVersion = build.vecxt.jvm.scalaVersion
1010
def jmhCoreVersion = "1.37"
1111
override def forkArgs: T[Seq[String]] = super.forkArgs() ++ build.vecIncubatorFlag
12-
override def moduleDeps: Seq[JavaModule] = Seq(build.vecxt.jvm, build.vecxtensions.jvm)
12+
override def moduleDeps: Seq[JavaModule] = Seq(build.vecxt.jvm, build.vecxtensions.jvm, build.vecxt_re.jvm)
1313
def enableBsp = false
1414

1515
// override def generateBenchmarkSources = T{
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package vecxt.benchmark
2+
3+
import org.openjdk.jmh.annotations.*
4+
import org.openjdk.jmh.infra.Blackhole
5+
import scala.compiletime.uninitialized
6+
import scala.util.Random
7+
import vecxt_re.*
8+
import vecxt_re.ReReporting.*
9+
import vecxt.all.*
10+
11+
// ./mill benchmark.runJmh "vecxt.benchmark.LossReportBenchmark" -jvmArgs --add-modules=jdk.incubator.vector -rf json -wi 1 -i 3 -f 1
12+
13+
/** 231] Benchmark (numEventsStr) (numIterationsStr) Mode Cnt Score Error Units 231] LossReportBenchmark.lossReport_fast
14+
* 10000 100 thrpt 3 177346.981 ± 24137.324 ops/s 231] LossReportBenchmark.lossReport_fast 10000 1000 thrpt 3
15+
* 180400.504 ± 8719.687 ops/s 231] LossReportBenchmark.lossReport_fast 100000 100 thrpt 3 11731.510 ± 1945.957 ops/s
16+
* 231] LossReportBenchmark.lossReport_fast 100000 1000 thrpt 3 17443.246 ± 425.030 ops/s 231]
17+
* LossReportBenchmark.lossReport_separate 10000 100 thrpt 3 46850.187 ± 7232.734 ops/s 231]
18+
* LossReportBenchmark.lossReport_separate 10000 1000 thrpt 3 49876.719 ± 5238.487 ops/s 231]
19+
* LossReportBenchmark.lossReport_separate 100000 100 thrpt 3 3360.234 ± 326.993 ops/s 231]
20+
* LossReportBenchmark.lossReport_separate 100000 1000 thrpt 3 4706.819 ± 615.832 ops/s
21+
*/
22+
23+
@State(Scope.Thread)
24+
class LossReportBenchmark extends BLASBenchmark:
25+
26+
@Param(Array("10000", "100000"))
27+
var numEventsStr: String = uninitialized
28+
29+
@Param(Array("100", "1000"))
30+
var numIterationsStr: String = uninitialized
31+
32+
var years: Array[Int] = uninitialized
33+
var ceded: Array[Double] = uninitialized
34+
var layerObj: Layer = uninitialized
35+
36+
@Setup(Level.Trial)
37+
def setup: Unit =
38+
val rng = new Random(0)
39+
val numEvents = numEventsStr.toInt
40+
val numIterations = numIterationsStr.toInt
41+
42+
val yrs = Array.ofDim[Int](numEvents)
43+
var i = 0
44+
while i < numEvents do
45+
yrs(i) = rng.nextInt(numIterations) + 1 // 1-based group indices
46+
i += 1
47+
end while
48+
49+
java.util.Arrays.sort(yrs)
50+
51+
years = yrs
52+
53+
ceded = Array.ofDim[Double](numEvents)
54+
i = 0
55+
while i < numEvents do
56+
// random loss values between 0 and 100
57+
ceded(i) = rng.nextDouble() * 100.0
58+
i += 1
59+
end while
60+
61+
// Choose a layer with a moderate aggLimit to cause some exhaustion hits
62+
layerObj = Layer(occLimit = Some(100.0), aggLimit = Some(50.0))
63+
()
64+
end setup
65+
66+
@Benchmark
67+
def lossReport_fast(bh: Blackhole) =
68+
val calcd = (layerObj, ceded)
69+
val r = calcd.lossReport(numIterationsStr.toInt, years, ReportDenominator.FirstLimit)
70+
// consume fields so JMH doesn't optimize away
71+
bh.consume(r.el)
72+
bh.consume(r.stdDev)
73+
bh.consume(r.attachProb)
74+
bh.consume(r.exhaustProb)
75+
end lossReport_fast
76+
77+
@Benchmark
78+
def lossReport_separate(bh: Blackhole) =
79+
val calcd = (layerObj, ceded)
80+
val n = numIterationsStr.toInt
81+
val reportLimit = ReportDenominator.FirstLimit.fromlayer(layerObj)
82+
83+
val el = calcd.expectedLoss(n) / reportLimit
84+
val std = calcd.std(n, years) / reportLimit
85+
val attach = calcd.attachmentProbability(n, years)
86+
val exhaust = calcd.exhaustionProbability(n, years)
87+
88+
bh.consume(el)
89+
bh.consume(std)
90+
bh.consume(attach)
91+
bh.consume(exhaust)
92+
end lossReport_separate
93+
94+
end LossReportBenchmark

benchmark/src/groupOpsBenchmark.scala

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import org.openjdk.jmh.annotations.*
99
import org.openjdk.jmh.infra.Blackhole
1010
import scala.compiletime.uninitialized
1111
import vecxtensions.*
12+
import vecxt_re.*
1213
import java.util.Random
1314
import java.util.concurrent.TimeUnit
1415

16+
// ./mill benchmark.runJmh "vecxt.benchmark.LossReportBenchmark" -jvmArgs --add-modules=jdk.incubator.vector -rf json -wi 1 -i 3 -f 1
17+
1518
@State(Scope.Thread)
1619
@BenchmarkMode(Array(Mode.AverageTime))
1720
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@@ -91,11 +94,21 @@ class GroupOpsBenchmark:
9194
bh.consume(valuesCopy2)
9295
end benchGroupDiffInPlace
9396

94-
@Benchmark
95-
def benchGroupSum(bh: Blackhole): Unit =
96-
val (uniqueGroups, sums) = groupSum(groups, values)
97-
bh.consume(uniqueGroups)
98-
bh.consume(sums)
99-
end benchGroupSum
97+
// @Benchmark
98+
// def benchGroupSum(bh: Blackhole): Unit =
99+
// // groupSum in vecxt_re takes nitr; compute number of groups then call it
100+
// var maxGroup = 0
101+
// var i = 0
102+
// while i < groups.length do
103+
// if groups(i) > maxGroup then maxGroup = groups(i)
104+
// end if
105+
// i += 1
106+
// end while
107+
// val numGroups = maxGroup + 1
108+
// val sums = groupSum(groups, values, numGroups)
109+
// val uniqueGroups = Array.tabulate(numGroups)(identity)
110+
// bh.consume(uniqueGroups)
111+
// bh.consume(sums)
112+
// end benchGroupSum
100113

101114
end GroupOpsBenchmark

0 commit comments

Comments
 (0)