-
Notifications
You must be signed in to change notification settings - Fork 308
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
Support things like matrix > scalar
? Or matrix.greater_than(scalar)
?
#1087
Comments
Thank you! The use case: I am porting python numpy code to rust (you know, from research experiment to industry product). So there are a lot of things like |
I understand, although I'm still not sure these should be added to use ndarray::prelude::*;
use ndarray::Data;
pub trait CompareScalarExt<Rhs> {
type Elem: PartialOrd<Rhs>;
type Dim;
fn lt(&self, scalar: &Rhs) -> Array<bool, Self::Dim>;
// ...
}
impl<A, S, D, Rhs> CompareScalarExt<Rhs> for ArrayBase<S, D>
where
A: PartialOrd<Rhs>,
S: Data<Elem = A>,
D: Dimension,
{
type Elem = A;
type Dim = D;
fn lt(&self, scalar: &Rhs) -> Array<bool, D> {
self.map(move |elem| elem < scalar)
}
// ...
}
fn main() {
let a = array![1, 2, 3];
assert_eq!(a.lt(&2), array![true, false, false]);
} You may also be interested in PR #1042, which is similar in spirit to this issue, but for float math functions. |
Thank you! After my reply, I have made a proc macro. Now I can use: |
Hi thanks for the lib! After looking at doc, it seems that we do not have the things mentioned in the title yet. Can we implement it?
I guess
>
must return bool in Rust so we cannot do that easily. But can we have a function likege
/gt
/greater_than
?The text was updated successfully, but these errors were encountered: