Skip to content

Commit

Permalink
fix tvar
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Jul 26, 2024
1 parent fc798e5 commit 70178d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vecxt/src/tvar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension [N <: Int](thisVector: NArray[Double])
def tVar(alpha: Double): Double =
val numYears = thisVector.length
val nte = numYears * (1.0 - alpha);
val fte = Math.floor(nte).toInt;
val fte = Math.floor(nte+0.001).toInt;
val sorted = thisVector.sort()
var i = 0
var tailSum = 0.0;
Expand All @@ -41,7 +41,7 @@ extension [N <: Int](thisVector: NArray[Double])
def tVarIdx(alpha: Double): NArray[Boolean] =
val numYears = thisVector.length
val nte = numYears * (1.0 - alpha);
val fte = Math.floor(nte).toInt;
val fte = Math.floor(nte+0.001).toInt;
val sorted = thisVector.toVector.zipWithIndex.sortBy(_._1).map(_._2)
val idx = NArray.fill[Boolean](numYears)(false)
var i = 0
Expand Down
20 changes: 20 additions & 0 deletions vecxt/test/src/arrayExtensions.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,25 @@ class ArrayExtensionSuite extends munit.FunSuite:
end for
}

test("tvar index 2") {
import vecxt.rpt.tVarIdx
val v1 = NArray.from(Array(6.0, 2.0, 5.0, 5.0, 10.0, 1.0, 2.0, 3.0, 5.0, 8.0))
val tvar = v1.tVarIdx(0.90)

assertEquals(tvar.countTrue, 1)
assert(tvar(5))
}


test("tvar index 3") {
import vecxt.rpt.tVarIdx
val v1 = NArray.from(Array(6.0, 2.0, 5.0, 5.0, 10.0, 1.0, 2.0, 3.0, 5.0, 8.0))
val tvar = v1.tVarIdx(0.8)

assertEquals(tvar.countTrue, 1)
assert(tvar(5))
assert(tvar(6))
}


end ArrayExtensionSuite

0 comments on commit 70178d9

Please sign in to comment.