diff --git a/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res b/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res index 74a378c5..21e029db 100644 --- a/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res +++ b/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res @@ -4,7 +4,7 @@ open TestHelpers describe("combine with discrete", () => { makeTest( "keep order when multiplying by negative number", - AlgebraicShapeCombination.checkOrdered( + AlgebraicShapeCombination.isOrdered( AlgebraicShapeCombination.combineShapesContinuousDiscrete( #Multiply, {xs: [0., 1.], ys: [1., 1.]}, diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res index d4060cb8..b544fb33 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res @@ -255,4 +255,4 @@ let combineShapesContinuousDiscrete = ( ) } -let checkOrdered = (a: XYShape.T.t): bool => a.xs[0] < a.xs[1] +let isOrdered = (a: XYShape.T.t): bool => E.A.Sorted.Floats.isSorted(a.xs) diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 78c872ff..c3ba48a2 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -363,6 +363,9 @@ module A = { |> Rationale.Result.return } + let tail = Belt.Array.sliceToEnd(_, 1) + + let zip = Belt.Array.zip // This zips while taking the longest elements of each array. let zipMaxLength = (array1, array2) => { let maxLength = Int.max(length(array1), length(array2)) @@ -506,6 +509,9 @@ module A = { } module Floats = { + let isSorted = (ar: array): bool => + reduce(zip(ar, tail(ar)), true, (acc, (first, second)) => acc && first < second) + let makeIncrementalUp = (a, b) => Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i) |> Belt.Array.map(_, float_of_int)