Add multiply-by-positive-constant primitive hmulpos.#9
Add multiply-by-positive-constant primitive hmulpos.#9cheater wants to merge 3 commits intochrisnc:masterfrom
Conversation
|
I'm still skeptical about adding more exports. Also it seems unrelated to the other changes you're making. |
src/HVX/Primitives.hs
Outdated
| infixl 7 *~+ | ||
| (*~+) :: (ApplyVex 'Affine 'Nondec v1 m1 ~ v2, ValidVex v2) | ||
| => Expr 'Affine 'Const -> Expr v1 m1 -> Expr v2 (ApplyMon 'Nondec m1) | ||
| (*~+) (EConst a) e |
There was a problem hiding this comment.
Can you collapse this to just (*~+) = hmulpos? While you're here might as well to the same for (*~). I did that for the other operator aliases but I guess I missed one.
There was a problem hiding this comment.
Sure, I just did it that way because you had (*~) and hmul.
src/HVX/Primitives.hs
Outdated
| => Expr 'Affine 'Const -> Expr v1 m1 -> Expr v2 (ApplyMon 'Nondec m1) | ||
| hmulpos (EConst a) e | ||
| | 0 <= minElement a = apply (MulPos a) e | ||
| | otherwise = error "The left argument of a left-positive multiply must have non-negative entries" |
There was a problem hiding this comment.
"left-positive" seems redundant. You already mentioned you're referring to the left argument. Same for the next line.
There was a problem hiding this comment.
Ok so the issue i'm trying to solve here is that when a non-positive entry is entered, we see an error like this:
> solve 1
([("x1",(1><1)
[ 10.0 ]),("x2",(1><1)
[ 200.0 ]),("x3",(1><1)
[ 400.0 ]),("lineVar",(1><1)
[ 10.0 ])],*** Exception: The left argument of a left-positive multiply must have non-negative entries
CallStack (from HasCallStack):
error, called at src/HVX/Primitives.hs:78:17 in hvx-0.3.1.0-HnMwpnJtEwx2GYI4IYHzYJ:HVX.Primitives
so we need to identify the function throwing the error, otherwise the user won't know why the error is happening and will be unable to debug it. We also identify the reason the function is throwing the error, so that the user doesn't have to look at the hmulpos source code to figure that out.
How would you do both without being redundant but maintaining a clear description of what went wrong and where?
There was a problem hiding this comment.
Sorry, I just meant that you could change left-positive to positive. This still distinguishes it from the generic multiply-by-constant function.
There was a problem hiding this comment.
I see! I'm worried "positive multiply" might imply that the right argument has to be positive too.
There was a problem hiding this comment.
But the message as a whole doesn't imply that. I think it's fine.
There was a problem hiding this comment.
I'm confused now :) ok can we just leave it as is? I think no one will find it offensive and we'll have ticked off this pr :)
There was a problem hiding this comment.
Still change it from "left-positive" to "positive". After that I think it's unambiguous.
There was a problem hiding this comment.
Sure, i just pushed
Following your tips I have rewritten the "concatenation" function a little and it seems I have found a simple primitive that should provide stronger monotonicity.
here
*~+is exactly the same as*~except you can only have non-negative constants on the left, or it will throw an exception. Is my understanding correct that this requirement on the left argument will preserve monotonicity of the right argument?