Skip to content

Commit

Permalink
Add serialize for rational.
Browse files Browse the repository at this point in the history
  • Loading branch information
MxmUrw committed Aug 29, 2023
1 parent bd41119 commit fcdc568
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hmac = { version = "0.12.1", optional = true }
num-bigint = { version = "0.4.3", optional = true, features = ["rand", "serde"] }
num-integer = { version = "0.1.45", optional = true }
num-iter = { version = "0.1.43", optional = true }
num-rational = { version = "0.4.1", optional = true }
num-rational = { version = "0.4.1", optional = true, features = ["serde"] }
num-traits = { version = "0.2.15", optional = true }
rand = { version = "0.8", optional = true }
rand_core = "0.6.4"
Expand Down
3 changes: 2 additions & 1 deletion src/dp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//!
use num_bigint::{BigInt, BigUint, TryFromBigIntError};
use num_rational::{BigRational, Ratio};
use serde::{Serialize, Deserialize};

/// Errors propagated by methods in this module.
#[derive(Debug, thiserror::Error)]
Expand All @@ -38,7 +39,7 @@ pub enum DpError {

/// Positive arbitrary precision rational number to represent DP and noise distribution parameters in
/// protocol messages and manipulate them without rounding errors.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Rational(Ratio<BigUint>);

impl Rational {
Expand Down
8 changes: 8 additions & 0 deletions src/flp/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

//! A collection of [`Type`] implementations.

#[cfg(feature = "experimental")]
use crate::dp::distributions::ZCdpDiscreteGaussian;
use crate::field::{FftFriendlyFieldElement, FieldElementWithIntegerExt};
use crate::flp::gadgets::{BlindPolyEval, Mul, ParallelSumGadget, PolyEval};
Expand All @@ -11,6 +13,7 @@ use std::convert::TryInto;
use std::fmt::{self, Debug};
use std::marker::PhantomData;

#[cfg(feature = "experimental")]
use super::TypeWithNoise;
/// The counter data type. Each measurement is `0` or `1` and the aggregate result is the sum of the measurements (i.e., the total number of `1s`).
#[derive(Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -39,6 +42,7 @@ impl<F: FftFriendlyFieldElement> Default for Count<F> {
}
}

#[cfg(feature = "experimental")]
impl<F: FftFriendlyFieldElement> TypeWithNoise<ZCdpDiscreteGaussian> for Count<F> {}

impl<F: FftFriendlyFieldElement> Type for Count<F> {
Expand Down Expand Up @@ -144,6 +148,7 @@ impl<F: FftFriendlyFieldElement> Sum<F> {
}
}

#[cfg(feature = "experimental")]
impl<F: FftFriendlyFieldElement> TypeWithNoise<ZCdpDiscreteGaussian> for Sum<F> {}

impl<F: FftFriendlyFieldElement> Type for Sum<F> {
Expand Down Expand Up @@ -245,6 +250,7 @@ impl<F: FftFriendlyFieldElement> Average<F> {
}
}

#[cfg(feature = "experimental")]
impl<F: FftFriendlyFieldElement> TypeWithNoise<ZCdpDiscreteGaussian> for Average<F> {}

impl<F: FftFriendlyFieldElement> Type for Average<F> {
Expand Down Expand Up @@ -353,6 +359,7 @@ impl<F: FftFriendlyFieldElement> Histogram<F> {
}
}

#[cfg(feature = "experimental")]
impl<F: FftFriendlyFieldElement> TypeWithNoise<ZCdpDiscreteGaussian> for Histogram<F> {}

impl<F: FftFriendlyFieldElement> Type for Histogram<F> {
Expand Down Expand Up @@ -531,6 +538,7 @@ impl<F: FftFriendlyFieldElement, S> Clone for SumVec<F, S> {
}


#[cfg(feature = "experimental")]
impl<F, S> TypeWithNoise<ZCdpDiscreteGaussian> for SumVec<F, S>
where
F: FftFriendlyFieldElement,
Expand Down

0 comments on commit fcdc568

Please sign in to comment.