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

PartialOrd for scalars #573

Merged

Conversation

Ilia-Kosenkov
Copy link
Member

@Ilia-Kosenkov Ilia-Kosenkov commented Jul 2, 2023

  • Scalar<T> to initiate abstraction of common scalar properties
  • PartialOrd for Rint, Rfloat, Rbool (NA-aware)
  • min()/max() on Rint & Rfloat based on PartialOrd
  • From<Rint> and From<i32> for Rfloat (note that i32::MIN_VALUE will not be treated as NA_real_)

Closes #570

@Ilia-Kosenkov Ilia-Kosenkov changed the title [WIPPartialOrd for scalars [WIP] PartialOrd for scalars Jul 2, 2023
@Ilia-Kosenkov Ilia-Kosenkov marked this pull request as draft July 2, 2023 20:06
@Ilia-Kosenkov
Copy link
Member Author

@JosiahParry , ready for initial review :-)

Copy link
Member

@CGMossa CGMossa left a comment

Choose a reason for hiding this comment

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

LGTM, if it passes test.. then it should be merged.

@Ilia-Kosenkov
Copy link
Member Author

Funny thing it does not really solve the original problem -- min() and max() require Ord , not PartialOrd. We cannot provide Ord of course, but at least now it should work like

vec![Rint::from(1), Rint::from(2)].iter().filter(|&x| x >= 2);

@yutannihilation
Copy link
Contributor

That's what I was wondering about when I commented on #570. The reason f64 has min() and max() is not that f64 is Ord, but it implements its own min() and max().

https://doc.rust-lang.org/std/primitive.f64.html#method.min

@Ilia-Kosenkov
Copy link
Member Author

Ah yeah, no problem! We already have some methods defined (mostly R-inspired), I can extend it to also include min(), max(), etc

@Ilia-Kosenkov Ilia-Kosenkov marked this pull request as ready for review July 3, 2023 18:49
@Ilia-Kosenkov Ilia-Kosenkov changed the title [WIP] PartialOrd for scalars PartialOrd for scalars Jul 3, 2023
@Ilia-Kosenkov Ilia-Kosenkov merged commit d34b6b7 into extendr:master Jul 5, 2023
sorhawell added a commit to rpolars/extendr that referenced this pull request Jul 12, 2023
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.

Support PartialOrd trait for R scalars
3 participants