Skip to content

Commit

Permalink
Refactored ai.dragonfly.math to slash.
Browse files Browse the repository at this point in the history
  • Loading branch information
c committed Oct 23, 2023
1 parent a52e21a commit b6d06d0
Show file tree
Hide file tree
Showing 92 changed files with 248 additions and 292 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ lazy val verification = project
.enablePlugins(NoPublishPlugin)
.settings(
name := "verification",
Compile / mainClass := Some("ai.dragonfly.math.Verify"),
Compile / mainClass := Some("verification.Verify"),
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-math3" % "3.6.1",
"gov.nist.math" % "jama" % "1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion docs/basics/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Let's create some vectors

```scala mdoc
import ai.dragonfly.math.vector.*
import slash.vector.*

val v = Vec.fromTuple(1.0, 2.0, 3.0, 4.0, 5.0)
val v2 = Vec[5](1.0, 2.0, 3.0, 4.0, 5.0)
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/factorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Example

```scala mdoc
import scala.language.postfixOps // don't forget this import
import ai.dragonfly.math.Factorial.!
import slash.Factorial.!
for (x:Int <- Seq(1, 2, 3, 4, 8, 16, 32, 64, 100)) {
println(s"${x}! = ${x!}")
}
Expand Down
3 changes: 1 addition & 2 deletions docs/demo/gamma.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
Try gamma function

```scala mdoc
import ai.dragonfly.math

for ( i <- 1 until 10 ) {
val i_1:Int = i - 1
println(s"\tΓ($i):$i_1! => ${math.gamma(i.toDouble)} : ${math.Factorial(i_1)}")
println(s"\tΓ($i):$i_1! => ${slash.gamma(i.toDouble)} : ${slash.Factorial(i_1)}")
}

```
4 changes: 2 additions & 2 deletions docs/demo/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Example

```scala mdoc
import ai.dragonfly.math.*
import ai.dragonfly.math.Constant
import slash.*
import slash.Constant

log[4](16)

Expand Down
4 changes: 2 additions & 2 deletions docs/demo/poisson.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Example

```scala mdoc
import ai.dragonfly.math.stats.probability.distributions.Poisson
import slash.stats.probability.distributions.Poisson
import narr.*

val dist1 = Poisson(1)
Expand All @@ -15,7 +15,7 @@ for (i <- 0 to 5) {
dist1.μ
dist1.`σ²`

val rand = ai.dragonfly.math.Random.defaultRandom
val rand = slash.Random.defaultRandom
type N = 10000
val v : NArray[Long] = dist1.sample(10000, rand)

Expand Down
2 changes: 1 addition & 1 deletion docs/demo/scalarOps.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Example

```scala mdoc
import ai.dragonfly.math.vector.*
import slash.vector.*

val v1 = Vec[2](1.5, 2.5)
v1 + 2.0
Expand Down
2 changes: 1 addition & 1 deletion docs/design/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ package object vector {
```
Please consider also, the flexibility to enable types that use Vectors of varying sizes:
```scala
package ai.dragonfly.math.vector
package slash.vector
import Vector.*

// instead of putting the Vector type in the type parameter, just place the vector dimensionality.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using dep ai.dragonfly::slash:@VERSION@
## Elevator pitch

```scala mdoc
import ai.dragonfly.math.vector.*
import slash.vector.*
val aVector = Vec[3](1,2,3)
val times2 = aVector * 2
aVector + times2
Expand Down
2 changes: 1 addition & 1 deletion docs/matrix/matrix.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Matricies introduction

```scala mdoc
import ai.dragonfly.math.matrix.*
import slash.matrix.*
// create a 3 x 2 matrix of zeros.
val m:Matrix[3, 2] = Matrix.zeros[3, 2]
```
Expand Down
11 changes: 5 additions & 6 deletions jsdocs/src/main/scala/poissonChart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package livechart
import scala.scalajs.js
import com.raquo.laminar.api.L.*
import viz.vega.plots.Histogram
import ai.dragonfly.math.stats.probability.distributions.Poisson
import narr.*

import viz.PlotTargets.doNothing

import viz.LaminarViz

import viz.vega.facades.VegaView
import viz.vega.facades.Helpers.*
import ai.dragonfly.math.vector.Vec
import slash.vector.Vec
import com.raquo.airstream.core.Signal
import narr.native.NArr

import scala.scalajs.js.typedarray.Float64Array
import io.circe.Encoder
import io.circe.Decoder
import io.circe.parser.decode
import slash.Random
import slash.stats.probability.distributions.Poisson

case class HistogramBin(
bin0: Double,
Expand All @@ -27,7 +26,7 @@ case class HistogramBin(
) derives Decoder, Encoder.AsObject

def poissonChart(): Div = {
val rand = ai.dragonfly.math.Random.defaultRandom
val rand = Random.defaultRandom
val λ_ = Var[Double](5.0)
val n_ = Var[Integer](1000)
val poissonDist: Signal[Poisson] = λ_.signal.map(Poisson(_))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package ai.dragonfly.math
package slash

trait Bijection[A, B](using a2b: A => B, b2a: B => A) {
given Conversion[A, B] with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package ai.dragonfly.math
package slash

object Constant {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package ai.dragonfly.math
package slash

import scala.language.postfixOps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package ai.dragonfly.math
package slash

import ai.dragonfly.math
import narr.*

object Gamma {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package ai.dragonfly.math
package slash

import ai.dragonfly.math.Constant.log2
import ai.dragonfly.math.vector.{Vec, *}
import Constant.log2
import slash.vector.*
import Vec.*
import narr.*

Expand All @@ -33,7 +33,7 @@ object Random {
private def digitCount(n: Int) = (n * log2).toInt
def nextBigInt(precision: Int): BigInt = BigInt(bitCount(precision), r)
def nextBigInt(norm: BigInt): BigInt = {
val precision: Int = digitCount(norm.bitLength);
val precision: Int = digitCount(norm.bitLength)
(BigDecimal(norm)(new MathContext(precision + 1)) * BigDecimal(nextBigInt(precision))).toBigInt
}
def between(min: BigInt, MAX: BigInt): BigInt = min + r.nextBigInt(MAX - min)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package ai.dragonfly.math.accumulation
package slash.accumulation

trait Accumulator[T <: BigInt | BigDecimal] {
def observe(n:T):Accumulator[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package ai.dragonfly.math.geometry
package slash.geometry

import ai.dragonfly.math.vector.*
import Vec2.*
import slash.vector.*
import slash.vector.Vec2.*

object Line {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package ai.dragonfly.math.geometry
package slash.geometry

import ai.dragonfly.math.stats.probability.distributions.Sampleable
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import slash.vector.*
import slash.vector.Vec.*
import narr.*
import slash.Random
import slash.stats.probability.distributions.Sampleable

object Tetrahedron {

Expand All @@ -46,7 +47,7 @@ case class Tetrahedron(vertices:NArray[Vec[3]]) extends Sampleable[Vec[3]] {

def volume:Double = `1/6` * Math.abs(`v1-v4` dot (`v2-v4` `v3-v4`))

override def random(r:scala.util.Random = ai.dragonfly.math.Random.defaultRandom): Vec[3] = {
override def random(r:scala.util.Random = Random.defaultRandom): Vec[3] = {

var w1 = r.nextDouble()
var w2 = r.nextDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package ai.dragonfly.math.interval
package slash.interval

import Interval.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package ai.dragonfly.math.interval
package slash.interval

import ai.dragonfly.math.{nextDown, nextUp}
import ai.dragonfly.math.stats.probability.distributions.Sampleable
import slash.{nextDown, nextUp}
import slash.stats.probability.distributions.Sampleable

import scala.reflect.ClassTag
import scala.util.Random
Expand Down Expand Up @@ -124,7 +124,7 @@ trait Interval[DOMAIN:ClassTag] extends Sampleable[DOMAIN] {

def rangeContains(x: Double): Boolean // = Interval.rangeContains(this, x)

import ai.dragonfly.math.Random.*
import slash.Random.*

override def random(r0:scala.util.Random = defaultRandom): DOMAIN// = Interval.randomFrom(this).asInstanceOf[DOMAIN]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

package ai.dragonfly.math
package slash

package object interval {

import ai.dragonfly.math.interval.Interval.*
import slash.interval.Interval.*

def `[]`(min: Long, MAX: Long): LongInterval = LongInterval(CLOSED, min, MAX)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

package ai.dragonfly.math.matrix
package slash.matrix

import ai.dragonfly.math.matrix.util.CannotExpressMatrixAsVector
import ai.dragonfly.math.vector.*
import ai.dragonfly.math.vector.Vec.*
import slash.matrix.util.CannotExpressMatrixAsVector
import slash.vector.*
import slash.vector.Vec.*
import narr.*

import scala.math.hypot
Expand Down Expand Up @@ -56,7 +56,7 @@ object Matrix {
*/
def random[M <: Int, N <: Int](
maxNorm:Double = 1.0,
r:scala.util.Random = ai.dragonfly.math.Random.defaultRandom
r:scala.util.Random = slash.Random.defaultRandom
)(using ValueOf[M], ValueOf[N]): Matrix[M, N] = new Matrix(
NArray.tabulate[NArray[Double]](valueOf[M])(
_ => NArray.tabulate[Double](valueOf[N])(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package ai.dragonfly.math.matrix.decomposition
package slash.matrix.decomposition

import ai.dragonfly.math.matrix.*
import ai.dragonfly.math.matrix.util.MatrixNotSymmetricPositiveDefinite
import slash.matrix.*
import slash.matrix.util.MatrixNotSymmetricPositiveDefinite
import narr.*

object Cholesky {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package ai.dragonfly.math.matrix.decomposition
package slash.matrix.decomposition

import ai.dragonfly.math.matrix.*
import ai.dragonfly.math.vector.Vec
import slash.matrix.*
import slash.vector.Vec
import narr.*

import scala.math.hypot
Expand Down
Loading

0 comments on commit b6d06d0

Please sign in to comment.