wrapped error in function

Value: [1e-5 to 1e-3]
This commit is contained in:
Quinn Dougherty 2022-05-09 15:24:46 -04:00
parent 814a5f2c58
commit 59edd7122e

View File

@ -119,19 +119,20 @@ module Helpers = {
mixtureWithGivenWeights(distributions, weights)
}
let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
let mixture = (args: array<expressionValue>): DistributionOperation.outputType => {
let error = (err: string): DistributionOperation.outputType => err->ArgumentError->GenDistError
switch args {
| [EvArray(distributions)] =>
switch parseDistributionArray(distributions) {
| Ok(distrs) => mixtureWithDefaultWeights(distrs)
| Error(err) => err->ArgumentError->GenDistError
| Error(err) => error(err)
}
| [EvArray(distributions), EvArray(weights)] =>
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts)
| (Error(err), Ok(_)) => err->ArgumentError->GenDistError
| (Ok(_), Error(err)) => err->ArgumentError->GenDistError
| (Error(err1), Error(err2)) => `${err1}|${err2}`->ArgumentError->GenDistError
| (Error(err), Ok(_)) => error(err)
| (Ok(_), Error(err)) => error(err)
| (Error(err1), Error(err2)) => error(`${err1}|${err2}`)
}
| _ =>
switch E.A.last(args) {
@ -142,16 +143,17 @@ module Helpers = {
)
switch E.R.merge(distributions, weights) {
| Ok(d, w) => mixtureWithGivenWeights(d, w)
| Error(err) => GenDistError(ArgumentError(err))
| Error(err) => error(err)
}
}
| Some(EvNumber(_))
| Some(EvDistribution(_)) =>
switch parseDistributionArray(args) {
| Ok(distributions) => mixtureWithDefaultWeights(distributions)
| Error(err) => GenDistError(ArgumentError(err))
| Error(err) => error(err)
}
| _ => error("Last argument of mx must be array or distribution")
}
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
}
}
}