Skip to content
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

Stats use ScalarValues and not Scalars #2069

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

robert3005
Copy link
Member

I think this leads to simpler stats api where for a scalarvalue you have to extract it as a type you desire but we seldom care about a precise dtype of a stats, where we do I have preserved the semantic and wrapped the scalarvalue back up into scalar

@robert3005 robert3005 requested a review from gatesn January 24, 2025 18:13
Copy link
Contributor

@gatesn gatesn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really like this. Couple of doc strings to write, and not sure about all the TryFrom impls , but I'll leave that up to you.

let encoded = match_each_integer_ptype!(array.ptype(), |$T| {
if shift == <$T>::PTYPE.bit_width() as u8 {
assert_eq!(min, Scalar::zero::<$T>(array.dtype().nullability()));
assert_eq!(min, Scalar::zero::<$T>(array.dtype().nullability()).into_value());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a shame to create a scalar with a DType then throw it away? Can you just do ScalarValue::from(0usize)?

@@ -225,7 +226,7 @@ where
}

impl dyn Statistics + '_ {
pub fn get_as<U: for<'a> TryFrom<&'a Scalar, Error = VortexError>>(
pub fn get_as<U: for<'a> TryFrom<&'a ScalarValue, Error = VortexError>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a doc string to this? Before get_as and get_as_cast had different behaviour, I think get_as will now always cast? But it's not clear with the docs.

use crate::scalarvalue::InnerScalarValue;
use crate::ScalarValue;

impl<'a> TryFrom<&'a ScalarValue> for String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not necessarily a fan of all of these "helper" impls, given it's not that hard to do value.as_buffer().into_string() or equivalent.

Don't feel too strongly, it's just a lot of code that's not obviously used anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants