How dragonfly-ai/slash works
Project Type and Purpose
• This is a multi‐module, cross‐platform Scala library (S.L.A.S.H: Scala Linear Algebra & Statistics Hacks).
• It provides high‐performance vector, matrix, and statistical/distribution APIs, compiling to three targets: JVM, Native, and JavaScript.
File‐Structure Analysis
• Top‐level modules:
• slash/shared – core implementation (vector, matrix, stats, distributions, geometry, etc.)
• slash/js – Scala.js platform adapter (compiles shared → JS)
• slash/jvm-native – JVM & Native adapter (compiles shared → JVM/Native)
• Supporting modules:
• tests/shared – unit tests against shared code
• verification – fidelity‐checking subproject comparing with JAMA implementation
• jsdocs/livechart – interactive JS demo of charting APIs
• docs & docs/js – Markdown and a small JS frontend for documentation website
• project & build.sbt – sbt build definitions & plugins
• .github/workflows – CI/CD pipelines (ci.yml, clean.yml)
• Other files: configuration (.gitignore, .scalafmt.conf), license, logo, verification spreadsheet.
Key Insights from README
• Design goals emphasize cross‐compilation, performance, minimal footprint, seamless interop.
• Uses Scala 3 features: opaque types, dependent types, extension methods.
• Relies on external NArr library for native arrays (Float64Array in JS; Array[Double] on JVM/Native).
• Has a rich feature set: vector/matrix ops with compile‐time dimension checks; parametric and streaming distributions; geometry; logarithm macros; histograms; bijections.
a. Main Components
1. Core Module (slash/shared): implements all algorithms, types, and common logic
2. Platform Adapters:
– JS Adapter (slash/js) → compiles core to Scala.js/JavaScript
– JVM/Native Adapter (slash/jvm-native) → compiles core to JVM and Scala Native
3. Build & Packaging (sbt): orchestrates compilation, testing, publishing to Maven/JS artifact repository
4. Testing & Verification:
– Unit Test Suite (tests/shared)
– Verification Subproject (verification) comparing against JAMA
5. Documentation & Demos:
– Markdown docs (docs/)
– jsdocs/livechart demo (interactive web chart)
6. CI/CD Pipeline (GitHub Actions): runs build, test, formatting, site deployment
7. External Dependencies: NArr library; sbt plugins; Scala.js, Scala Native, sbt‐bundler, etc.
b. Relationships & Data Flows
• The Build System (sbt) sits at the center, taking slash/shared and producing platform‐specific artifacts via slash/js and slash/jvm-native.
• The Core Module exports APIs consumed by both adapters.
• Tests and verification depend on the Core Module artifact (pre‐publish, local build).
• Documentation pipeline reads source and jsdocs to generate site.
• CI/CD pulls code, invokes sbt tasks, and publishes artifacts and doc site.
c. Architectural Patterns & Principles
• Multi‐module monorepo with clear separation of core logic and platform bindings.
• Code‐reuse by centralizing algorithms in slash/shared.
• Cross-compilation pattern: single codebase → multiple targets.
• Compile‐time safety: opaque & dependent types to enforce dimensional correctness.
• Extension methods to augment core types.
d. Key Technologies & Frameworks
• Scala 3 (opaque types, macros, dependent types)
• sbt (multi‐project build, cross‐compilation)
• Scala.js & Scala Native
• NArr (native array abstraction)
• GitHub Actions (ci.yml, clean.yml)
• jsdocs & a minimal JS frontend for interactive documentation