Merge pull request #905 from quantified-uncertainty/issue-904

fixes #904. E.O.default performance
This commit is contained in:
Ozzie Gooen 2022-07-28 17:26:42 -07:00 committed by GitHub
commit 4e2f0d1413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 5 deletions

View File

@ -250,7 +250,7 @@ module T = Dist({
let downsample = (length, t): t => let downsample = (length, t): t =>
t |> shapeMap(XYShape.XsConversion.proportionByProbabilityMass(length, integral(t).xyShape)) t |> shapeMap(XYShape.XsConversion.proportionByProbabilityMass(length, integral(t).xyShape))
let integralEndY = (t: t) => t.integralSumCache |> E.O.default(t |> integral |> lastY) let integralEndY = (t: t) => t.integralSumCache |> E.O.defaultFn(() => t |> integral |> lastY)
let integralXtoY = (f, t: t) => t |> integral |> shapeFn(XYShape.XtoY.linear(f)) let integralXtoY = (f, t: t) => t |> integral |> shapeFn(XYShape.XtoY.linear(f))
let integralYtoX = (f, t: t) => t |> integral |> shapeFn(XYShape.YtoX.linear(f)) let integralYtoX = (f, t: t) => t |> integral |> shapeFn(XYShape.YtoX.linear(f))
let toContinuous = t => Some(t) let toContinuous = t => Some(t)

View File

@ -158,7 +158,8 @@ module T = Dist({
Continuous.make(~interpolation=#Stepwise, integralShape) Continuous.make(~interpolation=#Stepwise, integralShape)
} }
let integralEndY = (t: t) => t.integralSumCache |> E.O.default(t |> integral |> Continuous.lastY) let integralEndY = (t: t) =>
t.integralSumCache |> E.O.defaultFn(() => t |> integral |> Continuous.lastY)
let minX = shapeFn(XYShape.T.minX) let minX = shapeFn(XYShape.T.minX)
let maxX = shapeFn(XYShape.T.maxX) let maxX = shapeFn(XYShape.T.maxX)
let toDiscreteProbabilityMassFraction = _ => 1.0 let toDiscreteProbabilityMassFraction = _ => 1.0

View File

@ -13,9 +13,11 @@ let buildSimple = (
~discrete: option<PointSetTypes.discreteShape>, ~discrete: option<PointSetTypes.discreteShape>,
): option<PointSetTypes.pointSetDist> => { ): option<PointSetTypes.pointSetDist> => {
let continuous = let continuous =
continuous |> E.O.default(Continuous.make(~integralSumCache=Some(0.0), {xs: [], ys: []})) continuous |> E.O.defaultFn(() =>
Continuous.make(~integralSumCache=Some(0.0), {xs: [], ys: []})
)
let discrete = let discrete =
discrete |> E.O.default(Discrete.make(~integralSumCache=Some(0.0), {xs: [], ys: []})) discrete |> E.O.defaultFn(() => Discrete.make(~integralSumCache=Some(0.0), {xs: [], ys: []}))
let cLength = continuous |> Continuous.getShape |> XYShape.T.xs |> E.A.length let cLength = continuous |> Continuous.getShape |> XYShape.T.xs |> E.A.length
let dLength = discrete |> Discrete.getShape |> XYShape.T.xs |> E.A.length let dLength = discrete |> Discrete.getShape |> XYShape.T.xs |> E.A.length
switch (cLength, dLength) { switch (cLength, dLength) {

View File

@ -16,7 +16,7 @@ let dispatch = (
() => ReducerInterface_Duration.dispatch(call, environment), () => ReducerInterface_Duration.dispatch(call, environment),
() => ReducerInterface_Number.dispatch(call, environment), () => ReducerInterface_Number.dispatch(call, environment),
() => FunctionRegistry_Library.dispatch(call, environment, reducer), () => FunctionRegistry_Library.dispatch(call, environment, reducer),
])->E.O2.default(chain(call, environment, reducer)) ])->E.O2.defaultFn(() => chain(call, environment, reducer))
} }
/* /*

View File

@ -82,6 +82,11 @@ module O = {
| None => d | None => d
| Some(a) => a | Some(a) => a
} }
let defaultFn = (d, o) =>
switch o {
| None => d()
| Some(a) => a
}
let isSome = o => let isSome = o =>
switch o { switch o {
| Some(_) => true | Some(_) => true
@ -158,6 +163,7 @@ module O = {
module O2 = { module O2 = {
let default = (a, b) => O.default(b, a) let default = (a, b) => O.default(b, a)
let defaultFn = (a, b) => O.defaultFn(b, a)
let toExn = (a, b) => O.toExn(b, a) let toExn = (a, b) => O.toExn(b, a)
let fmap = (a, b) => O.fmap(b, a) let fmap = (a, b) => O.fmap(b, a)
let toResult = (a, b) => O.toResult(b, a) let toResult = (a, b) => O.toResult(b, a)