Fix pointwise not commuting for subtraction

This commit is contained in:
Sam Nolan 2022-04-25 15:46:56 -04:00
parent aa192883e2
commit 62653d55b4
2 changed files with 6 additions and 1 deletions

View File

@ -54,6 +54,7 @@ describe("eval on distribution functions", () => {
describe("subtract", () => {
testEval("10 - normal(5, 1)", "Ok(Normal(5,1))")
testEval("normal(5, 1) - 10", "Ok(Normal(-5,1))")
testEval("mean(1 - toPointSet(normal(5, 2)))", "Ok(-4.002309896304692)")
})
describe("multiply", () => {
testEval("normal(10, 2) * 2", "Ok(Normal(20,4))")

View File

@ -209,9 +209,13 @@ let combineShapesContinuousDiscrete = (
// creates a new continuous shape for each one of the discrete points, and collects them in outXYShapes.
let dxyShape: array<(float, float)> = Belt.Array.makeUninitializedUnsafe(t1n)
for i in 0 to t1n - 1 {
// When this operation is flipped (like 1 - normal(5, 2)) then the
// x axis coordinates would all come out the wrong order. So we need
// to fill them out in the opposite direction
let index = flip ? t1n - 1 - i : i
Belt.Array.set(
dxyShape,
i,
index,
(
fn(continuousShape.xs[i], discreteShape.xs[j]),
continuousShape.ys[i] *. discreteShape.ys[j],