Skip to content

Rounding Vectors / Points. #276

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

Closed
Binero opened this issue Aug 4, 2017 · 7 comments
Closed

Rounding Vectors / Points. #276

Binero opened this issue Aug 4, 2017 · 7 comments

Comments

@Binero
Copy link

Binero commented Aug 4, 2017

Is there a way yet to round vectors or points, similar to std's round function implemented for f32 and f64? I cannot seem to find it, but the crate might use a non-standard naming convention, or assume other means of rounding.

Furthermore, if it is not present, would a round function be something to consider? How would we go about adding it, given a rounding operation might not necessarily make sense on any matrix.

@sebcrozet
Copy link
Member

This is currently not implemented.

Instead of defining a round method, it would be more useful to define a method apply that takes a closure Fn(N) -> N as parameter. Each component is then replaced by the result of the closure (the modification is in-place so this is not a map).

@Binero
Copy link
Author

Binero commented Aug 8, 2017

Hmm I was about to tinker a bit to resolve this issue but it seems that currently the master branch is broken, as the tests do not compile?

@sebcrozet
Copy link
Member

Could you paste the error you get please? I've made a fresh clone of the nalgebra repo and test do seem to compile on the master branch.

@Binero
Copy link
Author

Binero commented Aug 11, 2017

On stable:

error: cannot find macro `quickcheck!` in this scope
  --> tests/similarity.rs:15:1
   |
15 | quickcheck!(
   | ^^^^^^^^^^

error: aborting due to previous error(s)

On nightly, I get 1096 errors. They all seem to be of the unused result variety.

As for the original issue, wouldn't apply be essentially the same as iter_mut?

@sebcrozet
Copy link
Member

Tests and benchmarks can only be computed on nightly because we use #[feature(test)] which is unstable. The errors you have on nightly are strange though. Did you enable any features? Could you try with those features enabled:

cargo test --features "debug arbitrary serde-serialize"

Also, if this still doesn't work, could you try to compile tests on the linalg branch?

@milibopp
Copy link
Collaborator

It is a new issue on nightly. I already reported it yesterday in rust-lang/rust#43806. There is already a pull request in, so it should be fixed very soon. For the time being we could comment out the unused_results lint perhaps?

@sebcrozet
Copy link
Member

@aepsil0n Yes, or maybe we could just make it a warn instead of a deny so that we don't forget to deny it again later.
@Binero I forgot to answer your second question. The apply I propose would no be iter_mut exactly, but the same as:

for e in matrix.iter_mut() {
    *e = f(*e)
}

Assuming f is a Fn(N) -> N where N is the scalar type.
I am not sure there exists a clean one-liner way of doing this.

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

No branches or pull requests

3 participants