From 90d3f89c0ac3ce061b340b5f9e685362924d2218 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Tue, 19 Jul 2022 21:32:11 -0700 Subject: [PATCH] Trying to fix things, but breaking a lot of tests. --- .../Reducer_Dispatch_BuiltIn_test.res | 2 +- .../ReducerInterface_Distribution_test.res | 6 --- .../FunctionRegistry/Library/FR_Sampleset.res | 54 ++++++++++++++++--- packages/website/docs/Api/DistPointSet.md | 2 - 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res index 65048ebb..a4cc15b3 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res @@ -18,7 +18,7 @@ describe("builtin", () => { testEval("2>1", "Ok(true)") testEval("concat('a','b')", "Ok('ab')") testEval( - "addOne(t)=t+1; toList(mapSamples(fromSamples([1,2,3,4,5,6]), addOne))", + "addOne(t)=t+1; toList(Sampleset.map(fromSamples([1,2,3,4,5,6]), addOne))", "Ok([2,3,4,5,6,7])", ) testEval( diff --git a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res index ecc07bfa..3083b71b 100644 --- a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res +++ b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res @@ -41,12 +41,6 @@ describe("eval on distribution functions", () => { describe("normalize", () => { testEval("normalize(normal(5,2))", "Ok(Normal(5,2))") }) - describe("toPointSet", () => { - testEval("toPointSet(normal(5,2))", "Ok(Point Set Distribution)") - }) - describe("toSampleSet", () => { - testEval("toSampleSet(normal(5,2), 100)", "Ok(Sample Set Distribution)") - }) describe("add", () => { testEval("add(normal(5,2), normal(10,2))", "Ok(Normal(15,2.8284271247461903))") testEval("add(normal(5,2), lognormal(10,2))", "Ok(Sample Set Distribution)") diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res index a19f740e..fd27c5f7 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res @@ -90,14 +90,57 @@ let library = [ (), ), Function.make( - ~name="map", + ~name="fromLlist", ~nameSpace, - ~requiresNamespace, - ~examples=[`Sampleset.map(Sampleset.maker(normal(5,2)), {|x| x + 1})`], + ~requiresNamespace=true, + ~examples=[`Sampleset.fromLlist([3,5,2,3,5,2,3,5,2,3,3,5,3,2,3,1,1,3])`], ~output=ReducerInterface_InternalExpressionValue.EvtDistribution, ~definitions=[ FnDefinition.make( - ~name="map", + ~name="fromLlist", + ~inputs=[FRTypeArray(FRTypeNumber)], + ~run=(_, inputs, _, _) => { + let sampleSet = + Prepare.ToTypedArray.numbers(inputs) |> E.R2.bind(r => + SampleSetDist.make(r)->E.R2.errMap(_ => "") + ) + sampleSet->E.R2.fmap(Wrappers.sampleSet)->E.R2.fmap(Wrappers.evDistribution) + }, + (), + ), + ], + (), + ), + Function.make( + ~name="toLlist", + ~nameSpace, + ~requiresNamespace=false, + ~examples=[`Sampleset.toLlist(Sampleset.maker(normal(5,2))`], + ~output=ReducerInterface_InternalExpressionValue.EvtArray, + ~definitions=[ + FnDefinition.make( + ~name="toLlist", + ~inputs=[FRTypeDist], + ~run=(inputs, _, _, _) => + switch inputs { + | [IEvDistribution(SampleSet(dist))] => + dist->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok + | _ => Error(impossibleError) + }, + (), + ), + ], + (), + ), + Function.make( + ~name="mapp", + ~nameSpace, + ~requiresNamespace, + ~examples=[`Sampleset.mapp(Sampleset.maker(normal(5,2)), {|x| x + 1})`], + ~output=ReducerInterface_InternalExpressionValue.EvtDistribution, + ~definitions=[ + FnDefinition.make( + ~name="mapp", ~inputs=[FRTypeDist, FRTypeLambda], ~run=(inputs, _, env, reducer) => switch inputs { @@ -123,7 +166,6 @@ let library = [ ~name="map2", ~inputs=[FRTypeDist, FRTypeDist, FRTypeLambda], ~run=(inputs, _, env, reducer) => { - Js.log2("WHY DIDNT IT MATCH", inputs) switch inputs { | [ IEvDistribution(SampleSet(dist1)), @@ -182,7 +224,7 @@ let library = [ ~run=(inputs, _, env, reducer) => switch inputs { | [IEvArray(dists), IEvLambda(lambda)] => - Internal.mapN(dists, lambda, env, reducer)->E.R2.errMap(_ => "") + Internal.mapN(dists, lambda, env, reducer)->E.R2.errMap(e => {Js.log2("HI", e); "AHHH doesn't work"}) | _ => Error(impossibleError) }, (), diff --git a/packages/website/docs/Api/DistPointSet.md b/packages/website/docs/Api/DistPointSet.md index f3840055..9c9c3d0d 100644 --- a/packages/website/docs/Api/DistPointSet.md +++ b/packages/website/docs/Api/DistPointSet.md @@ -34,8 +34,6 @@ PointSet.makeContinuous([ ### makeDiscrete -Converts a set of x-y coordinates directly into a discrete distribution. - ``` PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist ```