fixes #904. E.O.default performance

This commit is contained in:
Umur Ozkul 2022-07-29 02:12:07 +02:00
parent f7e6061f17
commit 5576bf2ef3
5 changed files with 14 additions and 5 deletions

View File

@ -250,7 +250,7 @@ module T = Dist({
let downsample = (length, t): t =>
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 integralYtoX = (f, t: t) => t |> integral |> shapeFn(XYShape.YtoX.linear(f))
let toContinuous = t => Some(t)

View File

@ -158,7 +158,8 @@ module T = Dist({
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 maxX = shapeFn(XYShape.T.maxX)
let toDiscreteProbabilityMassFraction = _ => 1.0

View File

@ -13,9 +13,11 @@ let buildSimple = (
~discrete: option<PointSetTypes.discreteShape>,
): option<PointSetTypes.pointSetDist> => {
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 =
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 dLength = discrete |> Discrete.getShape |> XYShape.T.xs |> E.A.length
switch (cLength, dLength) {

View File

@ -16,7 +16,7 @@ let dispatch = (
() => ReducerInterface_Duration.dispatch(call, environment),
() => ReducerInterface_Number.dispatch(call, environment),
() => 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
| Some(a) => a
}
let defaultFn = (d, o) =>
switch o {
| None => d()
| Some(a) => a
}
let isSome = o =>
switch o {
| Some(_) => true
@ -158,6 +163,7 @@ module O = {
module O2 = {
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 fmap = (a, b) => O.fmap(b, a)
let toResult = (a, b) => O.toResult(b, a)