Skip to content

Debug trait with meaningful output #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/integer/mat_poly_over_z.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use flint_sys::fmpz_poly_mat::fmpz_poly_mat_struct;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -76,7 +77,12 @@ mod vector;
/// assert!(row_vec.is_row_vector());
/// assert!(col_vec.is_column_vector());
/// ```
#[derive(Debug)]
pub struct MatPolyOverZ {
pub(crate) matrix: fmpz_poly_mat_struct,
}

impl fmt::Debug for MatPolyOverZ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/integer/mat_z.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use flint_sys::fmpz_mat::fmpz_mat_struct;
use std::fmt;

mod arithmetic;
mod basis_reductions;
Expand Down Expand Up @@ -89,7 +90,12 @@ mod vector;
/// assert_eq!(col_vec.norm_eucl_sqrd().unwrap(), Z::from(2));
/// assert_eq!(row_vec.norm_infty().unwrap(), Z::ONE);
/// ```
#[derive(Debug)]
pub struct MatZ {
pub(crate) matrix: fmpz_mat_struct,
}

impl fmt::Debug for MatZ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/integer/poly_over_z.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use flint_sys::fmpz_poly::fmpz_poly_struct;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -58,7 +59,12 @@ mod unsafe_functions;
/// // comparison
/// assert_ne!(poly_1, poly_2);
/// ```
#[derive(Debug)]
pub struct PolyOverZ {
pub(crate) poly: fmpz_poly_struct,
}

impl fmt::Debug for PolyOverZ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/integer/z.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use flint_sys::fmpz::fmpz;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -67,7 +68,12 @@ mod unsafe_functions;
/// );
/// # Ok::<(), qfall_math::error::MathError>(())
/// ```
#[derive(Debug)]
pub struct Z {
pub(crate) value: fmpz,
}

impl fmt::Debug for Z {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
9 changes: 8 additions & 1 deletion src/integer_mod_q/mat_polynomial_ring_zq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::ModulusPolynomialRingZq;
use crate::integer::MatPolyOverZ;
use derive_more::Display;
use serde::{Deserialize, Serialize};
use std::fmt;

mod arithmetic;
mod coefficient_embedding;
Expand Down Expand Up @@ -87,9 +88,15 @@ mod vector;
/// assert!(row_vec.is_row_vector());
/// assert!(col_vec.is_column_vector());
/// ```
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Display, Clone)]
#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone)]
#[display("{matrix} / {modulus}")]
pub struct MatPolynomialRingZq {
pub(crate) matrix: MatPolyOverZ,
pub(crate) modulus: ModulusPolynomialRingZq,
}

