Skip to content

Commit

Permalink
v0.8.2: NotNan<f64> -> f64
Browse files Browse the repository at this point in the history
  • Loading branch information
zao111222333 committed Dec 31, 2024
1 parent cb7adfb commit 7ce2c47
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 397 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
members = ["macros", "dev", "dev/utils", "dev/include/liberty2json"]

[workspace.package]
version = "0.8.1"
version = "0.8.2"
license = "MIT"
edition = "2021"
authors = ["Junzhuo <[email protected]>"]
Expand Down Expand Up @@ -64,7 +64,7 @@ ryu = "1.0"
itoa = "1.0"
biodivine-lib-bdd = { version = "0.5.23", features = ["serde"] }
# biodivine-lib-bdd = { git = "https://github.com/zao111222333/biodivine-lib-bdd.git", features = ["serde"] }
mut_set = "0.6.0"
mut_set = "0.6.1"
# mut_set = { version="0.5.2", features = ["__dbg_disable_mem_layout"] }
# mut_set = { path = "../mut_set" }
duplicate = "2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main(){
}
```

And can see more [examples](examples), and run them if you clone this repo:
See more [examples](examples), and run them if you clone this repo:

``` shell
# example0
Expand Down
4 changes: 2 additions & 2 deletions examples/2_prune_lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use liberty_db::{cell::CellCtx, DefaultCtx, Library, NotNan};
use liberty_db::{cell::CellCtx, DefaultCtx, Library};
use std::{
env,
fs::{read_to_string, File},
Expand All @@ -20,7 +20,7 @@ fn main() {
.unwrap();
library.technology = "cmos".into();
for operating_condition in library.operating_conditions.iter_mut() {
operating_condition.voltage = unsafe { NotNan::<f64>::new_unchecked(0.8) };
operating_condition.voltage = 0.8;
}
log::warn!("Attributes Items: {:?}", library.attributes);
for cell in library.cell.iter_mut() {
Expand Down
99 changes: 80 additions & 19 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
mod fmt;
pub mod parser;
use crate::{library::AttributeType, ArcStr, NotNan};
use crate::{library::AttributeType, ArcStr};
use core::hash::{BuildHasher as _, Hash, Hasher as _};
use core::{fmt::Write, num::ParseIntError, str::FromStr};
pub use fmt::{CodeFormatter, DefaultCodeFormatter, DefaultIndentation, Indentation};
use itertools::Itertools as _;
use itertools::{izip, Itertools as _};
use nom::{error::Error, IResult};
use ordered_float::NotNan;
use std::collections::HashMap;
const DEFINED_COMMENT: &str = " /* user defined attribute */";

Expand All @@ -18,7 +19,7 @@ pub(crate) type RandomState = std::hash::RandomState;
#[cfg(feature = "fast_hash")]
pub(crate) type RandomState = ahash::RandomState;

pub(crate) type GroupSet<T> = <T as mut_set::Item>::MutSet<RandomState>;
pub type GroupSet<T> = <T as mut_set::Item>::MutSet<RandomState>;

#[expect(clippy::field_scoped_visibility_modifiers)]
#[derive(Default)]
Expand Down Expand Up @@ -112,7 +113,7 @@ pub(crate) enum UndefinedAttriValue {
Group(GroupWrapper),
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum SimpleDefined {
/// Boolean `Simple`
Expand All @@ -122,7 +123,67 @@ pub enum SimpleDefined {
/// integer `Simple`
Integer(Vec<Result<isize, ArcStr>>),
/// float `Simple`
Float(Vec<Result<NotNan<f64>, ArcStr>>),
Float(Vec<Result<f64, ArcStr>>),
}
impl PartialEq for SimpleDefined {
#[inline]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Boolean(l0), Self::Boolean(r0)) => l0 == r0,
(Self::String(l0), Self::String(r0)) => l0 == r0,
(Self::Integer(l0), Self::Integer(r0)) => l0 == r0,
(Self::Float(l0), Self::Float(r0)) => {
l0.len() == r0.len()
&& izip!(l0, r0).all(|lr| match lr {
(Ok(l), Ok(r)) => unsafe {
NotNan::new_unchecked(*l) == NotNan::new_unchecked(*r)
},
(Err(l), Err(r)) => l == r,
_ => false,
})
}
_ => false,
}
}
}
impl Eq for SimpleDefined {}
impl PartialOrd for SimpleDefined {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SimpleDefined {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match (self, other) {
(SimpleDefined::Boolean(l), SimpleDefined::Boolean(r)) => l.cmp(r),
(SimpleDefined::String(l), SimpleDefined::String(r)) => l.cmp(r),
(SimpleDefined::Integer(l), SimpleDefined::Integer(r)) => l.cmp(r),
(SimpleDefined::Float(l), SimpleDefined::Float(r)) => match l.len().cmp(&r.len()) {
std::cmp::Ordering::Less => std::cmp::Ordering::Less,
std::cmp::Ordering::Greater => std::cmp::Ordering::Greater,
std::cmp::Ordering::Equal => l
.iter()
.map(|res| match res {
Ok(f) => Ok(unsafe { NotNan::new_unchecked(*f) }),
Err(s) => Err(s),
})
.cmp(r.iter().map(|res| match res {
Ok(f) => Ok(unsafe { NotNan::new_unchecked(*f) }),
Err(s) => Err(s),
})),
},
(SimpleDefined::Boolean(_), _) => std::cmp::Ordering::Less,
(_, SimpleDefined::Boolean(_)) => std::cmp::Ordering::Greater,
(_, SimpleDefined::Float(_)) => std::cmp::Ordering::Less,
(SimpleDefined::Float(_), _) => std::cmp::Ordering::Greater,
(SimpleDefined::String(_), SimpleDefined::Integer(_)) => std::cmp::Ordering::Less,
(SimpleDefined::Integer(_), SimpleDefined::String(_)) => {
std::cmp::Ordering::Greater
}
}
}
}

#[inline]
Expand Down Expand Up @@ -409,20 +470,20 @@ pub(crate) fn define_id(hash_builder: &RandomState, group_name: &str, key: &str)
// }
// }

#[derive(Debug, Clone)]
#[derive(Hash, PartialEq, Eq)]
#[derive(Ord, PartialOrd)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum DefinedAttribute {
/// Boolean
Boolean(Vec<bool>),
/// string
String(Vec<ArcStr>),
/// integer
Integer(Vec<isize>),
/// float
Float(Vec<NotNan<f64>>),
}
// #[derive(Debug, Clone)]
// #[derive(Hash, PartialEq, Eq)]
// #[derive(Ord, PartialOrd)]
// #[derive(serde::Serialize, serde::Deserialize)]
// pub enum DefinedAttribute {
// /// Boolean
// Boolean(Vec<bool>),
// /// string
// String(Vec<ArcStr>),
// /// integer
// Integer(Vec<isize>),
// /// float
// Float(Vec<f64>),
// }

pub(crate) type SimpleParseRes<'a, T> =
IResult<&'a str, Result<T, ArcStr>, Error<&'a str>>;
Expand Down
32 changes: 9 additions & 23 deletions src/ast/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! All parser utilis.
//!
use crate::{ast::GroupWrapper, ArcStr, NotNan};
use crate::{ast::GroupWrapper, ArcStr};
use nom::{
branch::alt,
bytes::complete::{escaped, is_not, tag, take, take_until, take_while},
Expand Down Expand Up @@ -362,15 +362,15 @@ pub(crate) fn simple<'a>(
)(i)
}
#[inline]
fn float_one(i: &str) -> IResult<&str, NotNan<f64>, Error<&str>> {
pub(crate) fn float_one(i: &str) -> IResult<&str, f64, Error<&str>> {
#[expect(clippy::string_slice, clippy::undocumented_unsafe_blocks)]
match fast_float2::parse_partial(i) {
Ok((f, pos)) => Ok((&i[pos..], unsafe { NotNan::new_unchecked(f) })),
Ok((f, pos)) => Ok((&i[pos..], f)),
Err(_) => Err(nom::Err::Error(Error::new(i, ErrorKind::Float))),
}
}
#[inline]
fn float_vec(i: &str) -> IResult<&str, Vec<NotNan<f64>>, Error<&str>> {
fn float_vec(i: &str) -> IResult<&str, Vec<f64>, Error<&str>> {
delimited(
pair(char('"'), space),
terminated(
Expand All @@ -392,7 +392,7 @@ fn int_usize(i: &str) -> IResult<&str, usize, Error<&str>> {
pub(crate) fn complex_id_vector<'a>(
i: &'a str,
line_num: &mut usize,
) -> IResult<&'a str, (usize, Vec<NotNan<f64>>), Error<&'a str>> {
) -> IResult<&'a str, (usize, Vec<f64>), Error<&'a str>> {
map(
tuple((
space,
Expand Down Expand Up @@ -448,7 +448,7 @@ pub(crate) fn complex_multi_line<'a, T, F: nom::Parser<&'a str, T, Error<&'a str
pub(crate) fn complex_float_vec<'a>(
i: &'a str,
line_num: &mut usize,
) -> IResult<&'a str, Vec<NotNan<f64>>, Error<&'a str>> {
) -> IResult<&'a str, Vec<f64>, Error<&'a str>> {
map(
tuple((
space,
Expand Down Expand Up @@ -500,7 +500,7 @@ pub(crate) fn complex_float_vec<'a>(
pub(crate) fn complex_values<'a>(
i: &'a str,
line_num: &mut usize,
) -> IResult<&'a str, Vec<(usize, Vec<NotNan<f64>>)>, Error<&'a str>> {
) -> IResult<&'a str, Vec<(usize, Vec<f64>)>, Error<&'a str>> {
complex_multi_line(i, line_num, float_vec)
}

Expand Down Expand Up @@ -601,25 +601,11 @@ mod test_key {
)
);
assert_eq!(
Ok((
"}",
vec![
unsafe { NotNan::new_unchecked(3.0) },
unsafe { NotNan::new_unchecked(4.0) },
unsafe { NotNan::new_unchecked(5.0) },
]
)),
Ok(("}", vec![3.0, 4.0, 5.0,])),
complex_float_vec(r#" ("3, 4, 5"); }"#, &mut 1)
);
assert_eq!(
Ok((
"}",
vec![
unsafe { NotNan::new_unchecked(3.0) },
unsafe { NotNan::new_unchecked(4.0) },
unsafe { NotNan::new_unchecked(5.0) },
]
)),
Ok(("}", vec![3.0, 4.0, 5.0,])),
complex_float_vec(r#" ("3, 4, 5,"); }"#, &mut 1)
);
assert_eq!(
Expand Down
10 changes: 5 additions & 5 deletions src/ccsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
},
expression::LogicBooleanExpression,
timing::items::Mode,
ArcStr, Ctx, NotNan,
ArcStr, Ctx,
};
use core::fmt::{self, Write};
use num_traits::Zero as _;
Expand Down Expand Up @@ -66,10 +66,10 @@ pub struct CCSNStage<C: Ctx> {
pub attributes: Attributes,
#[size = 16]
#[liberty(simple(type = Option))]
pub load_cap_fall: Option<NotNan<f64>>,
pub load_cap_fall: Option<f64>,
#[size = 16]
#[liberty(simple(type = Option))]
pub load_cap_rise: Option<NotNan<f64>>,
pub load_cap_rise: Option<f64>,
/// Use the `is_inverting` attribute to specify whether the channel-connecting block is inverting.
/// This attribute is mandatory if the `is_needed` attribute value is true.
/// If the channel-connecting block is inverting, set the attribute to true.
Expand Down Expand Up @@ -107,15 +107,15 @@ pub struct CCSNStage<C: Ctx> {
/// ">Reference-Definition</a>
#[size = 16]
#[liberty(simple(type = Option))]
pub miller_cap_fall: Option<NotNan<f64>>,
pub miller_cap_fall: Option<f64>,
/// Use the `miller_cap_rise` attribute to specify the Miller capacitance value for the channel-connecting block.
/// A floating-point number representing the Miller capacitance value. The value must be greater or equal to zero.
/// <a name ="reference_link" href="
/// https://zao111222333.github.io/liberty-db/2020.09/reference_manual.html?field=null&bgn=287.3&end=287.11
/// ">Reference-Definition</a>
#[size = 16]
#[liberty(simple(type = Option))]
pub miller_cap_rise: Option<NotNan<f64>>,
pub miller_cap_rise: Option<f64>,
/// The optional `related_ccb_node` attribute specifies the SPICE node
/// in the subcircuit netlist that is used for the `dc_current`
/// table characterization and waveform measurements.
Expand Down
Loading

0 comments on commit 7ce2c47

Please sign in to comment.