fastSort in toPointSet conversion

This commit is contained in:
Vyacheslav Matyukhin 2022-09-21 01:42:54 +04:00
parent 9f103f5cbe
commit 5db63fbe9f
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C

View File

@ -39,6 +39,13 @@ module Internals = {
module T = {
type t = array<float>
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)
@ -62,7 +69,7 @@ let toPointSetDist = (
~samplingInputs: SamplingInputs.samplingInputs,
(),
): Internals.Types.outputs => {
let samples = samples->Js.Array2.copy->Js.Array2.sortInPlaceWith(compare)
let samples = samples->Internals.T.fastSort
let minDiscreteToKeep = MagicNumbers.ToPointSet.minDiscreteToKeep(samples)
let (continuousPart, discretePart) = E.A.Floats.Sorted.splitContinuousAndDiscreteForMinWeight(