Skip to content

Commit

Permalink
tidy range extender
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Nov 18, 2024
1 parent 9a33975 commit b7c40f2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
6 changes: 4 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
- [x] reusable plot elements
- [x] via named tuples and upickle?
- [x] unit testing
- [ ] Switch to named tuples for the Matrix type
- [ ] Make matrix high dimensional
- [ ] Test with spire
- [ ] Beautiful display in scala JS through MathMl
- [ ] PR to scala JS dom in progress
- [ ] PR to scalal DOM types
- [ ] PR to laminar
- [ ] Investiagte the feasibility of WASM?
- [ ] Make matrix high dimensional
- [ ] Test with spire

- [ ] xPlatform LAPACK facade
10 changes: 2 additions & 8 deletions vecxt/js/src/matrix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import narr.*
import scala.scalajs.js.typedarray.Float64Array
import vecxt.BoundsCheck.BoundsCheck
import vecxt.arrays.*
import vecxt.rangeExtender.MatrixRange.range
import vecxt.rangeExtender.MatrixRange.RangeExtender

object matrix:

Expand Down Expand Up @@ -31,8 +33,6 @@ object matrix:
*/
opaque type Matrix = (NArray[Double], Tuple2[Int, Int])

type RangeExtender = Range | Int | NArray[Int] | ::.type

// type Matrix = Matrix1 & Tensor

object Matrix:
Expand Down Expand Up @@ -135,12 +135,6 @@ object matrix:
m._1(idx) = value
end update

private inline def range(r: RangeExtender, max: Int): NArray[Int] = r match
case _: ::.type => NArray.from((0 until max).toArray)
case r: Range => NArray.from(r.toArray)
case l: NArray[Int] => l
case i: Int => NArray(i)

def apply(rowRange: RangeExtender, colRange: RangeExtender): Matrix =
val newRows = range(rowRange, m.rows)
val newCols = range(colRange, m.cols)
Expand Down
7 changes: 1 addition & 6 deletions vecxt/native/src/matrix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.ekrich.blas.unsafe.blas
import org.ekrich.blas.unsafe.blasEnums
import scala.scalanative.unsafe.*
import vecxt.matrixUtil.*
import vecxt.rangeExtender.MatrixRange.range

object matrix:
/** This is a matrix
Expand Down Expand Up @@ -119,12 +120,6 @@ object matrix:
m._1(idx) = value
end update

private inline def range(r: RangeExtender, max: Int): NArray[Int] = r match
case _: ::.type => NArray.from((0 until max).toArray)
case r: Range => NArray.from(r.toArray)
case l: NArray[Int] => l
case i: Int => NArray(i)

def apply(rowRange: RangeExtender, colRange: RangeExtender): Matrix =
val newRows = range(rowRange, m.rows)
val newCols = range(colRange, m.cols)
Expand Down
17 changes: 11 additions & 6 deletions vecxt/src/rangeExtender.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package vecxt.rangeExtender

import narr.*

type RangeExtender = Range | Int | NArray[Int] | ::.type
export MatrixRange.*

inline def range(r: RangeExtender, max: Int): NArray[Int] = r match
case _: ::.type => NArray.from((0 until max).toArray)
case r: Range => NArray.from(r.toArray)
case l: NArray[Int] => l
case i: Int => NArray(i)
object MatrixRange:

type RangeExtender = Range | Int | NArray[Int] | ::.type

inline def range(r: RangeExtender, max: Int): NArray[Int] = r match
case _: ::.type => NArray.from((0 until max).toArray)
case r: Range => NArray.from(r.toArray)
case l: NArray[Int] => l
case i: Int => NArray(i)
end MatrixRange

// import narr.*

Expand Down

0 comments on commit b7c40f2

Please sign in to comment.