Skip to content

Commit

Permalink
hmmm
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Nov 7, 2023
1 parent 72f6505 commit 26fadad
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
8 changes: 8 additions & 0 deletions core/js/src/main/scala/conv.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package vecxt

import scala.scalajs.js.typedarray.Float64Array

type vecxting = Float64Array with vecxt

given Conversion[Float64Array, vecxting] with
def apply(in: Float64Array): vecxting = in.asInstanceOf[vecxting]
9 changes: 9 additions & 0 deletions core/jvm/src/main/scala/conv.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package vecxt

import scala.language.implicitConversions


type vecxting = Array[Double] with vecxt

given Conversion[Array[Double], vecxting] with
def apply(in: Array[Double]): vecxting = in.asInstanceOf[vecxting]
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package vecxt

import scala.language.implicitConversions

import vecxt.given_Conversion_Array_vecxting

import vecxt.*

@main def checkBytecode =
val a = Array[Double](1,2,3)
Expand Down
26 changes: 17 additions & 9 deletions core/shared/src/main/scala/vecxt/array.extensions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ import vecxt.Retentions.Retention
import scala.util.chaining.*
import vecxt.BoundsCheck


enum LossCalc:
case Agg, Occ
end LossCalc

transparent trait vecxt {

def update(i: Int, d: Double): Unit
def apply(i:Int) : Double
def length: Int

}


extension (vec: Array[Boolean])
inline def countTrue: Int =
var sum = 0
Expand Down Expand Up @@ -56,7 +64,7 @@ extension (vec: Array[Boolean])
// end copy
end extension

extension (vec: Array[Double])
extension (vec: vecxt)

def idxBoolean(index: Array[Boolean]) =
val trues = index.countTrue
Expand All @@ -82,12 +90,12 @@ extension (vec: Array[Double])
out
end increments

inline def stdDev: Double =
// https://www.cuemath.com/data/standard-deviation/
val mu = vec.mean
val diffs_2 = vec.map(num => Math.pow(num - mu, 2))
Math.sqrt(diffs_2.sum / (vec.length - 1))
end stdDev
// inline def stdDev: Double =
// // https://www.cuemath.com/data/standard-deviation/
// val mu = vec.mean
// val diffs_2 = vec.map(num => Math.pow(num - mu, 2))
// Math.sqrt(diffs_2.sum / (vec.length - 1))
// end stdDev

inline def mean: Double = vec.sum / vec.length

Expand All @@ -110,7 +118,7 @@ extension (vec: Array[Double])
end cumsum

inline def -(vec2: Array[Double])(using inline boundsCheck : BoundsCheck) =
dimCheck(vec, vec2)
//dimCheck(vec, vec2)
val out = new Array[Double](vec.length)
var i = 0
while i < vec.length do
Expand Down
4 changes: 4 additions & 0 deletions tests/shared/src/test/scala/arrayExtensions.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
package vecxt

import scala.util.chaining.*
import scala.language.implicitConversions
import vecxt.given_Conversion_Array_vecxting

class ArrayExtensionSuite extends munit.FunSuite:
import vecxt.BoundsCheck.yes

//import vecxt.given_Conversion_Array_vecxting

lazy val v_fill = Array.tabulate(5)(i => i.toDouble)

test("Array horizontal sum") {
Expand Down
1 change: 1 addition & 0 deletions tests/shared/src/test/scala/boundsCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package vecxt

import scala.util.chaining.*
import scala.language.implicitConversions

class BoundsCheckSuite extends munit.FunSuite:

Expand Down
1 change: 1 addition & 0 deletions tests/shared/src/test/scala/rpt.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vecxt

import Retentions.*
import Limits.*
import scala.language.implicitConversions

extension [A <: AnyRef](o: A) def some = Some(o)

Expand Down

0 comments on commit 26fadad

Please sign in to comment.