Skip to content

chore: Use Rust 2024 #119

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pmcore"
version = "0.10.0"
edition = "2021"
edition = "2024"
authors = [
"Julián D. Otálvaro <[email protected]>",
"Markus Hovd",
Expand Down
2 changes: 1 addition & 1 deletion benches/bimodal_ke.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};
use pmcore::prelude::*;

fn create_equation() -> equation::ODE {
Expand Down
10 changes: 5 additions & 5 deletions src/algorithms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ pub trait Algorithms<E: Equation>: Sync {
}

return Err(anyhow::anyhow!(
"The probability of {}/{} subjects is zero given the model. Affected subjects: {:?}",
indices.len(),
self.psi().matrix().nrows(),
zero_probability_subjects
));
"The probability of {}/{} subjects is zero given the model. Affected subjects: {:?}",
indices.len(),
self.psi().matrix().nrows(),
zero_probability_subjects
));
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/npag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pub use crate::routines::evaluation::qr;
use crate::routines::settings::Settings;

use crate::routines::output::{CycleLog, NPCycle, NPResult};
use crate::structs::psi::{calculate_psi, Psi};
use crate::structs::psi::{Psi, calculate_psi};
use crate::structs::theta::Theta;

use anyhow::bail;
use anyhow::Result;
use anyhow::bail;
use pharmsol::prelude::{
data::{Data, ErrorModel, ErrorType},
simulator::Equation,
Expand Down
11 changes: 6 additions & 5 deletions src/algorithms/npod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ use crate::{
},
},
structs::{
psi::{calculate_psi, Psi},
psi::{Psi, calculate_psi},
theta::Theta,
},
};
use anyhow::bail;
use anyhow::Result;
use anyhow::bail;
use faer_ext::IntoNdarray;
use pharmsol::{
Subject,
prelude::{
data::{Data, ErrorModel},
simulator::Equation,
},
Subject,
};

use faer::Col;

use ndarray::{
parallel::prelude::{IntoParallelRefMutIterator, ParallelIterator},
Array, Array1, ArrayBase, Dim, OwnedRepr,
parallel::prelude::{IntoParallelRefMutIterator, ParallelIterator},
};

