Merge pull request #1165 from quantified-uncertainty/typed-pointset-conversion

Typed pointset conversion
This commit is contained in:
Vyacheslav Matyukhin 2022-09-21 03:21:22 +04:00 committed by GitHub
commit 14070a589d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -62,7 +62,7 @@ let toPointSetDist = (
~samplingInputs: SamplingInputs.samplingInputs, ~samplingInputs: SamplingInputs.samplingInputs,
(), (),
): Internals.Types.outputs => { ): Internals.Types.outputs => {
let samples = samples->Js.Array2.copy->Js.Array2.sortInPlaceWith(compare) let samples = samples->E.A.Floats.sort
let minDiscreteToKeep = MagicNumbers.ToPointSet.minDiscreteToKeep(samples) let minDiscreteToKeep = MagicNumbers.ToPointSet.minDiscreteToKeep(samples)
let (continuousPart, discretePart) = E.A.Floats.Sorted.splitContinuousAndDiscreteForMinWeight( let (continuousPart, discretePart) = E.A.Floats.Sorted.splitContinuousAndDiscreteForMinWeight(

View File

@ -229,9 +229,11 @@ module Floats = {
let floatCompare: (float, float) => int = compare let floatCompare: (float, float) => int = compare
let sort = t => { let sort = t => {
let r = t let typedArray = t->Js.TypedArray2.Float64Array.make
r |> Array.fast_sort(floatCompare) typedArray->Js.TypedArray2.Float64Array.sortInPlace->ignore
r // why is there no standard function in Resctipt for this?
let typedArrayToArray: Js.TypedArray2.Float64Array.t => t = %raw(`a => Array.from(a)`)
typedArrayToArray(typedArray)
} }
let getNonFinite = (t: t) => Belt.Array.getBy(t, r => !Js.Float.isFinite(r)) let getNonFinite = (t: t) => Belt.Array.getBy(t, r => !Js.Float.isFinite(r))