-
Notifications
You must be signed in to change notification settings - Fork 323
Implement numpy's triu
and tril
methods
#1323
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
Comments
A test of this code: use ndarray::Array
// ... paste the `Tri` implementation and trait here or import it
fn main() {
let a = Array::<f64, _>::ones((3, 3).f());
println!("a.triu(0) = {:?}\n", a.clone().triu(0));
println!("a.triu(1) = {:?}\n\n", a.clone().triu(1));
println!("a.tril(0) = {:?}\n", a.clone().tril(0));
println!("a.tril(1) = {:?}\n", a.clone().tril(1));
} The result is: Compiling nbody_code v0.1.0 (C:\Users\Rebel1\projects\nbody_code)
Finished dev [unoptimized + debuginfo] target(s) in 1.40s
Running `target\debug\nbody_code.exe`
a.triu(0) = [[1.0, 1.0, 1.0],
[0.0, 1.0, 1.0],
[0.0, 0.0, 1.0]], shape=[3, 3], strides=[1, 3], layout=Ff (0xa), const ndim=2
a.triu(1) = [[0.0, 1.0, 1.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, 0.0]], shape=[3, 3], strides=[1, 3], layout=Ff (0xa), const ndim=2
a.tril(0) = [[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 1.0]], shape=[3, 3], strides=[3, 1], layout=Cc (0x5), const ndim=2
a.tril(1) = [[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0]], shape=[3, 3], strides=[3, 1], layout=Cc (0x5), const ndim=2
|
ndarray should probably have those functions. Making it generic, and with less |
Sweet, I'll be waiting for the upgrade. |
Just to be clear, we're mostly offering bug fixes and support at the moment because all maintainers are busy. If you are actually waiting for it, I advise you to be patient :) |
No worries, the code snippet I wrote is currently good enough for my pet project, so I won't need to hold my breath. Thanks for the heads-up though! |
…ray#1323. The implementation seems to work, but unsure about whether this should be a free function vs bound directly to ArrayBase vs a trait.
I've been wanting to get involved in |
Hi, I want to propose an implementation of
numpy.triu
andnumpy.tril
methods (link here) for arrays that are atleast 2 dimensions.returns:
and
returns:
and
returns:
I implemented a basic version of
np.triu
andnp.tril
for 2D owned float square ndarrays for personal use, however I did not write it to support negative values ofk
.The text was updated successfully, but these errors were encountered: