minor fixes/updates
This commit is contained in:
parent
5c254723a9
commit
baa4c70c0c
5 changed files with 20 additions and 5 deletions
|
|
@ -5,7 +5,7 @@ use ansi_term::Color::Yellow;
|
|||
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};
|
||||
use nalgebra::{DMatrix, DVector};
|
||||
|
||||
/// struct representing the circle counting task to be used by `crate::search::Searcher` to compute
|
||||
/// Struct representing the circle counting task to be used by `crate::search::Searcher` to compute
|
||||
/// the fractal dimension via the circle counting method
|
||||
struct CircleCountingTask {
|
||||
counts: Vec<usize>,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ fn main() {
|
|||
max,
|
||||
n,
|
||||
debug,
|
||||
0,
|
||||
recursion_depth,
|
||||
&timer,
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("Regression went wrong: {}", e));
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@ use nom::{
|
|||
IResult,
|
||||
};
|
||||
|
||||
/// Combinator to skip "whitespace"
|
||||
fn whitespace<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
|
||||
is_a(" \t\r\n`\\,")(i)
|
||||
}
|
||||
|
||||
/// Combinator to parse a positive integer and return the integer it represents as a value
|
||||
fn int<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, usize, E> {
|
||||
map(digit0, |s: &str| {
|
||||
if let Ok(val) = s.parse::<usize>() {
|
||||
|
|
@ -27,6 +29,8 @@ fn int<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, usize, E> {
|
|||
})(i)
|
||||
}
|
||||
|
||||
/// Function that, given a combinator representing the kind of element, returns a combinator that
|
||||
/// parses a list delimited by braces
|
||||
fn list<'a, F: 'a, O, E: ParseError<&'a str>>(
|
||||
element: F,
|
||||
) -> impl FnMut(&'a str) -> IResult<&'a str, Vec<O>, E>
|
||||
|
|
@ -36,6 +40,7 @@ where
|
|||
delimited(char('{'), separated_list0(whitespace, element), char('}'))
|
||||
}
|
||||
|
||||
/// Combinator that parses a matrix: i.e. a nested list of floats, and returns a `DMatrix`
|
||||
fn matrix<'a, E: 'a + ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, DMatrix<f64>, E> {
|
||||
let (tail, output) = list(list(double))(i)?;
|
||||
let n = output.len();
|
||||
|
|
@ -48,6 +53,8 @@ fn matrix<'a, E: 'a + ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, DMatr
|
|||
Ok((tail, DMatrix::from_row_slice(n, m, &output.concat())))
|
||||
}
|
||||
|
||||
/// Reads the file `filename`, which should first have the gram matrix, and then the face scheme,
|
||||
/// parses it, and returns the gram matrix and face scheme
|
||||
pub fn read_file(filename: &str) -> (DMatrix<f64>, Vec<Vec<usize>>) {
|
||||
let contents = read_to_string(filename)
|
||||
.unwrap_or_else(|e| panic!("Something went wrong reading {}: {}", filename, e));
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ impl PictureTask {
|
|||
fn new(max_curvature: f64, width: usize, height: usize) -> PictureTask {
|
||||
PictureTask {
|
||||
svg: format!(
|
||||
"<?xml version=\"1.0\" standalone=\"no\"?>\n<svg width=\"{}\" height=\"{}\">\n",
|
||||
"<?xml version=\"1.0\" standalone=\"no\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{}\" height=\"{}\">\n",
|
||||
width, height
|
||||
),
|
||||
max_curvature,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
#![allow(dead_code)]
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// Handy struct to keep track of timing things and making predictions
|
||||
pub struct Timer {
|
||||
start: Instant,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
/// Constructor returning a timer. `active` tells whether or not to enable message printing.
|
||||
pub fn new(active: bool) -> Self {
|
||||
Self {
|
||||
start: Instant::now(),
|
||||
|
|
@ -14,10 +16,13 @@ impl Timer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the time elapsed since the timer was constructed
|
||||
pub fn time_elapsed(&self) -> Duration {
|
||||
Instant::now().duration_since(self.start)
|
||||
}
|
||||
|
||||
/// Given a duration, prints `before` followed by the duration, in minutes/seconds, followed by
|
||||
/// `after`.
|
||||
fn print_time_message(&self, duration: Duration, before: &str, after: &str) {
|
||||
if self.active {
|
||||
let time = duration.as_secs_f64();
|
||||
|
|
@ -32,13 +37,16 @@ impl Timer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Prints `before` + time elapsed since timer was activated + `after`
|
||||
pub fn time_stamp(&self, before: &str, after: &str) {
|
||||
self.print_time_message(self.time_elapsed(), before, after);
|
||||
}
|
||||
|
||||
pub fn time_remaining(&self, portion: f64, before: &str, after: &str) {
|
||||
/// Exactly like `time_stamp` by prints `factor * self.time_elapsed()` rather than just
|
||||
/// `self.time_elapsed()`
|
||||
pub fn time_remaining(&self, factor: f64, before: &str, after: &str) {
|
||||
self.print_time_message(
|
||||
Duration::from_secs_f64(self.time_elapsed().as_secs_f64() * portion),
|
||||
Duration::from_secs_f64(self.time_elapsed().as_secs_f64() * factor),
|
||||
before,
|
||||
after,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue