Rename invalidOperationError

This commit is contained in:
Sam Nolan 2022-04-23 14:35:49 -04:00
parent 4544268429
commit df4b734a49
8 changed files with 24 additions and 23 deletions

View File

@ -11,7 +11,7 @@ type error =
| DistributionVerticalShiftIsInvalid
| TooFewSamples
| ArgumentError(string)
| OperationError(Operation.Error.invalidOperationError)
| OperationError(Operation.Error.t)
| PointSetConversionError(SampleSetDist.pointsetConversionError)
| SparklineError(PointSetTypes.sparklineError) // This type of error is for when we find a sparkline of a discrete distribution. This should probably at some point be actually implemented
| OtherError(string)
@ -30,7 +30,7 @@ module Error = {
| DistributionVerticalShiftIsInvalid => "Distribution Vertical Shift is Invalid"
| ArgumentError(s) => `Argument Error ${s}`
| TooFewSamples => "Too Few Samples"
| OperationError(err) => Operation.Error.invalidOperationErrorToString(err)
| OperationError(err) => Operation.Error.toString(err)
| PointSetConversionError(err) => SampleSetDist.pointsetConversionErrorToString(err)
| SparklineError(err) => PointSetTypes.sparklineErrorToString(err)
| OtherError(s) => s

View File

@ -151,7 +151,7 @@ module AlgebraicCombination = {
arithmeticOperation: Operation.algebraicOperation,
t1: t,
t2: t,
): option<result<SymbolicDistTypes.symbolicDist, Operation.Error.invalidOperationError>> =>
): option<result<SymbolicDistTypes.symbolicDist, Operation.Error.t>> =>
switch (arithmeticOperation, t1, t2) {
| (arithmeticOperation, Symbolic(d1), Symbolic(d2)) =>
switch SymbolicDist.T.tryAnalyticalSimplification(d1, d2, arithmeticOperation) {

View File

@ -88,7 +88,7 @@ let stepwiseToLinear = (t: t): t =>
let combinePointwise = (
~integralSumCachesFn=(_, _) => None,
~distributionType: PointSetTypes.distributionType=#PDF,
fn: (float, float) => result<float, Operation.Error.invalidOperationError>,
fn: (float, float) => result<float, Operation.Error.t>,
t1: PointSetTypes.continuousShape,
t2: PointSetTypes.continuousShape,
): result<PointSetTypes.continuousShape, 'e> => {

View File

@ -60,10 +60,10 @@ let combinePointwise = (
PointSetTypes.continuousShape,
PointSetTypes.continuousShape,
) => option<PointSetTypes.continuousShape>=(_, _) => None,
fn: (float, float) => result<float, Operation.Error.invalidOperationError>,
fn: (float, float) => result<float, Operation.Error.t>,
t1: t,
t2: t,
): result<PointSetTypes.pointSetDist, Operation.Error.invalidOperationError> =>
): result<PointSetTypes.pointSetDist, Operation.Error.t> =>
switch (t1, t2) {
| (Continuous(m1), Continuous(m2)) =>
Continuous.combinePointwise(

View File

@ -83,11 +83,10 @@ let sampleN = (t: t, n) => {
}
//TODO: Figure out what to do if distributions are different lengths. ``zip`` is kind of inelegant for this.
let map2 = (
~fn: (float, float) => result<float, Operation.Error.invalidOperationError>,
~t1: t,
~t2: t,
): result<t, Operation.Error.invalidOperationError> => {
let map2 = (~fn: (float, float) => result<float, Operation.Error.t>, ~t1: t, ~t2: t): result<
t,
Operation.Error.t,
> => {
let samples = Belt.Array.zip(get(t1), get(t2))->E.A2.fmap(((a, b)) => fn(a, b))
// This assertion should never be reached. In order for it to be reached, one

View File

@ -45,6 +45,6 @@ type symbolicDist = [
type analyticalSimplificationResult = [
| #AnalyticalSolution(symbolicDist)
| #Error(Operation.Error.invalidOperationError)
| #Error(Operation.Error.t)
| #NoSolution
]

View File

@ -37,35 +37,37 @@ module Convolution = {
}
}
type operationError =
| DivisionByZeroError
| ComplexNumberError
@genType
module Error = {
@genType
type invalidOperationError =
| DivisionByZeroError
| ComplexNumberError
type t = operationError
let invalidOperationErrorToString = (err: invalidOperationError): string =>
let toString = (err: t): string =>
switch err {
| DivisionByZeroError => "Cannot divide by zero"
| ComplexNumberError => "Operation returned complex result"
}
}
let power = (a: float, b: float): result<float, Error.invalidOperationError> =>
let power = (a: float, b: float): result<float, Error.t> =>
if a >= 0.0 {
Ok(a ** b)
} else {
Error(ComplexNumberError)
}
let divide = (a: float, b: float): result<float, Error.invalidOperationError> =>
let divide = (a: float, b: float): result<float, Error.t> =>
if b != 0.0 {
Ok(a /. b)
} else {
Error(DivisionByZeroError)
}
let logarithm = (a: float, b: float): result<float, Error.invalidOperationError> =>
let logarithm = (a: float, b: float): result<float, Error.t> =>
if b == 1. {
Error(DivisionByZeroError)
} else if b == 0. {
@ -80,7 +82,7 @@ let logarithm = (a: float, b: float): result<float, Error.invalidOperationError>
module Algebraic = {
@genType
type t = algebraicOperation
let toFn: (t, float, float) => result<float, Error.invalidOperationError> = (x, a, b) =>
let toFn: (t, float, float) => result<float, Error.t> = (x, a, b) =>
switch x {
| #Add => Ok(a +. b)
| #Subtract => Ok(a -. b)
@ -131,7 +133,7 @@ module DistToFloat = {
// Note that different logarithms don't really do anything.
module Scale = {
type t = scaleOperation
let toFn = (x: t, a: float, b: float): result<float, Error.invalidOperationError> =>
let toFn = (x: t, a: float, b: float): result<float, Error.t> =>
switch x {
| #Multiply => Ok(a *. b)
| #Divide => divide(a, b)

View File

@ -234,11 +234,11 @@ module Zipped = {
module PointwiseCombination = {
// t1Interpolator and t2Interpolator are functions from XYShape.XtoY, e.g. linearBetweenPointsExtrapolateFlat.
let combine: (
(float, float) => result<float, Operation.Error.invalidOperationError>,
(float, float) => result<float, Operation.Error.t>,
interpolator,
T.t,
T.t,
) => result<T.t, Operation.Error.invalidOperationError> = %raw(`
) => result<T.t, Operation.Error.t> = %raw(`
// This function combines two xyShapes by looping through both of them simultaneously.
// It always moves on to the next smallest x, whether that's in the first or second input's xs,
// and interpolates the value on the other side, thus accumulating xs and ys.