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

Make use of slog a feature #136

Merged
merged 2 commits into from
Sep 22, 2021
Merged

Conversation

ThatGeoGuy
Copy link
Contributor

See the two commits provided for more context.

The main crux of this is that I want to use argmin, but I don't want to include slog in the process. It makes sense then to make it a feature. Given how prolific this feature is throughout the library (it is the default terminal logger, even the file logger just goes to bincode / JSON), I opted to leave it as a default feature. Of course, if users don't want slog themselves, then they just have to specify the following in their Cargo.toml:

[dependencies.argmin]
version = "0.4"
default-features = false
features = ["nalgebral", "ndarrayl"]

With whatever features they do want enabled explicitly in the dependencies.argmin.features array.
The first commit just cleaned up a bunch of clippy lints. The command I'm using is:

$ cargo clippy --all-targets --all-features -- -D warnings

I'm also on clippy (0.1.54). Hopefully the reasoning in the commit message tracks.

Copy link
Member

@stefan-k stefan-k left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this PR! It makes absolutely sense to allow for disabling any slog related code.
I only have a few minor comments regarding the test in iterstate.rs.

src/core/iterstate.rs Show resolved Hide resolved
src/core/iterstate.rs Outdated Show resolved Hide resolved
@stefan-k
Copy link
Member

Thanks a lot for your contribution and for the fruitful discussion! :) Let me know when you think it is ready to go and I will merge the PR.

There were a few errors to take care of here:

1. In `sr1_trustregion.rs`, there was an unnecessary borrow.

2. In many cases `assert_eq!(..., true)` or `assert_eq!(..., false)`
were being used. This is easily replaced by doing `assert!(...)`.

3. There were quite a number of checks on floating point numbers in
`iterstate.rs` that related to determining if a number was finite or
not. These are easily replaced by checking `value.is_infinite()`, along
with changing the `assert_eq!` to `assert!`.

4. There were a number of checks in the tests for the cost function that
compared two floating point values directly. This is always wrong. For
byte equality, it should compare `state.get_cost().to_ne_bytes()` to
`cost.to_ne_bytes()`. However, here the comparison is to validate that
these are in fact the same number. As the crate already depends on
`approx`, it is better to use `assert_relative_eq!` and set an epsilon.
Here I chose `f64::EPSILON`, which I would normally argue is a bad
choice, because it does not respect significance. However, I'm just
fixing lints, so I leave better choices of epsilon values to the
official maintainers.
The flag is set as a default feature. If users don't want slog, now they
can turn it off by doing:

```TOML
[dependencies.argmin]
version = "0.4"
default-features = false
features = ["nalgebral", "ndarrayl"]
```

And they won't need to worry about building SLOG or its dependencies.
This is especially useful if you want to use a different logger (e.g.
env_logger), but argmin carries in slog as a transient dependency.
@ThatGeoGuy
Copy link
Contributor Author

Apologies, I saw this and completely forgot about it (oof).

I've force pushed, should be good to merge now.

@stefan-k stefan-k self-requested a review September 22, 2021 14:17
@stefan-k
Copy link
Member

No problem! Thanks again! :)

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.

None yet

2 participants