E.A.Floats.sort uses typed arrays
This commit is contained in:
		
							parent
							
								
									5db63fbe9f
								
							
						
					
					
						commit
						59d38f7885
					
				| 
						 | 
					@ -39,13 +39,6 @@ module Internals = {
 | 
				
			||||||
  module T = {
 | 
					  module T = {
 | 
				
			||||||
    type t = array<float>
 | 
					    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 xWidthToUnitWidth = (samples, outputXYPoints, xWidth) => {
 | 
				
			||||||
      let xyPointRange = E.A.Sorted.range(samples)->E.O2.default(0.0)
 | 
					      let xyPointRange = E.A.Sorted.range(samples)->E.O2.default(0.0)
 | 
				
			||||||
      let xyPointWidth = xyPointRange /. float_of_int(outputXYPoints)
 | 
					      let xyPointWidth = xyPointRange /. float_of_int(outputXYPoints)
 | 
				
			||||||
| 
						 | 
					@ -69,7 +62,7 @@ let toPointSetDist = (
 | 
				
			||||||
  ~samplingInputs: SamplingInputs.samplingInputs,
 | 
					  ~samplingInputs: SamplingInputs.samplingInputs,
 | 
				
			||||||
  (),
 | 
					  (),
 | 
				
			||||||
): Internals.Types.outputs => {
 | 
					): Internals.Types.outputs => {
 | 
				
			||||||
  let samples = samples->Internals.T.fastSort
 | 
					  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(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -229,9 +229,10 @@ module Floats = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let floatCompare: (float, float) => int = compare
 | 
					  let floatCompare: (float, float) => int = compare
 | 
				
			||||||
  let sort = t => {
 | 
					  let sort = t => {
 | 
				
			||||||
    let r = t
 | 
					    let typed = t->Js.TypedArray2.Float64Array.make->Js.TypedArray2.Float64Array.sortInPlace
 | 
				
			||||||
    r |> Array.fast_sort(floatCompare)
 | 
					    // why is there no standard function in Resctipt for this?
 | 
				
			||||||
    r
 | 
					    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))
 | 
					  let getNonFinite = (t: t) => Belt.Array.getBy(t, r => !Js.Float.isFinite(r))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user