use crate::routines::{initialization, optimization::SppOptimizer};
Expand Down Expand Up @@ -404,7 +404,8 @@ impl<E: Equation> NPOD<E> {
indices.iter().map(|&i| subject[i].id()).collect();

return Err(anyhow::anyhow!(
"The probability of one or more subjects, given the model, is zero. The following subjects have zero probability: {:?}", zero_probability_subjects
"The probability of one or more subjects, given the model, is zero. The following subjects have zero probability: {:?}",
zero_probability_subjects
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/postprob.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
prelude::algorithms::Algorithms,
structs::{
psi::{calculate_psi, Psi},
psi::{Psi, calculate_psi},
theta::Theta,
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub mod prelude {
pub use super::HashMap;
pub use super::Result;
pub use crate::algorithms;
pub use crate::algorithms::dispatch_algorithm;
pub use crate::algorithms::Algorithm;
pub use crate::algorithms::dispatch_algorithm;
pub use crate::routines;
pub use crate::routines::logger;

Expand All @@ -89,15 +89,15 @@ pub mod prelude {
}

//traits
pub use pharmsol::ODE;
pub use pharmsol::SDE;
pub use pharmsol::data::*;
pub use pharmsol::equation::Equation;
pub use pharmsol::equation::EquationTypes;
pub use pharmsol::equation::Predictions;
pub use pharmsol::equation::*;
pub use pharmsol::prelude::*;
pub use pharmsol::simulator::*;
pub use pharmsol::ODE;
pub use pharmsol::SDE;

//macros
pub use pharmsol::fa;
Expand Down
2 changes: 1 addition & 1 deletion src/routines/evaluation/qr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::structs::psi::Psi;
use faer::linalg::solvers::ColPivQr;
use faer::Mat;
use faer::linalg::solvers::ColPivQr;

pub fn calculate_r(psi: &Psi) -> (Mat<f64>, Vec<usize>) {
// Clone the matrix, as we will modify it
Expand Down
2 changes: 1 addition & 1 deletion src/routines/initialization/latin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use faer::Mat;
use rand::Rng;
use rand::prelude::*;
use rand::rngs::StdRng;
use rand::Rng;

use crate::prelude::Parameters;
use crate::structs::theta::Theta;
Expand Down
6 changes: 3 additions & 3 deletions src/routines/initialization/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;

use crate::structs::theta::Theta;
use anyhow::{bail, Context, Result};
use anyhow::{Context, Result, bail};
use faer::Mat;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -66,8 +66,8 @@ pub fn sample_space(settings: &Settings) -> Result<Theta> {
let prior = match settings.prior() {
Prior::Sobol(points, seed) => sobol::generate(settings.parameters(), *points, *seed)?,
Prior::Latin(points, seed) => latin::generate(settings.parameters(), *points, *seed)?,
Prior::File(ref path) => parse_prior(path, settings)?,
Prior::Theta(ref theta) => {
Prior::File(path) => parse_prior(path, settings)?,
Prior::Theta(theta) => {
// If a custom prior is provided, return it directly
return Ok(theta.clone());
}
Expand Down
2 changes: 1 addition & 1 deletion src/routines/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::time::Instant;
use crate::routines::output::OutputFile;
use crate::routines::settings::Settings;
use anyhow::Result;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::fmt::time::FormatTime;
use tracing_subscriber::fmt::{self};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::registry::Registry;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

/// Setup logging for the library
///
Expand Down
2 changes: 1 addition & 1 deletion src/routines/optimization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ndarray::{Array1, Axis};

use pharmsol::prelude::{
data::{Data, ErrorModel},
simulator::{psi, Equation},
simulator::{Equation, psi},
};

pub struct SppOptimizer<'a, E: Equation> {
Expand Down
11 changes: 8 additions & 3 deletions src/routines/output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::structs::psi::Psi;
use crate::structs::theta::Theta;
use anyhow::{bail, Context, Result};
use anyhow::{Context, Result, bail};
use csv::WriterBuilder;
use faer::linalg::zip::IntoView;
use faer_ext::IntoNdarray;
Expand All @@ -12,7 +12,7 @@ use serde::Serialize;
// use pharmsol::Cache;
use crate::routines::settings::Settings;
use faer::{Col, Mat};
use std::fs::{create_dir_all, File, OpenOptions};
use std::fs::{File, OpenOptions, create_dir_all};
use std::path::{Path, PathBuf};

/// Defines the result objects from an NPAG run
Expand Down Expand Up @@ -810,7 +810,12 @@ pub fn posterior_mean_median(

// Check for compatible sizes
if theta.nrows() != w.len() || theta.nrows() != psi.ncols() || psi.ncols() != w.len() {
bail!("Number of parameters and number of weights do not match, theta.nrows(): {}, w.len(): {}, psi.ncols(): {}", theta.nrows(), w.len(), psi.ncols());
bail!(
"Number of parameters and number of weights do not match, theta.nrows(): {}, w.len(): {}, psi.ncols(): {}",
theta.nrows(),
w.len(),
psi.ncols()
);
}

// Normalize psi to get probabilities of each spp for each id
Expand Down
2 changes: 1 addition & 1 deletion src/routines/settings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::algorithms::Algorithm;
use crate::routines::initialization::Prior;
use crate::routines::output::OutputFile;
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use pharmsol::prelude::data::ErrorType;
use serde::{Deserialize, Serialize};
use serde_json;
Expand Down
2 changes: 1 addition & 1 deletion src/structs/psi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use faer::Mat;
use faer_ext::IntoFaer;
use faer_ext::IntoNdarray;
use ndarray::{Array2, ArrayView2};
use pharmsol::prelude::simulator::psi;
use pharmsol::Data;
use pharmsol::Equation;
use pharmsol::ErrorModel;
use pharmsol::prelude::simulator::psi;

use super::theta::Theta;

Expand Down
Loading