Skip to content

Commit

Permalink
Merge branch 'main' into feat/const-fold2
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jan 3, 2024
2 parents 6e36684 + 23987a0 commit b0c686d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/algorithm/const_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ pub fn constant_fold_pass(h: &mut impl HugrMut, reg: &ExtensionRegistry) {
#[cfg(test)]
mod test {

use super::*;
use crate::extension::prelude::sum_with_error;
use crate::extension::{ExtensionRegistry, PRELUDE};
use crate::std_extensions::arithmetic;
use crate::std_extensions::arithmetic::conversions::ConvertOpDef;
use crate::std_extensions::arithmetic::float_ops::FloatOps;
use crate::std_extensions::arithmetic::float_types::{ConstF64, FLOAT64_TYPE};
use crate::std_extensions::arithmetic::int_types::{ConstIntU, INT_TYPES};

use super::*;
use rstest::rstest;

/// int to constant
fn i2c(b: u64) -> Const {
Expand All @@ -241,6 +241,18 @@ mod test {
ConstF64::new(f).into()
}

#[rstest]
#[case(0.0, 0.0, 0.0)]
#[case(0.0, 1.0, 1.0)]
#[case(23.5, 435.5, 459.0)]
// c = a + b
fn test_add(#[case] a: f64, #[case] b: f64, #[case] c: f64) {
let consts = vec![(0.into(), f2c(a)), (1.into(), f2c(b))];
let add_op: OpType = FloatOps::fadd.into();
let out = fold_const(&add_op, &consts).unwrap();

assert_eq!(&out[..], &[(0.into(), f2c(c))]);
}
#[test]
fn test_big() {
/*
Expand Down
4 changes: 2 additions & 2 deletions src/std_extensions/arithmetic/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
use super::int_types::int_tv;
use super::{float_types::FLOAT64_TYPE, int_types::LOG_WIDTH_TYPE_PARAM};
use lazy_static::lazy_static;
mod fold;
mod const_fold;
/// The extension identifier.
pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("arithmetic.conversions");

Expand Down Expand Up @@ -66,7 +66,7 @@ impl MakeOpDef for ConvertOpDef {
}

fn post_opdef(&self, def: &mut OpDef) {
fold::set_fold(self, def)
const_fold::set_fold(self, def)
}
}

Expand Down

0 comments on commit b0c686d

Please sign in to comment.