Skip to content

Commit

Permalink
Added todo
Browse files Browse the repository at this point in the history
  • Loading branch information
robinhundt committed Mar 25, 2024
1 parent 9bee7f4 commit 49a0f11
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions crates/seec/src/circuit/base_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ pub enum BaseGate<T, D = ScalarDim> {
}

#[derive(
Debug,
Default,
Copy,
Clone,
Ord,
PartialOrd,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
Pod,
Zeroable,
Debug,
Default,
Copy,
Clone,
Ord,
PartialOrd,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
Pod,
Zeroable,
)]
#[repr(transparent)]
pub struct GateId<Idx = DefaultIdx>(pub(crate) Idx);
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<G: Gate, Idx: GateIdx, W: Wire> BaseCircuit<G, Idx, W> {
pub fn parent_gates(
&self,
id: impl Into<GateId<Idx>>,
) -> impl Iterator<Item = GateId<Idx>> + '_ {
) -> impl Iterator<Item=GateId<Idx>> + '_ {
self.graph
.neighbors_directed(id.into().into(), Direction::Incoming)
.map(GateId::from)
Expand Down Expand Up @@ -176,21 +176,21 @@ impl<G: Gate, Idx: GateIdx, W: Wire> BaseCircuit<G, Idx, W> {
&self.graph
}

pub fn interactive_iter(&self) -> impl Iterator<Item = (G, GateId<Idx>)> + '_ {
pub fn interactive_iter(&self) -> impl Iterator<Item=(G, GateId<Idx>)> + '_ {
self.layer_iter()
.visit_sc_inputs()
.flat_map(|layer| layer.into_interactive_iter())
}

pub fn iter(&self) -> impl Iterator<Item = (G, GateId<Idx>)> + '_ {
pub fn iter(&self) -> impl Iterator<Item=(G, GateId<Idx>)> + '_ {
self.layer_iter()
.visit_sc_inputs()
.flat_map(|layer| layer.into_iter())
}
}

