Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Updated: vector 1.01, cliviz 0.102, app 0.101
Browse files Browse the repository at this point in the history
Added:
  sonatype resolver
  DemoVectorInterop
  Vec[N] * Matrix[M, N] extension method.

Removed: JaMa comment.
  • Loading branch information
c committed May 31, 2023
1 parent b06c791 commit 53325e0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
val appVersion:String = "0.1"
val appVersion:String = "0.101"
val globalScalaVersion = "3.2.2"

ThisBuild / organization := "ai.dragonfly"
ThisBuild / organizationName := "dragonfly.ai"
ThisBuild / resolvers := Resolver.sonatypeOssRepos("releases")
ThisBuild / startYear := Some(2023)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List( tlGitHubDev("dragonfly-ai", "dragonfly.ai") )
Expand All @@ -22,7 +23,7 @@ lazy val matrix = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.settings(
description := "High performance, low footprint, cross platform, matrix math and machine learning library!",
libraryDependencies += "ai.dragonfly" %%% "vector" % "0.1",
libraryDependencies += "ai.dragonfly" %%% "vector" % "0.101",
)
.jvmSettings(
libraryDependencies ++= Seq("org.scala-js" %% "scalajs-stubs" % "1.1.0")
Expand All @@ -46,7 +47,7 @@ lazy val demo = crossProject(JSPlatform, JVMPlatform, NativePlatform)
name := "demo",
Compile / mainClass := Some("Demo"),
libraryDependencies ++= Seq(
"ai.dragonfly" %%% "cliviz" % "0.101",
"ai.dragonfly" %%% "cliviz" % "0.102",
"ai.dragonfly" %%% "democrossy" % "0.102"
)
).jsSettings(
Expand Down
3 changes: 2 additions & 1 deletion demo/shared/src/main/scala/Demo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ object Demo extends XApp(NativeConsole(style = "padding: 8px; overflow: scroll;"
val allDemos: Array[Demonstration] = Array[Demonstration](
DemoPCA,
DemoLinearRegression,
DemoEigenDecomposition
DemoEigenDecomposition,
DemoVectorInterop
)

for (d <- allDemos) d.demonstrate
Expand Down
1 change: 0 additions & 1 deletion demo/shared/src/main/scala/DemoEigenDecomposition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ai.dragonfly.math.matrix.Matrix
import ai.dragonfly.math.matrix.decomposition.*
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import ai.dragonfly.math.vector.Vec4.*
import narr.*

object DemoEigenDecomposition extends Demonstration {
Expand Down
27 changes: 27 additions & 0 deletions demo/shared/src/main/scala/DemoVectorInterop.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ai.dragonfly.democrossy.Demonstration
import ai.dragonfly.math.matrix.Matrix
import ai.dragonfly.math.matrix.util.*
import ai.dragonfly.math.matrix.decomposition.*
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import ai.dragonfly.math.vector.Vec2.*
import narr.*

import ai.dragonfly.math.Constant.*

object DemoVectorInterop extends Demonstration {
def demo(): Unit = {
val M0: Matrix[2, 3] = Matrix[2, 3](
NArray[NArray[Double]](
NArray[Double](1.0, `𝜑`, `√2`),
NArray[Double](2.0, π, e),
)
)

val v2: Vec[2] = Vec[2](1.0, 2.0)

println(s"${v2.show}.times($M0\n) = ${v2.times[3](M0)}")
}

def name: String = "DemoVectorInterop"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,9 @@ import scala.compiletime.ops.int.*
import scala.math.hypot

/**
* Jama = Java Matrix class.
* <P>
* The Java Matrix Class provides the fundamental operations of numerical
* linear algebra. Various constructors create Matrices from two dimensional
* arrays of double precision floating point numbers. Various "gets" and
* "sets" provide access to submatrices and matrix elements. Several methods
* implement basic matrix arithmetic, including matrix addition and
* multiplication, matrix norms, and element-by-element array operations.
* Methods for reading and printing matrices are also included. All the
* operations in this version of the Matrix Class involve real matrices.
* Complex matrices may be handled in a future version.
* <P>
* Five fundamental matrix decompositions, which consist of pairs or triples
* of matrices, permutation vectors, and the like, produce results in five
* decomposition classes. These decompositions are accessed by the Matrix
* class to compute solutions of simultaneous linear equations, determinants,
* inverses and other matrix functions. The five decompositions are:
* <P><UL>
* <LI>Cholesky Decomposition of symmetric, positive definite matrices.
* <LI>LU Decomposition of rectangular matrices.
* <LI>QR Decomposition of rectangular matrices.
* <LI>Singular Value Decomposition of rectangular matrices.
* <LI>Eigenvalue Decomposition of both symmetric and nonsymmetric square matrices.
* </UL>
* <DL>
* <DT><B>Example of use:</B></DT>
* <P>
* <DD>Solve a linear system A x = b and compute the residual norm, ||b - A x||.
* <P><PRE>
* double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
* Matrix A = new Matrix(vals);
* Matrix b = Matrix.random(3,1);
* Matrix x = A.solve(b);
* Matrix r = A.times(x).minus(b);
* double rnorm = r.normInfinity;
* </PRE></DD>
* </DL>
* *
*
* @author The MathWorks, Inc. and the National Institute of Standards and Technology.
* @version 5 August 1998
* This library is fundamentally an adaptation of the Java Matrix library, JaMa, by MathWorks Inc. and the National Institute of Standards and Technology.
*/


/*
Because scala.js does not support static methods or fields, this object is not exported.
However, the MatrixExports export of Matrix contains the native JS static methods for the Matrix class.
*/
object Matrix {
/** Construct a matrix from a copy of a 2-D array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object SV {

val minDim:Int = Math.min(rows, columns);

val s: Vec[N] = Vec.fill[N](0.0) // zeros
val s: Vec[N] = Vec.zeros[N]
val U: Matrix[M, N] = Matrix.zeros[M, N]
val V: Matrix[N, N] = Matrix.zeros[N, N]
val e: Vec[M] = Vec.fill[M](0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ package object util {
extension[N <: Int] (thisVector: Vec[N])(using ValueOf[N]) {
inline def asRowMatrix: Matrix[1, N] = Matrix[1, N](thisVector.asInstanceOf[NArray[Double]])
inline def asColumnMatrix: Matrix[N, 1] = Matrix[N, 1](thisVector.asInstanceOf[NArray[Double]])

def times [M <: Int] (thatMatrix: Matrix[N, M])(using ValueOf[M]): Matrix[1, M] = asRowMatrix * thatMatrix
inline def * [M <: Int] (thatMatrix: Matrix[N, M])(using ValueOf[M]): Matrix[1, M] = times(thatMatrix)
}

/**
Expand Down

0 comments on commit 53325e0

Please sign in to comment.