-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: impl subtract for primitive_scalar #1592
base: develop
Are you sure you want to change the base?
Conversation
Hey @doki23, are these PRs ready for review? Mark them non-draft when ready and we can take a look |
Yes, I had a travel last days:), I'll change its state, PTAL |
Maybe we could impl |
db06957
to
01b8b6c
Compare
fe28b95
to
8164019
Compare
Can you explain a bit about how this is going to be used? I'm wondering whether these operations should be implemented on |
If we implement |
Hey @gatesn , please take a look and let's move it forward. |
vortex-scalar/src/primitive.rs
Outdated
@@ -103,6 +105,27 @@ impl<'a> PrimitiveScalar<'a> { | |||
}?)), | |||
} | |||
} | |||
|
|||
pub fn subtract(&self, other: &PrimitiveScalar) -> VortexResult<Self> { |
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.
Could you call this checked_sub(&self, other: &PrimitiveScalar) -> VortexResult<Option<Self>>
and then use num-traits CheckedSub to ensure the subtraction doesn't overflow. Otherwise this function can panic.
Otherwise looks good to me!
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'm not sure the float checked_sub is correct, please review.
vortex-scalar/src/primitive.rs
Outdated
} | ||
}) | ||
} else { | ||
match_each_float_ptype!(self.ptype, |$T| { |
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 would just do regular subtraction for floats. There's not exactly overflow behavior
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 it's ok now
Sorry to be a pain again! @danking merged a change to the macro to let you implement different code blocks for ints and floats, e.g. https://github.com/spiraldb/vortex/pull/1640/files#diff-8f1cbe207a4076299ad7913ac7d7d0db5fd2e99d1a689f984fcedfd1b91208faR308-R329 And also actually that PR added arithmetic operations to arrays. Not sure if that's sufficient for you? |
I merged and switched to the new macro for you @doki23 . My general inclination is to use the (just added; sorry, we were working in parallel!) In the use cases I had (implementing BinaryNumericFn for ConstantArray and SparseArray), I always needed a Scalar anyway. But I think your approach seems better. Let me rework checked_numeric_operator to return a I'll plan to have this pushed later today. |
…Type allocation) 2. `checked_sub` delegates to `checked_numeric_operator` As a consequence of (2), `checked_sub` now returns an `None` when there is an underflow/overflow rather than returning a Null PrimitiveScalar (the return type is now `VortexResult<Option<PrimitiveScalar<'a>>>`). Moreover, `std::ops::Sub` now returns an error on underflow/overflow rather than a Null PrimitiveScalar.
Okay, here's what I did:
As a consequence of (2), Moreover, |
@doki23 does this suit your needs? |
Thanks, I'll have a look. |
Hey @danking , thanks for your excellent work! I have only one suggestion — I prefer using a |
Sounds good. I’ll approve with that change |
I've done, PTAL @danking |
part of #1591