From 13ea8ca6564e2d497b183fe031d7b243b77fec42 Mon Sep 17 00:00:00 2001 From: seyon Date: Fri, 23 Jun 2023 12:27:11 +0100 Subject: [PATCH 1/3] `new` for OpaqueOp --- src/ops/custom.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ops/custom.rs b/src/ops/custom.rs index 28ff420cd..a458cd9cb 100644 --- a/src/ops/custom.rs +++ b/src/ops/custom.rs @@ -24,6 +24,14 @@ pub struct OpaqueOp { } impl OpaqueOp { + /// Initialize a new named OpaqueOp + pub fn new(id: impl Into, custom: Box) -> Self { + Self { + id: id.into(), + custom, + } + } + /// The name of the operation, cached for fast equality checks. pub fn name(&self) -> SmolStr { self.id.clone() From 014c91bc2a0ab07e3b61a150cda79241ff20352c Mon Sep 17 00:00:00 2001 From: seyon Date: Fri, 23 Jun 2023 12:32:58 +0100 Subject: [PATCH 2/3] add float const value --- src/ops/constant.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ops/constant.rs b/src/ops/constant.rs index c3450ca6c..0715f610b 100644 --- a/src/ops/constant.rs +++ b/src/ops/constant.rs @@ -54,6 +54,8 @@ pub enum ConstValue { value: HugrIntValueStore, width: HugrIntWidthStore, }, + /// Double precision float + F64(f64), /// A constant specifying a variant of a Sum type. Sum { tag: usize, @@ -90,6 +92,8 @@ impl PartialEq for ConstValue { ) => tag == t1 && variants == type1 && val == v1, (Self::Tuple(v1), Self::Tuple(v2)) => v1.eq(v2), + (Self::F64(f1), Self::F64(f2)) => f1 == f2, + _ => false, } } @@ -122,12 +126,14 @@ impl ConstValue { .collect(); ClassicType::Container(Container::Tuple(Box::new(row.into()))) } + Self::F64(_) => ClassicType::F64, } } /// Unique name of the constant. pub fn name(&self) -> SmolStr { match self { Self::Int { value, width } => format!("const:int<{width}>:{value}"), + Self::F64(f) => format!("const:float:{f}"), Self::Opaque(_, v) => format!("const:{}", v.name()), Self::Sum { tag, val, .. } => { format!("const:sum:{{tag:{tag}, val:{}}}", val.name()) From c9ea695ed8cb10ef828efb199f45cee70adc8a25 Mon Sep 17 00:00:00 2001 From: seyon Date: Thu, 29 Jun 2023 13:11:41 +0100 Subject: [PATCH 3/3] use impl in new --- src/ops/custom.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ops/custom.rs b/src/ops/custom.rs index a458cd9cb..ee06ae624 100644 --- a/src/ops/custom.rs +++ b/src/ops/custom.rs @@ -25,10 +25,11 @@ pub struct OpaqueOp { impl OpaqueOp { /// Initialize a new named OpaqueOp - pub fn new(id: impl Into, custom: Box) -> Self { + pub fn new(id: impl Into, custom: impl CustomOp) -> Self { Self { id: id.into(), - custom, + + custom: Box::new(custom), } }