Ran formatter and fixed tests

This commit is contained in:
Ozzie Gooen 2022-06-11 08:47:52 -07:00
parent 2d4d8a8f4d
commit 79b71c39a0
6 changed files with 32 additions and 34 deletions

View File

@ -88,8 +88,8 @@ describe("Peggy Types to Expression", () => {
}) })
describe("squiggle expressions in type modifiers", () => { describe("squiggle expressions in type modifiers", () => {
testToExpression( testToExpression(
"odds1 = [1,3,5]; odds2 = [7, 9]; type odds = number<-memberOf(odds1 + odds2)", "odds1 = [1,3,5]; odds2 = [7, 9]; type odds = number<-memberOf(concat(odds1, odds2))",
"{(:$_let_$ :odds1 {(:$_constructArray_$ (1 3 5))}); (:$_let_$ :odds2 {(:$_constructArray_$ (7 9))}); (:$_typeAlias_$ #odds (:$_typeModifier_memberOf_$ #number (:add :odds1 :odds2)))}", "{(:$_let_$ :odds1 {(:$_constructArray_$ (1 3 5))}); (:$_let_$ :odds2 {(:$_constructArray_$ (7 9))}); (:$_typeAlias_$ #odds (:$_typeModifier_memberOf_$ #number (:concat :odds1 :odds2)))}",
~v="{_typeAliases_: {odds: {typeTag: 'typeIdentifier',typeIdentifier: #number,memberOf: [1,3,5,7,9]}},odds1: [1,3,5],odds2: [7,9]}", ~v="{_typeAliases_: {odds: {typeTag: 'typeIdentifier',typeIdentifier: #number,memberOf: [1,3,5,7,9]}},odds1: [1,3,5],odds2: [7,9]}",
(), (),
) )

View File

@ -7,7 +7,7 @@ describe("map reduce", () => {
testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; reduce(arr, 0, change)", "Ok(15)") testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; reduce(arr, 0, change)", "Ok(15)")
testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; reduceReverse(arr, 0, change)", "Ok(9)") testEvalToBe("change(acc,x)=acc*x+x; arr=[1,2,3]; reduceReverse(arr, 0, change)", "Ok(9)")
testEvalToBe("arr=[1,2,3]; reverse(arr)", "Ok([3,2,1])") testEvalToBe("arr=[1,2,3]; reverse(arr)", "Ok([3,2,1])")
testEvalToBe("check(x)=(x==2);arr=[1,2,3]; keep(arr,check)", "Ok([2])") testEvalToBe("check(x)=(x==2);arr=[1,2,3]; filter(arr,check)", "Ok([2])")
}) })
Skip.describe("map reduce (sam)", () => { Skip.describe("map reduce (sam)", () => {

View File

@ -350,7 +350,7 @@ module Function = {
description: description, description: description,
} }
let toSimple = (t: t): functionJson => { let toJson = (t: t): functionJson => {
name: t.name, name: t.name,
definitions: t.definitions->E.A2.fmap(FnDefinition.toString), definitions: t.definitions->E.A2.fmap(FnDefinition.toString),
examples: t.examples, examples: t.examples,
@ -360,7 +360,7 @@ module Function = {
} }
module Registry = { module Registry = {
let toSimple = (r: registry) => r->E.A2.fmap(Function.toSimple) let toJson = (r: registry) => r->E.A2.fmap(Function.toJson)
/* /*
There's a (potential+minor) bug here: If a function definition is called outside of the calls There's a (potential+minor) bug here: If a function definition is called outside of the calls
@ -374,7 +374,7 @@ module Registry = {
~env: DistributionOperation.env, ~env: DistributionOperation.env,
) => { ) => {
let matchToDef = m => Matcher.Registry.matchToDef(registry, m) let matchToDef = m => Matcher.Registry.matchToDef(registry, m)
Js.log(toSimple(registry)) //Js.log(toSimple(registry))
let showNameMatchDefinitions = matches => { let showNameMatchDefinitions = matches => {
let defs = let defs =
matches matches

View File

@ -27,8 +27,7 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
EV.EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some EV.EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some
| ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) =>
EV.EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some EV.EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some
| ("divide", [EvTimeDuration(d1), EvTimeDuration(d2)]) => | ("divide", [EvTimeDuration(d1), EvTimeDuration(d2)]) => EV.EvNumber(d1 /. d2)->Ok->Some
EV.EvNumber(d1 /. d2)->Ok->Some
| _ => None | _ => None
} }
} }

View File

@ -277,8 +277,7 @@ let dispatchToGenericOutput = (
Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env) Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env)
| ("toSampleSet", [EvDistribution(dist)]) => | ("toSampleSet", [EvDistribution(dist)]) =>
Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env) Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env)
| ("toList", [EvDistribution(SampleSet(dist))]) => | ("toList", [EvDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist)))
Some(FloatArray(SampleSetDist.T.get(dist)))
| ("fromSamples", [EvArray(inputArray)]) => { | ("fromSamples", [EvArray(inputArray)]) => {
let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x) let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x)
let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors) let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors)

View File

@ -14,15 +14,15 @@ import TOCInline from "@theme/TOCInline";
**Definitions** **Definitions**
```javascript ```javascript
normal: (frValueDistOrNumber, frValueDistOrNumber); normal: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
```javascript ```javascript
normal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) normal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) => distribution
``` ```
```javascript ```javascript
normal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) normal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) => distribution
``` ```
**Examples** **Examples**
@ -38,15 +38,15 @@ normal({ mean: 5, stdev: 2 });
**Definitions** **Definitions**
```javascript ```javascript
lognormal: (frValueDistOrNumber, frValueDistOrNumber); lognormal: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
```javascript ```javascript
lognormal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) lognormal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) => distribution
``` ```
```javascript ```javascript
lognormal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) lognormal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) => distribution
``` ```
**Examples** **Examples**
@ -62,7 +62,7 @@ lognormal({ mean: 5, stdev: 2 });
**Definitions** **Definitions**
```javascript ```javascript
uniform: (frValueDistOrNumber, frValueDistOrNumber); uniform: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -76,7 +76,7 @@ uniform(10, 12);
**Definitions** **Definitions**
```javascript ```javascript
beta: (frValueDistOrNumber, frValueDistOrNumber); beta: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -90,7 +90,7 @@ beta(20, 25);
**Definitions** **Definitions**
```javascript ```javascript
cauchy: (frValueDistOrNumber, frValueDistOrNumber); cauchy: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -104,7 +104,7 @@ cauchy(5, 1);
**Definitions** **Definitions**
```javascript ```javascript
gamma: (frValueDistOrNumber, frValueDistOrNumber); gamma: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -118,7 +118,7 @@ gamma(5, 1);
**Definitions** **Definitions**
```javascript ```javascript
logistic: (frValueDistOrNumber, frValueDistOrNumber); logistic: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -132,11 +132,11 @@ gamma(5, 1);
**Definitions** **Definitions**
```javascript ```javascript
to: (frValueDistOrNumber, frValueDistOrNumber); to: (frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
```javascript ```javascript
credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber); credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -152,7 +152,7 @@ to(5,10)
**Definitions** **Definitions**
```javascript ```javascript
exponential: (frValueDistOrNumber); exponential: (frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -166,7 +166,7 @@ exponential(2);
**Definitions** **Definitions**
```javascript ```javascript
bernoulli: (frValueDistOrNumber); bernoulli: (frValueDistOrNumber) => distribution;
``` ```
**Examples** **Examples**
@ -182,7 +182,7 @@ Converts a set of points to a continuous distribution
**Definitions** **Definitions**
```javascript ```javascript
toContinuousPointSet: (array<dict<{x: numeric, y: numeric}>>) toContinuousPointSet: (array<dict<{x: numeric, y: numeric}>>) => distribution
``` ```
**Examples** **Examples**
@ -203,7 +203,7 @@ Converts a set of points to a discrete distribution
**Definitions** **Definitions**
```javascript ```javascript
toDiscretePointSet: (array<dict<{x: numeric, y: numeric}>>) toDiscretePointSet: (array<dict<{x: numeric, y: numeric}>>) => distribution
``` ```
**Examples** **Examples**
@ -251,7 +251,7 @@ sample(normal(5, 2));
Get n random samples from the distribution Get n random samples from the distribution
```javascript ```javascript
sampleN: (distribution, number):list<number> sampleN: (distribution, number) => list<number>
``` ```
**Examples** **Examples**
@ -313,7 +313,7 @@ pdf: (distribution, number) => number
**Examples** **Examples**
```javascript ```javascript
pdf: (normal(5, 2), 3); pdf(normal(5, 2), 3);
``` ```
### inv ### inv
@ -333,7 +333,7 @@ inv(normal(5, 2), 0.5);
Converts a distribution to the pointSet format Converts a distribution to the pointSet format
```javascript ```javascript
toPointSet: (distribution):pointSetDistribution toPointSet: (distribution) => pointSetDistribution
``` ```
**Examples** **Examples**
@ -347,7 +347,7 @@ toPointSet(normal(5, 2));
Converts a distribution to the sampleSet format, with n samples Converts a distribution to the sampleSet format, with n samples
```javascript ```javascript
toSampleSet: (distribution,number):sampleSetDistribution toSampleSet: (distribution,number) => sampleSetDistribution
``` ```
**Examples** **Examples**
@ -405,7 +405,7 @@ klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
### toString ### toString
```javascript ```javascript
: (distribution) => string toString: (distribution) => string
``` ```
**Examples** **Examples**
@ -463,7 +463,7 @@ normalize(normal(5, 2));
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions. Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
```javascript ```javascript
isNormalized: (distribution):bool isNormalized: (distribution) => bool
``` ```
**Examples** **Examples**
@ -631,7 +631,7 @@ scaleLog10: (distributionLike, number) => distribution
Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within. Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.
```javascript ```javascript
declareFn: (dict<{fn: lambda, inputs: array<dict<{min: number, max: number}>>}>) declareFn: (dict<{fn: lambda, inputs: array<dict<{min: number, max: number}>>}>) => declaration
``` ```
**Examples** **Examples**