diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res index 81bfc760..4cf2b868 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res @@ -62,7 +62,7 @@ let toPointSetDist = ( ~samplingInputs: SamplingInputs.samplingInputs, (), ): 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 (continuousPart, discretePart) = E.A.Floats.Sorted.splitContinuousAndDiscreteForMinWeight( diff --git a/packages/squiggle-lang/src/rescript/Utility/E/E_A.res b/packages/squiggle-lang/src/rescript/Utility/E/E_A.res index 46ada15f..14ba187c 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E/E_A.res +++ b/packages/squiggle-lang/src/rescript/Utility/E/E_A.res @@ -229,9 +229,11 @@ module Floats = { let floatCompare: (float, float) => int = compare let sort = t => { - let r = t - r |> Array.fast_sort(floatCompare) - r + let typedArray = t->Js.TypedArray2.Float64Array.make + typedArray->Js.TypedArray2.Float64Array.sortInPlace->ignore + // 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))