-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Quafadas/higher_kinded
Higher kinded
- Loading branch information
Showing
32 changed files
with
901 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
It can be confusing, why certain methods are placed in certain objects. It boils down to constraints and keeping the compiler happy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package vecxt | ||
|
||
import narr.* | ||
import vecxt.matrix.Matrix | ||
|
||
// These use project panama (SIMD) on the JVM, so need own JS native implementation | ||
object JsNativeDoubleArrays: | ||
|
||
extension (m: Matrix[Double]) | ||
inline def >=(d: Double): Matrix[Boolean] = | ||
Matrix[Boolean](m.raw >= d, m.shape)(using BoundsCheck.DoBoundsCheck.no) | ||
|
||
inline def >(d: Double): Matrix[Boolean] = | ||
Matrix[Boolean](m.raw > d, m.shape)(using BoundsCheck.DoBoundsCheck.no) | ||
|
||
inline def <=(d: Double): Matrix[Boolean] = | ||
Matrix[Boolean](m.raw <= d, m.shape)(using BoundsCheck.DoBoundsCheck.no) | ||
|
||
inline def <(d: Double): Matrix[Boolean] = | ||
Matrix[Boolean](m.raw < d, m.shape)(using BoundsCheck.DoBoundsCheck.no) | ||
end extension | ||
|
||
extension (vec: NArray[Double]) | ||
|
||
inline def <(num: Double): NArray[Boolean] = | ||
logicalIdx((a, b) => a < b, num) | ||
|
||
inline def <=(num: Double): NArray[Boolean] = | ||
logicalIdx((a, b) => a <= b, num) | ||
|
||
inline def >(num: Double): NArray[Boolean] = | ||
logicalIdx((a, b) => a > b, num) | ||
|
||
inline def >=(num: Double): NArray[Boolean] = | ||
logicalIdx((a, b) => a >= b, num) | ||
|
||
inline def logicalIdx( | ||
inline op: (Double, Double) => Boolean, | ||
inline num: Double | ||
): NArray[Boolean] = | ||
val n = vec.length | ||
val idx = NArray.fill(n)(false) | ||
|
||
var i = 0 | ||
while i < n do | ||
if op(vec(i), num) then idx(i) = true | ||
end if | ||
i = i + 1 | ||
end while | ||
idx | ||
end logicalIdx | ||
end extension | ||
end JsNativeDoubleArrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package vecxt | ||
|
||
import narr.* | ||
import matrix.* | ||
import vecxt.MatrixHelper.* | ||
import vecxt.MatrixInstance.* | ||
import scala.scalajs.js.typedarray.Float64Array | ||
import vecxt.BoundsCheck.BoundsCheck | ||
import vecxt.arrays.* | ||
import vecxt.rangeExtender.MatrixRange.range | ||
import vecxt.rangeExtender.MatrixRange.RangeExtender | ||
|
||
object JsDoubleMatrix: | ||
|
||
extension (m: Matrix[Double]) | ||
|
||
// inline def tupleFromIdx(b: Int)(using inline boundsCheck: BoundsCheck) = | ||
// dimCheckLen(m.raw, b) | ||
// (b / m.rows, b % m.rows) | ||
// end tupleFromIdx | ||
|
||
inline def +(m2: Matrix[Double])(using inline boundsCheck: BoundsCheck): Matrix[Double] = | ||
sameDimMatCheck(m, m2) | ||
val newArr: NArray[Double] = m.raw.add(m2.raw) | ||
Matrix[Double](newArr, m.shape)(using BoundsCheck.DoBoundsCheck.no) | ||
end + | ||
|
||
inline def matmul(b: Matrix[Double])(using inline boundsCheck: BoundsCheck): Matrix[Double] = | ||
dimMatCheck(m, b) | ||
val newArr = Float64Array(m.rows * b.cols) | ||
// Note, might need to deal with transpose later. | ||
dgemm( | ||
"column-major", | ||
"no-transpose", | ||
"no-transpose", | ||
m.rows, | ||
b.cols, | ||
m.cols, | ||
1.0, | ||
m.raw, | ||
m.rows, | ||
b.raw, | ||
b.rows, | ||
1.0, | ||
newArr, | ||
m.rows | ||
) | ||
Matrix[Double](newArr, (m.rows, b.cols)) | ||
end matmul | ||
end extension | ||
end JsDoubleMatrix | ||
|
||
object JvmDoubleMatrix: | ||
|
||
end JvmDoubleMatrix | ||
|
||
object NativeDoubleMatrix: | ||
|
||
end NativeDoubleMatrix | ||
|
||
object JvmNativeDoubleMatrix: | ||
|
||
end JvmNativeDoubleMatrix |
Oops, something went wrong.