impl fmt::Debug for MatPolynomialRingZq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/integer_mod_q/mat_zq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use crate::integer_mod_q::Modulus;
use flint_sys::fmpz_mod_mat::fmpz_mod_mat_struct;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -82,7 +83,6 @@ mod vector;
/// assert!(row_vec.is_row_vector());
/// assert!(col_vec.is_column_vector());
/// ```
#[derive(Debug)]
pub struct MatZq {
pub(crate) matrix: fmpz_mod_mat_struct,

Expand All @@ -94,3 +94,9 @@ pub struct MatZq {
// attribute and `modulus` attribute, if they are both initalized from the same value.
modulus: Modulus,
}

impl fmt::Debug for MatZq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
9 changes: 7 additions & 2 deletions src/integer_mod_q/modulus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use flint_sys::fmpz_mod::fmpz_mod_ctx;
use std::rc::Rc;
use std::{fmt, rc::Rc};

mod cmp;
mod distance;
Expand Down Expand Up @@ -63,7 +63,12 @@ mod unsafe_functions;
/// // comparison
/// assert_eq!(a, clone);
/// ```
#[derive(Debug)]
pub struct Modulus {
pub(crate) modulus: Rc<fmpz_mod_ctx>,
}

impl fmt::Debug for Modulus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
9 changes: 7 additions & 2 deletions src/integer_mod_q/modulus_polynomial_ring_zq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use flint_sys::fq::fq_ctx_struct;
use std::rc::Rc;
use std::{fmt, rc::Rc};

mod cmp;
mod coefficient_embedding;
Expand Down Expand Up @@ -40,7 +40,12 @@ mod unsafe_functions;
/// let poly_mod = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap();
/// let modulus = ModulusPolynomialRingZq::from(poly_mod);
/// ```
#[derive(Debug)]
pub struct ModulusPolynomialRingZq {
modulus: Rc<fq_ctx_struct>,
}

impl fmt::Debug for ModulusPolynomialRingZq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/integer_mod_q/poly_over_zq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use super::modulus::Modulus;
use flint_sys::fmpz_mod_poly::fmpz_mod_poly_struct;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -61,8 +62,13 @@ mod unsafe_functions;
/// // comparison
/// assert_eq!(poly_1, poly_2);
/// ```
#[derive(Debug)]
pub struct PolyOverZq {
pub(crate) poly: fmpz_mod_poly_struct,
pub(crate) modulus: Modulus,
}

impl fmt::Debug for PolyOverZq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
9 changes: 8 additions & 1 deletion src/integer_mod_q/polynomial_ring_zq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::ModulusPolynomialRingZq;
use crate::integer::PolyOverZ;
use derive_more::Display;
use serde::{Deserialize, Serialize};
use std::fmt;

mod arithmetic;
mod coefficient_embedding;
Expand Down Expand Up @@ -67,9 +68,15 @@ mod unsafe_functions;
///
/// # Ok::<(), MathError>(())
/// ```
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Display, Clone)]
#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone)]
#[display("{poly} / {modulus}")]
pub struct PolynomialRingZq {
pub(crate) poly: PolyOverZ,
pub(crate) modulus: ModulusPolynomialRingZq,
}

impl fmt::Debug for PolynomialRingZq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
9 changes: 8 additions & 1 deletion src/integer_mod_q/z_q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use super::Modulus;
use crate::integer::Z;
use serde::{Deserialize, Serialize};
use std::fmt;

mod arithmetic;
pub(crate) mod fmpz_mod_helpers;
Expand Down Expand Up @@ -59,8 +60,14 @@ mod unsafe_functions;
///
/// # Ok::<(), MathError>(())
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Zq {
pub(crate) value: Z,
pub(crate) modulus: Modulus,
}

impl fmt::Debug for Zq {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/rational/mat_q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//! values. The end-user should be unable to obtain a non-reduced value.

use flint_sys::fmpq_mat::fmpq_mat_struct;
use std::fmt;

mod arithmetic;
mod cholesky_decomp;
Expand Down Expand Up @@ -84,7 +85,12 @@ mod vector;
/// assert!(row_vec.is_row_vector());
/// assert!(col_vec.is_column_vector());
/// ```
#[derive(Debug)]
pub struct MatQ {
pub(crate) matrix: fmpq_mat_struct,
}

impl fmt::Debug for MatQ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/rational/poly_over_q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! non-reduced value.

use flint_sys::fmpq_poly::fmpq_poly_struct;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -58,7 +59,12 @@ mod unsafe_functions;
/// // comparison
/// assert_ne!(poly_1, poly_2);
/// ```
#[derive(Debug)]
pub struct PolyOverQ {
pub(crate) poly: fmpq_poly_struct,
}

impl fmt::Debug for PolyOverQ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}
8 changes: 7 additions & 1 deletion src/rational/q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//! values. The end-user should be unable to obtain a non-reduced value.

use flint_sys::fmpq::fmpq;
use std::fmt;

mod arithmetic;
mod cmp;
Expand Down Expand Up @@ -71,7 +72,12 @@ mod unsafe_functions;
/// assert_ne!(a, b);
/// # Ok::<(), qfall_math::error::MathError>(())
/// ```
#[derive(Debug)]
pub struct Q {
pub(crate) value: fmpq,
}

impl fmt::Debug for Q {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}