Move SSD cell JSON helpers to typed Kotlin
ober
12d73611877dd525a3db6f51f6f421f966b272be
--- a/.build.yml +++ b/.build.yml @@ -5,7 +5,7 @@ packages: - make=4.4.1-r4 sources: # Build dependency: full immutable commit, mirrored in dependencies.lock.json. - - "https://git.sr.ht/~lisp/jerboa#063dc728b171b6039887edb42acecd201f5dd3f0" + - "https://git.sr.ht/~lisp/jerboa#778d80053579958c2297c6f183517fdf1db94950" # The second source is the build subject selected by the SourceHut submitter. - https://git.sr.ht/~lisp/jerboa-android tasks: @@ -14,6 +14,6 @@ tasks: test "$(apk info -v chez-scheme)" = chez-scheme-10.3.0-r2 test "$(apk info -v git)" = git-2.54.0-r0 test "$(apk info -v make)" = make-4.4.1-r4 - test "$(git -C ../jerboa rev-parse HEAD)" = 063dc728b171b6039887edb42acecd201f5dd3f0 - test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = 08e730fabd0754a09c6b50b072823385540bc627 + test "$(git -C ../jerboa rev-parse HEAD)" = 778d80053579958c2297c6f183517fdf1db94950 + test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = d643e4a71c3d517cc14732ff7e7b87fe578b014b JERBOA="chez --libdirs .:../jerboa/lib --script" make test --- a/dependencies.lock.json +++ b/dependencies.lock.json @@ -11,8 +11,8 @@ "generator_runtime": { "name": "jerboa", "repository": "https://git.sr.ht/~lisp/jerboa", - "commit": "063dc728b171b6039887edb42acecd201f5dd3f0", - "tree": "08e730fabd0754a09c6b50b072823385540bc627" + "commit": "778d80053579958c2297c6f183517fdf1db94950", + "tree": "d643e4a71c3d517cc14732ff7e7b87fe578b014b" }, "assurance_tools": { "osv_scanner": { --- a/scripts/verify-supply-chain.sh +++ b/scripts/verify-supply-chain.sh @@ -3,8 +3,8 @@ set -eu repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P) lock="$repo/dependencies.lock.json" -jerboa_commit=063dc728b171b6039887edb42acecd201f5dd3f0 # gitsafe:ignore -jerboa_tree=08e730fabd0754a09c6b50b072823385540bc627 # gitsafe:ignore +jerboa_commit=778d80053579958c2297c6f183517fdf1db94950 # gitsafe:ignore +jerboa_tree=d643e4a71c3d517cc14732ff7e7b87fe578b014b # gitsafe:ignore gradle_sha=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78 jdk_macos_sha=8fa1eff40bb637a33613b2ccb8b12c70dc3661cc22cf8e784943715769a05336 jdk_linux_sha=d8afc263758141a66e0e3aafc321e783f7016696f4eaea067d340a269037d331 --- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -777,6 +777,44 @@ (json-array-opt-float32 (nullable-get json) (int32 2) (float32 0.0)) (json-array-opt-float32 (nullable-get json) (int32 3) (float32 0.0))))))))) + (typed-kotlin-file "com/sfb/ssdreview/SsdCellJson.kt" + (kotlin-imports (org json JSONArray) (org json JSONObject)) + (typed-library (com sfb ssdreview) + (export ssdCellToJson ssdCellFromJson) + (type JSONObject) + (type JSONArray) + (type SsdCell) + (type Float32) + (type Int32) + (def (zeroMeanBgr) : JSONArray + (let ((mean (json-array-empty))) + (begin + (json-array-put-int32! mean (int32 0)) + (json-array-put-int32! mean (int32 0)) + (json-array-put-int32! mean (int32 0)) + mean))) + (def (ssdCellToJson (cell : SsdCell)) : JSONObject + (let ((json (json-object-empty))) + (begin + (json-object-put-string! json "id" (SsdCell-id cell)) + (json-object-put-float32! json "x" (SsdCell-x cell)) + (json-object-put-float32! json "y" (SsdCell-y cell)) + (json-object-put-float32! json "w" (SsdCell-w cell)) + (json-object-put-float32! json "h" (SsdCell-h cell)) + (json-object-put-float32! json "cx" (ssdCellCx cell)) + (json-object-put-float32! json "cy" (ssdCellCy cell)) + (json-object-put-string! json "detector" (SsdCell-detector cell)) + (json-object-put-json-array! json "mean_bgr" (zeroMeanBgr)) + json))) + (def (ssdCellFromJson (json : JSONObject)) : SsdCell + (make-SsdCell + (json-object-opt-string json "id") + (json-object-opt-float32 json "x") + (json-object-opt-float32 json "y") + (json-object-opt-float32 json "w") + (json-object-opt-float32 json "h") + (json-object-opt-string-default json "detector" "truth"))))) + (typed-kotlin-file "com/sfb/ssdreview/Guess.kt" (typed-library (com sfb ssdreview) (export make-Guess Guess? Guess-label Guess-boxType Guess-reason) @@ -3533,26 +3571,6 @@ "import kotlin.math.max" "import kotlin.math.min" "" - "fun ssdCellToJson(cell: SsdCell): JSONObject = JSONObject()" - " .put(\"id\", cell.id)" - " .put(\"x\", cell.x.toDouble())" - " .put(\"y\", cell.y.toDouble())" - " .put(\"w\", cell.w.toDouble())" - " .put(\"h\", cell.h.toDouble())" - " .put(\"cx\", ssdCellCx(cell).toDouble())" - " .put(\"cy\", ssdCellCy(cell).toDouble())" - " .put(\"detector\", cell.detector)" - " .put(\"mean_bgr\", JSONArray(listOf(0, 0, 0)))" - "" - "fun ssdCellFromJson(json: JSONObject): SsdCell = SsdCell(" - " id = json.optString(\"id\")," - " x = json.optDouble(\"x\").toFloat()," - " y = json.optDouble(\"y\").toFloat()," - " w = json.optDouble(\"w\").toFloat()," - " h = json.optDouble(\"h\").toFloat()," - " detector = json.optString(\"detector\", \"truth\")" - ")" - "" "fun ssdGroupToTruthJson(group: SsdGroup, cellsById: Map<String, SsdCell>): JSONObject {" " val groupCells = group.cellIds.mapNotNull { cellsById[it] }" " val ids = JSONArray()"