use crate::defaults::capacity::DimVec;
use std::str::FromStr;
pub mod algebra;
pub mod err;
pub fn is_line_functional(line: &String) -> bool {
line.len() > 0 && line.chars().next() != Some('#')
}
pub fn add(a: &DimVec<f64>, b: &DimVec<f64>) -> DimVec<f64> {
a.iter().zip(b).map(|(aa, bb)| aa + bb).collect()
}
pub fn add_assign(a: &mut DimVec<f64>, b: &DimVec<f64>) {
a.iter_mut().zip(b).for_each(|(aa, bb)| *aa += bb);
}
pub fn sub(a: &DimVec<f64>, b: &DimVec<f64>) -> DimVec<f64> {
a.iter().zip(b).map(|(aa, bb)| aa - bb).collect()
}
pub fn dot_product(a: &[f64], b: &[f64]) -> f64 {
a.iter()
.zip(b)
.fold(0.0, |start, (aa, &bb)| start + aa * bb)
}
pub fn le(a: &[f64], b: &[f64]) -> bool {
a.iter()
.zip(b)
.fold(true, |start, (aa, bb)| start && aa.le(bb))
}
pub trait MemSize {
fn mem_size_b() -> usize;
}
pub fn init_logging(max_log_level: &str, modules: &[&str]) -> err::Feedback {
let mut builder = env_logger::Builder::new();
builder.filter(None, log::LevelFilter::Warn);
let max_log_level = log::LevelFilter::from_str(&max_log_level.to_ascii_uppercase())
.ok()
.ok_or(format!(
"The provided max-log-level {} is not supported.",
max_log_level
))?;
for module in modules {
builder.filter(Some(module), max_log_level);
}
builder.filter(Some(env!("CARGO_PKG_NAME")), max_log_level);
if let Ok(filters) = std::env::var("RUST_LOG") {
builder.parse_filters(&filters);
}
if let Ok(write_style) = std::env::var("RUST_LOG_STYLE") {
builder.parse_write_style(&write_style);
}
builder.init();
Ok(())
}