From 59d38f7885240d97a41526401ca4803a39f1ccb7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Wed, 21 Sep 2022 03:17:25 +0400 Subject: [PATCH] E.A.Floats.sort uses typed arrays --- .../SampleSetDist/SampleSetDist_ToPointSet.res | 9 +-------- packages/squiggle-lang/src/rescript/Utility/E/E_A.res | 7 ++++--- 2 files changed, 5 insertions(+), 11 deletions(-) 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 7d5498f7..4cf2b868 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res @@ -39,13 +39,6 @@ module Internals = { module T = { type t = array - let fastSort = (samples: t): t => { - let typedSamples = samples->Js.TypedArray2.Float64Array.make->Js.TypedArray2.Float64Array.sortInPlace - // why is there no standard function in Resctipt for this? - let typedToArray: Js.TypedArray2.Float64Array.t => t = %raw(`a => Array.from(a)`) - typedToArray(typedSamples) - } - let xWidthToUnitWidth = (samples, outputXYPoints, xWidth) => { let xyPointRange = E.A.Sorted.range(samples)->E.O2.default(0.0) let xyPointWidth = xyPointRange /. float_of_int(outputXYPoints) @@ -69,7 +62,7 @@ let toPointSetDist = ( ~samplingInputs: SamplingInputs.samplingInputs, (), ): Internals.Types.outputs => { - let samples = samples->Internals.T.fastSort + 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..dd7b7c90 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,10 @@ module Floats = { let floatCompare: (float, float) => int = compare let sort = t => { - let r = t - r |> Array.fast_sort(floatCompare) - r + let typed = t->Js.TypedArray2.Float64Array.make->Js.TypedArray2.Float64Array.sortInPlace + // why is there no standard function in Resctipt for this? + let typedToArray: Js.TypedArray2.Float64Array.t => t = %raw(`a => Array.from(a)`) + typedToArray(typed) } let getNonFinite = (t: t) => Belt.Array.getBy(t, r => !Js.Float.isFinite(r))