use std::error::Error;
use clap::{Arg, App};
#[macro_use]
extern crate clap;
#[macro_use]
extern crate ndarray;
mod array_implementation;
pub struct Config {
pub rows: usize,
pub cols: usize,
}
impl Config {
pub fn new() -> Result<Config, String> {
let matches = App::new("Convolician")
.version("1.0")
.author(crate_authors!())
.about("Calculates the central difference of a 2d unsigned char matrix")
.arg(Arg::with_name("rows")
.required(true)
.help("Number of rows in the random matrix"))
.arg(Arg::with_name("cols")
.required(true)
.help("Number of columns in the random matrix"))
.get_matches();
let rows = value_t!(matches, "rows", usize).map_err(|e| { e.message })?;
let cols = value_t!(matches, "cols", usize).map_err(|e| { e.message })?;
if rows < 1 || cols < 1 {
return Err(String::from("<rows> and <cols> arguments must be positive integers"));
}
println!("Convolving a random {}x{} matrix...", rows, cols);
Ok(Config { rows, cols })
}
}
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
array_implementation::run(config.rows, config.cols)
}