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

chore: define lints in Cargo.toml instead of each crate's lib.rs #138

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ iai = "0.1.1"
pprof = { version = "0.13.0", features = ["criterion", "frame-pointer", "prost-codec"] }
pretty_assertions = "1.4.1"

[workspace.lints.rust]
missing_debug_implementations = "warn"
missing_docs = "warn"
rust_2018_idioms = "warn"
# Allow `non_local_definitions` until https://github.com/rust-lang/rust/issues/131643
# is resolved.
non_local_definitions = { level = "allow", priority = 1 }
unreachable_pub = "warn"

# See https://nnethercote.github.io/perf-book/build-configuration.html
# for more information on why we're using these settings.
[profile.release]
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-changepoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ augurs-testing.workspace = true
criterion.workspace = true
iai.workspace = true
pprof.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/augurs-changepoint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
use std::{fmt, num::NonZeroUsize};

pub use changepoint::rv::{dist, process::gaussian::kernel};
Expand Down Expand Up @@ -144,6 +143,7 @@ impl Default for DefaultArgpcpDetector {
}

/// Builder for a [`DefaultArgpcpDetector`].
#[derive(Debug, Clone)]
pub struct DefaultArgpcpDetectorBuilder {
constant_value: f64,
length_scale: f64,
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-clustering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ bench = false
[[bench]]
name = "dbscan"
harness = false

[lints]
workspace = true
6 changes: 0 additions & 6 deletions crates/augurs-clustering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

use std::collections::VecDeque;

Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ bench = false

[dependencies]
serde = { version = "1.0.166", optional = true, features = ["derive"] }

[lints]
workspace = true
6 changes: 0 additions & 6 deletions crates/augurs-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

/// Common traits and types for time series forecasting models.
pub mod prelude {
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-dtw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ bench = false
[[bench]]
name = "dtw"
harness = false

[lints]
workspace = true
6 changes: 0 additions & 6 deletions crates/augurs-dtw/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

use augurs_core::DistanceMatrix;

Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-ets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ harness = false
[[bench]]
name = "air_passengers_iai"
harness = false

[lints]
workspace = true
26 changes: 13 additions & 13 deletions crates/augurs-ets/src/ets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const TOLERANCE: f64 = 1e-10;
const HUGEN: f64 = 1e10;

#[derive(Debug, Clone)]
pub struct FitState {
pub(crate) struct FitState {
x: Vec<f64>,
params: Params,
lik: f64,
Expand All @@ -29,73 +29,73 @@ pub struct FitState {
impl FitState {
/// The likelihood of the model, given the data.
#[inline]
pub fn likelihood(&self) -> f64 {
pub(crate) fn likelihood(&self) -> f64 {
self.lik
}

/// The mean squared error (MSE) of the model.
#[inline]
pub fn mse(&self) -> f64 {
pub(crate) fn mse(&self) -> f64 {
self.amse[0]
}

/// The average mean squared error (AMSE) of the model.
///
/// This is the average of the MSE over the number of forecasting horizons (`nmse`).
#[inline]
pub fn amse(&self) -> f64 {
pub(crate) fn amse(&self) -> f64 {
self.amse.iter().sum::<f64>() / self.amse.len() as f64
}

#[inline]
pub fn sigma_squared(&self) -> f64 {
pub(crate) fn sigma_squared(&self) -> f64 {
self.residuals.iter().map(|e| e.powi(2)).sum::<f64>()
/ (self.residuals.len() as f64 - self.n_params as f64 - 2.0)
}

/// The mean absolute error (MAE) of the model.
#[inline]
pub fn mae(&self) -> f64 {
pub(crate) fn mae(&self) -> f64 {
self.residuals.iter().map(|e| e.abs()).sum::<f64>() / self.residuals.len() as f64
}

/// Returns an iterator over the states of the model.
///
/// Each element is a slice of length `n_states` containing the level,
/// growth and seasonal parameters of the model.
pub fn states(&self) -> impl Iterator<Item = &[f64]> {
pub(crate) fn states(&self) -> impl Iterator<Item = &[f64]> {
self.x.chunks_exact(self.n_states)
}

/// The last state of the model.
///
/// This should be the best value found while fitting the model,
/// after which training stopped.
pub fn last_state(&self) -> &[f64] {
pub(crate) fn last_state(&self) -> &[f64] {
self.states().last().unwrap()
}

/// The parameters used when fitting the model.
#[inline]
pub fn params(&self) -> &Params {
pub(crate) fn params(&self) -> &Params {
&self.params
}

/// The number of parameters used when fitting the model.
#[inline]
pub fn n_params(&self) -> usize {
pub(crate) fn n_params(&self) -> usize {
self.n_params
}

/// The residuals of the model against the training data.
#[inline]
pub fn residuals(&self) -> &[f64] {
pub(crate) fn residuals(&self) -> &[f64] {
&self.residuals
}

/// The fitted values of the model.
#[inline]
pub fn fitted(&self) -> &[f64] {
pub(crate) fn fitted(&self) -> &[f64] {
&self.fitted
}
}
Expand All @@ -105,7 +105,7 @@ impl FitState {
/// This includes everything specified by the user, but not the state of the
/// model (which is stored in [`FitState`]).
#[derive(Debug, Clone)]
pub struct Ets {
pub(crate) struct Ets {
pub model_type: ModelType,
#[allow(dead_code)] // unused for now as seasonal models are unimplemented.
pub season_length: usize,
Expand Down
1 change: 0 additions & 1 deletion crates/augurs-ets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! ```
//!
//! [statsforecast]: https://nixtla.github.io/statsforecast/models.html#autoets
#![warn(missing_docs)]
mod auto;
mod ets;
Expand Down
4 changes: 2 additions & 2 deletions crates/augurs-ets/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub(crate) struct OptimizeParams {
}

impl OptimizeParams {
pub fn n_included(&self) -> usize {
pub(crate) fn n_included(&self) -> usize {
self.alpha as usize + self.beta as usize + self.gamma as usize + self.phi as usize
}
}
Expand Down Expand Up @@ -1225,7 +1225,7 @@ impl Predict for Model {

struct Forecast<'a>(&'a mut augurs_core::Forecast);

impl<'a> Forecast<'a> {
impl Forecast<'_> {
/// Calculate the prediction intervals for the forecast.
fn calculate_intervals(&mut self, ets: &Ets, fit: &FitState, horizon: usize, level: f64) {
let sigma = fit.sigma_squared();
Expand Down
2 changes: 1 addition & 1 deletion crates/augurs-ets/src/stat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub trait VarExt {
pub(crate) trait VarExt {
fn var(&self, ddof: usize) -> f64;
fn std(&self, ddof: usize) -> f64 {
self.var(ddof).sqrt()
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-forecaster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ thiserror.workspace = true
[dev-dependencies]
augurs.workspace = true
augurs-testing.workspace = true

[lints]
workspace = true
6 changes: 0 additions & 6 deletions crates/augurs-forecaster/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

mod data;
mod error;
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ wasm-tracing = { version = "0.2.1", optional = true }
[package.metadata.wasm-pack.profile.release]
# previously had just ['-O4']
wasm-opt = ['-O4', '--enable-bulk-memory', '--enable-threads']
Comment on lines 49 to 50
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent wasm-opt flags across Cargo.toml files.

Only crates/augurs-js/Cargo.toml includes the updated wasm-opt flags (['-O4', '--enable-bulk-memory', '--enable-threads']). The following crates are missing these configurations:

  • crates/augurs-changepoint/Cargo.toml
  • crates/augurs-clustering/Cargo.toml
  • crates/augurs-core/Cargo.toml
  • crates/augurs-dtw/Cargo.toml
  • crates/augurs-ets/Cargo.toml
  • crates/augurs-forecaster/Cargo.toml
  • crates/augurs-mstl/Cargo.toml
  • crates/augurs-outlier/Cargo.toml
  • crates/augurs-prophet/Cargo.toml
  • crates/augurs-seasons/Cargo.toml
  • crates/augurs-testing/Cargo.toml
  • crates/augurs/Cargo.toml
  • crates/pyaugurs/Cargo.toml

Please update these Cargo.toml files to include the new wasm-opt flags to ensure consistent WebAssembly optimizations across the workspace.

🔗 Analysis chain

Improved WebAssembly optimization configuration.

The addition of --enable-bulk-memory and --enable-threads flags to the wasm-opt configuration is a good improvement. These flags can potentially enhance the performance of the WebAssembly output.

  • --enable-bulk-memory allows for more efficient memory operations.
  • --enable-threads enables support for multi-threading in WebAssembly.

To ensure consistency across the workspace, let's verify if similar changes have been made in other relevant Cargo.toml files:


🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent wasm-opt flags across the workspace

# Test: Search for wasm-opt configurations in all Cargo.toml files
# Expect: Consistent use of new flags in relevant crates
rg -U --type toml 'wasm-opt.*\[.*\]' crates/*/Cargo.toml

Length of output: 1723


Script:

#!/bin/bash
# Description: Verify consistency of wasm-opt flags across the workspace

# Test: Search for wasm-opt configurations in all Cargo.toml files
# Expect: All relevant Cargo.toml files contain the updated wasm-opt flags

rg -U --type toml '\bwasm-opt\s*=\s*\[.*\]' crates/*/Cargo.toml

Length of output: 575


[lints]
workspace = true
6 changes: 0 additions & 6 deletions crates/augurs-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
// Annoying, hopefully https://github.com/madonoharu/tsify/issues/42 will
// be resolved at some point.
#![allow(non_snake_case, clippy::empty_docs)]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

use serde::Serialize;
use tsify_next::Tsify;
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-mstl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ harness = false
[[bench]]
name = "vic_elec_iai"
harness = false

[lints]
workspace = true
6 changes: 0 additions & 6 deletions crates/augurs-mstl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

use stlrs::MstlResult;
use tracing::instrument;
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-outlier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ serde_json.workspace = true

[features]
parallel = ["rayon"]

[lints]
workspace = true
4 changes: 2 additions & 2 deletions crates/augurs-outlier/src/dbscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl DbscanDetector {
}
}

pub struct DBScan1DResults {
pub(crate) struct DBScan1DResults {
cluster_min: Option<f64>,
cluster_max: Option<f64>,
outlier_indices: TinyVec<[Index; 24]>,
Expand Down Expand Up @@ -368,7 +368,7 @@ mod tests {
// Transposed dataset for testing DBSCAN.
// There are 13 timestamps and 9 series: each inner
// array contains the values for the all series at that timestamp.
pub static DBSCAN_DATASET: &[&[f64]] = &[
static DBSCAN_DATASET: &[&[f64]] = &[
// all in cluster if eps<=1
&[1., 2., 3., 4., 5., 6., 7., 8., 9.],
// all anomalous unless eps>=3
Expand Down
1 change: 0 additions & 1 deletion crates/augurs-outlier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]

use std::collections::BTreeSet;

Expand Down
4 changes: 2 additions & 2 deletions crates/augurs-outlier/src/mad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ mod test {
lower.into_iter().interleave(upper).collect()
}

const MAD_TEST_CASES: &[MADTestCase] = &[
const MAD_TEST_CASES: &[MADTestCase<'_>] = &[
MADTestCase {
name: "normal",
data: BASE_SAMPLE,
Expand Down Expand Up @@ -618,7 +618,7 @@ mod test {
},
];

fn test_calculate_mad(tc: &MADTestCase) {
fn test_calculate_mad(tc: &MADTestCase<'_>) {
let mad = MADDetector::with_sensitivity(0.5).unwrap();
let result = tc
.precalculated_medians
Expand Down
2 changes: 1 addition & 1 deletion crates/augurs-outlier/src/sensitivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// Crucially, though, sensitivity will always be a value between 0.0
/// and 1.0 to make it easier to reason about for users.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct Sensitivity(pub f64);
pub(crate) struct Sensitivity(pub f64);

impl TryFrom<f64> for Sensitivity {
type Error = SensitivityError;
Expand Down
2 changes: 1 addition & 1 deletion crates/augurs-outlier/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::OutlierInterval;

pub const SERIES: &[&[f64]] = &[
pub(crate) const SERIES: &[&[f64]] = &[
&[
84.57766308278907,
1.4076132246566786,
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-prophet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ serde = ["dep:serde"]
name = "download-stan-model"
path = "src/bin/main.rs"
required-features = ["download"]

[lints]
workspace = true
2 changes: 2 additions & 0 deletions crates/augurs-prophet/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Build script for the Prophet model.
/// Compile the Prophet model (in prophet.stan) to a binary,
/// using the Makefile in the cmdstan installation.
///
Expand Down
6 changes: 0 additions & 6 deletions crates/augurs-prophet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
mod data;
mod error;
mod features;
Expand Down
3 changes: 3 additions & 0 deletions crates/augurs-seasons/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ pprof.workspace = true
[[bench]]
name = "periodogram"
harness = false

[lints]
workspace = true
7 changes: 0 additions & 7 deletions crates/augurs-seasons/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]

mod periodogram;
#[cfg(test)]
mod test_data;
Expand Down
Loading
Loading