Simple toContinousPointSet

This commit is contained in:
Ozzie Gooen 2022-05-27 13:37:37 -04:00
parent 70664c0a91
commit f49697b64a
5 changed files with 47 additions and 4 deletions

View File

@ -231,9 +231,8 @@ let doN = (n, fn) => {
}
let sample = (t: t): float => {
let randomItem = Random.float(1.)
let bar = t |> T.Integral.yToX(randomItem)
bar
let randomItem = Random.float(1.0)
t |> T.Integral.yToX(randomItem)
}
let isFloat = (t: t) =>

View File

@ -9,6 +9,7 @@ module Wrappers = {
}
module Prepare = {
type t = frValue
type ts = array<frValue>
type err = string
@ -26,6 +27,14 @@ module Prepare = {
| _ => Error(impossibleError)
}
}
module Array = {
let openA = (inputs: t): result<ts, err> =>
switch inputs {
| FRValueArray(n) => Ok(n)
| _ => Error(impossibleError)
}
}
}
module ToValueTuple = {

View File

@ -32,7 +32,36 @@ module Declaration = {
let registry = [
Function.make(
~name="FnMake",
~name="toContinuousPointSet",
~definitions=[
FnDefinition.make(
~name="toContinuousPointSet",
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
~run=(inputs, _) => {
let array = inputs->E.A.unsafe_get(0)->Prepare.ToValueArray.Array.openA
let xyCoords =
array->E.R.bind(xyCoords =>
xyCoords
->E.A2.fmap(xyCoord =>
[xyCoord]
->Prepare.ToValueArray.Record.twoArgs
->E.R.bind(Prepare.ToValueTuple.twoNumbers)
)
->E.A.R.firstErrorOrOpen
)
let expressionValue =
xyCoords
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
->E.R2.fmap(r => ReducerInterface_ExpressionValue.EvDistribution(
PointSet(Continuous(Continuous.make(r))),
))
expressionValue
},
),
],
),
Function.make(
~name="Declaration",
~definitions=[
FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => {
inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue

View File

@ -571,6 +571,7 @@ module A = {
let tail = Belt.Array.sliceToEnd(_, 1)
let zip = Belt.Array.zip
let unzip = Belt.Array.unzip
let zip3 = (a, b, c) =>
Belt.Array.zip(a, b)->Belt.Array.zip(c)->Belt.Array.map((((v1, v2), v3)) => (v1, v2, v3))
// This zips while taking the longest elements of each array.

View File

@ -148,6 +148,11 @@ module T = {
| None => Ok(attempt)
}
}
let makeFromZipped = (values: array<(float, float)>) => {
let (xs, ys) = E.A.unzip(values)
make(~xs, ~ys)
}
}
module Ts = {