impl<G: Gate, Idx: GateIdx> BaseCircuit<G, Idx, ()> {
#[tracing::instrument(level="trace", skip(self), fields(%from, %to))]
#[tracing::instrument(level = "trace", skip(self), fields(% from, % to))]
pub fn add_wire(&mut self, from: GateId<Idx>, to: GateId<Idx>) {
self.graph.add_edge(from.into(), to.into(), ());
trace!("Added wire");
Expand All @@ -213,7 +213,7 @@ impl<G: Gate, Idx: GateIdx> BaseCircuit<G, Idx, ()> {
pub fn add_sub_circuit(
&mut self,
circuit: &Self,
inputs: impl IntoIterator<Item = GateId<Idx>>,
inputs: impl IntoIterator<Item=GateId<Idx>>,
) -> Vec<GateId<Idx>> {
assert!(!circuit.is_main, "Can't add main circuit as sub circuit");
assert!(
Expand Down Expand Up @@ -304,9 +304,9 @@ pub enum Load {
}

impl<Share, G, Idx: GateIdx> BaseCircuit<G, Idx>
where
Share: Clone,
G: Gate<Share = Share> + From<BaseGate<Share>> + for<'a> From<&'a bristol::Gate>,
where
Share: Clone,
G: Gate<Share=Share> + From<BaseGate<Share>> + for<'a> From<&'a bristol::Gate>,
{
#[tracing::instrument(skip(bristol))]
pub fn from_bristol(bristol: bristol::Circuit, load: Load) -> Result<Self, CircuitError> {
Expand Down Expand Up @@ -407,7 +407,7 @@ impl<G, Idx, W> Debug for BaseCircuit<G, Idx, W> {
impl<T: Share, D: Dimension> BaseGate<T, D> {
pub(crate) fn evaluate_sc_input_simd(
&self,
inputs: impl Iterator<Item = <Self as Gate>::Share>,
inputs: impl Iterator<Item=<Self as Gate>::Share>,
) -> <<Self as Gate>::Share as Share>::SimdShare {
let Self::SubCircuitInput(_) = self else {
panic!("Called evaluate_sc_input_simd on wrong gate {self:?}");
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<T: Share, D: Dimension> Gate for BaseGate<T, D> {
fn evaluate_non_interactive(
&self,
party_id: usize,
mut inputs: impl Iterator<Item = Self::Share>,
mut inputs: impl Iterator<Item=Self::Share>,
) -> Self::Share {
match self {
Self::Constant(constant) => {
Expand Down Expand Up @@ -480,7 +480,7 @@ impl<T: Share, D: Dimension> Gate for BaseGate<T, D> {
fn evaluate_non_interactive_simd<'e>(
&self,
_party_id: usize,
mut inputs: impl Iterator<Item = &'e <Self::Share as Share>::SimdShare>,
mut inputs: impl Iterator<Item=&'e <Self::Share as Share>::SimdShare>,
) -> <Self::Share as Share>::SimdShare {
match self {
BaseGate::Output(_)
Expand Down Expand Up @@ -512,6 +512,7 @@ pub struct BaseLayerIter<'a, G, Idx: GateIdx, W> {
visited: <CircuitGraph<G, Idx, W> as Visitable>::Map,
added_to_next: <CircuitGraph<G, Idx, W> as Visitable>::Map,
// only used for SIMD circuits
// TODO remove entries from hashmap when count recheas 0
inputs_left_to_provide: HashMap<NodeIndex<Idx>, u32>,
// (non_interactive, interactive)
last_layer_size: (usize, usize),
Expand Down Expand Up @@ -598,7 +599,7 @@ pub struct CircuitLayer<G, Idx> {
pub(crate) interactive_ids: Vec<GateId<Idx>>,
/// SIMD Gates that can be freed after this layer
pub(crate) freeable_gates: Vec<GateId<Idx>>, // TODO add output gates here so that the CircuitLayerIter::next doesn't need to iterate
// over all potential outs
// over all potential outs
}

impl<G, Idx> CircuitLayer<G, Idx> {
Expand Down Expand Up @@ -636,27 +637,27 @@ impl<G, Idx> CircuitLayer<G, Idx> {
}

impl<G: Clone, Idx: Clone> CircuitLayer<G, Idx> {
pub(crate) fn iter_ids(&self) -> impl Iterator<Item = GateId<Idx>> + '_ {
pub(crate) fn iter_ids(&self) -> impl Iterator<Item=GateId<Idx>> + '_ {
self.non_interactive_ids
.iter()
.chain(&self.interactive_ids)
.cloned()
}

pub(crate) fn into_interactive_iter(self) -> impl Iterator<Item = (G, GateId<Idx>)> + Clone {
pub(crate) fn into_interactive_iter(self) -> impl Iterator<Item=(G, GateId<Idx>)> + Clone {
self.interactive_gates.into_iter().zip(self.interactive_ids)
}

#[allow(unused)]
pub(crate) fn into_non_interactive_iter(
self,
) -> impl Iterator<Item = (G, GateId<Idx>)> + Clone {
) -> impl Iterator<Item=(G, GateId<Idx>)> + Clone {
self.non_interactive_gates
.into_iter()
.zip(self.non_interactive_ids)
}

pub(crate) fn interactive_iter(&self) -> impl Iterator<Item = (G, GateId<Idx>)> + Clone + '_ {
pub(crate) fn interactive_iter(&self) -> impl Iterator<Item=(G, GateId<Idx>)> + Clone + '_ {
self.interactive_gates
.clone()
.into_iter()
Expand All @@ -665,7 +666,7 @@ impl<G: Clone, Idx: Clone> CircuitLayer<G, Idx> {

pub(crate) fn non_interactive_iter(
&self,
) -> impl Iterator<Item = (G, GateId<Idx>)> + Clone + '_ {
) -> impl Iterator<Item=(G, GateId<Idx>)> + Clone + '_ {
self.non_interactive_gates
.clone()
.into_iter()
Expand All @@ -674,7 +675,7 @@ impl<G: Clone, Idx: Clone> CircuitLayer<G, Idx> {
}

impl<G: Clone, Idx: GateIdx> CircuitLayer<G, Idx> {
pub(crate) fn into_iter(self) -> impl Iterator<Item = (G, GateId<Idx>)> + Clone {
pub(crate) fn into_iter(self) -> impl Iterator<Item=(G, GateId<Idx>)> + Clone {
let ni = self
.non_interactive_gates
.into_iter()
Expand All @@ -686,7 +687,7 @@ impl<G: Clone, Idx: GateIdx> CircuitLayer<G, Idx> {
pub(crate) fn into_sc_iter(
self,
sc_id: CircuitId,
) -> impl Iterator<Item = (G, SubCircuitGate<Idx>)> + Clone {
) -> impl Iterator<Item=(G, SubCircuitGate<Idx>)> + Clone {
self.into_iter()
.map(move |(g, gate_id)| (g, SubCircuitGate::new(sc_id, gate_id)))
}
Expand Down Expand Up @@ -801,8 +802,8 @@ impl<Idx: GateIdx> GateId<Idx> {
}

impl<Idx> From<NodeIndex<Idx>> for GateId<Idx>
where
Idx: GateIdx,
where
Idx: GateIdx,
{
fn from(idx: NodeIndex<Idx>) -> Self {
Self(
Expand All @@ -821,8 +822,8 @@ impl<Idx: GateIdx> From<GateId<Idx>> for NodeIndex<Idx> {
}

impl<Idx> From<u16> for GateId<Idx>
where
Idx: TryFrom<u16>,
where
Idx: TryFrom<u16>,
{
fn from(val: u16) -> Self {
GateId(
Expand All @@ -834,8 +835,8 @@ where
}

impl<Idx> From<u32> for GateId<Idx>
where
Idx: TryFrom<u32>,
where
Idx: TryFrom<u32>,
{
fn from(val: u32) -> Self {
GateId(
Expand All @@ -847,8 +848,8 @@ where
}

impl<Idx> From<usize> for GateId<Idx>
where
Idx: TryFrom<usize>,
where
Idx: TryFrom<usize>,
{
fn from(val: usize) -> Self {
GateId(
Expand Down

0 comments on commit 49a0f11

Please sign in to comment.