From b2b51c8f462d2b2a2407ac9aadc9e4055afdac1b Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 15 May 2022 10:52:35 -0400 Subject: [PATCH 1/2] Added sampleN to interface --- .../src/rescript/Distributions/DistributionOperation.res | 1 + .../src/rescript/Distributions/DistributionOperation.resi | 1 + .../ReducerInterface/ReducerInterface_GenericDistribution.res | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res index 80a53eb8..da4c010a 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res @@ -18,6 +18,7 @@ type outputType = | Dist(genericDist) | Float(float) | String(string) + | FloatArray(array) | Bool(bool) | GenDistError(error) diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi index 200be7d7..a8d61a9a 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi @@ -14,6 +14,7 @@ type outputType = | Dist(genericDist) | Float(float) | String(string) + | FloatArray(array) | Bool(bool) | GenDistError(error) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index 8dae2586..37bffeef 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -216,6 +216,9 @@ let dispatchToGenericOutput = (call: ExpressionValue.functionCall, _environment) ->E.R.bind(r => r(f1, f2, f3)) ->SymbolicConstructors.symbolicResultToOutput | ("sample", [EvDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist) + | ("sampleN", [EvDistribution(dist), EvNumber(n)]) => Some( + FloatArray(GenericDist.sampleN(dist, Belt.Int.fromFloat(n))), + ) | ("mean", [EvDistribution(dist)]) => Helpers.toFloatFn(#Mean, dist) | ("integralSum", [EvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist) | ("toString", [EvDistribution(dist)]) => Helpers.toStringFn(ToString, dist) @@ -315,6 +318,7 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result< | Float(d) => Ok(EvNumber(d)) | String(d) => Ok(EvString(d)) | Bool(d) => Ok(EvBool(d)) + | FloatArray(d) => Ok(EvArray(d |> E.A.fmap(r =>ReducerInterface_ExpressionValue.EvNumber(r)))) | GenDistError(err) => Error(REDistributionError(err)) } From 4676026aa0e26670ef23860f7cef977591de9bb7 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 15 May 2022 10:58:29 -0400 Subject: [PATCH 2/2] Ran formatter --- packages/squiggle-lang/package.json | 1 - .../ReducerInterface_GenericDistribution.res | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index d21f2eb6..c1705471 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -33,7 +33,6 @@ "Rescript" ], "author": "Quantified Uncertainty Research Institute", - "license": "MIT", "dependencies": { "rescript": "^9.1.4", "jstat": "^1.9.5", diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index 448d7f1b..f36c21bf 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -222,9 +222,8 @@ let dispatchToGenericOutput = ( ->E.R.bind(r => r(f1, f2, f3)) ->SymbolicConstructors.symbolicResultToOutput | ("sample", [EvDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist, ~env) - | ("sampleN", [EvDistribution(dist), EvNumber(n)]) => Some( - FloatArray(GenericDist.sampleN(dist, Belt.Int.fromFloat(n))), - ) + | ("sampleN", [EvDistribution(dist), EvNumber(n)]) => + Some(FloatArray(GenericDist.sampleN(dist, Belt.Int.fromFloat(n)))) | ("mean", [EvDistribution(dist)]) => Helpers.toFloatFn(#Mean, dist, ~env) | ("integralSum", [EvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env) | ("toString", [EvDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env) @@ -339,7 +338,7 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result< | Float(d) => Ok(EvNumber(d)) | String(d) => Ok(EvString(d)) | Bool(d) => Ok(EvBool(d)) - | FloatArray(d) => Ok(EvArray(d |> E.A.fmap(r =>ReducerInterface_ExpressionValue.EvNumber(r)))) + | FloatArray(d) => Ok(EvArray(d |> E.A.fmap(r => ReducerInterface_ExpressionValue.EvNumber(r)))) | GenDistError(err) => Error(REDistributionError(err)) }