Cross Platform
Vecxt wants to be cross platform. It compiles to both scalaJS and native - check your browser console to observer the output. On scala JS, target WASM for better performance.
import vecxt.all.{*, given}
import org.scalajs.dom
def algo(a: Array[Double], b :Array[Double], c: Double ) = (a + b) / c
val a = Array[Double](1.0, 2.0, 3.0, 2.0)
val b = Array[Double](4.0, 5.0, 6.0, 2.0)
val c = 2.0
// you'll have to look in the browser console to see this.
val p1 = dom.document.createElement("p")
val p2 = dom.document.createElement("p")
println("boo")
p1.textContent = "In browser!"
p2.textContent = algo(a, b, c).mkString("[",", ", "]")
node.appendChild(p1)
node.appendChild(p2)
This simple algo method can be shared across JS, native and the JVM.
On JVM and Native, BLAS shims out to external libraries for zoer copy performance. On JS, we data copy as right now can't share between WASM and JS heap memory. Expect poor performance on JS.
Math ML
https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Matrix_math_for_the_web
It should be possible, to make lovely renders of our matricies in browser, for the purposes of communication.
Although it currently requires a rather hacky workaround, PRs are in flight for (hopefully scala js and laminar)
import org.scalajs.dom
import com.raquo.laminar.api.L._
import com.raquo.laminar.DomApi
import vecxt.all.{*, given}
import vecxtensions.MathTagsLaminar.*
val base = Array[Double](11, 12, 13, 14, 15)
val mat1 = Matrix.fromRows[Double](
base,
base + 10.0,
base + 20.0,
base + 30.0,
base + 40.0
)
val nodeId = "matrixExample"
node.id = "nodeId"
render(dom.document.querySelector("#nodeId"),
foreignHtmlElement(
DomApi.unsafeParseHtmlString(
p(
math(
xmlns1 := "http://www.w3.org/1998/Math/MathML",
mat1.printMl
)
).toString.dropRight(1).drop(20)
)
)
)