Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Sep 26, 2024
1 parent 7769bbe commit 7ea8347
Showing 1 changed file with 50 additions and 29 deletions.
79 changes: 50 additions & 29 deletions vecxt/jvm/src/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,45 +122,66 @@ object extensions:

extension (vec: Array[Double])

inline def apply(index: Array[Boolean])(using inline boundsCheck: BoundsCheck): Array[Double] =
inline def apply(index: Array[Boolean])(using inline boundsCheck: BoundsCheck) =
dimCheck(vec, index)
val newVec: Array[Double] = new Array[Double](index.length)
val out = new Array[Double](vec.length)
val sp = Matrix.doubleSpecies
val l = sp.length()

var i = 0
val trues = index.countTrue
val newVec: Array[Double] = new Array[Double](trues)
var j = 0
while i < sp.loopBound(vec.length) do
println(s"i: $i || j: $j")
val mask = VectorMask.fromArray[java.lang.Double](sp, index, i)
for i <- 0 until index.length do
// println(s"i: $i || j: $j || ${index(i)} ${vec(i)} ")
if index(i) then
newVec(j) = vec(i)
j = 1 + j
end for
newVec
end apply

val vals = DoubleVector
.fromArray(sp, vec, i)

// val selected = vals.selectFrom(vals, mask)
/**
* Apparently, left packing is hard problem in SIMD land.
* https://stackoverflow.com/questions/79025873/selecting-values-from-java-simd-doublevector
*
*/

println(s"mask: ${mask.toArray().print}")
println(s"vals: ${vals.toArray().print}")
vals.intoArray(newVec, j, mask)
println(newVec.print)
// inline def apply(index: Array[Boolean])(using inline boundsCheck: BoundsCheck): Array[Double] =
// dimCheck(vec, index)
// val newVec: Array[Double] = new Array[Double](index.length)
// val out = new Array[Double](vec.length)
// val sp = Matrix.doubleSpecies
// val l = sp.length()

i += l
j = j + mask.trueCount()
// var i = 0
// var j = 0
// while i < sp.loopBound(vec.length) do
// println(s"i: $i || j: $j")
// val mask = VectorMask.fromArray[java.lang.Double](sp, index, i)

end while
// val vals = DoubleVector
// .fromArray(sp, vec, i)

while i < vec.length do
if index(i) then
newVec(j) = vec(i)
j += 1
end if
i += 1
end while
// // val selected = vals.selectFrom(vals, mask)

newVec
// println(s"mask: ${mask.toArray().print}")
// println(s"vals: ${vals.toArray().print}")
// vals.intoArray(newVec, j, mask)
// println(newVec.print)

end apply
// i += l
// j = j + mask.trueCount()

// end while

// while i < vec.length do
// if index(i) then
// newVec(j) = vec(i)
// j += 1
// end if
// i += 1
// end while

// newVec

// end apply

inline def increments: Array[Double] =
val out = new Array[Double](vec.length)
Expand Down

0 comments on commit 7ea8347

Please sign in to comment.