Skip to content

Commit

Permalink
set a minimum variable value for logic paths (#48)
Browse files Browse the repository at this point in the history
* set a minimum variable value for logic paths

* add api for setting min var value
  • Loading branch information
rahulk29 authored Oct 13, 2024
1 parent b7e4e6b commit db38d52
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions substrate/src/logic/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ new_key_type! {
pub struct VarKey;
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogicPath {
segments: Vec<Segment>,
variables: SlotMap<VarKey, VarState>,
min_var_value: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
impl Default for LogicPath {
fn default() -> Self {
Self {
segments: Vec::new(),
variables: Default::default(),
min_var_value: 1.,
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
struct VarState {
value: f64,
}
Expand Down Expand Up @@ -86,6 +97,10 @@ impl LogicPath {
Self::default()
}

pub fn set_min_var_value(&mut self, min_var_value: f64) {
self.min_var_value = min_var_value;
}

pub fn create_variable(&mut self) -> VarKey {
self.variables.insert(VarState::default())
}
Expand Down Expand Up @@ -198,7 +213,7 @@ impl LogicPath {

#[inline]
pub fn value(&self, var: VarKey) -> f64 {
self.variables[var].value
f64::max(self.variables[var].value, self.min_var_value)
}

fn segment_delay_grad(&self, idx: usize, grad: &mut Gradient) -> f64 {
Expand Down

0 comments on commit db38d52

Please sign in to comment.