-
Notifications
You must be signed in to change notification settings - Fork 499
Add ScaleValue primitive
#7398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ScaleValue primitive
#7398
Conversation
| -- alg n inner = n + Map.size (Map.filter (< zeroQuantity) inner) | ||
|
|
||
| -- TODO: make sure (size - neg) is correct | ||
| BuiltinSuccess $ Value outer' sizes size (size - neg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check here!
Need to make sure if I can just size - neg here or if I need to count all negative quantities again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is correct, but it's a good idea to add a prop_scaleValueBookkeeping test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, added bookkeeping property as well. It seems to be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's right.
4730720 to
ea0f767
Compare
| prop_negateIsInverse v = | ||
| let | ||
| inverseUnion = do | ||
| vInv <- V.scaleValue (-1) v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will occasionally fail, right? You may want to use suchThat to ensure that v doesn't contain minBound :: Quantity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will occasionally fail, right? You may want to use
suchThatto ensure thatvdoesn't containminBound :: Quantity.
Can we avoid problems like this by making minBound equal to -(2^127-1) (ie, -maxBound) instead of -2^127?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird things might also happen if the scalar is close to the upper or lower bound for Quantity. I think that ArbitraryBuiltin for Integer will generate values like that, or you could do it yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid problems like this by making minBound equal to -(2^127-1) (ie, -maxBound) instead of -2^127?
I think that's more problematic (i.e., weird) in a different way.
| -- alg n inner = n + Map.size (Map.filter (< zeroQuantity) inner) | ||
|
|
||
| -- TODO: make sure (size - neg) is correct | ||
| BuiltinSuccess $ Value outer' sizes size (size - neg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is correct, but it's a good idea to add a prop_scaleValueBookkeeping test.
299d38b to
1a1603c
Compare
kwxm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. There was a discussion about whether we should have a negateValue function instead/as well because it might be more efficient than scaling by -1. I suspect that it wouldn't be much different, but we could do a quick implementation and check benchmark times against this to make sure. If negateValue surprises us by turning out to be noticeably faster then I suppose we could have a special case when the scalar is -1 here that traverses the value and just negates everything. That'd need some special treament in the costing to reflect the improved efficiency for that case though, so it might be a bit of a pain.
| -- alg n inner = n + Map.size (Map.filter (< zeroQuantity) inner) | ||
|
|
||
| -- TODO: make sure (size - neg) is correct | ||
| BuiltinSuccess $ Value outer' sizes size (size - neg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's right.
| prop_negateIsInverse v = | ||
| let | ||
| inverseUnion = do | ||
| vInv <- V.scaleValue (-1) v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird things might also happen if the scalar is close to the upper or lower bound for Quantity. I think that ArbitraryBuiltin for Integer will generate values like that, or you could do it yourself.
zliu41
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| prop_negateIsInverse v = | ||
| let | ||
| inverseUnion = do | ||
| vInv <- V.scaleValue (-1) v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid problems like this by making minBound equal to -(2^127-1) (ie, -maxBound) instead of -2^127?
I think that's more problematic (i.e., weird) in a different way.
|
For some reason, goldens changed (a577ce9). I'm trying to figure out why. Update: |
|
I don't think it's the number of CSE passes - unless of course you have clear evidence of that. I think it's likely that the additional definitions in |
|
Okay. I saw some cse term not being pulled out and thought it was something to do with CSE. But, in that case, I'll ignore and merge when CI passes. |
2970a9c to
d5040c9
Compare
effectfully
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review. LGTM.
adds
where all of the quantities of the value (second argument) get multiplied by the given constant factor(first argument)