review updates

This commit is contained in:
Vyacheslav Matyukhin 2022-09-21 02:20:17 +04:00
parent 6fc21ddda6
commit 13f352752e
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C

View File

@ -307,9 +307,12 @@ module Floats = {
continuous samples and discrete samples. The discrete samples are stored in a mutable map. continuous samples and discrete samples. The discrete samples are stored in a mutable map.
Samples are thought to be discrete if they have at least `minDiscreteWight` duplicates. Samples are thought to be discrete if they have at least `minDiscreteWight` duplicates.
If the min discreet weight is 4, that would mean that at least four elements needed from a specific If the min discrete weight is 4, that would mean that at least four elements needed from a specific
value for that to be kept as discrete. This is important because in some cases, we can expect that value for that to be kept as discrete. This is important because in some cases, we can expect that
some common elements will be generated by regular operations. The final continous array will be sorted. some common elements will be generated by regular operations. The final continuous array will be sorted.
This function is performance-critical, don't change it significantly without benchmarking
SampleSet->PointSet conversion performance.
*/ */
let splitContinuousAndDiscreteForMinWeight = ( let splitContinuousAndDiscreteForMinWeight = (
sortedArray: array<float>, sortedArray: array<float>,
@ -318,34 +321,32 @@ module Floats = {
let continuous: array<float> = [] let continuous: array<float> = []
let discrete = FloatFloatMap.empty() let discrete = FloatFloatMap.empty()
let flush = (cnt: int, value: float): unit => { let addData = (count: int, value: float): unit => {
if cnt >= minDiscreteWeight { if count >= minDiscreteWeight {
FloatFloatMap.add(value, cnt->Belt.Int.toFloat, discrete) FloatFloatMap.add(value, count->Belt.Int.toFloat, discrete)
} else { } else {
for _ in 1 to cnt { for _ in 1 to count {
let _ = continuous->Js.Array2.push(value) continuous->Js.Array2.push(value)->ignore
} }
} }
} }
if sortedArray->Js.Array2.length != 0 { let (finalCount, finalValue) = sortedArray->Belt.Array.reduce(
let (finalCnt, finalValue) = sortedArray->Belt.Array.reduce(
// initial prev value doesn't matter; if it collides with the first element of the array, flush won't do anything // initial prev value doesn't matter; if it collides with the first element of the array, flush won't do anything
(0, 0.), (0, 0.),
((cnt, prev), element) => { ((count, prev), element) => {
if element == prev { if element == prev {
(cnt + 1, prev) (count + 1, prev)
} else { } else {
// new value, process previous ones // new value, process previous ones
flush(cnt, prev) addData(count, prev)
(1, element) (1, element)
} }
}, },
) )
// flush final values // flush final values
flush(finalCnt, finalValue) addData(finalCount, finalValue)
}
(continuous, discrete) (continuous, discrete)
} }