From 9d54a9ccc62a0693b25b55deba34fbb905b64f2d Mon Sep 17 00:00:00 2001 From: Johnnie Gray Date: Fri, 1 Sep 2023 17:32:56 -0700 Subject: [PATCH] remove rregex dependency --- Cargo.lock | 45 --------------------------------------------- Cargo.toml | 1 - src/lib.rs | 24 +++++++++++------------- 3 files changed, 11 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f77aee..cbcdbc9 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" -dependencies = [ - "memchr", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -52,7 +43,6 @@ dependencies = [ "ordered-float", "pyo3", "rand", - "regex", "rustc-hash", ] @@ -89,12 +79,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "memchr" -version = "2.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486aed0026218e61b8a01d5fbd5a0a134649abb71a0e53b7bc088529dced86e" - [[package]] name = "memoffset" version = "0.9.0" @@ -274,35 +258,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex" -version = "1.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - [[package]] name = "rustc-hash" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index fc299f8..c13a4cb 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ bit-set = "0.5" pyo3 = "0.19" ordered-float = "3.9" rand = "0.8" -regex = "1.9" rustc-hash = "1.1" [profile.release] diff --git a/src/lib.rs b/src/lib.rs index 40f1be0..f34173f 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ use bit_set::BitSet; use ordered_float::OrderedFloat; use pyo3::prelude::*; use rand::Rng; -use regex::Regex; use rustc_hash::FxHashMap; use std::collections::{BTreeSet, BinaryHeap}; use std::f32; @@ -620,19 +619,18 @@ impl ContractionProcessor { cost_cap: Option, allow_outer: Option, ) { - // parse the minimize + // parse the minimize argument let minimize = minimize.unwrap_or("flops".to_string()); - - let re = Regex::new(r"^(flops|size|write|combo|limit)(?:-(\d+(?:\.\d+)?))?$").unwrap(); - let captures = re.captures(minimize.as_str()).unwrap(); - let minimize_type = captures.get(1).unwrap().as_str(); - let factor = f32::ln( - captures - .get(2) - .map(|m| m.as_str().parse::().unwrap()) - .unwrap_or(64.), - ); - + let mut minimize_split = minimize.split('-'); + let minimize_type = minimize_split.next().unwrap(); + let factor = minimize_split + .next() + .map_or(64.0, |s| s.parse::().unwrap()) + .ln(); + if minimize_split.next().is_some() { + // multiple hyphens -> raise error + panic!("invalid minimize: {:?}", minimize); + } let compute_cost = match minimize_type { "flops" => compute_con_cost_flops, "size" => compute_con_cost_size,