From 2afb0dc422109e08c62bc78cfb0273c2bd76a9c5 Mon Sep 17 00:00:00 2001 From: jnsiemer Date: Fri, 1 May 2026 20:39:42 +0100 Subject: [PATCH 1/6] Upgrade to FLINT 3.5, memory bugs remain --- Cargo.toml | 2 +- src/integer.rs | 3 + src/integer/mat_poly_over_z.rs | 16 ++++- src/integer/mat_poly_over_z/get.rs | 19 ++--- src/integer/mat_poly_over_z/ownership.rs | 49 ++++++++----- .../mat_poly_over_z/unsafe_functions.rs | 2 +- src/integer/mat_z.rs | 16 ++++- src/integer/mat_z/arithmetic/mul.rs | 4 +- src/integer/mat_z/arithmetic/sub.rs | 4 +- src/integer/mat_z/get.rs | 21 +++--- src/integer/mat_z/ownership.rs | 22 +++--- src/integer/mat_z/set.rs | 10 +-- src/integer/mat_z/unsafe_functions.rs | 10 ++- src/integer/poly_over_z.rs | 16 ++++- src/integer/poly_over_z/fmpz_poly_helpers.rs | 14 ++-- src/integer/poly_over_z/ownership.rs | 8 +-- src/integer/poly_over_z/unsafe_functions.rs | 7 +- src/integer/z.rs | 11 ++- src/integer/z/arithmetic/add.rs | 5 +- src/integer/z/arithmetic/mul.rs | 5 +- src/integer/z/arithmetic/root.rs | 4 +- src/integer/z/arithmetic/sub.rs | 9 +-- src/integer/z/cmp.rs | 6 +- src/integer/z/default.rs | 12 +--- src/integer/z/fmpz_helpers.rs | 35 +++++----- src/integer/z/from.rs | 15 ++-- src/integer/z/hash.rs | 2 +- src/integer/z/ownership.rs | 19 ++--- src/integer/z/properties.rs | 7 +- src/integer/z/unsafe_functions.rs | 8 +-- .../mat_ntt_polynomial_ring_zq.rs | 17 +---- .../arithmetic/mul.rs | 5 +- src/integer_mod_q/mat_polynomial_ring_zq.rs | 19 +---- .../mat_polynomial_ring_zq/get.rs | 5 +- .../mat_polynomial_ring_zq/reduce.rs | 2 +- .../unsafe_functions.rs | 2 +- src/integer_mod_q/mat_zq.rs | 10 +-- src/integer_mod_q/mat_zq/arithmetic/add.rs | 24 +++++-- src/integer_mod_q/mat_zq/arithmetic/mul.rs | 13 +++- .../mat_zq/arithmetic/mul_scalar.rs | 48 +++++++++++-- src/integer_mod_q/mat_zq/arithmetic/sub.rs | 24 +++++-- src/integer_mod_q/mat_zq/cmp.rs | 11 +-- src/integer_mod_q/mat_zq/concat.rs | 14 +++- src/integer_mod_q/mat_zq/default.rs | 7 +- src/integer_mod_q/mat_zq/from.rs | 7 +- src/integer_mod_q/mat_zq/get.rs | 38 +++++----- src/integer_mod_q/mat_zq/inverse.rs | 8 ++- src/integer_mod_q/mat_zq/ownership.rs | 34 +++++---- src/integer_mod_q/mat_zq/properties.rs | 6 +- src/integer_mod_q/mat_zq/set.rs | 63 +++++++++++------ src/integer_mod_q/mat_zq/tensor.rs | 10 +-- src/integer_mod_q/mat_zq/trace.rs | 6 +- src/integer_mod_q/mat_zq/transpose.rs | 2 +- src/integer_mod_q/mat_zq/unsafe_functions.rs | 37 ++++++---- src/integer_mod_q/mat_zq/vector/norm.rs | 9 ++- src/integer_mod_q/modulus.rs | 37 +++++++++- src/integer_mod_q/modulus/cmp.rs | 10 +-- src/integer_mod_q/modulus/fmpz_helpers.rs | 4 +- src/integer_mod_q/modulus/from.rs | 5 +- src/integer_mod_q/modulus/get.rs | 2 +- src/integer_mod_q/modulus/ownership.rs | 12 ++-- src/integer_mod_q/modulus/properties.rs | 2 +- src/integer_mod_q/modulus/unsafe_functions.rs | 8 +-- .../modulus_polynomial_ring_zq.rs | 13 +--- .../modulus_polynomial_ring_zq/ownership.rs | 2 +- .../ntt_basis_polynomial_ring_zq/inv_ntt.rs | 3 +- .../ntt_basis_polynomial_ring_zq/ntt.rs | 5 +- src/integer_mod_q/ntt_polynomial_ring_zq.rs | 17 +---- src/integer_mod_q/poly_over_zq.rs | 17 ++++- src/integer_mod_q/poly_over_zq/ownership.rs | 39 +++++------ .../poly_over_zq/unsafe_functions.rs | 4 +- src/integer_mod_q/polynomial_ring_zq.rs | 13 +--- .../polynomial_ring_zq/unsafe_functions.rs | 2 +- src/integer_mod_q/z_q.rs | 13 +--- src/integer_mod_q/z_q/arithmetic/add.rs | 4 +- src/integer_mod_q/z_q/arithmetic/mul.rs | 4 +- src/integer_mod_q/z_q/arithmetic/sub.rs | 4 +- src/integer_mod_q/z_q/fmpz_mod_helpers.rs | 22 +++--- src/integer_mod_q/z_q/unsafe_functions.rs | 2 +- src/rational/mat_q.rs | 16 ++++- src/rational/mat_q/cmp.rs | 7 +- src/rational/mat_q/get.rs | 39 +++++------ src/rational/mat_q/ownership.rs | 32 ++++----- src/rational/mat_q/set.rs | 10 +-- src/rational/mat_q/unsafe_functions.rs | 2 +- src/rational/poly_over_q.rs | 17 ++++- src/rational/poly_over_q/ownership.rs | 70 ++++++++----------- src/rational/poly_over_q/unsafe_functions.rs | 2 +- src/rational/q.rs | 15 +++- src/rational/q/cmp.rs | 10 +-- src/rational/q/default.rs | 62 +++++++--------- src/rational/q/from.rs | 5 +- src/rational/q/ownership.rs | 20 +++--- src/rational/q/unsafe_functions.rs | 12 ++-- src/traits.rs | 2 +- src/utils/factorization.rs | 26 ++++++- 96 files changed, 765 insertions(+), 608 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9271fe2c..15f088bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ autobenches = false [dependencies] criterion = { version = "0.8", features = ["html_reports"] } -flint-sys = "0.7" +flint-sys = "0.9.0" libc = "0" paste = "1" rand = "0.10" diff --git a/src/integer.rs b/src/integer.rs index 56548db7..6d578ef9 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -26,3 +26,6 @@ pub use poly_over_z::PolyOverZ; pub(crate) use poly_over_z::fmpz_poly_helpers; pub use z::Z; pub(crate) use z::fmpz_helpers; + +pub(crate) use mat_z::debug_fmpz_mat_struct; +pub(crate) use z::debug_fmpz; diff --git a/src/integer/mat_poly_over_z.rs b/src/integer/mat_poly_over_z.rs index 9b75c7be..3b9a4846 100644 --- a/src/integer/mat_poly_over_z.rs +++ b/src/integer/mat_poly_over_z.rs @@ -10,7 +10,7 @@ //! This implementation uses the [FLINT](https://flintlib.org/) library. use crate::utils::parse::partial_string; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_struct; +use flint_sys::fmpz_types::fmpz_poly_mat_struct; use std::fmt; mod arithmetic; @@ -88,10 +88,20 @@ impl fmt::Debug for MatPolyOverZ { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "MatPolyOverZ: {{matrix: {}, storage: {:?}}}", + "MatPolyOverZ: {{matrix: {}, storage: {{ matrix: {}}}}}", // printing the entire matrix is not meaningful for large matrices partial_string(self, 3, 3), - self.matrix + debug_fmpz_poly_mat_struct(&self.matrix) ) } } + +pub(crate) fn debug_fmpz_poly_mat_struct(value: &fmpz_poly_mat_struct) -> String { + format!( + "fmpz_poly_mat_struct {{ entries: {:#x}, r: {}, c: {}, stride: {} }}", + value.entries.addr(), + value.r, + value.c, + value.stride + ) +} diff --git a/src/integer/mat_poly_over_z/get.rs b/src/integer/mat_poly_over_z/get.rs index 12999ca4..e9a81f62 100644 --- a/src/integer/mat_poly_over_z/get.rs +++ b/src/integer/mat_poly_over_z/get.rs @@ -14,11 +14,12 @@ use crate::{ traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}, }; use flint_sys::{ - fmpz_poly::{fmpz_poly_set, fmpz_poly_struct}, + fmpz_poly::fmpz_poly_set, fmpz_poly_mat::{ fmpz_poly_mat_entry, fmpz_poly_mat_init_set, fmpz_poly_mat_window_clear, fmpz_poly_mat_window_init, }, + fmpz_types::fmpz_poly_struct, }; use std::mem::MaybeUninit; @@ -178,7 +179,7 @@ impl MatPolyOverZ { for row in 0..self.get_num_rows() { for col in 0..self.get_num_columns() { // efficiently get entry without cloning the entry itself - let entry = unsafe { *fmpz_poly_mat_entry(&self.matrix, row, col) }; + let entry = unsafe { std::ptr::read(fmpz_poly_mat_entry(&self.matrix, row, col)) }; entries.push(entry); } } @@ -592,16 +593,16 @@ mod test_collect_entries { let entries_2 = mat_2.collect_entries(); assert_eq!(entries_1.len(), 6); - assert_eq!(unsafe { *entries_1[0].coeffs }.0, 1); - assert!(unsafe { *entries_1[2].coeffs }.0 >= 2_i64.pow(62)); - assert!(unsafe { *entries_1[3].coeffs }.0 >= 2_i64.pow(62)); - assert_eq!(unsafe { *entries_1[4].coeffs }.0, -3); + assert_eq!(unsafe { *entries_1[0].coeffs }, 1); + assert!(unsafe { *entries_1[2].coeffs } >= 2_i64.pow(62)); + assert!(unsafe { *entries_1[3].coeffs } >= 2_i64.pow(62)); + assert_eq!(unsafe { *entries_1[4].coeffs }, -3); assert_eq!(entries_2.len(), 2); - assert_eq!(unsafe { *entries_2[0].coeffs.offset(0) }.0, -1); + assert_eq!(unsafe { *entries_2[0].coeffs.offset(0) }, -1); assert_eq!(entries_2[0].length, 1); - assert_eq!(unsafe { *entries_2[1].coeffs.offset(0) }.0, 1); - assert_eq!(unsafe { *entries_2[1].coeffs.offset(1) }.0, 2); + assert_eq!(unsafe { *entries_2[1].coeffs.offset(0) }, 1); + assert_eq!(unsafe { *entries_2[1].coeffs.offset(1) }, 2); assert_eq!(entries_2[1].length, 2); } } diff --git a/src/integer/mat_poly_over_z/ownership.rs b/src/integer/mat_poly_over_z/ownership.rs index 1e962462..c33cae20 100644 --- a/src/integer/mat_poly_over_z/ownership.rs +++ b/src/integer/mat_poly_over_z/ownership.rs @@ -30,7 +30,7 @@ impl Clone for MatPolyOverZ { // we can unwrap since we know, that the number of rows and columns is positive and fits into an [`i64`] let mut clone = MatPolyOverZ::new(self.get_num_rows(), self.get_num_columns()); - unsafe { fmpz_poly_mat_set(&mut clone.matrix, &mut self.matrix.to_owned()) } + unsafe { fmpz_poly_mat_set(&mut clone.matrix, &self.matrix) } clone } @@ -78,20 +78,26 @@ mod test_clone { // an i64, both should be a pointer and their values should differ unsafe { assert_ne!( - (*(*poly_1.matrix.entries).coeffs.offset(0)).0, - (*(*poly_2.matrix.entries).coeffs.offset(0)).0 + (*(*poly_1.matrix.entries).coeffs.offset(0)), + (*(*poly_2.matrix.entries).coeffs.offset(0)) ); } unsafe { assert_ne!( - (*(*poly_1.matrix.entries).coeffs.offset(1)).0, - (*(*poly_2.matrix.entries).coeffs.offset(1)).0 + (*(*poly_1.matrix.entries).coeffs.offset(1)), + (*(*poly_2.matrix.entries).coeffs.offset(1)) ); } // check if length of polynomial is correctly cloned - assert_eq!(unsafe { *poly_1.matrix.entries.offset(0) }.length, 2); - assert_eq!(unsafe { *poly_2.matrix.entries.offset(0) }.length, 2); + assert_eq!( + unsafe { std::ptr::read(poly_1.matrix.entries.offset(0)) }.length, + 2 + ); + assert_eq!( + unsafe { std::ptr::read(poly_2.matrix.entries.offset(0)) }.length, + 2 + ); assert_eq!(poly_1, poly_2); } @@ -110,20 +116,26 @@ mod test_clone { // both should be stored directly on stack and their values should be equal unsafe { assert_eq!( - (*(*poly_1.matrix.entries).coeffs.offset(0)).0, - (*(*poly_2.matrix.entries).coeffs.offset(0)).0 + (*(*poly_1.matrix.entries).coeffs.offset(0)), + (*(*poly_2.matrix.entries).coeffs.offset(0)) ); } unsafe { assert_eq!( - (*(*poly_1.matrix.entries).coeffs.offset(1)).0, - (*(*poly_2.matrix.entries).coeffs.offset(1)).0 + (*(*poly_1.matrix.entries).coeffs.offset(1)), + (*(*poly_2.matrix.entries).coeffs.offset(1)) ); } // check if length of polynomial is correctly cloned - assert_eq!(unsafe { *poly_1.matrix.entries.offset(0) }.length, 2); - assert_eq!(unsafe { *poly_2.matrix.entries.offset(0) }.length, 2); + assert_eq!( + unsafe { std::ptr::read(poly_1.matrix.entries.offset(0)) }.length, + 2 + ); + assert_eq!( + unsafe { std::ptr::read(poly_2.matrix.entries.offset(0)) }.length, + 2 + ); assert_eq!(poly_1, poly_2); } @@ -151,7 +163,7 @@ mod test_drop { /// Creates and drops a [`MatPolyOverZ`], and returns the storage points in memory fn create_and_drop_poly_over_z() -> i64 { let a = MatPolyOverZ::from_str(&format!("[[1 {}]]", u64::MAX)).unwrap(); - unsafe { *(*a.matrix.entries).coeffs.offset(0) }.0 + unsafe { *(*a.matrix.entries).coeffs.offset(0) } } /// Check whether freed memory is reused afterwards @@ -166,13 +178,12 @@ mod test_drop { assert!(set.capacity() < 5); let a = MatPolyOverZ::from_str(&format!("[[2 {} {}]]", u64::MAX - 1, u64::MAX)).unwrap(); - let storage_point = unsafe { *(*a.matrix.entries).coeffs.offset(0) }.0; + let storage_point = unsafe { *(*a.matrix.entries).coeffs.offset(0) }; // memory slots differ due to previously created large integer let d = MatPolyOverZ::from_str(&format!("[[2 {} {}]]", u64::MAX - 1, u64::MAX)).unwrap(); - assert_ne!( - storage_point, - unsafe { *(*d.matrix.entries).coeffs.offset(0) }.0 - ); + assert_ne!(storage_point, unsafe { + *(*d.matrix.entries).coeffs.offset(0) + }); } } diff --git a/src/integer/mat_poly_over_z/unsafe_functions.rs b/src/integer/mat_poly_over_z/unsafe_functions.rs index 04288aff..272065ab 100644 --- a/src/integer/mat_poly_over_z/unsafe_functions.rs +++ b/src/integer/mat_poly_over_z/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::MatPolyOverZ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_clear, fmpz_poly_mat_struct}; +use flint_sys::{fmpz_poly_mat::fmpz_poly_mat_clear, fmpz_types::fmpz_poly_mat_struct}; unsafe_getter!(MatPolyOverZ, matrix, fmpz_poly_mat_struct); unsafe_setter!( diff --git a/src/integer/mat_z.rs b/src/integer/mat_z.rs index e6017099..e836d753 100644 --- a/src/integer/mat_z.rs +++ b/src/integer/mat_z.rs @@ -10,7 +10,7 @@ //! This implementation uses the [FLINT](https://flintlib.org/) library. use crate::utils::parse::partial_string; -use flint_sys::fmpz_mat::fmpz_mat_struct; +use flint_sys::fmpz_types::fmpz_mat_struct; use std::fmt; mod arithmetic; @@ -99,10 +99,20 @@ impl fmt::Debug for MatZ { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "MatZ: {{matrix: {}, storage: {:?}}}", + "MatZ: {{matrix: {}, storage: {{ matrix: {}}}}}", // printing the entire matrix is not meaningful for large matrices partial_string(self, 3, 3), - self.matrix + debug_fmpz_mat_struct(&self.matrix) ) } } + +pub(crate) fn debug_fmpz_mat_struct(value: &fmpz_mat_struct) -> String { + format!( + "fmpz_mat_struct {{ entries: {:#x}, r: {}, c: {}, stride: {} }}", + value.entries.addr(), + value.r, + value.c, + value.stride + ) +} diff --git a/src/integer/mat_z/arithmetic/mul.rs b/src/integer/mat_z/arithmetic/mul.rs index 5ea17c42..ae30430b 100644 --- a/src/integer/mat_z/arithmetic/mul.rs +++ b/src/integer/mat_z/arithmetic/mul.rs @@ -97,8 +97,8 @@ impl Mul<&MatZq> for &MatZ { other.get_mod(), ); unsafe { - fmpz_mat_mul(&mut new.matrix.mat[0], &self.matrix, &other.matrix.mat[0]); - _fmpz_mod_mat_reduce(&mut new.matrix) + fmpz_mat_mul(&mut new.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut new.matrix, other.modulus.get_fmpz_mod_ctx_struct()) } new } diff --git a/src/integer/mat_z/arithmetic/sub.rs b/src/integer/mat_z/arithmetic/sub.rs index ed34e04c..95983186 100644 --- a/src/integer/mat_z/arithmetic/sub.rs +++ b/src/integer/mat_z/arithmetic/sub.rs @@ -135,8 +135,8 @@ impl Sub<&MatZq> for &MatZ { let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), other.get_mod()); unsafe { - fmpz_mat_sub(&mut out.matrix.mat[0], &self.matrix, &other.matrix.mat[0]); - _fmpz_mod_mat_reduce(&mut out.matrix); + fmpz_mat_sub(&mut out.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut out.matrix, other.modulus.get_fmpz_mod_ctx_struct()); } out } diff --git a/src/integer/mat_z/get.rs b/src/integer/mat_z/get.rs index e00112e7..85c00c4c 100644 --- a/src/integer/mat_z/get.rs +++ b/src/integer/mat_z/get.rs @@ -14,7 +14,8 @@ use crate::{ traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}, }; use flint_sys::{ - fmpz::{fmpz, fmpz_init_set}, + flint::fmpz, + fmpz::fmpz_init_set, fmpz_mat::{fmpz_mat_entry, fmpz_mat_init_set, fmpz_mat_window_clear, fmpz_mat_window_init}, }; use std::mem::MaybeUninit; @@ -78,7 +79,7 @@ impl MatrixGetEntry for MatZ { /// assert_eq!(unsafe { matrix.get_entry_unchecked(2, 1) }, Z::from(8)); /// ``` unsafe fn get_entry_unchecked(&self, row: i64, column: i64) -> Z { - let mut copy = fmpz(0); + let mut copy: fmpz = 0; let entry = unsafe { fmpz_mat_entry(&self.matrix, row, column) }; unsafe { fmpz_init_set(&mut copy, entry) }; @@ -685,15 +686,15 @@ mod test_collect_entries { let entries_2 = mat_2.collect_entries(); assert_eq!(entries_1.len(), 6); - assert_eq!(entries_1[0].0, 1); - assert_eq!(entries_1[1].0, 2); - assert!(entries_1[2].0 >= 2_i64.pow(62)); - assert!(entries_1[3].0 >= 2_i64.pow(62)); - assert_eq!(entries_1[4].0, 3); - assert_eq!(entries_1[5].0, 4); + assert_eq!(entries_1[0], 1); + assert_eq!(entries_1[1], 2); + assert!(entries_1[2] >= 2_i64.pow(62)); + assert!(entries_1[3] >= 2_i64.pow(62)); + assert_eq!(entries_1[4], 3); + assert_eq!(entries_1[5], 4); assert_eq!(entries_2.len(), 2); - assert_eq!(entries_2[0].0, -1); - assert_eq!(entries_2[1].0, 2); + assert_eq!(entries_2[0], -1); + assert_eq!(entries_2[1], 2); } } diff --git a/src/integer/mat_z/ownership.rs b/src/integer/mat_z/ownership.rs index 8f49ccc2..98a7400d 100644 --- a/src/integer/mat_z/ownership.rs +++ b/src/integer/mat_z/ownership.rs @@ -105,20 +105,20 @@ mod test_clone { a = b.clone(); assert_ne!( - a.get_entry(0, 0).unwrap().value.0, - b.get_entry(0, 0).unwrap().value.0 + a.get_entry(0, 0).unwrap().value, + b.get_entry(0, 0).unwrap().value ); assert_ne!( - a.get_entry(0, 1).unwrap().value.0, - b.get_entry(0, 1).unwrap().value.0 + a.get_entry(0, 1).unwrap().value, + b.get_entry(0, 1).unwrap().value ); assert_ne!( - a.get_entry(1, 0).unwrap().value.0, - b.get_entry(1, 0).unwrap().value.0 + a.get_entry(1, 0).unwrap().value, + b.get_entry(1, 0).unwrap().value ); assert_ne!( - a.get_entry(1, 1).unwrap().value.0, - b.get_entry(1, 1).unwrap().value.0 + a.get_entry(1, 1).unwrap().value, + b.get_entry(1, 1).unwrap().value ); } } @@ -138,9 +138,9 @@ mod test_drop { let str_1 = "[[36893488147419103232, 36893488147419103232]]"; let a = MatZ::from_str(str_1).unwrap(); - let storage_mat = unsafe { (*a.matrix.entries).0 }; - let storage_0 = a.get_entry(0, 0).unwrap().value.0; - let storage_1 = a.get_entry(0, 1).unwrap().value.0; + let storage_mat = unsafe { (*a.matrix.entries) }; + let storage_0 = a.get_entry(0, 0).unwrap().value; + let storage_1 = a.get_entry(0, 1).unwrap().value; (storage_mat, storage_0, storage_1) } diff --git a/src/integer/mat_z/set.rs b/src/integer/mat_z/set.rs index cbfaf703..a2c25f3a 100644 --- a/src/integer/mat_z/set.rs +++ b/src/integer/mat_z/set.rs @@ -22,11 +22,7 @@ use flint_sys::{ fmpz_mat_swap_cols, fmpz_mat_swap_rows, fmpz_mat_window_clear, fmpz_mat_window_init, }, }; -use std::{ - fmt::Display, - mem::MaybeUninit, - ptr::{null, null_mut}, -}; +use std::{fmt::Display, mem::MaybeUninit, ptr::null_mut}; impl> MatrixSetEntry for MatZ { /// Sets the value of a specific matrix entry according to the provided value @@ -237,7 +233,7 @@ impl MatrixSwaps for MatZ { }, )); } - unsafe { fmpz_mat_swap_cols(&mut self.matrix, null(), col_0, col_1) } + unsafe { fmpz_mat_swap_cols(&mut self.matrix, null_mut(), col_0, col_1) } Ok(()) } @@ -283,7 +279,7 @@ impl MatrixSwaps for MatZ { }, )); } - unsafe { fmpz_mat_swap_rows(&mut self.matrix, null(), row_0, row_1) } + unsafe { fmpz_mat_swap_rows(&mut self.matrix, null_mut(), row_0, row_1) } Ok(()) } } diff --git a/src/integer/mat_z/unsafe_functions.rs b/src/integer/mat_z/unsafe_functions.rs index 5c3c7b26..038f51c0 100644 --- a/src/integer/mat_z/unsafe_functions.rs +++ b/src/integer/mat_z/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::MatZ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::fmpz_mat::{fmpz_mat_clear, fmpz_mat_struct}; +use flint_sys::{fmpz_mat::fmpz_mat_clear, fmpz_types::fmpz_mat_struct}; unsafe_getter!(MatZ, matrix, fmpz_mat_struct); unsafe_setter!(MatZ, matrix, fmpz_mat_struct, fmpz_mat_clear); @@ -20,10 +20,7 @@ unsafe_setter!(MatZ, matrix, fmpz_mat_struct, fmpz_mat_clear); mod test_get_fmpz_mat_struct { use super::MatZ; use crate::{integer::Z, traits::MatrixGetEntry}; - use flint_sys::{ - fmpz::{fmpz, fmpz_set}, - fmpz_mat::fmpz_mat_entry, - }; + use flint_sys::{flint::fmpz, fmpz::fmpz_set, fmpz_mat::fmpz_mat_entry}; use std::str::FromStr; /// Checks availability of the getter for [`MatZ::matrix`] @@ -34,10 +31,11 @@ mod test_get_fmpz_mat_struct { let mut mat = MatZ::from_str("[[1]]").unwrap(); let mut fmpz_mat = unsafe { mat.get_fmpz_mat_struct() }; + let value: fmpz = 2; unsafe { let entry = fmpz_mat_entry(fmpz_mat, 0, 0); - fmpz_set(entry, &fmpz(2)) + fmpz_set(entry, &value) }; assert_eq!(Z::from(2), mat.get_entry(0, 0).unwrap()); diff --git a/src/integer/poly_over_z.rs b/src/integer/poly_over_z.rs index 3bdc9536..e30cc073 100644 --- a/src/integer/poly_over_z.rs +++ b/src/integer/poly_over_z.rs @@ -10,7 +10,7 @@ //! [`Z`](crate::integer::Z) //! This implementation uses the [FLINT](https://flintlib.org/) library. -use flint_sys::fmpz_poly::fmpz_poly_struct; +use flint_sys::fmpz_types::fmpz_poly_struct; use std::fmt; mod arithmetic; @@ -67,8 +67,18 @@ impl fmt::Debug for PolyOverZ { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "PolyOverZ {{poly: {}, storage: {{poly: {:?}}}}}", - self, self.poly + "PolyOverZ {{ poly: {}, storage: {{ poly: {}}}}}", + self, + debug_fmpz_poly_struct(&self.poly) ) } } + +pub(crate) fn debug_fmpz_poly_struct(value: &fmpz_poly_struct) -> String { + format!( + "fmpz_poly_struct {{ coeffs: {:#x}, alloc: {}, length: {} }}", + value.coeffs.addr(), + value.alloc, + value.length + ) +} diff --git a/src/integer/poly_over_z/fmpz_poly_helpers.rs b/src/integer/poly_over_z/fmpz_poly_helpers.rs index 35fa4dac..91bbab06 100644 --- a/src/integer/poly_over_z/fmpz_poly_helpers.rs +++ b/src/integer/poly_over_z/fmpz_poly_helpers.rs @@ -10,10 +10,12 @@ use super::PolyOverZ; use flint_sys::{ - fmpz::{fmpz, fmpz_is_one, fmpz_is_zero, fmpz_submul, fmpz_zero}, - fmpz_mod::{fmpz_mod_ctx_struct, fmpz_mod_set_fmpz}, - fmpz_mod_poly::fmpz_mod_poly_struct, - fmpz_poly::{_fmpz_poly_normalise, fmpz_poly_struct}, + flint::fmpz, + fmpz::{fmpz_is_one, fmpz_is_zero, fmpz_submul, fmpz_zero}, + fmpz_mod::fmpz_mod_set_fmpz, + fmpz_mod_types::{fmpz_mod_ctx_struct, fmpz_mod_poly_struct}, + fmpz_poly::_fmpz_poly_normalise, + fmpz_types::fmpz_poly_struct, }; use std::cmp::min; @@ -266,7 +268,7 @@ mod test_reduce_fmpz_poly_by_fmpz_poly { let mut poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap(); let entry = unsafe { fmpz_poly_mat_entry(&poly_mat.matrix, 0, 0) }; - if (unsafe { *entry }).length > 0 { + if (unsafe { std::ptr::read(entry) }).length > 0 { unsafe { reduce_fmpz_poly_by_fmpz_poly_sparse( (*entry).coeffs, @@ -304,7 +306,7 @@ mod test_reduce_fmpz_poly_by_fmpz_mod_poly { let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus)); let entry = unsafe { fmpz_poly_mat_entry(&poly_ring_mat.matrix.matrix, 0, 0) }; - if (unsafe { *entry }).length > 0 { + if (unsafe { std::ptr::read(entry) }).length > 0 { unsafe { reduce_fmpz_poly_by_fmpz_poly_sparse( (*entry).coeffs, diff --git a/src/integer/poly_over_z/ownership.rs b/src/integer/poly_over_z/ownership.rs index 956931b6..8dbdbf62 100644 --- a/src/integer/poly_over_z/ownership.rs +++ b/src/integer/poly_over_z/ownership.rs @@ -79,7 +79,7 @@ mod test_clone { // tests where the first coefficient is stored. Since both are larger than // an i64, both should be a pointer and their values should differ unsafe { - assert_ne!((*poly_1.poly.coeffs).0, (*poly_2.poly.coeffs).0); + assert_ne!((*poly_1.poly.coeffs), (*poly_2.poly.coeffs)); } assert_eq!(poly_1.to_string(), poly_2.to_string()); } @@ -122,7 +122,7 @@ mod test_drop { /// Creates and drops a [`PolyOverZ`], and returns the storage points in memory fn create_and_drop_poly_over_z() -> i64 { let a = PolyOverZ::from_str("2 36893488147419103232 36893488147419103233").unwrap(); - unsafe { *a.poly.coeffs }.0 + unsafe { *a.poly.coeffs } } /// Check whether freed memory is reused afterwards @@ -137,10 +137,10 @@ mod test_drop { assert!(set.len() < 5); let a = PolyOverZ::from_str("2 36893488147419103232 36893488147419103233").unwrap(); - let storage_point = unsafe { *a.poly.coeffs }.0; + let storage_point = unsafe { *a.poly.coeffs }; // memory slots differ due to previously created large integer let d = PolyOverZ::from_str("2 36893488147419103232 36893488147419103233").unwrap(); - assert_ne!(storage_point, unsafe { *d.poly.coeffs }.0); + assert_ne!(storage_point, unsafe { *d.poly.coeffs }); } } diff --git a/src/integer/poly_over_z/unsafe_functions.rs b/src/integer/poly_over_z/unsafe_functions.rs index 8c3bf579..71676cc1 100644 --- a/src/integer/poly_over_z/unsafe_functions.rs +++ b/src/integer/poly_over_z/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::PolyOverZ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::fmpz_poly::{fmpz_poly_clear, fmpz_poly_struct}; +use flint_sys::{fmpz_poly::fmpz_poly_clear, fmpz_types::fmpz_poly_struct}; unsafe_getter!(PolyOverZ, poly, fmpz_poly_struct); unsafe_setter!(PolyOverZ, poly, fmpz_poly_struct, fmpz_poly_clear); @@ -19,7 +19,7 @@ unsafe_setter!(PolyOverZ, poly, fmpz_poly_struct, fmpz_poly_clear); #[cfg(test)] mod test_get_fmpz_poly_struct { use super::PolyOverZ; - use flint_sys::{fmpz::fmpz, fmpz_poly::fmpz_poly_set_fmpz}; + use flint_sys::{flint::fmpz, fmpz_poly::fmpz_poly_set_fmpz}; /// Checks availability of the getter for [`PolyOverZ::poly`] /// and its ability to be modified. @@ -29,8 +29,9 @@ mod test_get_fmpz_poly_struct { let mut poly = PolyOverZ::from(1); let mut fmpz_poly = unsafe { poly.get_fmpz_poly_struct() }; + let value: fmpz = 2; - unsafe { fmpz_poly_set_fmpz(fmpz_poly, &fmpz(2)) }; + unsafe { fmpz_poly_set_fmpz(fmpz_poly, &value) }; assert_eq!(PolyOverZ::from(2), poly); } diff --git a/src/integer/z.rs b/src/integer/z.rs index e306bd12..9b287c7b 100644 --- a/src/integer/z.rs +++ b/src/integer/z.rs @@ -9,7 +9,7 @@ //! `Z` is a type for integers with arbitrary length. //! This implementation uses the [FLINT](https://flintlib.org/) library. -use flint_sys::fmpz::fmpz; +use flint_sys::flint::fmpz; use std::fmt; mod arithmetic; @@ -76,8 +76,13 @@ impl fmt::Debug for Z { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "Z {{value: {}, storage: {{value: {:?}}}}}", - self, self.value + "Z {{value: {}, storage: {{ value: {}}}}}", + self, + debug_fmpz(&self.value) ) } } + +pub(crate) fn debug_fmpz(value: &fmpz) -> String { + format!("fmpz({})", value) +} diff --git a/src/integer/z/arithmetic/add.rs b/src/integer/z/arithmetic/add.rs index b2d7bca4..5f5cbae5 100644 --- a/src/integer/z/arithmetic/add.rs +++ b/src/integer/z/arithmetic/add.rs @@ -20,8 +20,9 @@ use crate::{ rational::Q, }; use flint_sys::{ + flint::fmpz, fmpq::fmpq_add_fmpz, - fmpz::{fmpz, fmpz_add, fmpz_add_si, fmpz_add_ui}, + fmpz::{fmpz_add, fmpz_add_si, fmpz_add_ui}, fmpz_mod::fmpz_mod_add_fmpz, }; use std::ops::{Add, AddAssign}; @@ -167,7 +168,7 @@ impl Add<&Zq> for &Z { /// let f: Zq = Z::from(42) + &e; /// ``` fn add(self, other: &Zq) -> Self::Output { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_mod_add_fmpz( &mut out, diff --git a/src/integer/z/arithmetic/mul.rs b/src/integer/z/arithmetic/mul.rs index 1a507651..0b208add 100644 --- a/src/integer/z/arithmetic/mul.rs +++ b/src/integer/z/arithmetic/mul.rs @@ -19,8 +19,9 @@ use crate::{ rational::Q, }; use flint_sys::{ + flint::fmpz, fmpq::fmpq_mul_fmpz, - fmpz::{fmpz, fmpz_mul, fmpz_mul_si, fmpz_mul_ui}, + fmpz::{fmpz_mul, fmpz_mul_si, fmpz_mul_ui}, fmpz_mod::fmpz_mod_mul_fmpz, }; use std::ops::{Mul, MulAssign}; @@ -166,7 +167,7 @@ impl Mul<&Zq> for &Z { /// let f: Zq = Z::from(42) * &e; /// ``` fn mul(self, other: &Zq) -> Self::Output { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_mod_mul_fmpz( &mut out, diff --git a/src/integer/z/arithmetic/root.rs b/src/integer/z/arithmetic/root.rs index 479d6cb1..373ecd92 100644 --- a/src/integer/z/arithmetic/root.rs +++ b/src/integer/z/arithmetic/root.rs @@ -74,13 +74,13 @@ impl Z { } let mut integer_result = Q::default(); - let remainder = Q::default(); + let mut remainder = Q::default(); unsafe { // self = integer_result^2 + remainder fmpz_sqrtrem( &mut integer_result.value.num, - &remainder.value.num, + &mut remainder.value.num, &self.value, ); } diff --git a/src/integer/z/arithmetic/sub.rs b/src/integer/z/arithmetic/sub.rs index 3e76c64c..0925ca1b 100644 --- a/src/integer/z/arithmetic/sub.rs +++ b/src/integer/z/arithmetic/sub.rs @@ -19,8 +19,9 @@ use crate::{ rational::Q, }; use flint_sys::{ - fmpq::{fmpq, fmpq_set_fmpz_frac, fmpq_sub}, - fmpz::{fmpz, fmpz_sub, fmpz_sub_si, fmpz_sub_ui}, + flint::{fmpq, fmpz}, + fmpq::{fmpq_set_fmpz_frac, fmpq_sub}, + fmpz::{fmpz_sub, fmpz_sub_si, fmpz_sub_ui}, fmpz_mod::fmpz_mod_sub_fmpz, }; use std::ops::{Sub, SubAssign}; @@ -131,7 +132,7 @@ impl Sub<&Q> for &Z { fn sub(self, other: &Q) -> Self::Output { let mut out = Q::default(); let mut fmpq_1 = fmpq::default(); - unsafe { fmpq_set_fmpz_frac(&mut fmpq_1, &self.value, &fmpz(1)) } + unsafe { fmpq_set_fmpz_frac(&mut fmpq_1, &self.value, &1) } unsafe { fmpq_sub(&mut out.value, &fmpq_1, &other.value); } @@ -168,7 +169,7 @@ impl Sub<&Zq> for &Z { /// let f: Zq = Z::from(42) - &e; /// ``` fn sub(self, other: &Zq) -> Self::Output { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_mod_sub_fmpz( &mut out, diff --git a/src/integer/z/cmp.rs b/src/integer/z/cmp.rs index 19cf4352..458689d0 100644 --- a/src/integer/z/cmp.rs +++ b/src/integer/z/cmp.rs @@ -11,7 +11,7 @@ use super::Z; use crate::{integer_mod_q::Modulus, macros::for_others::implement_for_others}; -use flint_sys::fmpz::{fmpz, fmpz_cmp, fmpz_equal}; +use flint_sys::fmpz::{fmpz_cmp, fmpz_equal}; use std::cmp::Ordering; impl PartialEq for Z { @@ -47,7 +47,7 @@ impl PartialEq for Z { // This is not guaranteed by the [`PartialEq`] trait. impl Eq for Z {} -implement_for_others!(Z, Z, PartialEq for fmpz i8 i16 i32 i64 u8 u16 u32 u64); +implement_for_others!(Z, Z, PartialEq for i8 i16 i32 i64 u8 u16 u32 u64); impl PartialOrd for Z { /// Compares two [`Z`] values. Used by the `<`, `<=`, `>`, and `>=` operators. @@ -141,7 +141,7 @@ impl PartialOrd for Z { } } -implement_for_others!(Z, Z, PartialOrd for fmpz i8 i16 i32 i64 u8 u16 u32 u64); +implement_for_others!(Z, Z, PartialOrd for i8 i16 i32 i64 u8 u16 u32 u64); /// Test that the [`PartialEq`] trait is correctly implemented. #[cfg(test)] diff --git a/src/integer/z/default.rs b/src/integer/z/default.rs index ea0da778..26169a06 100644 --- a/src/integer/z/default.rs +++ b/src/integer/z/default.rs @@ -34,9 +34,7 @@ impl Z { /// /// let a: Z = Z::ONE; /// ``` - pub const ONE: Z = Z { - value: flint_sys::fmpz::fmpz(1), - }; + pub const ONE: Z = Z { value: 1 }; /// Returns an instantiation of [`Z`] with value `0`. /// @@ -46,9 +44,7 @@ impl Z { /// /// let a: Z = Z::ZERO; /// ``` - pub const ZERO: Z = Z { - value: flint_sys::fmpz::fmpz(0), - }; + pub const ZERO: Z = Z { value: 0 }; /// Returns an instantiation of [`Z`] with value `-1`. /// @@ -58,9 +54,7 @@ impl Z { /// /// let a: Z = Z::MINUS_ONE; /// ``` - pub const MINUS_ONE: Z = Z { - value: flint_sys::fmpz::fmpz(-1), - }; + pub const MINUS_ONE: Z = Z { value: -1 }; } #[cfg(test)] diff --git a/src/integer/z/fmpz_helpers.rs b/src/integer/z/fmpz_helpers.rs index bd193cd7..1b294f86 100644 --- a/src/integer/z/fmpz_helpers.rs +++ b/src/integer/z/fmpz_helpers.rs @@ -10,9 +10,9 @@ use super::Z; use crate::traits::AsInteger; +use flint_sys::flint::fmpz; use flint_sys::fmpz::{ - fmpz, fmpz_abs, fmpz_cmpabs, fmpz_init_set, fmpz_init_set_si, fmpz_init_set_ui, fmpz_sub, - fmpz_swap, + fmpz_abs, fmpz_cmpabs, fmpz_init_set, fmpz_init_set_si, fmpz_init_set_ui, fmpz_sub, fmpz_swap, }; /// Efficiently finds maximum absolute value and returns @@ -37,7 +37,7 @@ use flint_sys::fmpz::{ pub(crate) fn find_max_abs(fmpz_vector: &Vec) -> Z { // find maximum of absolute fmpz entries // It's not necessary to clear `fmpz(0)` since it's small - let mut max = &fmpz(0); + let mut max: &fmpz = &0; for entry in fmpz_vector { if unsafe { fmpz_cmpabs(max, entry) } < 0 { max = entry; @@ -88,7 +88,7 @@ unsafe impl AsInteger for u64 { unsafe impl AsInteger for &u64 { /// Documentation at [`AsInteger::into_fmpz`] unsafe fn into_fmpz(self) -> fmpz { - let mut ret_value = fmpz(0); + let mut ret_value: fmpz = 0; unsafe { fmpz_init_set_ui(&mut ret_value, *self) }; ret_value } @@ -110,7 +110,7 @@ macro_rules! implement_as_integer_over_i64 { /// Documentation at [`AsInteger::into_fmpz`] unsafe impl AsInteger for &$type { unsafe fn into_fmpz(self) -> fmpz { - let mut ret_value = fmpz(0); + let mut ret_value: fmpz = 0; unsafe { fmpz_init_set_si(&mut ret_value, *self as i64) }; ret_value } @@ -119,12 +119,12 @@ macro_rules! implement_as_integer_over_i64 { }; } -implement_as_integer_over_i64!(i8 u8 i16 u16 i32 u32 i64); +implement_as_integer_over_i64!(i8 u8 i16 u16 i32 u32); unsafe impl AsInteger for Z { /// Documentation at [`AsInteger::into_fmpz`] unsafe fn into_fmpz(mut self) -> fmpz { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_swap(&mut out, &mut self.value) }; out } @@ -138,7 +138,7 @@ unsafe impl AsInteger for Z { unsafe impl AsInteger for &Z { /// Documentation at [`AsInteger::into_fmpz`] unsafe fn into_fmpz(self) -> fmpz { - let mut value = fmpz(0); + let mut value: fmpz = 0; unsafe { fmpz_init_set(&mut value, &self.value) }; value } @@ -164,7 +164,7 @@ unsafe impl AsInteger for fmpz { unsafe impl AsInteger for &fmpz { /// Documentation at [`AsInteger::into_fmpz`] unsafe fn into_fmpz(self) -> fmpz { - let mut value = fmpz(0); + let mut value: fmpz = 0; unsafe { fmpz_init_set(&mut value, self) }; value } @@ -249,7 +249,7 @@ mod test_as_integer_z { let value = unsafe { (&z).into_fmpz() }; // The `fmpz` values have to point to different memory locations. - assert_ne!(value.0, z.value.0); + assert_ne!(value, z.value); } /// Assert that `get_fmpz_ref` returns a correct reference for small values @@ -261,8 +261,8 @@ mod test_as_integer_z { let z_ref_1 = z.get_fmpz_ref().unwrap(); let z_ref_2 = (&z).get_fmpz_ref().unwrap(); - assert_eq!(z.value.0, z_ref_1.0); - assert_eq!(z.value.0, z_ref_2.0); + assert_eq!(&z.value, z_ref_1); + assert_eq!(&z.value, z_ref_2); } /// Assert that `get_fmpz_ref` returns a correct reference for large values @@ -274,8 +274,8 @@ mod test_as_integer_z { let z_ref_1 = z.get_fmpz_ref().unwrap(); let z_ref_2 = (&z).get_fmpz_ref().unwrap(); - assert_eq!(z.value.0, z_ref_1.0); - assert_eq!(z.value.0, z_ref_2.0); + assert_eq!(&z.value, z_ref_1); + assert_eq!(&z.value, z_ref_2); } } @@ -338,15 +338,14 @@ mod test_find_max_abs { mod test_distance { use super::Z; use super::distance; - use flint_sys::fmpz::fmpz; /// Checks if distance is correctly output for small [`Z`] values /// and whether distance(a, b) == distance(b, a), distance(a, a) == 0 #[test] fn small_values() { - let a = fmpz(1); - let b = fmpz(-15); - let zero = fmpz(0); + let a = 1; + let b = -15; + let zero = 0; assert_eq!(Z::ONE, distance(&a, &zero)); assert_eq!(Z::ONE, distance(&zero, &a)); diff --git a/src/integer/z/from.rs b/src/integer/z/from.rs index 7afda7b5..63b09efe 100644 --- a/src/integer/z/from.rs +++ b/src/integer/z/from.rs @@ -17,7 +17,8 @@ use crate::{ macros::for_others::implement_empty_trait_owned_ref, traits::AsInteger, }; -use flint_sys::fmpz::{fmpz, fmpz_get_si, fmpz_get_ui, fmpz_init_set, fmpz_set_str, fmpz_setbit}; +use flint_sys::flint::fmpz; +use flint_sys::fmpz::{fmpz_get_si, fmpz_get_ui, fmpz_init_set, fmpz_set_str, fmpz_setbit}; use std::{ffi::CString, str::FromStr}; impl Z { @@ -123,7 +124,7 @@ impl Z { } // since |value| = |0| < 62 bits, we do not need to free the allocated space manually - let mut value: fmpz = fmpz(0); + let mut value: fmpz = 0; let c_string = CString::new(s)?; @@ -227,7 +228,7 @@ impl Z { /// with the default implementation for [`Z`] and also to filter out [`Zq`](crate::integer_mod_q::Zq). trait IntoZ {} impl IntoZ for &Z {} -implement_empty_trait_owned_ref!(IntoZ for Modulus fmpz u8 u16 u32 u64 i8 i16 i32 i64); +implement_empty_trait_owned_ref!(IntoZ for Modulus u8 u16 u32 u64 i8 i16 i32 i64); impl From for Z { /// Converts an integer to [`Z`]. @@ -772,13 +773,13 @@ mod test_from_str_b { #[cfg(test)] mod test_from_fmpz { use super::Z; - use flint_sys::fmpz::{fmpz, fmpz_set_ui}; + use flint_sys::{flint::fmpz, fmpz::fmpz_set_ui}; /// Ensure that `from_fmpz` is available for small and large numbers #[test] fn small_numbers() { - let fmpz_1 = fmpz(0); - let fmpz_2 = fmpz(100); + let fmpz_1: fmpz = 0; + let fmpz_2: fmpz = 100; assert_eq!(unsafe { Z::from_fmpz(fmpz_1) }, Z::ZERO); assert_eq!(unsafe { Z::from_fmpz(fmpz_2) }, Z::from(100)); @@ -787,7 +788,7 @@ mod test_from_fmpz { /// Ensure that `from_fmpz` is available for small and large numbers #[test] fn large_numbers() { - let mut fmpz_1 = fmpz(0); + let mut fmpz_1: fmpz = 0; unsafe { fmpz_set_ui(&mut fmpz_1, u64::MAX) } assert_eq!(unsafe { Z::from_fmpz(fmpz_1) }, Z::from(u64::MAX)); diff --git a/src/integer/z/hash.rs b/src/integer/z/hash.rs index 1b3d4d5f..8c93fa0b 100644 --- a/src/integer/z/hash.rs +++ b/src/integer/z/hash.rs @@ -22,7 +22,7 @@ impl Hash for Z { fn hash(&self, state: &mut H) { // We use Hash of i64 instead of String or Vec as it // significantly reduces the runtime of this function. - let modulo_value = (self % MODULUS).value.0; + let modulo_value = (self % MODULUS).value; modulo_value.hash(state); } } diff --git a/src/integer/z/ownership.rs b/src/integer/z/ownership.rs index 180beac6..e0a97359 100644 --- a/src/integer/z/ownership.rs +++ b/src/integer/z/ownership.rs @@ -12,7 +12,8 @@ //! The explicit functions contain the documentation. use super::Z; -use flint_sys::fmpz::{fmpz, fmpz_clear, fmpz_init_set}; +use flint_sys::flint::fmpz; +use flint_sys::fmpz::{fmpz_clear, fmpz_init_set}; impl Clone for Z { /// Clones the given element and returns a deep clone of the [`Z`] element. @@ -27,7 +28,7 @@ impl Clone for Z { fn clone(&self) -> Self { // a fresh fmpz value is created, set to the same value as the cloned one, // and wrapped in a new [`Z`] value. Hence, a fresh deep clone is created. - let mut value = fmpz(0); + let mut value: fmpz = 0; unsafe { fmpz_init_set(&mut value, &self.value) }; Self { value } } @@ -77,8 +78,8 @@ mod test_clone { let max_2 = max_1.clone(); let min_2 = min_1.clone(); - assert_ne!(max_1.value.0, max_2.value.0); - assert_ne!(min_1.value.0, min_2.value.0); + assert_ne!(max_1.value, max_2.value); + assert_ne!(min_1.value, min_2.value); assert_eq!(max_1, max_2); assert_eq!(min_1, min_2); } @@ -95,9 +96,9 @@ mod test_clone { let zero_2 = zero_1.clone(); let neg_2 = neg_1.clone(); - assert_eq!(pos_1.value.0, pos_2.value.0); - assert_eq!(zero_1.value.0, zero_2.value.0); - assert_eq!(neg_1.value.0, neg_2.value.0); + assert_eq!(pos_1.value, pos_2.value); + assert_eq!(zero_1.value, zero_2.value); + assert_eq!(neg_1.value, neg_2.value); assert_eq!(pos_1, pos_2); assert_eq!(zero_1, zero_2); assert_eq!(neg_1, neg_2); @@ -131,10 +132,10 @@ mod test_drop { // instantiate different [`Z`] value to check if memory slot is reused for different value let c = Z::from(i64::MIN); - assert_eq!(c.value.0, b.value.0); + assert_eq!(c.value, b.value); // memory slots differ due to previously created large integer - assert_ne!(b.value.0, Z::from(u64::MAX).value.0); + assert_ne!(b.value, Z::from(u64::MAX).value); } /// This test shows why false copies are a problem, which are prevented for users of the library diff --git a/src/integer/z/properties.rs b/src/integer/z/properties.rs index 8569b324..dc5432df 100644 --- a/src/integer/z/properties.rs +++ b/src/integer/z/properties.rs @@ -11,9 +11,10 @@ use super::Z; use crate::rational::Q; use flint_sys::{ - fmpq::{fmpq, fmpq_inv}, + flint::fmpq, + fmpq::fmpq_inv, fmpz::{ - fmpz, fmpz_abs, fmpz_bits, fmpz_is_one, fmpz_is_perfect_power, fmpz_is_prime, fmpz_is_zero, + fmpz_abs, fmpz_bits, fmpz_is_one, fmpz_is_perfect_power, fmpz_is_prime, fmpz_is_zero, fmpz_tstbit, }, }; @@ -107,7 +108,7 @@ impl Z { // dropped automatically, but the numerator/ self's value is kept alive let self_fmpq = fmpq { num: self.value, - den: fmpz(1), + den: 1, }; unsafe { fmpq_inv(&mut out.value, &self_fmpq) }; Some(out) diff --git a/src/integer/z/unsafe_functions.rs b/src/integer/z/unsafe_functions.rs index 3781847a..a8a72dac 100644 --- a/src/integer/z/unsafe_functions.rs +++ b/src/integer/z/unsafe_functions.rs @@ -13,7 +13,7 @@ use crate::{ integer::Z, macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}, }; -use flint_sys::fmpz::{fmpz, fmpz_clear}; +use flint_sys::{flint::fmpz, fmpz::fmpz_clear}; unsafe_getter!(Z, value, fmpz); unsafe_setter!(Z, value, fmpz, fmpz_clear); @@ -31,7 +31,7 @@ mod test_get_fmpz { let mut fmpz_int = unsafe { integer.get_fmpz() }; - fmpz_int.0 = 2; + fmpz_int = &mut 2i64; assert_eq!(Z::from(2), integer); } @@ -40,7 +40,7 @@ mod test_get_fmpz { #[cfg(test)] mod test_set_fmpz { use super::Z; - use flint_sys::fmpz::fmpz; + use flint_sys::flint::fmpz; /// Checks availability of the setter for [`Z::value`] /// and its ability to modify [`Z`]. @@ -48,7 +48,7 @@ mod test_set_fmpz { #[allow(unused_mut)] fn availability_and_modification() { let mut integer = Z::from(1); - let b = fmpz(2); + let b: fmpz = 2; unsafe { integer.set_fmpz(b) }; diff --git a/src/integer_mod_q/mat_ntt_polynomial_ring_zq.rs b/src/integer_mod_q/mat_ntt_polynomial_ring_zq.rs index 4572c31a..14db0e0e 100644 --- a/src/integer_mod_q/mat_ntt_polynomial_ring_zq.rs +++ b/src/integer_mod_q/mat_ntt_polynomial_ring_zq.rs @@ -11,7 +11,6 @@ use crate::{integer::Z, integer_mod_q::ModulusPolynomialRingZq}; use derive_more::Display; use serde::{Deserialize, Serialize}; -use std::fmt; mod arithmetic; mod cmp; @@ -54,7 +53,7 @@ mod sample; /// // Return to MatPolynomialRingZq /// let res = tmp_mat_ntt.inv_ntt(); /// ``` -#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone)] +#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone, Debug)] #[display("{} / {}", print_vec_z(&self.matrix), self.modulus)] pub struct MatNTTPolynomialRingZq { pub matrix: Vec, @@ -63,20 +62,6 @@ pub struct MatNTTPolynomialRingZq { pub modulus: ModulusPolynomialRingZq, } -impl fmt::Debug for MatNTTPolynomialRingZq { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let short_print = print_vec_z(&self.matrix); - let a: Vec<&str> = short_print.split_whitespace().collect(); - let short_print = format!("{}{} ..., {}{}", a[0], a[1], a[a.len() - 2], a[a.len() - 1]); - - write!( - f, - "MatNTTPolynomialRingZq {{matrix: {}, nr_rows: {}, nr_columns: {}, modulus: {}, storage: {{matrix: {:?}, modulus: {:?}}}}}", - short_print, self.nr_rows, self.nr_columns, self.modulus, self.matrix, self.modulus - ) - } -} - /// Quick solution to print a vector of [`Z`] values in the format `[1, 2, 3, 4, 5]`. pub(crate) fn print_vec_z(vector: &Vec) -> String { let mut out = String::new(); diff --git a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs index 52aa1b5f..4915a32d 100644 --- a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs +++ b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs @@ -16,7 +16,10 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod::{fmpz_mod_add_fmpz, fmpz_mod_ctx, fmpz_mod_mul}; +use flint_sys::{ + fmpz_mod::{fmpz_mod_add_fmpz, fmpz_mod_mul}, + fmpz_mod_types::fmpz_mod_ctx, +}; use std::ops::Mul; impl Mul for &MatNTTPolynomialRingZq { diff --git a/src/integer_mod_q/mat_polynomial_ring_zq.rs b/src/integer_mod_q/mat_polynomial_ring_zq.rs index 1a22ed7e..ba68ae47 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq.rs @@ -10,10 +10,9 @@ //! This implementation uses the [FLINT](https://flintlib.org/) library. use super::ModulusPolynomialRingZq; -use crate::{integer::MatPolyOverZ, utils::parse::partial_string}; +use crate::integer::MatPolyOverZ; use derive_more::Display; use serde::{Deserialize, Serialize}; -use std::fmt; mod arithmetic; mod cmp; @@ -91,23 +90,9 @@ mod vector; /// assert!(row_vec.is_row_vector()); /// assert!(col_vec.is_column_vector()); /// ``` -#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone)] +#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone, Debug)] #[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, - "MatPolynomialRingZq: {{matrix: {}, modulus: {} storage: {{matrix: {:?}, modulus: {:?}}}}}", - // printing the entire matrix is not meaningful for large matrices - partial_string(&self.get_representative_least_nonnegative_residue(), 3, 3), - self.modulus, - self.matrix, - self.modulus - ) - } -} diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/get.rs b/src/integer_mod_q/mat_polynomial_ring_zq/get.rs index 4240fa79..311038a1 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/get.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/get.rs @@ -14,7 +14,7 @@ use crate::{ integer_mod_q::{ModulusPolynomialRingZq, PolynomialRingZq}, traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}, }; -use flint_sys::{fmpz_poly::fmpz_poly_struct, fmpz_poly_mat::fmpz_poly_mat_entry}; +use flint_sys::{fmpz_poly_mat::fmpz_poly_mat_entry, fmpz_types::fmpz_poly_struct}; impl MatPolynomialRingZq { /// Returns the modulus of the matrix as a [`ModulusPolynomialRingZq`]. @@ -266,7 +266,8 @@ impl MatPolynomialRingZq { for row in 0..self.get_num_rows() { for col in 0..self.get_num_columns() { // efficiently get entry without cloning the entry itself - let entry = unsafe { *fmpz_poly_mat_entry(&self.matrix.matrix, row, col) }; + let entry = + unsafe { std::ptr::read(fmpz_poly_mat_entry(&self.matrix.matrix, row, col)) }; entries.push(entry); } } diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs b/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs index dd51920b..1037ff38 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs @@ -68,7 +68,7 @@ impl MatPolynomialRingZq { /// ``` pub(crate) unsafe fn reduce_entry(&mut self, row: i64, column: i64) { let entry = unsafe { fmpz_poly_mat_entry(&self.matrix.matrix, row, column) }; - if (unsafe { *entry }).length > 0 { + if (unsafe { std::ptr::read(entry) }).length > 0 { unsafe { reduce_fmpz_poly_by_fmpz_mod_poly_sparse( &mut *entry, diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs b/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs index 97e2b284..85fadbdc 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs @@ -10,7 +10,7 @@ //! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe. use super::MatPolynomialRingZq; use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect}; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_struct; +use flint_sys::fmpz_types::fmpz_poly_mat_struct; unsafe_getter_indirect!( MatPolynomialRingZq, diff --git a/src/integer_mod_q/mat_zq.rs b/src/integer_mod_q/mat_zq.rs index fbf664dc..35cefecc 100644 --- a/src/integer_mod_q/mat_zq.rs +++ b/src/integer_mod_q/mat_zq.rs @@ -13,8 +13,8 @@ // To avoid unnecessary checks and reductions, always return canonical/reduced // values. The end-user should be unable to obtain a non-reduced value. -use crate::{integer_mod_q::Modulus, utils::parse::partial_string}; -use flint_sys::fmpz_mod_mat::fmpz_mod_mat_struct; +use crate::{integer::debug_fmpz_mat_struct, integer_mod_q::Modulus, utils::parse::partial_string}; +use flint_sys::fmpz_mod_types::fmpz_mod_mat_struct; use std::fmt; mod arithmetic; @@ -92,18 +92,18 @@ pub struct MatZq { // The modulus of a `MatZq` is not able to be modified afterwards. Hence, we // do not need to care about conformity of the modulus stored in the `matrix` // attribute and `modulus` attribute, if they are both initialized from the same value. - modulus: Modulus, + pub(crate) modulus: Modulus, } impl fmt::Debug for MatZq { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "MatZq: {{matrix: {}, modulus: {}, storage: {{matrix: {:?}, modulus: {:?}}}}}", + "MatZq: {{matrix: {}, modulus: {}, storage: {{ matrix: {}, modulus: {:?}}}}}", // printing the entire matrix is not meaningful for large matrices partial_string(&self.get_representative_least_nonnegative_residue(), 3, 3), self.modulus, - self.matrix, + debug_fmpz_mat_struct(&self.matrix), self.modulus ) } diff --git a/src/integer_mod_q/mat_zq/arithmetic/add.rs b/src/integer_mod_q/mat_zq/arithmetic/add.rs index 4747b0df..3168039d 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/add.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/add.rs @@ -61,7 +61,14 @@ impl AddAssign<&MatZq> for MatZq { panic!("{}", self.call_compare_base_error(other).unwrap()); } - unsafe { fmpz_mod_mat_add(&mut self.matrix, &self.matrix, &other.matrix) }; + unsafe { + fmpz_mod_mat_add( + &mut self.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ) + }; } } impl AddAssign<&MatZ> for MatZq { @@ -80,8 +87,8 @@ impl AddAssign<&MatZ> for MatZq { } unsafe { - fmpz_mat_add(&mut self.matrix.mat[0], &self.matrix.mat[0], &other.matrix); - _fmpz_mod_mat_reduce(&mut self.matrix); + fmpz_mat_add(&mut self.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut self.matrix, self.modulus.get_fmpz_mod_ctx_struct()); }; } } @@ -163,8 +170,8 @@ impl Add<&MatZ> for &MatZq { let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { - fmpz_mat_add(&mut out.matrix.mat[0], &self.matrix.mat[0], &other.matrix); - _fmpz_mod_mat_reduce(&mut out.matrix); + fmpz_mat_add(&mut out.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut out.matrix, self.modulus.get_fmpz_mod_ctx_struct()); } out } @@ -218,7 +225,12 @@ impl MatZq { } let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { - fmpz_mod_mat_add(&mut out.matrix, &self.matrix, &other.matrix); + fmpz_mod_mat_add( + &mut out.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } Ok(out) } diff --git a/src/integer_mod_q/mat_zq/arithmetic/mul.rs b/src/integer_mod_q/mat_zq/arithmetic/mul.rs index ba6b0879..f197aea0 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/mul.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/mul.rs @@ -92,8 +92,8 @@ impl Mul<&MatZ> for &MatZq { let mut new = MatZq::new(self.get_num_rows(), other.get_num_columns(), self.get_mod()); unsafe { - fmpz_mat_mul(&mut new.matrix.mat[0], &self.matrix.mat[0], &other.matrix); - _fmpz_mod_mat_reduce(&mut new.matrix) + fmpz_mat_mul(&mut new.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut new.matrix, self.modulus.get_fmpz_mod_ctx_struct()) } new } @@ -143,7 +143,14 @@ impl MatZq { } let mut new = MatZq::new(self.get_num_rows(), other.get_num_columns(), self.get_mod()); - unsafe { fmpz_mod_mat_mul(&mut new.matrix, &self.matrix, &other.matrix) }; + unsafe { + fmpz_mod_mat_mul( + &mut new.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ) + }; Ok(new) } } diff --git a/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs b/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs index 7e263c23..c1bb3f80 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs @@ -48,7 +48,12 @@ impl Mul<&Z> for &MatZq { fn mul(self, scalar: &Z) -> Self::Output { let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { - fmpz_mod_mat_scalar_mul_fmpz(&mut out.matrix, &self.matrix, &scalar.value); + fmpz_mod_mat_scalar_mul_fmpz( + &mut out.matrix, + &self.matrix, + &mut std::ptr::read(scalar).value, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } out } @@ -128,7 +133,12 @@ impl MatZq { let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { - fmpz_mod_mat_scalar_mul_fmpz(&mut out.matrix, &self.matrix, &scalar.value.value); + fmpz_mod_mat_scalar_mul_fmpz( + &mut out.matrix, + &self.matrix, + &mut std::ptr::read(scalar).value.value, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } Ok(out) } @@ -161,7 +171,14 @@ impl MulAssign<&Z> for MatZq { /// a *= c; /// ``` fn mul_assign(&mut self, scalar: &Z) { - unsafe { fmpz_mod_mat_scalar_mul_fmpz(&mut self.matrix, &self.matrix, &scalar.value) }; + unsafe { + fmpz_mod_mat_scalar_mul_fmpz( + &mut self.matrix, + &self.matrix, + &mut std::ptr::read(scalar).value, + self.modulus.get_fmpz_mod_ctx_struct(), + ) + }; } } @@ -175,7 +192,12 @@ impl MulAssign<&Zq> for MatZq { panic!("{}", self.call_compare_base_error(scalar).unwrap()) } unsafe { - fmpz_mod_mat_scalar_mul_fmpz(&mut self.matrix, &self.matrix, &scalar.value.value) + fmpz_mod_mat_scalar_mul_fmpz( + &mut self.matrix, + &self.matrix, + &mut std::ptr::read(scalar).value.value, + self.modulus.get_fmpz_mod_ctx_struct(), + ) }; } } @@ -185,14 +207,28 @@ arithmetic_assign_trait_borrowed_to_owned!(MulAssign, mul_assign, MatZq, Zq); impl MulAssign for MatZq { /// Documentation at [`MatZq::mul_assign`]. fn mul_assign(&mut self, other: i64) { - unsafe { fmpz_mod_mat_scalar_mul_si(&mut self.matrix, &self.matrix, other) }; + unsafe { + fmpz_mod_mat_scalar_mul_si( + &mut self.matrix, + &self.matrix, + other, + self.modulus.get_fmpz_mod_ctx_struct(), + ) + }; } } impl MulAssign for MatZq { /// Documentation at [`MatZq::mul_assign`]. fn mul_assign(&mut self, other: u64) { - unsafe { fmpz_mod_mat_scalar_mul_ui(&mut self.matrix, &self.matrix, other) }; + unsafe { + fmpz_mod_mat_scalar_mul_ui( + &mut self.matrix, + &self.matrix, + other, + self.modulus.get_fmpz_mod_ctx_struct(), + ) + }; } } diff --git a/src/integer_mod_q/mat_zq/arithmetic/sub.rs b/src/integer_mod_q/mat_zq/arithmetic/sub.rs index 79dced62..6da701f3 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/sub.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/sub.rs @@ -61,7 +61,14 @@ impl SubAssign<&MatZq> for MatZq { panic!("{}", self.call_compare_base_error(other).unwrap()); } - unsafe { fmpz_mod_mat_sub(&mut self.matrix, &self.matrix, &other.matrix) }; + unsafe { + fmpz_mod_mat_sub( + &mut self.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ) + }; } } impl SubAssign<&MatZ> for MatZq { @@ -80,8 +87,8 @@ impl SubAssign<&MatZ> for MatZq { } unsafe { - fmpz_mat_sub(&mut self.matrix.mat[0], &self.matrix.mat[0], &other.matrix); - _fmpz_mod_mat_reduce(&mut self.matrix); + fmpz_mat_sub(&mut self.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut self.matrix, self.modulus.get_fmpz_mod_ctx_struct()); }; } } @@ -166,8 +173,8 @@ impl Sub<&MatZ> for &MatZq { let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { - fmpz_mat_sub(&mut out.matrix.mat[0], &self.matrix.mat[0], &other.matrix); - _fmpz_mod_mat_reduce(&mut out.matrix); + fmpz_mat_sub(&mut out.matrix, &self.matrix, &other.matrix); + _fmpz_mod_mat_reduce(&mut out.matrix, self.modulus.get_fmpz_mod_ctx_struct()); } out } @@ -218,7 +225,12 @@ impl MatZq { } let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { - fmpz_mod_mat_sub(&mut out.matrix, &self.matrix, &other.matrix); + fmpz_mod_mat_sub( + &mut out.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } Ok(out) } diff --git a/src/integer_mod_q/mat_zq/cmp.rs b/src/integer_mod_q/mat_zq/cmp.rs index 38bd200b..fb0aaee5 100644 --- a/src/integer_mod_q/mat_zq/cmp.rs +++ b/src/integer_mod_q/mat_zq/cmp.rs @@ -16,7 +16,7 @@ use crate::{ macros::compare_base::{compare_base_default, compare_base_get_mod, compare_base_impl}, traits::CompareBase, }; -use flint_sys::{fmpz::fmpz_equal, fmpz_mat::fmpz_mat_equal}; +use flint_sys::fmpz_mat::fmpz_mat_equal; impl PartialEq for MatZq { /// Checks if two [`MatZq`] instances are equal. Used by the `==` and `!=` operators. @@ -47,8 +47,7 @@ impl PartialEq for MatZq { /// ``` fn eq(&self, other: &Self) -> bool { unsafe { - fmpz_equal(&self.matrix.mod_[0], &other.matrix.mod_[0]) != 0 - && fmpz_mat_equal(&self.matrix.mat[0], &other.matrix.mat[0]) != 0 + self.get_mod() == other.get_mod() && fmpz_mat_equal(&self.matrix, &other.matrix) != 0 } } } @@ -65,7 +64,7 @@ impl Eq for MatZq {} #[cfg(test)] mod test_partial_eq { use super::MatZq; - use crate::traits::MatrixSetEntry; + use crate::traits::{AsInteger, MatrixSetEntry}; use std::str::FromStr; /// Ensures that different instantiations do not break the equality between matrices @@ -137,7 +136,9 @@ mod test_partial_eq { let c = MatZq::from_str(&format!("[[0]] mod {}", u64::MAX)).unwrap(); let d = MatZq::from_str(&format!("[[0]] mod {}", u64::MAX - 1)).unwrap(); - let e = MatZq::from_str(&format!("[[0]] mod {}", c.matrix.mod_[0].0 as u64)).unwrap(); + let e = + MatZq::from_str(&format!("[[0]] mod {}", unsafe { c.get_mod().into_fmpz() } as u64)) + .unwrap(); assert_ne!(a, b); diff --git a/src/integer_mod_q/mat_zq/concat.rs b/src/integer_mod_q/mat_zq/concat.rs index 2dfbeb20..2dbd2562 100644 --- a/src/integer_mod_q/mat_zq/concat.rs +++ b/src/integer_mod_q/mat_zq/concat.rs @@ -65,7 +65,12 @@ impl Concatenate for &MatZq { self.get_mod(), ); unsafe { - fmpz_mod_mat_concat_vertical(&mut out.matrix, &self.matrix, &other.matrix); + fmpz_mod_mat_concat_vertical( + &mut out.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } Ok(out) } @@ -117,7 +122,12 @@ impl Concatenate for &MatZq { self.get_mod(), ); unsafe { - fmpz_mod_mat_concat_horizontal(&mut out.matrix, &self.matrix, &other.matrix); + fmpz_mod_mat_concat_horizontal( + &mut out.matrix, + &self.matrix, + &other.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } Ok(out) diff --git a/src/integer_mod_q/mat_zq/default.rs b/src/integer_mod_q/mat_zq/default.rs index 3d2ec14b..97f305a0 100644 --- a/src/integer_mod_q/mat_zq/default.rs +++ b/src/integer_mod_q/mat_zq/default.rs @@ -54,7 +54,7 @@ impl MatZq { matrix.as_mut_ptr(), num_rows_i64, num_cols_i64, - &modulus.get_fmpz_mod_ctx_struct().n[0], + modulus.get_fmpz_mod_ctx_struct(), ); MatZq { @@ -92,8 +92,9 @@ impl MatZq { num_cols: impl TryInto + Display, modulus: impl Into, ) -> Self { - let mut out = MatZq::new(num_rows, num_cols, modulus); - unsafe { fmpz_mod_mat_one(&mut out.matrix) }; + let modulus = modulus.into(); + let mut out = MatZq::new(num_rows, num_cols, &modulus); + unsafe { fmpz_mod_mat_one(&mut out.matrix, modulus.get_fmpz_mod_ctx_struct()) }; out } } diff --git a/src/integer_mod_q/mat_zq/from.rs b/src/integer_mod_q/mat_zq/from.rs index ca9f7556..d8abed39 100644 --- a/src/integer_mod_q/mat_zq/from.rs +++ b/src/integer_mod_q/mat_zq/from.rs @@ -125,10 +125,11 @@ impl> From<(&MatZ, Mod)> for MatZq { /// let a = MatZq::from((&m, 17)); /// ``` fn from((matrix, modulus): (&MatZ, Mod)) -> Self { - let mut out = MatZq::new(matrix.get_num_rows(), matrix.get_num_columns(), modulus); + let modulus = modulus.into(); + let mut out = MatZq::new(matrix.get_num_rows(), matrix.get_num_columns(), &modulus); unsafe { - fmpz_mat_set(&mut out.matrix.mat[0], &matrix.matrix); - _fmpz_mod_mat_reduce(&mut out.matrix); + fmpz_mat_set(&mut out.matrix, &matrix.matrix); + _fmpz_mod_mat_reduce(&mut out.matrix, modulus.get_fmpz_mod_ctx_struct()); } out } diff --git a/src/integer_mod_q/mat_zq/get.rs b/src/integer_mod_q/mat_zq/get.rs index 7bdff0a0..374b80b2 100644 --- a/src/integer_mod_q/mat_zq/get.rs +++ b/src/integer_mod_q/mat_zq/get.rs @@ -12,10 +12,11 @@ use super::MatZq; use crate::{ integer::{MatZ, Z}, integer_mod_q::{Modulus, Zq, fmpz_mod_helpers::length}, - traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix, MatrixSetEntry}, + traits::{AsInteger, MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix, MatrixSetEntry}, }; use flint_sys::{ - fmpz::{fmpz, fmpz_init_set}, + flint::fmpz, + fmpz::fmpz_init_set, fmpz_mat::fmpz_mat_set, fmpz_mod_mat::{ fmpz_mod_mat_entry, fmpz_mod_mat_init_set, fmpz_mod_mat_window_clear, @@ -48,7 +49,7 @@ impl MatZq { /// ``` pub fn get_representative_least_nonnegative_residue(&self) -> MatZ { let mut out = MatZ::new(self.get_num_rows(), self.get_num_columns()); - unsafe { fmpz_mat_set(&mut out.matrix, &self.matrix.mat[0]) }; + unsafe { fmpz_mat_set(&mut out.matrix, &self.matrix) }; out } @@ -165,15 +166,20 @@ impl MatrixGetSubmatrix for MatZq { col_1, row_2, col_2, + self.modulus.get_fmpz_mod_ctx_struct(), ) }; let mut window_copy = MaybeUninit::uninit(); unsafe { // Deep clone of the content of the window - fmpz_mod_mat_init_set(window_copy.as_mut_ptr(), window.as_ptr()); + fmpz_mod_mat_init_set( + window_copy.as_mut_ptr(), + window.as_ptr(), + self.modulus.get_fmpz_mod_ctx_struct(), + ); // Clears the matrix window and releases any memory that it uses. Note that // the memory to the underlying matrix that window points to is not freed - fmpz_mod_mat_window_clear(window.as_mut_ptr()); + fmpz_mod_mat_window_clear(window.as_mut_ptr(), self.modulus.get_fmpz_mod_ctx_struct()); } MatZq { matrix: unsafe { window_copy.assume_init() }, @@ -228,7 +234,7 @@ impl MatZq { pub(crate) fn collect_lengths(&self) -> Vec { let entries_fmpz = self.collect_entries(); - let modulus_fmpz = self.matrix.mod_[0]; + let modulus_fmpz = unsafe { self.get_mod().into_fmpz() }; let mut entry_lengths = Vec::with_capacity(entries_fmpz.len()); for value in entries_fmpz { entry_lengths.push(length(&value, &modulus_fmpz)); @@ -250,7 +256,7 @@ impl MatrixDimensions for MatZq { /// let rows = matrix.get_num_rows(); /// ``` fn get_num_rows(&self) -> i64 { - self.matrix.mat[0].r + self.matrix.r } /// Returns the number of columns of the matrix as a [`i64`]. @@ -264,7 +270,7 @@ impl MatrixDimensions for MatZq { /// let rows = matrix.get_num_columns(); /// ``` fn get_num_columns(&self) -> i64 { - self.matrix.mat[0].c + self.matrix.c } } @@ -879,16 +885,16 @@ mod test_collect_entries { let entries_2 = mat_2.collect_entries(); assert_eq!(entries_1.len(), 6); - assert_eq!(entries_1[0].0, 1); - assert_eq!(entries_1[1].0, 2); - assert!(entries_1[2].0 >= 2_i64.pow(62)); - assert!(entries_1[3].0 >= 2_i64.pow(62)); - assert_eq!(entries_1[4].0, 3); - assert_eq!(entries_1[5].0, 4); + assert_eq!(entries_1[0], 1); + assert_eq!(entries_1[1], 2); + assert!(entries_1[2] >= 2_i64.pow(62)); + assert!(entries_1[3] >= 2_i64.pow(62)); + assert_eq!(entries_1[4], 3); + assert_eq!(entries_1[5], 4); assert_eq!(entries_2.len(), 2); - assert_eq!(entries_2[0].0, 1); - assert_eq!(entries_2[1].0, 0); + assert_eq!(entries_2[0], 1); + assert_eq!(entries_2[1], 0); } } diff --git a/src/integer_mod_q/mat_zq/inverse.rs b/src/integer_mod_q/mat_zq/inverse.rs index 20d8ae8d..058695a9 100644 --- a/src/integer_mod_q/mat_zq/inverse.rs +++ b/src/integer_mod_q/mat_zq/inverse.rs @@ -158,7 +158,13 @@ impl MatZq { ); // Since we only want the echelon form, the permutation `perm` is not relevant. - let _ = unsafe { fmpz_mod_mat_rref(std::ptr::null_mut(), &self.matrix) }; + let _ = unsafe { + fmpz_mod_mat_rref( + std::ptr::null_mut(), + &self.matrix, + self.get_mod().get_fmpz_mod_ctx_struct(), + ) + }; self } diff --git a/src/integer_mod_q/mat_zq/ownership.rs b/src/integer_mod_q/mat_zq/ownership.rs index 39cb34e0..81895993 100644 --- a/src/integer_mod_q/mat_zq/ownership.rs +++ b/src/integer_mod_q/mat_zq/ownership.rs @@ -35,7 +35,11 @@ impl Clone for MatZq { Z::from(self.get_mod()), ); unsafe { - fmpz_mod_mat_init_set(&mut out.matrix, &self.matrix); + fmpz_mod_mat_init_set( + &mut out.matrix, + &self.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } out } @@ -64,7 +68,7 @@ impl Drop for MatZq { /// drop(a); // explicitly drops a's value /// ``` fn drop(&mut self) { - unsafe { fmpz_mod_mat_clear(&mut self.matrix) } + unsafe { fmpz_mod_mat_clear(&mut self.matrix, self.modulus.get_fmpz_mod_ctx_struct()) } } } @@ -109,20 +113,20 @@ mod test_clone { a = b.clone(); assert_ne!( - MatrixGetEntry::::get_entry(&a, 0, 0).unwrap().value.0, - MatrixGetEntry::::get_entry(&b, 0, 0).unwrap().value.0 + MatrixGetEntry::::get_entry(&a, 0, 0).unwrap().value, + MatrixGetEntry::::get_entry(&b, 0, 0).unwrap().value ); assert_ne!( - MatrixGetEntry::::get_entry(&a, 0, 1).unwrap().value.0, - MatrixGetEntry::::get_entry(&b, 0, 1).unwrap().value.0 + MatrixGetEntry::::get_entry(&a, 0, 1).unwrap().value, + MatrixGetEntry::::get_entry(&b, 0, 1).unwrap().value ); assert_ne!( - MatrixGetEntry::::get_entry(&a, 1, 0).unwrap().value.0, - MatrixGetEntry::::get_entry(&b, 1, 0).unwrap().value.0 + MatrixGetEntry::::get_entry(&a, 1, 0).unwrap().value, + MatrixGetEntry::::get_entry(&b, 1, 0).unwrap().value ); assert_eq!( - MatrixGetEntry::::get_entry(&a, 1, 1).unwrap().value.0, - MatrixGetEntry::::get_entry(&b, 1, 1).unwrap().value.0 + MatrixGetEntry::::get_entry(&a, 1, 1).unwrap().value, + MatrixGetEntry::::get_entry(&b, 1, 1).unwrap().value ); // kept on stack } @@ -147,7 +151,7 @@ mod test_clone { let a = b.clone(); - assert_ne!(a.matrix.mod_[0].0, b.matrix.mod_[0].0); + assert_ne!(a.modulus, b.modulus); } } @@ -156,7 +160,7 @@ mod test_clone { mod test_drop { use super::MatZq; use crate::integer::Z; - use crate::traits::MatrixGetEntry; + use crate::traits::{AsInteger, MatrixGetEntry}; use std::collections::HashSet; use std::str::FromStr; @@ -166,9 +170,9 @@ mod test_drop { let string = format!("[[{}, {}]] mod {}", i64::MAX, i64::MIN, u64::MAX); let a = MatZq::from_str(&string).unwrap(); - let storage_mod = a.matrix.mod_[0].0; - let storage_0 = MatrixGetEntry::::get_entry(&a, 0, 0).unwrap().value.0; - let storage_1 = MatrixGetEntry::::get_entry(&a, 0, 1).unwrap().value.0; + let storage_mod = unsafe { a.get_mod().into_fmpz() }; + let storage_0 = MatrixGetEntry::::get_entry(&a, 0, 0).unwrap().value; + let storage_1 = MatrixGetEntry::::get_entry(&a, 0, 1).unwrap().value; (storage_mod, storage_0, storage_1) } diff --git a/src/integer_mod_q/mat_zq/properties.rs b/src/integer_mod_q/mat_zq/properties.rs index f23b657f..514dbd05 100644 --- a/src/integer_mod_q/mat_zq/properties.rs +++ b/src/integer_mod_q/mat_zq/properties.rs @@ -41,7 +41,7 @@ impl MatZq { /// assert!(value.is_identity()); /// ``` pub fn is_identity(&self) -> bool { - unsafe { 1 == fmpz_mat_is_one(&self.matrix.mat[0]) } + unsafe { 1 == fmpz_mat_is_one(&self.matrix) } } /// Checks if a [`MatZq`] is a square matrix. @@ -57,7 +57,7 @@ impl MatZq { /// assert!(value.is_square()); /// ``` pub fn is_square(&self) -> bool { - 1 == unsafe { fmpz_mod_mat_is_square(&self.matrix) } + 1 == unsafe { fmpz_mod_mat_is_square(&self.matrix, self.modulus.get_fmpz_mod_ctx_struct()) } } /// Checks if every entry of a [`MatZq`] is `0`. @@ -73,7 +73,7 @@ impl MatZq { /// assert!(value.is_zero()); /// ``` pub fn is_zero(&self) -> bool { - 1 == unsafe { fmpz_mod_mat_is_zero(&self.matrix) } + 1 == unsafe { fmpz_mod_mat_is_zero(&self.matrix, self.modulus.get_fmpz_mod_ctx_struct()) } } /// Checks if a [`MatZq`] is symmetric. diff --git a/src/integer_mod_q/mat_zq/set.rs b/src/integer_mod_q/mat_zq/set.rs index 4a261c0c..1098e623 100644 --- a/src/integer_mod_q/mat_zq/set.rs +++ b/src/integer_mod_q/mat_zq/set.rs @@ -13,7 +13,7 @@ use crate::{ integer::Z, integer_mod_q::{MatZq, Modulus, Zq}, macros::for_others::implement_for_owned, - traits::{AsInteger, MatrixDimensions, MatrixSetEntry, MatrixSetSubmatrix, MatrixSwaps}, + traits::{MatrixDimensions, MatrixSetEntry, MatrixSetSubmatrix, MatrixSwaps}, utils::index::{evaluate_index_for_vector, evaluate_indices_for_matrix}, }; use flint_sys::{ @@ -23,15 +23,11 @@ use flint_sys::{ fmpz_mat_swap_rows, }, fmpz_mod_mat::{ - _fmpz_mod_mat_reduce, _fmpz_mod_mat_set_mod, fmpz_mod_mat_set, fmpz_mod_mat_set_entry, - fmpz_mod_mat_window_clear, fmpz_mod_mat_window_init, + _fmpz_mod_mat_reduce, fmpz_mod_mat_set, fmpz_mod_mat_set_entry, fmpz_mod_mat_window_clear, + fmpz_mod_mat_window_init, }, }; -use std::{ - fmt::Display, - mem::MaybeUninit, - ptr::{null, null_mut}, -}; +use std::{fmt::Display, mem::MaybeUninit, ptr::null_mut}; impl> MatrixSetEntry for MatZq { /// Sets the value of a specific matrix entry according to a given `value` @@ -109,7 +105,13 @@ impl> MatrixSetEntry for MatZq { unsafe { // get entry and replace the pointed at value with the specified value - fmpz_mod_mat_set_entry(&mut self.matrix, row, column, &value.value) + fmpz_mod_mat_set_entry( + &mut self.matrix, + row, + column, + &value.value, + self.modulus.get_fmpz_mod_ctx_struct(), + ) }; } } @@ -147,7 +149,13 @@ impl MatrixSetEntry<&Zq> for MatZq { unsafe fn set_entry_unchecked(&mut self, row: i64, column: i64, value: &Zq) { unsafe { // get entry and replace the pointed at value with the specified value - fmpz_mod_mat_set_entry(&mut self.matrix, row, column, &value.value.value) + fmpz_mod_mat_set_entry( + &mut self.matrix, + row, + column, + &value.value.value, + self.modulus.get_fmpz_mod_ctx_struct(), + ) }; } } @@ -218,6 +226,7 @@ impl MatrixSetSubmatrix for MatZq { col_self_start, row_self_end, col_self_end, + self.modulus.get_fmpz_mod_ctx_struct(), ) }; let mut window_other = MaybeUninit::uninit(); @@ -230,15 +239,26 @@ impl MatrixSetSubmatrix for MatZq { col_other_start, row_other_end, col_other_end, + self.modulus.get_fmpz_mod_ctx_struct(), ) }; unsafe { - fmpz_mod_mat_set(window_self.as_mut_ptr(), window_other.as_ptr()); + fmpz_mod_mat_set( + window_self.as_mut_ptr(), + window_other.as_ptr(), + self.modulus.get_fmpz_mod_ctx_struct(), + ); // Clears the matrix window and releases any memory that it uses. Note that // the memory to the underlying matrix that window points to is not freed - fmpz_mod_mat_window_clear(window_self.as_mut_ptr()); - fmpz_mod_mat_window_clear(window_other.as_mut_ptr()); + fmpz_mod_mat_window_clear( + window_self.as_mut_ptr(), + self.modulus.get_fmpz_mod_ctx_struct(), + ); + fmpz_mod_mat_window_clear( + window_other.as_mut_ptr(), + self.modulus.get_fmpz_mod_ctx_struct(), + ); } } } @@ -282,8 +302,8 @@ impl MatrixSwaps for MatZq { unsafe { fmpz_swap( - fmpz_mat_entry(&self.matrix.mat[0], row_0, col_0), - fmpz_mat_entry(&self.matrix.mat[0], row_1, col_1), + fmpz_mat_entry(&self.matrix, row_0, col_0), + fmpz_mat_entry(&self.matrix, row_1, col_1), ) }; Ok(()) @@ -331,7 +351,7 @@ impl MatrixSwaps for MatZq { }, )); } - unsafe { fmpz_mat_swap_cols(&mut self.matrix.mat[0], null(), col_0, col_1) } + unsafe { fmpz_mat_swap_cols(&mut self.matrix, null_mut(), col_0, col_1) } Ok(()) } @@ -377,7 +397,7 @@ impl MatrixSwaps for MatZq { }, )); } - unsafe { fmpz_mat_swap_rows(&mut self.matrix.mat[0], null(), row_0, row_1) } + unsafe { fmpz_mat_swap_rows(&mut self.matrix, null_mut(), row_0, row_1) } Ok(()) } } @@ -397,7 +417,7 @@ impl MatZq { // If the second argument to this function is not null, the permutation // of the columns is also applied to this argument. // Hence, passing in null is justified here. - unsafe { fmpz_mat_invert_cols(&mut self.matrix.mat[0], null_mut()) } + unsafe { fmpz_mat_invert_cols(&mut self.matrix, null_mut()) } } /// Swaps the `i`-th row with the `n-i`-th row for all `i <= n/2` @@ -414,7 +434,7 @@ impl MatZq { // If the second argument to this function is not null, the permutation // of the rows is also applied to this argument. // Hence, passing in null is justified here. - unsafe { fmpz_mat_invert_rows(&mut self.matrix.mat[0], null_mut()) } + unsafe { fmpz_mat_invert_rows(&mut self.matrix, null_mut()) } } /// Changes the modulus of the given matrix to the new modulus. @@ -437,10 +457,7 @@ impl MatZq { /// - if `modulus` is smaller than `2`. pub fn change_modulus(&mut self, modulus: impl Into) { self.modulus = modulus.into(); - unsafe { - _fmpz_mod_mat_set_mod(&mut self.matrix, self.modulus.get_fmpz_ref().unwrap()); - _fmpz_mod_mat_reduce(&mut self.matrix) - } + unsafe { _fmpz_mod_mat_reduce(&mut self.matrix, self.modulus.get_fmpz_mod_ctx()) } } } diff --git a/src/integer_mod_q/mat_zq/tensor.rs b/src/integer_mod_q/mat_zq/tensor.rs index fe86983c..ae742a4d 100644 --- a/src/integer_mod_q/mat_zq/tensor.rs +++ b/src/integer_mod_q/mat_zq/tensor.rs @@ -91,15 +91,9 @@ impl MatZq { self.get_mod(), ); - unsafe { - fmpz_mat_kronecker_product( - &mut out.matrix.mat[0], - &self.matrix.mat[0], - &other.matrix.mat[0], - ) - }; + unsafe { fmpz_mat_kronecker_product(&mut out.matrix, &self.matrix, &other.matrix) }; - unsafe { _fmpz_mod_mat_reduce(&mut out.matrix) } + unsafe { _fmpz_mod_mat_reduce(&mut out.matrix, self.modulus.get_fmpz_mod_ctx_struct()) } Ok(out) } diff --git a/src/integer_mod_q/mat_zq/trace.rs b/src/integer_mod_q/mat_zq/trace.rs index aaa098c3..6053bd7a 100644 --- a/src/integer_mod_q/mat_zq/trace.rs +++ b/src/integer_mod_q/mat_zq/trace.rs @@ -37,7 +37,11 @@ impl MatZq { let mut out = Zq::from((0, self.get_mod())); unsafe { - fmpz_mod_mat_trace(&mut out.value.value, &self.matrix); + fmpz_mod_mat_trace( + &mut out.value.value, + &self.matrix, + self.modulus.get_fmpz_mod_ctx_struct(), + ); } Ok(out) } diff --git a/src/integer_mod_q/mat_zq/transpose.rs b/src/integer_mod_q/mat_zq/transpose.rs index 92e63593..4c11538e 100644 --- a/src/integer_mod_q/mat_zq/transpose.rs +++ b/src/integer_mod_q/mat_zq/transpose.rs @@ -29,7 +29,7 @@ impl MatZq { /// ``` pub fn transpose(&self) -> Self { let mut out = Self::new(self.get_num_columns(), self.get_num_rows(), self.get_mod()); - unsafe { fmpz_mat_transpose(&mut out.matrix.mat[0], &self.matrix.mat[0]) }; + unsafe { fmpz_mat_transpose(&mut out.matrix, &self.matrix) }; out } } diff --git a/src/integer_mod_q/mat_zq/unsafe_functions.rs b/src/integer_mod_q/mat_zq/unsafe_functions.rs index bd601670..c325a255 100644 --- a/src/integer_mod_q/mat_zq/unsafe_functions.rs +++ b/src/integer_mod_q/mat_zq/unsafe_functions.rs @@ -14,14 +14,14 @@ use crate::macros::unsafe_passthrough::{ unsafe_getter, unsafe_getter_indirect, unsafe_setter, unsafe_setter_indirect, }; use flint_sys::{ - fmpz_mod::fmpz_mod_ctx, - fmpz_mod_mat::{fmpz_mod_mat_clear, fmpz_mod_mat_struct}, + fmpz_mat::fmpz_mat_clear, + fmpz_mod_types::{fmpz_mod_ctx, fmpz_mod_mat_struct}, }; unsafe_getter!(MatZq, matrix, fmpz_mod_mat_struct); unsafe_getter_indirect!(MatZq, modulus, get_fmpz_mod_ctx, fmpz_mod_ctx); -unsafe_setter!(MatZq, matrix, fmpz_mod_mat_struct, fmpz_mod_mat_clear); +unsafe_setter!(MatZq, matrix, fmpz_mod_mat_struct, fmpz_mat_clear); unsafe_setter_indirect!(MatZq, modulus, set_fmpz_mod_ctx, fmpz_mod_ctx); #[cfg(test)] @@ -29,25 +29,26 @@ mod test_get_fmpz_mod_mat_struct { use super::MatZq; use std::str::FromStr; - /// Checks availability of the getter for [`MatZq::matrix`] - /// and its ability to be modified. - #[test] - #[allow(unused_mut)] - fn availability_and_modification() { - let mut mat = MatZq::from_str("[[3]] mod 7").unwrap(); + // / Checks availability of the getter for [`MatZq::matrix`] + // / and its ability to be modified. + // #[test] + // #[allow(unused_mut)] + // fn availability_and_modification() { + // let mut mat = MatZq::from_str("[[3]] mod 7").unwrap(); - let mut fmpz_mat = unsafe { mat.get_fmpz_mod_mat_struct() }; + // let mut fmpz_mat = unsafe { mat.get_fmpz_mod_mat_struct() }; - fmpz_mat.mod_[0].0 = 5; + // fmpz_mat.mod_[0].0 = 5; - assert_eq!(MatZq::from_str("[[3]] mod 5").unwrap(), mat); - } + // assert_eq!(MatZq::from_str("[[3]] mod 5").unwrap(), mat); + // } } #[cfg(test)] mod test_set_fmpz_mod_mat_struct { use super::MatZq; - use flint_sys::{fmpz::fmpz, fmpz_mod_mat::fmpz_mod_mat_init}; + use crate::integer_mod_q::Modulus; + use flint_sys::fmpz_mod_mat::fmpz_mod_mat_init; use std::{mem::MaybeUninit, str::FromStr}; /// Checks availability of the setter for [`MatZq::matrix`] @@ -56,8 +57,14 @@ mod test_set_fmpz_mod_mat_struct { fn availability_and_modification() { let mut mat = MatZq::from_str("[[3]] mod 7").unwrap(); let mut flint_struct = MaybeUninit::uninit(); + let modulus = Modulus::from(7); let flint_struct = unsafe { - fmpz_mod_mat_init(flint_struct.as_mut_ptr(), 1, 1, &fmpz(7)); + fmpz_mod_mat_init( + flint_struct.as_mut_ptr(), + 1, + 1, + modulus.get_fmpz_mod_ctx_struct(), + ); flint_struct.assume_init() }; diff --git a/src/integer_mod_q/mat_zq/vector/norm.rs b/src/integer_mod_q/mat_zq/vector/norm.rs index 3a1c37c6..dcf99e9e 100644 --- a/src/integer_mod_q/mat_zq/vector/norm.rs +++ b/src/integer_mod_q/mat_zq/vector/norm.rs @@ -11,8 +11,11 @@ use super::super::MatZq; use crate::{ - error::MathError, integer::Z, integer_mod_q::fmpz_mod_helpers::length, rational::Q, - traits::MatrixDimensions, + error::MathError, + integer::Z, + integer_mod_q::fmpz_mod_helpers::length, + rational::Q, + traits::{AsInteger, MatrixDimensions}, }; use flint_sys::fmpz::fmpz_addmul; @@ -131,7 +134,7 @@ impl MatZq { // compute lengths of all entries in matrix with regards to modulus // and find maximum length - let modulus = self.matrix.mod_[0]; + let modulus = unsafe { self.get_mod().into_fmpz() }; let mut max = Z::ZERO; for fmpz_entry in fmpz_entries { let length = length(&fmpz_entry, &modulus); diff --git a/src/integer_mod_q/modulus.rs b/src/integer_mod_q/modulus.rs index faa57c1c..29ca3490 100644 --- a/src/integer_mod_q/modulus.rs +++ b/src/integer_mod_q/modulus.rs @@ -14,7 +14,8 @@ //! //! This implementation uses the [FLINT](https://flintlib.org/) library. -use flint_sys::fmpz_mod::fmpz_mod_ctx; +use crate::integer::debug_fmpz; +use flint_sys::{flint::nmod_t, fmpz_mod_types::fmpz_mod_ctx}; use std::{fmt, rc::Rc}; mod cmp; @@ -71,8 +72,38 @@ impl fmt::Debug for Modulus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "Modulus {{ modulus: {}, storage: {{modulus: {:?}}}}}", - self, self.modulus + "Modulus {{ modulus: {}, storage: {{ modulus: {}}}}}", + self, + debug_fmpz_mod_ctx(&self.modulus) ) } } + +macro_rules! debug_fn_ptr { + ($opt_fn:expr) => { + match $opt_fn { + Some(f) => format!("Some({:#x})", f as usize), + None => "None".to_string(), + } + }; +} + +fn debug_fmpz_mod_ctx(value: &fmpz_mod_ctx) -> String { + format!( + "fmpz_mod_ctx {{ n: [{}], add_fxn: {}, sub_fxn: {}, mul_fxn: {}, mod_: {}, n_limbs: {:?}, ninv_limbs: {:?}}}", + debug_fmpz(&value.n[0]), + debug_fn_ptr!(value.add_fxn), + debug_fn_ptr!(value.sub_fxn), + debug_fn_ptr!(value.mul_fxn), + debug_nmod_t(&value.mod_), + value.n_limbs, + value.ninv_limbs + ) +} + +fn debug_nmod_t(value: &nmod_t) -> String { + format!( + "nmod_t {{ n: {}, ninv: {}, norm: {} }}", + value.n, value.ninv, value.norm + ) +} diff --git a/src/integer_mod_q/modulus/cmp.rs b/src/integer_mod_q/modulus/cmp.rs index e3c9622f..75fb415f 100644 --- a/src/integer_mod_q/modulus/cmp.rs +++ b/src/integer_mod_q/modulus/cmp.rs @@ -16,11 +16,11 @@ use crate::{ integer::Z, macros::for_others::{implement_for_others, implement_trait_reverse}, }; -use flint_sys::fmpz::{fmpz, fmpz_cmp, fmpz_equal}; +use flint_sys::fmpz::{fmpz_cmp, fmpz_equal}; use std::cmp::Ordering; impl PartialEq for Modulus { - /// Compares the two [`fmpz`](flint_sys::fmpz::fmpz) structs hiding behind the + /// Compares the two [`fmpz`](flint_sys::flint::fmpz) structs hiding behind the /// given [`Modulus`] instances to check whether the given [`Modulus`] instances /// have the same value. /// @@ -42,7 +42,7 @@ impl PartialEq for Modulus { fn eq(&self, other: &Self) -> bool { unsafe { 1 == flint_sys::fmpz::fmpz_equal( - &self.get_fmpz_mod_ctx_struct().to_owned().n[0], + &self.modulus.n[0], &other.get_fmpz_mod_ctx_struct().to_owned().n[0], ) } @@ -94,7 +94,7 @@ impl PartialEq for Modulus { implement_trait_reverse!(PartialEq, eq, Z, Modulus, bool); -implement_for_others!(Z, Modulus, PartialEq for fmpz i8 i16 i32 i64 u8 u16 u32 u64); +implement_for_others!(Z, Modulus, PartialEq for i8 i16 i32 i64 u8 u16 u32 u64); impl PartialOrd for Modulus { /// Compares two [`Modulus`] values. Used by the `<`, `<=`, `>`, and `>=` operators. @@ -190,7 +190,7 @@ impl PartialOrd for Modulus { } } -implement_for_others!(Z, Modulus, PartialOrd for fmpz i8 i16 i32 i64 u8 u16 u32 u64); +implement_for_others!(Z, Modulus, PartialOrd for i8 i16 i32 i64 u8 u16 u32 u64); #[cfg(test)] mod test_eq { diff --git a/src/integer_mod_q/modulus/fmpz_helpers.rs b/src/integer_mod_q/modulus/fmpz_helpers.rs index 987d2033..eec00f1c 100644 --- a/src/integer_mod_q/modulus/fmpz_helpers.rs +++ b/src/integer_mod_q/modulus/fmpz_helpers.rs @@ -10,7 +10,7 @@ use super::Modulus; use crate::traits::AsInteger; -use flint_sys::fmpz::{fmpz, fmpz_init_set}; +use flint_sys::{flint::fmpz, fmpz::fmpz_init_set}; unsafe impl AsInteger for Modulus { /// Documentation at [`AsInteger::into_fmpz`] @@ -27,7 +27,7 @@ unsafe impl AsInteger for Modulus { unsafe impl AsInteger for &Modulus { /// Documentation at [`AsInteger::into_fmpz`] unsafe fn into_fmpz(self) -> fmpz { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_init_set(&mut out, &self.modulus.n[0]) }; out } diff --git a/src/integer_mod_q/modulus/from.rs b/src/integer_mod_q/modulus/from.rs index 194ff2cf..7002779c 100644 --- a/src/integer_mod_q/modulus/from.rs +++ b/src/integer_mod_q/modulus/from.rs @@ -15,7 +15,8 @@ use crate::{ error::MathError, integer::Z, macros::for_others::implement_empty_trait_owned_ref, traits::*, }; use flint_sys::{ - fmpz::{fmpz, fmpz_clear, fmpz_cmp_si}, + flint::fmpz, + fmpz::{fmpz_clear, fmpz_cmp_si}, fmpz_mod::fmpz_mod_ctx_init, }; use std::{mem::MaybeUninit, rc::Rc, str::FromStr}; @@ -68,7 +69,7 @@ impl Modulus { /// with the default implementation for [`Modulus`] and also to filter out /// [`Zq`](crate::integer_mod_q::Zq) and &[`Modulus`]. trait IntoModulus {} -implement_empty_trait_owned_ref!(IntoModulus for Z fmpz u8 u16 u32 u64 i8 i16 i32 i64); +implement_empty_trait_owned_ref!(IntoModulus for Z u8 u16 u32 u64 i8 i16 i32 i64); impl From for Modulus { /// Creates a [`Modulus`] from a positive integer. diff --git a/src/integer_mod_q/modulus/get.rs b/src/integer_mod_q/modulus/get.rs index a1ae72a1..99ab1c24 100644 --- a/src/integer_mod_q/modulus/get.rs +++ b/src/integer_mod_q/modulus/get.rs @@ -9,7 +9,7 @@ //! Implementations to get information about a [`Modulus`]. use super::Modulus; -use flint_sys::fmpz_mod::fmpz_mod_ctx_struct; +use flint_sys::fmpz_mod_types::fmpz_mod_ctx_struct; impl Modulus { /// Returns the [`fmpz_mod_ctx_struct`] of a modulus and is only used internally. diff --git a/src/integer_mod_q/modulus/ownership.rs b/src/integer_mod_q/modulus/ownership.rs index 4eb4389b..5960e7ed 100644 --- a/src/integer_mod_q/modulus/ownership.rs +++ b/src/integer_mod_q/modulus/ownership.rs @@ -17,7 +17,7 @@ use std::rc::Rc; impl Clone for Modulus { /// Clones the given element and returns another cloned reference - /// to the [`fmpz_mod_ctx`](flint_sys::fmpz_mod::fmpz_mod_ctx) element. + /// to the [`fmpz_mod_ctx`](flint_sys::fmpz_mod_types::fmpz_mod_ctx) element. /// /// # Examples /// ``` @@ -35,7 +35,7 @@ impl Clone for Modulus { } impl Drop for Modulus { - /// Drops the given reference to the [`fmpz_mod_ctx`](flint_sys::fmpz_mod::fmpz_mod_ctx) element + /// Drops the given reference to the [`fmpz_mod_ctx`](flint_sys::fmpz_mod_types::fmpz_mod_ctx) element /// and frees the allocated memory if no references are left. /// /// # Examples @@ -56,7 +56,7 @@ impl Drop for Modulus { /// ``` fn drop(&mut self) { if Rc::strong_count(&self.modulus) <= 1 { - let mut a = *self.modulus; + let mut a = unsafe { std::ptr::read(self.modulus.as_ref()) }; unsafe { fmpz_mod_ctx_clear(&mut a); } @@ -96,8 +96,8 @@ mod test_clone { let b = a.clone(); assert_eq!( - &a.get_fmpz_mod_ctx_struct().to_owned().n[0].0, - &b.get_fmpz_mod_ctx_struct().to_owned().n[0].0 + &a.get_fmpz_mod_ctx_struct().to_owned().n[0], + &b.get_fmpz_mod_ctx_struct().to_owned().n[0] ); } } @@ -139,7 +139,7 @@ mod test_drop { /// the storage point in memory of that [`Modulus`] fn create_and_drop_modulus() -> i64 { let a = Modulus::from_str(&"1".repeat(65)).unwrap(); - a.get_fmpz_mod_ctx_struct().n[0].0 + a.get_fmpz_mod_ctx_struct().n[0] } /// Check whether freed memory is reused afterwards diff --git a/src/integer_mod_q/modulus/properties.rs b/src/integer_mod_q/modulus/properties.rs index 65cc3868..38268fee 100644 --- a/src/integer_mod_q/modulus/properties.rs +++ b/src/integer_mod_q/modulus/properties.rs @@ -25,7 +25,7 @@ impl Modulus { /// assert!(modulus.is_prime()); /// ``` pub fn is_prime(&self) -> bool { - 1 == unsafe { fmpz_is_prime(&self.get_fmpz_mod_ctx_struct().n[0]) } + 1 == unsafe { fmpz_is_prime(&self.modulus.n[0]) } } } diff --git a/src/integer_mod_q/modulus/unsafe_functions.rs b/src/integer_mod_q/modulus/unsafe_functions.rs index 86278cc4..752a6143 100644 --- a/src/integer_mod_q/modulus/unsafe_functions.rs +++ b/src/integer_mod_q/modulus/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::Modulus; use crate::macros::unsafe_passthrough::unsafe_getter_mod; -use flint_sys::fmpz_mod::{fmpz_mod_ctx, fmpz_mod_ctx_clear}; +use flint_sys::{fmpz_mod::fmpz_mod_ctx_clear, fmpz_mod_types::fmpz_mod_ctx}; unsafe_getter_mod!(Modulus, modulus, fmpz_mod_ctx); @@ -70,7 +70,7 @@ mod test_get_fmpz_mod_ctx { let mut fmpz_mod = unsafe { modulus.get_fmpz_mod_ctx() }; - fmpz_mod.n[0].0 = 2; + fmpz_mod.n[0] = 2; assert_eq!(Modulus::from(2), modulus); } @@ -79,7 +79,7 @@ mod test_get_fmpz_mod_ctx { #[cfg(test)] mod test_set_fmpz_mod_ctx { use super::Modulus; - use flint_sys::{fmpz::fmpz, fmpz_mod::fmpz_mod_ctx_init}; + use flint_sys::fmpz_mod::fmpz_mod_ctx_init; use std::mem::MaybeUninit; /// Checks availability of the setter for [`Modulus::modulus`] @@ -91,7 +91,7 @@ mod test_set_fmpz_mod_ctx { let mut flint_struct = MaybeUninit::uninit(); let mut flint_struct = unsafe { - fmpz_mod_ctx_init(flint_struct.as_mut_ptr(), &fmpz(2)); + fmpz_mod_ctx_init(flint_struct.as_mut_ptr(), &2); flint_struct.assume_init() }; diff --git a/src/integer_mod_q/modulus_polynomial_ring_zq.rs b/src/integer_mod_q/modulus_polynomial_ring_zq.rs index 28df45de..e5102cf2 100644 --- a/src/integer_mod_q/modulus_polynomial_ring_zq.rs +++ b/src/integer_mod_q/modulus_polynomial_ring_zq.rs @@ -12,7 +12,7 @@ use super::ntt_basis_polynomial_ring_zq::NTTBasisPolynomialRingZq; use crate::integer_mod_q::PolyOverZq; -use std::{fmt, rc::Rc}; +use std::rc::Rc; mod cmp; mod coefficient_embedding; @@ -40,18 +40,9 @@ mod to_string; /// let poly_mod = PolyOverZq::from_str("3 1 0 1 mod 17").unwrap(); /// let modulus = ModulusPolynomialRingZq::from(poly_mod); /// ``` +#[derive(Debug)] pub struct ModulusPolynomialRingZq { pub(crate) modulus: Rc, pub(crate) ntt_basis: Rc>, pub(crate) non_zero: Vec, } - -impl fmt::Debug for ModulusPolynomialRingZq { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "ModulusPolynomialRingZq {{ modulus: {}, storage: {{modulus: {:?}}}}}", - self, self.modulus - ) - } -} diff --git a/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs b/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs index 60bb9cd2..095ef591 100644 --- a/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs +++ b/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs @@ -16,7 +16,7 @@ use std::rc::Rc; impl Clone for ModulusPolynomialRingZq { /// Clones the given element and returns another cloned reference - /// to the [`fq_ctx_struct`](flint_sys::fq::fq_ctx_struct) element. + /// to the [`fq_ctx_struct`](flint_sys::fq_types::fq_ctx_struct) element. /// /// # Examples /// ``` diff --git a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs index a74aa285..c1b80e0e 100644 --- a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs +++ b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs @@ -20,8 +20,9 @@ use crate::{ }; use flint_sys::{ fmpz::fmpz_swap, - fmpz_mod::{fmpz_mod_add, fmpz_mod_ctx, fmpz_mod_mul, fmpz_mod_sub_fmpz}, + fmpz_mod::{fmpz_mod_add, fmpz_mod_mul, fmpz_mod_sub_fmpz}, fmpz_mod_poly::fmpz_mod_poly_set_coeff_fmpz, + fmpz_mod_types::fmpz_mod_ctx, }; impl NTTBasisPolynomialRingZq { diff --git a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs index 02039057..d2040211 100644 --- a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs +++ b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs @@ -19,7 +19,10 @@ use crate::{ traits::GetCoefficient, utils::index::bit_reverse_permutation, }; -use flint_sys::fmpz_mod::{fmpz_mod_add, fmpz_mod_ctx, fmpz_mod_mul, fmpz_mod_sub}; +use flint_sys::{ + fmpz_mod::{fmpz_mod_add, fmpz_mod_mul, fmpz_mod_sub}, + fmpz_mod_types::fmpz_mod_ctx, +}; impl NTTBasisPolynomialRingZq { /// For a given polynomial viewed in the polynomial ring defined by the `self`, it computes the NTT. diff --git a/src/integer_mod_q/ntt_polynomial_ring_zq.rs b/src/integer_mod_q/ntt_polynomial_ring_zq.rs index b498a4b1..23bfef12 100644 --- a/src/integer_mod_q/ntt_polynomial_ring_zq.rs +++ b/src/integer_mod_q/ntt_polynomial_ring_zq.rs @@ -14,7 +14,6 @@ use crate::{ }; use derive_more::Display; use serde::{Deserialize, Serialize}; -use std::fmt; mod arithmetic; mod cmp; @@ -54,23 +53,9 @@ mod sample; /// // Return to PolynomialRingZq /// let res = tmp_ntt.inv_ntt(); /// ``` -#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone)] +#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone, Debug)] #[display("{} / {}", print_vec_z(&self.poly), self.modulus)] pub struct NTTPolynomialRingZq { pub poly: Vec, pub modulus: ModulusPolynomialRingZq, } - -impl fmt::Debug for NTTPolynomialRingZq { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let short_print = print_vec_z(&self.poly); - let a: Vec<&str> = short_print.split_whitespace().collect(); - let short_print = format!("{}{} ..., {}{}", a[0], a[1], a[a.len() - 2], a[a.len() - 1]); - - write!( - f, - "NTTPolynomialRingZq {{poly: {}, modulus: {}, storage: {{poly: {:?}, modulus: {:?}}}}}", - short_print, self.modulus, self.poly, self.modulus - ) - } -} diff --git a/src/integer_mod_q/poly_over_zq.rs b/src/integer_mod_q/poly_over_zq.rs index 535703c2..167a84fa 100644 --- a/src/integer_mod_q/poly_over_zq.rs +++ b/src/integer_mod_q/poly_over_zq.rs @@ -15,7 +15,7 @@ // values. The end-user should be unable to obtain a non-reduced value. use super::modulus::Modulus; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_struct; +use flint_sys::fmpz_mod_types::fmpz_mod_poly_struct; use std::fmt; mod arithmetic; @@ -72,8 +72,19 @@ impl fmt::Debug for PolyOverZq { write!( f, "PolyOverZq {{poly: {}\ - storage: {{poly: {:?}, modulus: {:?}}}}}", - self, self.poly, self.modulus + storage: {{poly: {}, modulus: {:?}}}}}", + self, + debug_fmpz_mod_poly_struct(&self.poly), + self.modulus ) } } + +fn debug_fmpz_mod_poly_struct(value: &fmpz_mod_poly_struct) -> String { + format!( + "fmpz_mod_poly_struct {{ coeffs: {:#x}, alloc: {}, length: {} }}", + value.coeffs.addr(), + value.alloc, + value.length + ) +} diff --git a/src/integer_mod_q/poly_over_zq/ownership.rs b/src/integer_mod_q/poly_over_zq/ownership.rs index a9b8bd96..90943e7c 100644 --- a/src/integer_mod_q/poly_over_zq/ownership.rs +++ b/src/integer_mod_q/poly_over_zq/ownership.rs @@ -100,27 +100,23 @@ mod test_clone { // check that Modulus isn't stored twice assert_eq!( - a.modulus.get_fmpz_mod_ctx_struct().n[0].0, - b.modulus.get_fmpz_mod_ctx_struct().n[0].0 + a.modulus.get_fmpz_mod_ctx_struct().n[0], + b.modulus.get_fmpz_mod_ctx_struct().n[0] ); // check that values on heap are stored separately - assert_ne!( - unsafe { *a.poly.coeffs.offset(0) }.0, - unsafe { *b.poly.coeffs.offset(0) }.0 - ); // heap - assert_eq!( - unsafe { *a.poly.coeffs.offset(1) }.0, - unsafe { *b.poly.coeffs.offset(1) }.0 - ); // stack - assert_ne!( - unsafe { *a.poly.coeffs.offset(2) }.0, - unsafe { *b.poly.coeffs.offset(2) }.0 - ); // heap - assert_eq!( - unsafe { *a.poly.coeffs.offset(3) }.0, - unsafe { *b.poly.coeffs.offset(3) }.0 - ); // stack + assert_ne!(unsafe { *a.poly.coeffs.offset(0) }, unsafe { + *b.poly.coeffs.offset(0) + }); // heap + assert_eq!(unsafe { *a.poly.coeffs.offset(1) }, unsafe { + *b.poly.coeffs.offset(1) + }); // stack + assert_ne!(unsafe { *a.poly.coeffs.offset(2) }, unsafe { + *b.poly.coeffs.offset(2) + }); // heap + assert_eq!(unsafe { *a.poly.coeffs.offset(3) }, unsafe { + *b.poly.coeffs.offset(3) + }); // stack // check if length of polynomials is equal assert_eq!(a.poly.length, b.poly.length); @@ -137,10 +133,9 @@ mod test_drop { fn create_and_drop_modulus() -> (i64, i64) { let a = PolyOverZq::from_str(&format!("2 {} -2 mod {}", i64::MAX, u64::MAX)).unwrap(); - ( - unsafe { *a.poly.coeffs.offset(0) }.0, - unsafe { *a.poly.coeffs.offset(1) }.0, - ) + (unsafe { *a.poly.coeffs.offset(0) }, unsafe { + *a.poly.coeffs.offset(1) + }) } /// Check whether freed memory is reused afterwards diff --git a/src/integer_mod_q/poly_over_zq/unsafe_functions.rs b/src/integer_mod_q/poly_over_zq/unsafe_functions.rs index e5a2702a..b5127faf 100644 --- a/src/integer_mod_q/poly_over_zq/unsafe_functions.rs +++ b/src/integer_mod_q/poly_over_zq/unsafe_functions.rs @@ -14,8 +14,8 @@ use crate::macros::unsafe_passthrough::{ unsafe_getter, unsafe_getter_indirect, unsafe_setter_indirect, }; use flint_sys::{ - fmpz_mod::fmpz_mod_ctx, - fmpz_mod_poly::{fmpz_mod_poly_clear, fmpz_mod_poly_struct}, + fmpz_mod_poly::fmpz_mod_poly_clear, fmpz_mod_types::fmpz_mod_ctx, + fmpz_mod_types::fmpz_mod_poly_struct, }; unsafe_getter!(PolyOverZq, poly, fmpz_mod_poly_struct); diff --git a/src/integer_mod_q/polynomial_ring_zq.rs b/src/integer_mod_q/polynomial_ring_zq.rs index d451537f..71b51370 100644 --- a/src/integer_mod_q/polynomial_ring_zq.rs +++ b/src/integer_mod_q/polynomial_ring_zq.rs @@ -20,7 +20,6 @@ use super::ModulusPolynomialRingZq; use crate::integer::PolyOverZ; use derive_more::Display; use serde::{Deserialize, Serialize}; -use std::fmt; mod arithmetic; mod cmp; @@ -69,19 +68,9 @@ mod unsafe_functions; /// /// # Ok::<(), MathError>(()) /// ``` -#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone)] +#[derive(PartialEq, Eq, Serialize, Deserialize, Display, Clone, Debug)] #[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, - "PolynomialRingZq {{poly: {}, modulus {}, storage: {{poly: {:?}, modulus: {:?}}}}}", - self.poly, self.modulus, self.poly, self.modulus - ) - } -} diff --git a/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs b/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs index b68cfa84..8017923f 100644 --- a/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs +++ b/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs @@ -10,7 +10,7 @@ //! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe. use super::PolynomialRingZq; use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect}; -use flint_sys::fmpz_poly::fmpz_poly_struct; +use flint_sys::fmpz_types::fmpz_poly_struct; unsafe_getter_indirect!( PolynomialRingZq, diff --git a/src/integer_mod_q/z_q.rs b/src/integer_mod_q/z_q.rs index 01a56383..26f53ce5 100644 --- a/src/integer_mod_q/z_q.rs +++ b/src/integer_mod_q/z_q.rs @@ -21,7 +21,6 @@ use super::Modulus; use crate::integer::Z; use serde::{Deserialize, Serialize}; -use std::fmt; mod arithmetic; mod cmp; @@ -61,18 +60,8 @@ mod unsafe_functions; /// /// # Ok::<(), MathError>(()) /// ``` -#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] 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, - "Zq {{value: {}, modulus: {}, storage: {{value: {:?} , modulus: {:?}}}}}", - self.value, self.modulus, self.value, self.modulus, - ) - } -} diff --git a/src/integer_mod_q/z_q/arithmetic/add.rs b/src/integer_mod_q/z_q/arithmetic/add.rs index e02a81cf..8ee53ea9 100644 --- a/src/integer_mod_q/z_q/arithmetic/add.rs +++ b/src/integer_mod_q/z_q/arithmetic/add.rs @@ -20,7 +20,7 @@ use crate::{ traits::CompareBase, }; use flint_sys::{ - fmpz::fmpz, + flint::fmpz, fmpz_mod::{fmpz_mod_add, fmpz_mod_add_fmpz, fmpz_mod_add_si, fmpz_mod_add_ui}, }; use std::ops::{Add, AddAssign}; @@ -215,7 +215,7 @@ impl Add<&Z> for &Zq { /// let f: Zq = c + &Z::from(42); /// ``` fn add(self, other: &Z) -> Self::Output { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_mod_add_fmpz( &mut out, diff --git a/src/integer_mod_q/z_q/arithmetic/mul.rs b/src/integer_mod_q/z_q/arithmetic/mul.rs index 6ac1494a..7cec8c6e 100644 --- a/src/integer_mod_q/z_q/arithmetic/mul.rs +++ b/src/integer_mod_q/z_q/arithmetic/mul.rs @@ -20,7 +20,7 @@ use crate::{ traits::CompareBase, }; use flint_sys::{ - fmpz::fmpz, + flint::fmpz, fmpz_mod::{fmpz_mod_mul, fmpz_mod_mul_fmpz, fmpz_mod_mul_si, fmpz_mod_mul_ui}, }; use std::ops::{Mul, MulAssign}; @@ -214,7 +214,7 @@ impl Mul<&Z> for &Zq { /// let f: Zq = c * &Z::from(42); /// ``` fn mul(self, other: &Z) -> Self::Output { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_mod_mul_fmpz( &mut out, diff --git a/src/integer_mod_q/z_q/arithmetic/sub.rs b/src/integer_mod_q/z_q/arithmetic/sub.rs index 2e1cce65..2fac9b5c 100644 --- a/src/integer_mod_q/z_q/arithmetic/sub.rs +++ b/src/integer_mod_q/z_q/arithmetic/sub.rs @@ -20,7 +20,7 @@ use crate::{ traits::CompareBase, }; use flint_sys::{ - fmpz::fmpz, + flint::fmpz, fmpz_mod::{fmpz_mod_sub, fmpz_mod_sub_fmpz, fmpz_mod_sub_si, fmpz_mod_sub_ui}, }; use std::ops::{Sub, SubAssign}; @@ -215,7 +215,7 @@ impl Sub<&Z> for &Zq { /// let f: Zq = c - &Z::from(42); /// ``` fn sub(self, other: &Z) -> Self::Output { - let mut out = fmpz(0); + let mut out: fmpz = 0; unsafe { fmpz_mod_sub_fmpz( &mut out, diff --git a/src/integer_mod_q/z_q/fmpz_mod_helpers.rs b/src/integer_mod_q/z_q/fmpz_mod_helpers.rs index e085656a..1f5c877c 100644 --- a/src/integer_mod_q/z_q/fmpz_mod_helpers.rs +++ b/src/integer_mod_q/z_q/fmpz_mod_helpers.rs @@ -13,9 +13,9 @@ use crate::{ integer::{Z, fmpz_helpers::distance}, traits::AsInteger, }; -use flint_sys::fmpz::fmpz; +use flint_sys::flint::fmpz; -const ZERO_FMPZ: fmpz = fmpz(0); +const ZERO_FMPZ: fmpz = 0; /// Computes the shortest distance of `self` to the next zero instance /// regarding the `modulus`. @@ -110,7 +110,7 @@ mod test_as_integer_zq { let value = unsafe { (&zq).into_fmpz() }; // The `fmpz` values have to point to different memory locations. - assert_ne!(value.0, zq.value.value.0); + assert_ne!(value, zq.value.value); } /// Assert that `get_fmpz_ref` returns a correct reference for small values @@ -122,8 +122,8 @@ mod test_as_integer_zq { let zq_ref_value_1 = zq.get_fmpz_ref().unwrap(); let zq_ref_value_2 = (&zq).get_fmpz_ref().unwrap(); - assert_eq!(zq.value.value.0, zq_ref_value_1.0); - assert_eq!(zq.value.value.0, zq_ref_value_2.0); + assert_eq!(&zq.value.value, zq_ref_value_1); + assert_eq!(&zq.value.value, zq_ref_value_2); } /// Assert that `get_fmpz_ref` returns a correct reference for large values @@ -135,8 +135,8 @@ mod test_as_integer_zq { let zq_ref_value_1 = zq.get_fmpz_ref().unwrap(); let zq_ref_value_2 = (&zq).get_fmpz_ref().unwrap(); - assert_eq!(zq.value.value.0, zq_ref_value_1.0); - assert_eq!(zq.value.value.0, zq_ref_value_2.0); + assert_eq!(&zq.value.value, zq_ref_value_1); + assert_eq!(&zq.value.value, zq_ref_value_2); } } @@ -149,10 +149,10 @@ mod test_length { /// (shortest distance to next zero is found) for small values #[test] fn small_values() { - let modulus = fmpz(15); - let pos_1 = fmpz(10); - let pos_2 = fmpz(7); - let zero = fmpz(0); + let modulus = 15; + let pos_1 = 10; + let pos_2 = 7; + let zero = 0; assert_eq!(Z::from(5), length(&pos_1, &modulus)); assert_eq!(Z::from(7), length(&pos_2, &modulus)); diff --git a/src/integer_mod_q/z_q/unsafe_functions.rs b/src/integer_mod_q/z_q/unsafe_functions.rs index 3cd91eb3..8bbc6dc0 100644 --- a/src/integer_mod_q/z_q/unsafe_functions.rs +++ b/src/integer_mod_q/z_q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::Zq; use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect}; -use flint_sys::{fmpz::fmpz, fmpz_mod::fmpz_mod_ctx}; +use flint_sys::{flint::fmpz, fmpz_mod_types::fmpz_mod_ctx}; unsafe_getter_indirect!(Zq, value, get_fmpz, fmpz); unsafe_getter_indirect!(Zq, modulus, get_fmpz_mod_ctx, fmpz_mod_ctx); diff --git a/src/rational/mat_q.rs b/src/rational/mat_q.rs index 28670dd4..699bf2c4 100644 --- a/src/rational/mat_q.rs +++ b/src/rational/mat_q.rs @@ -14,7 +14,7 @@ // values. The end-user should be unable to obtain a non-reduced value. use crate::utils::parse::partial_string; -use flint_sys::fmpq_mat::fmpq_mat_struct; +use flint_sys::fmpq_types::fmpq_mat_struct; use std::fmt; mod arithmetic; @@ -94,10 +94,20 @@ impl fmt::Debug for MatQ { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "MatQ: {{matrix: {}, storage: {:?}}}", + "MatQ: {{matrix: {}, storage: {{ matrix: {}}}}}", // printing the entire matrix is not meaningful for large matrices partial_string(self, 3, 3), - self.matrix + debug_fmpq_mat_struct(&self.matrix) ) } } + +fn debug_fmpq_mat_struct(value: &fmpq_mat_struct) -> String { + format!( + "fmpq_mat_struct {{ entries: {:#x}, r: {}, c: {}, stride: {} }}", + value.entries.addr(), + value.r, + value.c, + value.stride + ) +} diff --git a/src/rational/mat_q/cmp.rs b/src/rational/mat_q/cmp.rs index cf58fe5c..a9dbfdd5 100644 --- a/src/rational/mat_q/cmp.rs +++ b/src/rational/mat_q/cmp.rs @@ -15,10 +15,7 @@ use crate::{ rational::Q, traits::{CompareBase, MatrixDimensions, MatrixGetEntry}, }; -use flint_sys::{ - fmpq_mat::{fmpq_mat_equal, fmpq_mat_set_fmpz_mat_div_fmpz}, - fmpz::fmpz, -}; +use flint_sys::fmpq_mat::{fmpq_mat_equal, fmpq_mat_set_fmpz_mat_div_fmpz}; impl PartialEq for MatQ { /// Checks if two [`MatQ`] instances are equal. Used by the `==` and `!=` operators. @@ -116,7 +113,7 @@ impl PartialEq for MatQ { impl MatQ { pub fn equal(self, other: MatZ) -> bool { let mut other_matq = MatQ::new(other.get_num_rows(), other.get_num_columns()); - unsafe { fmpq_mat_set_fmpz_mat_div_fmpz(&mut other_matq.matrix, &other.matrix, &fmpz(1)) }; + unsafe { fmpq_mat_set_fmpz_mat_div_fmpz(&mut other_matq.matrix, &other.matrix, &1) }; 1 != unsafe { fmpq_mat_equal(&other_matq.matrix, &self.matrix) } } } diff --git a/src/rational/mat_q/get.rs b/src/rational/mat_q/get.rs index ccdd61b0..330a2bea 100644 --- a/src/rational/mat_q/get.rs +++ b/src/rational/mat_q/get.rs @@ -12,10 +12,7 @@ use super::MatQ; use crate::rational::Q; use crate::traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}; use flint_sys::fmpq_mat::{fmpq_mat_init_set, fmpq_mat_window_clear, fmpq_mat_window_init}; -use flint_sys::{ - fmpq::{fmpq, fmpq_set}, - fmpq_mat::fmpq_mat_entry, -}; +use flint_sys::{flint::fmpq, fmpq::fmpq_set, fmpq_mat::fmpq_mat_entry}; use std::mem::MaybeUninit; impl MatrixDimensions for MatQ { @@ -179,7 +176,7 @@ impl MatQ { for row in 0..self.get_num_rows() { for col in 0..self.get_num_columns() { // efficiently get entry without cloning the entry itself - let entry = unsafe { *fmpq_mat_entry(&self.matrix, row, col) }; + let entry = unsafe { std::ptr::read(fmpq_mat_entry(&self.matrix, row, col)) }; entries.push(entry); } } @@ -635,24 +632,24 @@ mod test_collect_entries { let entries_2 = mat_2.collect_entries(); assert_eq!(entries_1.len(), 6); - assert_eq!(entries_1[0].num.0, 1); - assert!(entries_1[0].den.0 >= 2_i64.pow(62)); - assert_eq!(entries_1[1].num.0, 2); - assert_eq!(entries_1[1].den.0, 1); - assert!(entries_1[2].num.0 >= 2_i64.pow(62)); - assert_eq!(entries_1[2].den.0, 1); - assert!(entries_1[3].num.0 >= 2_i64.pow(62)); - assert_eq!(entries_1[3].den.0, 1); - assert_eq!(entries_1[4].num.0, 3); - assert_eq!(entries_1[4].den.0, 4); - assert_eq!(entries_1[5].num.0, 4); - assert_eq!(entries_1[5].den.0, 1); + assert_eq!(entries_1[0].num, 1); + assert!(entries_1[0].den >= 2_i64.pow(62)); + assert_eq!(entries_1[1].num, 2); + assert_eq!(entries_1[1].den, 1); + assert!(entries_1[2].num >= 2_i64.pow(62)); + assert_eq!(entries_1[2].den, 1); + assert!(entries_1[3].num >= 2_i64.pow(62)); + assert_eq!(entries_1[3].den, 1); + assert_eq!(entries_1[4].num, 3); + assert_eq!(entries_1[4].den, 4); + assert_eq!(entries_1[5].num, 4); + assert_eq!(entries_1[5].den, 1); assert_eq!(entries_2.len(), 2); - assert_eq!(entries_2[0].num.0, -1); - assert_eq!(entries_2[0].den.0, 1); - assert_eq!(entries_2[1].num.0, -1); - assert_eq!(entries_2[1].den.0, 2); + assert_eq!(entries_2[0].num, -1); + assert_eq!(entries_2[0].den, 1); + assert_eq!(entries_2[1].num, -1); + assert_eq!(entries_2[1].den, 2); } /// Ensures that all entries from the matrices are actually collected diff --git a/src/rational/mat_q/ownership.rs b/src/rational/mat_q/ownership.rs index eaf9727a..a08ce938 100644 --- a/src/rational/mat_q/ownership.rs +++ b/src/rational/mat_q/ownership.rs @@ -114,29 +114,29 @@ mod test_clone { a = b.clone(); assert_ne!( - a.get_entry(0, 0).unwrap().value.num.0, - b.get_entry(0, 0).unwrap().value.num.0 + a.get_entry(0, 0).unwrap().value.num, + b.get_entry(0, 0).unwrap().value.num ); assert_ne!( - a.get_entry(0, 1).unwrap().value.num.0, - b.get_entry(0, 1).unwrap().value.num.0 + a.get_entry(0, 1).unwrap().value.num, + b.get_entry(0, 1).unwrap().value.num ); assert_ne!( - a.get_entry(1, 0).unwrap().value.num.0, - b.get_entry(1, 0).unwrap().value.num.0 + a.get_entry(1, 0).unwrap().value.num, + b.get_entry(1, 0).unwrap().value.num ); assert_ne!( - a.get_entry(1, 1).unwrap().value.num.0, - b.get_entry(1, 1).unwrap().value.num.0 + a.get_entry(1, 1).unwrap().value.num, + b.get_entry(1, 1).unwrap().value.num ); assert_ne!( - a.get_entry(1, 1).unwrap().value.den.0, - b.get_entry(1, 1).unwrap().value.den.0 + a.get_entry(1, 1).unwrap().value.den, + b.get_entry(1, 1).unwrap().value.den ); assert_eq!( - a.get_entry(0, 1).unwrap().value.den.0, - b.get_entry(0, 1).unwrap().value.den.0 + a.get_entry(0, 1).unwrap().value.den, + b.get_entry(0, 1).unwrap().value.den ); // reduction applied, hence kept on stack } } @@ -155,10 +155,10 @@ mod test_drop { let string = format!("[[{}/{}, {}/{}]]", u64::MAX, i64::MIN, i64::MAX, 1); let a = MatQ::from_str(&string).unwrap(); - let storage_num_0 = a.get_entry(0, 0).unwrap().value.num.0; - let storage_num_1 = a.get_entry(0, 1).unwrap().value.num.0; - let storage_den_0 = a.get_entry(0, 0).unwrap().value.den.0; - let storage_den_1 = a.get_entry(0, 1).unwrap().value.den.0; + let storage_num_0 = a.get_entry(0, 0).unwrap().value.num; + let storage_num_1 = a.get_entry(0, 1).unwrap().value.num; + let storage_den_0 = a.get_entry(0, 0).unwrap().value.den; + let storage_den_1 = a.get_entry(0, 1).unwrap().value.den; (storage_num_0, storage_num_1, storage_den_0, storage_den_1) } diff --git a/src/rational/mat_q/set.rs b/src/rational/mat_q/set.rs index 3ed745c5..294211eb 100644 --- a/src/rational/mat_q/set.rs +++ b/src/rational/mat_q/set.rs @@ -21,11 +21,7 @@ use flint_sys::{ fmpq_mat_swap_cols, fmpq_mat_swap_rows, fmpq_mat_window_clear, fmpq_mat_window_init, }, }; -use std::{ - fmt::Display, - mem::MaybeUninit, - ptr::{null, null_mut}, -}; +use std::{fmt::Display, mem::MaybeUninit, ptr::null_mut}; impl> MatrixSetEntry for MatQ { /// Sets the value of a specific matrix entry according to a given `value` @@ -241,7 +237,7 @@ impl MatrixSwaps for MatQ { }, )); } - unsafe { fmpq_mat_swap_cols(&mut self.matrix, null(), col_0, col_1) } + unsafe { fmpq_mat_swap_cols(&mut self.matrix, null_mut(), col_0, col_1) } Ok(()) } @@ -287,7 +283,7 @@ impl MatrixSwaps for MatQ { }, )); } - unsafe { fmpq_mat_swap_rows(&mut self.matrix, null(), row_0, row_1) } + unsafe { fmpq_mat_swap_rows(&mut self.matrix, null_mut(), row_0, row_1) } Ok(()) } } diff --git a/src/rational/mat_q/unsafe_functions.rs b/src/rational/mat_q/unsafe_functions.rs index d4733a05..12cde237 100644 --- a/src/rational/mat_q/unsafe_functions.rs +++ b/src/rational/mat_q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::MatQ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::fmpq_mat::{fmpq_mat_clear, fmpq_mat_struct}; +use flint_sys::{fmpq_mat::fmpq_mat_clear, fmpq_types::fmpq_mat_struct}; unsafe_getter!(MatQ, matrix, fmpq_mat_struct); diff --git a/src/rational/poly_over_q.rs b/src/rational/poly_over_q.rs index cac3e872..b98e827d 100644 --- a/src/rational/poly_over_q.rs +++ b/src/rational/poly_over_q.rs @@ -15,7 +15,8 @@ // canonical/reduced values. The end-user should be unable to obtain a // non-reduced value. -use flint_sys::fmpq_poly::fmpq_poly_struct; +use crate::integer::debug_fmpz; +use flint_sys::fmpq_types::fmpq_poly_struct; use std::fmt; mod arithmetic; @@ -68,10 +69,20 @@ impl fmt::Debug for PolyOverQ { write!( f, "PolyOverQ {{poly_f64(may be rounded; 5 decimals): {}, poly: {}, \ - storage: {{poly: {:?}}}}}", + storage: {{ poly: {}}}}}", self.to_string_decimal(5), self, - self.poly + debug_fmpq_poly_struct(&self.poly) ) } } + +fn debug_fmpq_poly_struct(value: &fmpq_poly_struct) -> String { + format!( + "fmpq_poly_struct {{ coeffs: {:#x}, den: [{}], alloc: {}, length: {} }}", + value.coeffs.addr(), + debug_fmpz(&value.den[0]), + value.alloc, + value.length + ) +} diff --git a/src/rational/poly_over_q/ownership.rs b/src/rational/poly_over_q/ownership.rs index 5f98c9ef..20b54880 100644 --- a/src/rational/poly_over_q/ownership.rs +++ b/src/rational/poly_over_q/ownership.rs @@ -25,7 +25,7 @@ unsafe impl Sync for PolyOverQ {} impl Clone for PolyOverQ { /// Clones the given [`PolyOverQ`] element by returning a deep clone, - /// storing two separately stored [fmpz](flint_sys::fmpz::fmpz) values + /// storing two separately stored [fmpz](flint_sys::flint::fmpz) values /// for `nominator` and `denominator` in memory. /// /// # Examples @@ -85,26 +85,22 @@ mod test_clone { // check that nominators on stack should are equal, // as they directly store the value in the `i64` - assert_eq!( - unsafe { *a.poly.coeffs.offset(0) }.0, - unsafe { *b.poly.coeffs.offset(0) }.0 - ); // stack - - assert_eq!( - unsafe { *a.poly.coeffs.offset(1) }.0, - unsafe { *b.poly.coeffs.offset(1) }.0 - ); // stack - assert_eq!( - unsafe { *a.poly.coeffs.offset(2) }.0, - unsafe { *b.poly.coeffs.offset(2) }.0 - ); // stack - assert_eq!( - unsafe { *a.poly.coeffs.offset(3) }.0, - unsafe { *b.poly.coeffs.offset(3) }.0 - ); // stack + assert_eq!(unsafe { *a.poly.coeffs.offset(0) }, unsafe { + *b.poly.coeffs.offset(0) + }); // stack + + assert_eq!(unsafe { *a.poly.coeffs.offset(1) }, unsafe { + *b.poly.coeffs.offset(1) + }); // stack + assert_eq!(unsafe { *a.poly.coeffs.offset(2) }, unsafe { + *b.poly.coeffs.offset(2) + }); // stack + assert_eq!(unsafe { *a.poly.coeffs.offset(3) }, unsafe { + *b.poly.coeffs.offset(3) + }); // stack // denominator should be kept on stack (since common denominator is 8) - assert_eq!(a.poly.den[0].0, b.poly.den[0].0); // stack + assert_eq!(a.poly.den[0], b.poly.den[0]); // stack // check that length is equal assert_eq!(a.poly.length, b.poly.length); @@ -119,26 +115,22 @@ mod test_clone { let b = a.clone(); // check that nominators on heap are stored separately - assert_ne!( - unsafe { *a.poly.coeffs.offset(0) }.0, - unsafe { *b.poly.coeffs.offset(0) }.0 - ); // heap - assert_eq!( - unsafe { *a.poly.coeffs.offset(1) }.0, - unsafe { *b.poly.coeffs.offset(1) }.0 - ); // stack - assert_ne!( - unsafe { *a.poly.coeffs.offset(2) }.0, - unsafe { *b.poly.coeffs.offset(2) }.0 - ); // heap - assert_ne!( - unsafe { *a.poly.coeffs.offset(3) }.0, - unsafe { *b.poly.coeffs.offset(3) }.0 - ); // heap + assert_ne!(unsafe { *a.poly.coeffs.offset(0) }, unsafe { + *b.poly.coeffs.offset(0) + }); // heap + assert_eq!(unsafe { *a.poly.coeffs.offset(1) }, unsafe { + *b.poly.coeffs.offset(1) + }); // stack + assert_ne!(unsafe { *a.poly.coeffs.offset(2) }, unsafe { + *b.poly.coeffs.offset(2) + }); // heap + assert_ne!(unsafe { *a.poly.coeffs.offset(3) }, unsafe { + *b.poly.coeffs.offset(3) + }); // heap // denominator should be kept on heap (as common denominator is at least i64::MIN) // hence stored separately - assert_ne!(a.poly.den[0].0, b.poly.den[0].0); // heap + assert_ne!(a.poly.den[0], b.poly.den[0]); // heap // check that length is equal assert_eq!(a.poly.length, b.poly.length); @@ -156,9 +148,9 @@ mod test_drop { let a = PolyOverQ::from_str(&format!("2 {}/1 -2/-3", i64::MAX)).unwrap(); ( - unsafe { *a.poly.coeffs.offset(0) }.0, - unsafe { *a.poly.coeffs.offset(1) }.0, - a.poly.den[0].0, + unsafe { *a.poly.coeffs.offset(0) }, + unsafe { *a.poly.coeffs.offset(1) }, + a.poly.den[0], ) } diff --git a/src/rational/poly_over_q/unsafe_functions.rs b/src/rational/poly_over_q/unsafe_functions.rs index 486311f5..7e5cf37d 100644 --- a/src/rational/poly_over_q/unsafe_functions.rs +++ b/src/rational/poly_over_q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::PolyOverQ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::fmpq_poly::{fmpq_poly_clear, fmpq_poly_struct}; +use flint_sys::{fmpq_poly::fmpq_poly_clear, fmpq_types::fmpq_poly_struct}; unsafe_getter!(PolyOverQ, poly, fmpq_poly_struct); diff --git a/src/rational/q.rs b/src/rational/q.rs index 91e2d5d9..8d68831c 100644 --- a/src/rational/q.rs +++ b/src/rational/q.rs @@ -13,7 +13,8 @@ // To avoid unnecessary checks and reductions, always return canonical/reduced // values. The end-user should be unable to obtain a non-reduced value. -use flint_sys::fmpq::fmpq; +use crate::integer::debug_fmpz; +use flint_sys::flint::fmpq; use std::fmt; mod arithmetic; @@ -80,10 +81,18 @@ impl fmt::Debug for Q { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "Q {{value_f64(may be rounded; 5 decimals): {}, value: {}, storage: {{value: {:?}}}}}", + "Q {{value_f64(may be rounded; 5 decimals): {}, value: {}, storage: {{value: {}}}}}", self.to_string_decimal(5), self, - self.value + debug_fmpq(&self.value) ) } } + +fn debug_fmpq(value: &fmpq) -> String { + format!( + "fmpq {{ num: {}, den: {} }}", + debug_fmpz(&value.num), + debug_fmpz(&value.den) + ) +} diff --git a/src/rational/q/cmp.rs b/src/rational/q/cmp.rs index 42ac0296..21d0bfb3 100644 --- a/src/rational/q/cmp.rs +++ b/src/rational/q/cmp.rs @@ -17,7 +17,7 @@ use crate::{ }; use flint_sys::{ fmpq::{fmpq_cmp, fmpq_equal}, - fmpz::{fmpz, fmpz_equal}, + fmpz::fmpz_equal, }; use std::cmp::Ordering; @@ -92,7 +92,7 @@ impl PartialEq for Q { /// ``` fn eq(&self, other: &Z) -> bool { unsafe { - (1 == fmpz_equal(&self.value.den, &fmpz(1))) + (1 == fmpz_equal(&self.value.den, &1)) && (1 == fmpz_equal(&self.value.num, &other.value)) } } @@ -136,7 +136,7 @@ impl PartialEq for Q { /// ``` fn eq(&self, other: &Modulus) -> bool { unsafe { - (1 == fmpz_equal(&self.value.den, &fmpz(1))) + (1 == fmpz_equal(&self.value.den, &1)) && (1 == fmpz_equal(&self.value.num, &other.modulus.n[0])) } } @@ -144,7 +144,7 @@ impl PartialEq for Q { implement_trait_reverse!(PartialEq, eq, Modulus, Q, bool); -implement_for_others!(Z, Q, PartialEq for fmpz i8 i16 i32 i64 u8 u16 u32 u64); +implement_for_others!(Z, Q, PartialEq for i8 i16 i32 i64 u8 u16 u32 u64); impl PartialOrd for Q { /// Compares two [`Q`] values. Used by the `<`, `<=`, `>`, and `>=` operators. @@ -215,7 +215,7 @@ impl Ord for Q { } } -implement_for_others!(Q, Q, PartialOrd for Modulus Z fmpz i8 i16 i32 i64 u8 u16 u32 u64); +implement_for_others!(Q, Q, PartialOrd for Modulus Z i8 i16 i32 i64 u8 u16 u32 u64); /// Test that the [`PartialEq`] trait is correctly implemented. #[cfg(test)] diff --git a/src/rational/q/default.rs b/src/rational/q/default.rs index fde0f23c..9f242b2a 100644 --- a/src/rational/q/default.rs +++ b/src/rational/q/default.rs @@ -9,7 +9,7 @@ //! Define default values for [`Q`]. use super::Q; -use flint_sys::{fmpq::fmpq, fmpz::fmpz}; +use flint_sys::flint::fmpq; impl Default for Q { /// Returns an instantiation of [`Q`] with value `0/1`. @@ -24,10 +24,7 @@ impl Default for Q { fn default() -> Self { // needs to stay a manual instantiation as try_from uses default inside Q { - value: fmpq { - num: fmpz(0), - den: fmpz(1), - }, + value: fmpq { num: 0, den: 1 }, } } } @@ -42,10 +39,7 @@ impl Q { /// let a: Q = Q::ONE; /// ``` pub const ONE: Q = Q { - value: fmpq { - num: fmpz(1), - den: fmpz(1), - }, + value: fmpq { num: 1, den: 1 }, }; /// Returns an instantiation of [`Q`] with value `0`. @@ -57,10 +51,7 @@ impl Q { /// let a: Q = Q::ZERO; /// ``` pub const ZERO: Q = Q { - value: fmpq { - num: fmpz(0), - den: fmpz(1), - }, + value: fmpq { num: 0, den: 1 }, }; /// Returns an instantiation of [`Q`] with value `-1`. @@ -72,10 +63,7 @@ impl Q { /// let a: Q = Q::MINUS_ONE; /// ``` pub const MINUS_ONE: Q = Q { - value: fmpq { - num: fmpz(-1), - den: fmpz(1), - }, + value: fmpq { num: -1, den: 1 }, }; /// Returns an instantiation of [`Q`] with value `e ≈ 2.718281...` @@ -90,8 +78,8 @@ impl Q { pub const E: Q = Q { // generated with continued fraction (40 factors) value: fmpq { - num: fmpz(2922842896378005707), - den: fmpz(1075253811351460636), + num: 2922842896378005707, + den: 1075253811351460636, }, }; @@ -107,8 +95,8 @@ impl Q { pub const PI: Q = Q { // generated with continued fraction (33 factors) value: fmpq { - num: fmpz(2646693125139304345), - den: fmpz(842468587426513207), + num: 2646693125139304345, + den: 842468587426513207, }, }; @@ -122,8 +110,8 @@ impl Q { /// ``` pub const MAX62: Q = Q { value: fmpq { - num: fmpz(i64::pow(2, 62) - 1), - den: fmpz(1), + num: i64::pow(2, 62) - 1, + den: 1, }, }; @@ -137,8 +125,8 @@ impl Q { /// ``` pub const INV_MAX62: Q = Q { value: fmpq { - num: fmpz(1), - den: fmpz(i64::pow(2, 62) - 1), + num: 1, + den: i64::pow(2, 62) - 1, }, }; @@ -152,8 +140,8 @@ impl Q { /// ``` pub const MAX32: Q = Q { value: fmpq { - num: fmpz(i64::pow(2, 32) - 1), - den: fmpz(1), + num: i64::pow(2, 32) - 1, + den: 1, }, }; @@ -167,8 +155,8 @@ impl Q { /// ``` pub const INV_MAX32: Q = Q { value: fmpq { - num: fmpz(1), - den: fmpz(i64::pow(2, 32) - 1), + num: 1, + den: i64::pow(2, 32) - 1, }, }; @@ -182,8 +170,8 @@ impl Q { /// ``` pub const MAX16: Q = Q { value: fmpq { - num: fmpz(i64::pow(2, 16) - 1), - den: fmpz(1), + num: i64::pow(2, 16) - 1, + den: 1, }, }; @@ -197,8 +185,8 @@ impl Q { /// ``` pub const INV_MAX16: Q = Q { value: fmpq { - num: fmpz(1), - den: fmpz(i64::pow(2, 16) - 1), + num: 1, + den: i64::pow(2, 16) - 1, }, }; @@ -212,8 +200,8 @@ impl Q { /// ``` pub const MAX8: Q = Q { value: fmpq { - num: fmpz(i64::pow(2, 8) - 1), - den: fmpz(1), + num: i64::pow(2, 8) - 1, + den: 1, }, }; @@ -227,8 +215,8 @@ impl Q { /// ``` pub const INV_MAX8: Q = Q { value: fmpq { - num: fmpz(1), - den: fmpz(i64::pow(2, 8) - 1), + num: 1, + den: i64::pow(2, 8) - 1, }, }; } diff --git a/src/rational/q/from.rs b/src/rational/q/from.rs index 9c2723df..917160a3 100644 --- a/src/rational/q/from.rs +++ b/src/rational/q/from.rs @@ -18,7 +18,8 @@ use crate::{ traits::{AsInteger, Pow}, }; use flint_sys::{ - fmpq::{fmpq, fmpq_canonicalise, fmpq_clear, fmpq_get_d, fmpq_set_str}, + flint::fmpq, + fmpq::{fmpq_canonicalise, fmpq_clear, fmpq_get_d, fmpq_set_str}, fmpz::{fmpz_init_set, fmpz_is_zero}, }; use std::{ffi::CString, str::FromStr}; @@ -100,7 +101,7 @@ impl let num = num.into_fmpz(); let den = den.into_fmpz(); - assert_ne!(den.0, 0, "The denominator can not be zero"); + assert_ne!(den, 0, "The denominator can not be zero"); let mut value = fmpq { num, den }; fmpq_canonicalise(&mut value); diff --git a/src/rational/q/ownership.rs b/src/rational/q/ownership.rs index d43b7553..0ee25a44 100644 --- a/src/rational/q/ownership.rs +++ b/src/rational/q/ownership.rs @@ -16,7 +16,7 @@ use flint_sys::fmpq::{fmpq_clear, fmpq_set}; impl Clone for Q { /// Clones the given element and returns another cloned reference - /// to the [`fmpq`](flint_sys::fmpq::fmpq) element. + /// to the [`fmpq`](flint_sys::flint::fmpq) element. /// /// # Examples /// ``` @@ -34,7 +34,7 @@ impl Clone for Q { } impl Drop for Q { - /// Drops the given reference to the [`fmpq`](flint_sys::fmpq::fmpq) element + /// Drops the given reference to the [`fmpq`](flint_sys::flint::fmpq) element /// and frees the allocated memory if no references are left. /// /// # Examples @@ -94,8 +94,8 @@ mod test_clone { assert_eq!(val, val_clone); // check if cloned values are kept on stack - assert_eq!(val.value.num.0, val_clone.value.num.0); - assert_eq!(val.value.den.0, val_clone.value.den.0); + assert_eq!(val.value.num, val_clone.value.num); + assert_eq!(val.value.den, val_clone.value.den); } } @@ -129,7 +129,7 @@ mod test_clone { assert_eq!(val, val_clone); // check if point in memory is different from clone - assert_ne!(val.value.num.0, val_clone.value.num.0); + assert_ne!(val.value.num, val_clone.value.num); } } @@ -157,20 +157,20 @@ mod test_drop { fn free_memory() { let string = format!("{}/2", "1".repeat(65)); let a = Q::from_str(&string).unwrap(); - let num_point_in_memory = a.value.num.0; - let den_point_in_memory = a.value.den.0; + let num_point_in_memory = a.value.num; + let den_point_in_memory = a.value.den; drop(a); // instantiate different values to check if memory slot is reused for different values let c = Q::from_str(&string).unwrap(); - assert_eq!(num_point_in_memory, c.value.num.0); - assert_eq!(den_point_in_memory, c.value.den.0); + assert_eq!(num_point_in_memory, c.value.num); + assert_eq!(den_point_in_memory, c.value.den); // memory slots differ due to previously created large integer assert_ne!( num_point_in_memory, - Q::from_str(&"1".repeat(65)).unwrap().value.num.0 + Q::from_str(&"1".repeat(65)).unwrap().value.num ); } } diff --git a/src/rational/q/unsafe_functions.rs b/src/rational/q/unsafe_functions.rs index 8f544b0c..94c7c2e3 100644 --- a/src/rational/q/unsafe_functions.rs +++ b/src/rational/q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::Q; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::fmpq::{fmpq, fmpq_clear}; +use flint_sys::{flint::fmpq, fmpq::fmpq_clear}; unsafe_getter!(Q, value, fmpq); @@ -20,7 +20,6 @@ unsafe_setter!(Q, value, fmpq, fmpq_clear); #[cfg(test)] mod test_get_fmpq { use super::Q; - use flint_sys::fmpz::fmpz; /// Checks availability of the getter for [`Q::value`] /// and its ability to be modified. @@ -31,7 +30,7 @@ mod test_get_fmpq { let mut fmpq_rat = unsafe { rational.get_fmpq() }; - fmpq_rat.num = fmpz(2); + fmpq_rat.num = 2; assert_eq!(Q::from(2), rational); } @@ -40,7 +39,7 @@ mod test_get_fmpq { #[cfg(test)] mod test_set_fmpq { use super::Q; - use flint_sys::{fmpq::fmpq, fmpz::fmpz}; + use flint_sys::flint::fmpq; /// Checks availability of the setter for [`Q::value`] /// and its ability to modify [`Q`]. @@ -48,10 +47,7 @@ mod test_set_fmpq { #[allow(unused_mut)] fn availability_and_modification() { let mut rational = Q::from(1); - let flint_struct = fmpq { - num: fmpz(2), - den: fmpz(1), - }; + let flint_struct = fmpq { num: 2, den: 1 }; unsafe { rational.set_fmpq(flint_struct) }; diff --git a/src/traits.rs b/src/traits.rs index 0f107235..95d47451 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -15,7 +15,7 @@ use crate::{ error::MathError, utils::index::{evaluate_index, evaluate_index_for_vector, evaluate_indices_for_matrix}, }; -use flint_sys::fmpz::fmpz; +use flint_sys::flint::fmpz; use std::fmt::Display; /// Is implemented by every type where a base-check might be needed. diff --git a/src/utils/factorization.rs b/src/utils/factorization.rs index 75b8a00c..33afa776 100644 --- a/src/utils/factorization.rs +++ b/src/utils/factorization.rs @@ -9,7 +9,8 @@ //! This module contains the type [`Factorization`], which is a factorized //! (or partly factorized) representation of integers with arbitrary length. -use flint_sys::fmpz_factor::fmpz_factor_struct; +use flint_sys::fmpz_types::fmpz_factor_struct; +use std::fmt; mod default; mod from; @@ -52,7 +53,28 @@ mod to_string; /// // to_string /// assert_eq!("[(3, 1), (20, 3)]", &fac_2.to_string()); /// ``` -#[derive(Debug)] pub struct Factorization { factors: fmpz_factor_struct, } + +impl fmt::Debug for Factorization { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Factorization {{ factors: {}, storage: {{ fmpz_factor_struct: {}}}}}", + self, + debug_fmpz_factor_struct(&self.factors) + ) + } +} + +fn debug_fmpz_factor_struct(value: &fmpz_factor_struct) -> String { + format!( + "fmpz_factor_struct {{ sign: {}, p: {:#x}, exp: {:#x}, alloc: {}, num: {} }}", + value.sign, + value.p.addr(), + value.exp.addr(), + value.alloc, + value.num + ) +} From 34d3af64e078dfc4499716f99502943a8b6e3e5c Mon Sep 17 00:00:00 2001 From: jnsiemer Date: Sat, 2 May 2026 02:49:12 +0100 Subject: [PATCH 2/6] Update to new flint-sys memory requirements --- src/integer/mat_poly_over_z/get.rs | 11 ++-- .../mat_poly_over_z/vector/dot_product.rs | 2 +- src/integer/mat_z/ownership.rs | 2 +- src/integer/z/fmpz_helpers.rs | 54 ++++++++++--------- src/integer/z/from.rs | 5 +- src/integer/z/unsafe_functions.rs | 6 +-- .../mat_polynomial_ring_zq/get.rs | 19 ++++--- .../mat_polynomial_ring_zq/reduce.rs | 4 +- .../vector/dot_product.rs | 2 +- .../mat_zq/arithmetic/mul_scalar.rs | 19 +++++-- src/integer_mod_q/mat_zq/inverse.rs | 10 ++-- src/integer_mod_q/mat_zq/ownership.rs | 18 +------ src/integer_mod_q/mat_zq/set.rs | 2 + src/integer_mod_q/mat_zq/unsafe_functions.rs | 21 ++++---- src/integer_mod_q/modulus/ownership.rs | 4 +- src/integer_mod_q/modulus/unsafe_functions.rs | 3 +- src/integer_mod_q/poly_over_zq/properties.rs | 5 ++ src/macros/unsafe_passthrough.rs | 3 +- src/rational/mat_q/get.rs | 11 ++-- src/rational/mat_q/vector/dot_product.rs | 2 +- src/rational/mat_q/vector/norm.rs | 4 +- 21 files changed, 112 insertions(+), 95 deletions(-) diff --git a/src/integer/mat_poly_over_z/get.rs b/src/integer/mat_poly_over_z/get.rs index e9a81f62..95b6e3d9 100644 --- a/src/integer/mat_poly_over_z/get.rs +++ b/src/integer/mat_poly_over_z/get.rs @@ -172,15 +172,18 @@ impl MatPolyOverZ { /// /// let fmpz_entries = mat.collect_entries(); /// ``` - pub(crate) fn collect_entries(&self) -> Vec { - let mut entries: Vec = + pub(crate) fn collect_entries<'a>(&self) -> Vec<&'a fmpz_poly_struct> { + let mut entries: Vec<&'a fmpz_poly_struct> = Vec::with_capacity((self.get_num_rows() * self.get_num_columns()) as usize); for row in 0..self.get_num_rows() { for col in 0..self.get_num_columns() { // efficiently get entry without cloning the entry itself - let entry = unsafe { std::ptr::read(fmpz_poly_mat_entry(&self.matrix, row, col)) }; - entries.push(entry); + unsafe { + let entry_ptr = fmpz_poly_mat_entry(&self.matrix, row, col); + let entry_ref: &'a fmpz_poly_struct = &*entry_ptr; + entries.push(entry_ref); + } } } diff --git a/src/integer/mat_poly_over_z/vector/dot_product.rs b/src/integer/mat_poly_over_z/vector/dot_product.rs index 73830bea..02b8c543 100644 --- a/src/integer/mat_poly_over_z/vector/dot_product.rs +++ b/src/integer/mat_poly_over_z/vector/dot_product.rs @@ -72,7 +72,7 @@ impl MatPolyOverZ { for i in 0..self_entries.len() { // sets result = result + self.entry[i] * other.entry[i] without cloned PolyOverZ element unsafe { - fmpz_poly_mul(&mut temp.poly, &self_entries[i], &other_entries[i]); + fmpz_poly_mul(&mut temp.poly, self_entries[i], other_entries[i]); fmpz_poly_add(&mut result.poly, &result.poly, &temp.poly) } diff --git a/src/integer/mat_z/ownership.rs b/src/integer/mat_z/ownership.rs index 98a7400d..978d95af 100644 --- a/src/integer/mat_z/ownership.rs +++ b/src/integer/mat_z/ownership.rs @@ -138,7 +138,7 @@ mod test_drop { let str_1 = "[[36893488147419103232, 36893488147419103232]]"; let a = MatZ::from_str(str_1).unwrap(); - let storage_mat = unsafe { (*a.matrix.entries) }; + let storage_mat = unsafe { *a.matrix.entries }; let storage_0 = a.get_entry(0, 0).unwrap().value; let storage_1 = a.get_entry(0, 1).unwrap().value; diff --git a/src/integer/z/fmpz_helpers.rs b/src/integer/z/fmpz_helpers.rs index 1b294f86..f4f1566d 100644 --- a/src/integer/z/fmpz_helpers.rs +++ b/src/integer/z/fmpz_helpers.rs @@ -105,6 +105,7 @@ macro_rules! implement_as_integer_over_i64 { unsafe fn into_fmpz(self) -> fmpz { unsafe { (&self).into_fmpz() } } + fn get_fmpz_ref(&self) -> Option<&fmpz> { None } } /// Documentation at [`AsInteger::into_fmpz`] @@ -114,12 +115,13 @@ macro_rules! implement_as_integer_over_i64 { unsafe { fmpz_init_set_si(&mut ret_value, *self as i64) }; ret_value } + fn get_fmpz_ref(&self) -> Option<&fmpz> { None } } )* }; } -implement_as_integer_over_i64!(i8 u8 i16 u16 i32 u32); +implement_as_integer_over_i64!(i8 u8 i16 u16 i32 u32 i64); unsafe impl AsInteger for Z { /// Documentation at [`AsInteger::into_fmpz`] @@ -149,31 +151,31 @@ unsafe impl AsInteger for &Z { } } -unsafe impl AsInteger for fmpz { - /// Documentation at [`AsInteger::into_fmpz`] - unsafe fn into_fmpz(self) -> fmpz { - unsafe { (&self).into_fmpz() } - } - - /// Documentation at [`AsInteger::get_fmpz_ref`] - fn get_fmpz_ref(&self) -> Option<&fmpz> { - Some(self) - } -} - -unsafe impl AsInteger for &fmpz { - /// Documentation at [`AsInteger::into_fmpz`] - unsafe fn into_fmpz(self) -> fmpz { - let mut value: fmpz = 0; - unsafe { fmpz_init_set(&mut value, self) }; - value - } - - /// Documentation at [`AsInteger::get_fmpz_ref`] - fn get_fmpz_ref(&self) -> Option<&fmpz> { - Some(self) - } -} +// unsafe impl AsInteger for fmpz { +// /// Documentation at [`AsInteger::into_fmpz`] +// unsafe fn into_fmpz(self) -> fmpz { +// unsafe { (&self).into_fmpz() } +// } + +// /// Documentation at [`AsInteger::get_fmpz_ref`] +// fn get_fmpz_ref(&self) -> Option<&fmpz> { +// Some(self) +// } +// } + +// unsafe impl AsInteger for &fmpz { +// /// Documentation at [`AsInteger::into_fmpz`] +// unsafe fn into_fmpz(self) -> fmpz { +// let mut value: fmpz = 0; +// unsafe { fmpz_init_set(&mut value, self) }; +// value +// } + +// /// Documentation at [`AsInteger::get_fmpz_ref`] +// fn get_fmpz_ref(&self) -> Option<&fmpz> { +// Some(self) +// } +// } #[cfg(test)] mod test_as_integer_rust_ints { diff --git a/src/integer/z/from.rs b/src/integer/z/from.rs index 63b09efe..1307c026 100644 --- a/src/integer/z/from.rs +++ b/src/integer/z/from.rs @@ -657,8 +657,9 @@ mod tests_from_int { let large_z = Z::from(u64::MAX); let small_z = Z::ONE; - assert_eq!(large_z, Z::from(&large_z.value)); - assert_eq!(large_z, Z::from(large_z.value)); + // fmpz = i64 now + assert_eq!(large_z, Z::from(&u64::MAX)); + assert_eq!(large_z, Z::from(u64::MAX)); assert_eq!(small_z, Z::from(&small_z.value)); assert_eq!(small_z, Z::from(small_z.value)); diff --git a/src/integer/z/unsafe_functions.rs b/src/integer/z/unsafe_functions.rs index a8a72dac..d21caeb5 100644 --- a/src/integer/z/unsafe_functions.rs +++ b/src/integer/z/unsafe_functions.rs @@ -26,14 +26,12 @@ mod test_get_fmpz { /// and its ability to be modified. #[test] #[allow(unused_mut)] - fn availability_and_modification() { + fn availability() { let mut integer = Z::from(1); let mut fmpz_int = unsafe { integer.get_fmpz() }; - fmpz_int = &mut 2i64; - - assert_eq!(Z::from(2), integer); + assert_eq!(&1, fmpz_int); } } diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/get.rs b/src/integer_mod_q/mat_polynomial_ring_zq/get.rs index 311038a1..5443d53b 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/get.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/get.rs @@ -259,16 +259,19 @@ impl MatPolynomialRingZq { /// let fmpz_entries = poly_ring_mat.collect_entries(); /// ``` #[allow(dead_code)] - pub(crate) fn collect_entries(&self) -> Vec { - let mut entries: Vec = + pub(crate) fn collect_entries<'a>(&self) -> Vec<&'a fmpz_poly_struct> { + let mut entries: Vec<&'a fmpz_poly_struct> = Vec::with_capacity((self.get_num_rows() * self.get_num_columns()) as usize); for row in 0..self.get_num_rows() { for col in 0..self.get_num_columns() { // efficiently get entry without cloning the entry itself - let entry = - unsafe { std::ptr::read(fmpz_poly_mat_entry(&self.matrix.matrix, row, col)) }; - entries.push(entry); + unsafe { + let entry_ptr = fmpz_poly_mat_entry(&self.matrix.matrix, row, col); + let entry_ref: &'a fmpz_poly_struct = &*entry_ptr; + entries.push(entry_ref); + } + // let entry = fmpz_poly_mat_entry(&self.matrix.matrix, row, col); } } @@ -792,9 +795,9 @@ mod test_collect_entries { let mut entry_2 = entry_1.clone(); let mut entry_3 = entry_1.clone(); - unsafe { fmpz_poly_set(&mut entry_1.poly, &entries_1[1]) } - unsafe { fmpz_poly_set(&mut entry_2.poly, &entries_1[3]) } - unsafe { fmpz_poly_set(&mut entry_3.poly, &entries_2[0]) } + unsafe { fmpz_poly_set(&mut entry_1.poly, entries_1[1]) } + unsafe { fmpz_poly_set(&mut entry_2.poly, entries_1[3]) } + unsafe { fmpz_poly_set(&mut entry_3.poly, entries_2[0]) } assert_eq!(entries_1.len(), 4); assert_eq!( diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs b/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs index 1037ff38..1a77c7c7 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs @@ -18,7 +18,7 @@ use super::MatPolynomialRingZq; use crate::{ integer::fmpz_poly_helpers::reduce_fmpz_poly_by_fmpz_mod_poly_sparse, traits::MatrixDimensions, }; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_entry; +use flint_sys::{fmpz_poly::fmpz_poly_length, fmpz_poly_mat::fmpz_poly_mat_entry}; impl MatPolynomialRingZq { /// This function manually applies the modulus @@ -68,7 +68,7 @@ impl MatPolynomialRingZq { /// ``` pub(crate) unsafe fn reduce_entry(&mut self, row: i64, column: i64) { let entry = unsafe { fmpz_poly_mat_entry(&self.matrix.matrix, row, column) }; - if (unsafe { std::ptr::read(entry) }).length > 0 { + if (unsafe { fmpz_poly_length(entry) }) > 0 { unsafe { reduce_fmpz_poly_by_fmpz_mod_poly_sparse( &mut *entry, diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs b/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs index 97a434d7..1327c71d 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs @@ -77,7 +77,7 @@ impl MatPolynomialRingZq { for i in 0..self_entries.len() { // sets result = result + self.entry[i] * other.entry[i] without cloned PolyOverZ element unsafe { - fmpz_poly_mul(&mut temp.poly, &self_entries[i], &other_entries[i]); + fmpz_poly_mul(&mut temp.poly, self_entries[i], other_entries[i]); } // reduce is applied in here result += &temp; diff --git a/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs b/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs index c1bb3f80..dd8f45d1 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs @@ -19,6 +19,7 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::traits::{CompareBase, MatrixDimensions}; +use flint_sys::flint::fmpz; use flint_sys::fmpz_mod_mat::{ fmpz_mod_mat_scalar_mul_fmpz, fmpz_mod_mat_scalar_mul_si, fmpz_mod_mat_scalar_mul_ui, }; @@ -47,11 +48,14 @@ impl Mul<&Z> for &MatZq { /// ``` fn mul(self, scalar: &Z) -> Self::Output { let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); + + let scalar_ptr = &scalar.value as *const fmpz as *mut fmpz; + unsafe { fmpz_mod_mat_scalar_mul_fmpz( &mut out.matrix, &self.matrix, - &mut std::ptr::read(scalar).value, + scalar_ptr, self.modulus.get_fmpz_mod_ctx_struct(), ); } @@ -131,12 +135,14 @@ impl MatZq { return Err(self.call_compare_base_error(scalar).unwrap()); } + let scalar_ptr = &scalar.value.value as *const fmpz as *mut fmpz; + let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { fmpz_mod_mat_scalar_mul_fmpz( &mut out.matrix, &self.matrix, - &mut std::ptr::read(scalar).value.value, + scalar_ptr, self.modulus.get_fmpz_mod_ctx_struct(), ); } @@ -171,11 +177,13 @@ impl MulAssign<&Z> for MatZq { /// a *= c; /// ``` fn mul_assign(&mut self, scalar: &Z) { + let scalar_ptr = &scalar.value as *const fmpz as *mut fmpz; + unsafe { fmpz_mod_mat_scalar_mul_fmpz( &mut self.matrix, &self.matrix, - &mut std::ptr::read(scalar).value, + scalar_ptr, self.modulus.get_fmpz_mod_ctx_struct(), ) }; @@ -191,11 +199,14 @@ impl MulAssign<&Zq> for MatZq { if !self.compare_base(scalar) { panic!("{}", self.call_compare_base_error(scalar).unwrap()) } + + let scalar_ptr = &scalar.value.value as *const fmpz as *mut fmpz; + unsafe { fmpz_mod_mat_scalar_mul_fmpz( &mut self.matrix, &self.matrix, - &mut std::ptr::read(scalar).value.value, + scalar_ptr, self.modulus.get_fmpz_mod_ctx_struct(), ) }; diff --git a/src/integer_mod_q/mat_zq/inverse.rs b/src/integer_mod_q/mat_zq/inverse.rs index 058695a9..794c6442 100644 --- a/src/integer_mod_q/mat_zq/inverse.rs +++ b/src/integer_mod_q/mat_zq/inverse.rs @@ -151,22 +151,24 @@ impl MatZq { /// /// # Panics ... /// - if the modulus is not prime. - pub fn gaussian_elimination_prime(self) -> MatZq { + pub fn gaussian_elimination_prime(&self) -> MatZq { assert!( self.get_mod().is_prime(), "The modulus of the matrix is not prime" ); + let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), &self.modulus); + // Since we only want the echelon form, the permutation `perm` is not relevant. let _ = unsafe { fmpz_mod_mat_rref( - std::ptr::null_mut(), + &mut out.matrix, &self.matrix, - self.get_mod().get_fmpz_mod_ctx_struct(), + self.modulus.get_fmpz_mod_ctx_struct(), ) }; - self + out } } diff --git a/src/integer_mod_q/mat_zq/ownership.rs b/src/integer_mod_q/mat_zq/ownership.rs index 81895993..ae565c9e 100644 --- a/src/integer_mod_q/mat_zq/ownership.rs +++ b/src/integer_mod_q/mat_zq/ownership.rs @@ -12,7 +12,6 @@ //! The explicit functions contain the documentation. use super::MatZq; -use crate::integer::Z; use crate::traits::MatrixDimensions; use flint_sys::fmpz_mod_mat::{fmpz_mod_mat_clear, fmpz_mod_mat_init_set}; @@ -29,11 +28,7 @@ impl Clone for MatZq { /// let b = a.clone(); /// ``` fn clone(&self) -> Self { - let mut out = MatZq::new( - self.get_num_rows(), - self.get_num_columns(), - Z::from(self.get_mod()), - ); + let mut out = MatZq::new(self.get_num_rows(), self.get_num_columns(), self.get_mod()); unsafe { fmpz_mod_mat_init_set( &mut out.matrix, @@ -142,17 +137,6 @@ mod test_clone { assert_eq!(MatrixGetEntry::::get_entry(&a, 1, 1).unwrap(), 1); assert_eq!(MatrixGetEntry::::get_entry(&a, 1, 0).unwrap(), 0); } - - /// Check if large modulus is stored separately and therefore cloned deeply - #[test] - fn modulus_storage() { - let string = format!("[[{}, {}],[-10, 0]] mod {}", i64::MAX, i64::MIN, u64::MAX); - let b = MatZq::from_str(&string).unwrap(); - - let a = b.clone(); - - assert_ne!(a.modulus, b.modulus); - } } /// Test that the [`Drop`] trait is correctly implemented. diff --git a/src/integer_mod_q/mat_zq/set.rs b/src/integer_mod_q/mat_zq/set.rs index 1098e623..dfa6f4d5 100644 --- a/src/integer_mod_q/mat_zq/set.rs +++ b/src/integer_mod_q/mat_zq/set.rs @@ -1133,6 +1133,8 @@ mod test_change_modulus { matrix.change_modulus(&modulus); + println!("{}", matrix); + assert_eq!("[[1, 2, 3],[4, 5, 6]] mod 8", matrix.to_string()); } diff --git a/src/integer_mod_q/mat_zq/unsafe_functions.rs b/src/integer_mod_q/mat_zq/unsafe_functions.rs index c325a255..fc242b01 100644 --- a/src/integer_mod_q/mat_zq/unsafe_functions.rs +++ b/src/integer_mod_q/mat_zq/unsafe_functions.rs @@ -27,21 +27,22 @@ unsafe_setter_indirect!(MatZq, modulus, set_fmpz_mod_ctx, fmpz_mod_ctx); #[cfg(test)] mod test_get_fmpz_mod_mat_struct { use super::MatZq; + use crate::traits::MatrixDimensions; use std::str::FromStr; - // / Checks availability of the getter for [`MatZq::matrix`] - // / and its ability to be modified. - // #[test] - // #[allow(unused_mut)] - // fn availability_and_modification() { - // let mut mat = MatZq::from_str("[[3]] mod 7").unwrap(); + /// Checks availability of the getter for [`MatZq::matrix`] + /// and its ability to be modified. + #[test] + #[allow(unused_mut)] + fn availability_and_modification() { + let mut mat = MatZq::from_str("[[3]] mod 7").unwrap(); - // let mut fmpz_mat = unsafe { mat.get_fmpz_mod_mat_struct() }; + let mut fmpz_mat = unsafe { mat.get_fmpz_mod_mat_struct() }; - // fmpz_mat.mod_[0].0 = 5; + fmpz_mat.c = 5; - // assert_eq!(MatZq::from_str("[[3]] mod 5").unwrap(), mat); - // } + assert_eq!(5, mat.get_num_columns()); + } } #[cfg(test)] diff --git a/src/integer_mod_q/modulus/ownership.rs b/src/integer_mod_q/modulus/ownership.rs index 5960e7ed..11aa94c8 100644 --- a/src/integer_mod_q/modulus/ownership.rs +++ b/src/integer_mod_q/modulus/ownership.rs @@ -56,9 +56,9 @@ impl Drop for Modulus { /// ``` fn drop(&mut self) { if Rc::strong_count(&self.modulus) <= 1 { - let mut a = unsafe { std::ptr::read(self.modulus.as_ref()) }; unsafe { - fmpz_mod_ctx_clear(&mut a); + let ctx_ptr = self.modulus.as_ref() as *const _ as *mut _; + fmpz_mod_ctx_clear(ctx_ptr); } } } diff --git a/src/integer_mod_q/modulus/unsafe_functions.rs b/src/integer_mod_q/modulus/unsafe_functions.rs index 752a6143..5dc1e2f4 100644 --- a/src/integer_mod_q/modulus/unsafe_functions.rs +++ b/src/integer_mod_q/modulus/unsafe_functions.rs @@ -42,7 +42,8 @@ impl Modulus { /// that Rust and our Wrapper provide. /// Thus, using functions of [`flint_sys`] can introduce memory leaks. pub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx) { - let modulus = std::rc::Rc::::get_mut(&mut self.modulus).unwrap(); + let ptr = std::rc::Rc::as_ptr(&self.modulus) as *mut _; + let modulus = unsafe { &mut *ptr }; // free memory of old modulus before new values of modulus are copied unsafe { fmpz_mod_ctx_clear(modulus) }; diff --git a/src/integer_mod_q/poly_over_zq/properties.rs b/src/integer_mod_q/poly_over_zq/properties.rs index 015834a8..5347a510 100644 --- a/src/integer_mod_q/poly_over_zq/properties.rs +++ b/src/integer_mod_q/poly_over_zq/properties.rs @@ -30,6 +30,11 @@ impl PolyOverZq { /// assert!(poly_irr.is_irreducible()); /// ``` pub fn is_irreducible(&self) -> bool { + // prevent running into FLINT error + if !self.get_mod().is_prime() { + return false; + } + 1 == unsafe { fmpz_mod_poly_is_irreducible(&self.poly, self.modulus.get_fmpz_mod_ctx_struct()) } diff --git a/src/macros/unsafe_passthrough.rs b/src/macros/unsafe_passthrough.rs index 4a79905f..cd0c9e15 100644 --- a/src/macros/unsafe_passthrough.rs +++ b/src/macros/unsafe_passthrough.rs @@ -80,7 +80,8 @@ macro_rules! unsafe_getter_mod { /// that Rust and our Wrapper provide. /// Thus, using functions of [`flint_sys`] can introduce memory leaks. pub unsafe fn [](&mut self) -> &mut $attribute_type { - std::rc::Rc::<$attribute_type>::get_mut(&mut self.$attribute_name).unwrap() + let ptr = std::rc::Rc::as_ptr(&self.$attribute_name) as *mut $attribute_type; + unsafe { &mut *ptr } } } } diff --git a/src/rational/mat_q/get.rs b/src/rational/mat_q/get.rs index 330a2bea..fb865696 100644 --- a/src/rational/mat_q/get.rs +++ b/src/rational/mat_q/get.rs @@ -169,15 +169,18 @@ impl MatQ { /// # Safety /// The user has to ensure that all entries are within the matrix dimensions. /// Otherwise, memory leaks can occur and no guarantees are given. - pub(crate) fn collect_entries(&self) -> Vec { - let mut entries: Vec = + pub(crate) fn collect_entries<'a>(&self) -> Vec<&'a fmpq> { + let mut entries: Vec<&'a fmpq> = Vec::with_capacity((self.get_num_rows() * self.get_num_columns()) as usize); for row in 0..self.get_num_rows() { for col in 0..self.get_num_columns() { // efficiently get entry without cloning the entry itself - let entry = unsafe { std::ptr::read(fmpq_mat_entry(&self.matrix, row, col)) }; - entries.push(entry); + unsafe { + let entry_ptr = fmpq_mat_entry(&self.matrix, row, col); + let entry_ref: &'a fmpq = &*entry_ptr; + entries.push(entry_ref); + } } } diff --git a/src/rational/mat_q/vector/dot_product.rs b/src/rational/mat_q/vector/dot_product.rs index 7c663efa..d8dfea89 100644 --- a/src/rational/mat_q/vector/dot_product.rs +++ b/src/rational/mat_q/vector/dot_product.rs @@ -73,7 +73,7 @@ impl MatQ { let mut result = Q::default(); for i in 0..self_entries.len() { // sets result = result + self.entry[i] * other.entry[i] without cloned Z element - unsafe { fmpq_addmul(&mut result.value, &self_entries[i], &other_entries[i]) } + unsafe { fmpq_addmul(&mut result.value, self_entries[i], other_entries[i]) } } Ok(result) diff --git a/src/rational/mat_q/vector/norm.rs b/src/rational/mat_q/vector/norm.rs index e54ade7a..917ecfba 100644 --- a/src/rational/mat_q/vector/norm.rs +++ b/src/rational/mat_q/vector/norm.rs @@ -48,7 +48,7 @@ impl MatQ { let mut result = Q::default(); for entry in entries { // sets result = result + entry * entry without cloned Q element - unsafe { fmpq_addmul(&mut result.value, &entry, &entry) } + unsafe { fmpq_addmul(&mut result.value, entry, entry) } } Ok(result) @@ -111,7 +111,7 @@ impl MatQ { for entry in entries { // compute absolute value of fmpq entry let mut abs_entry = Q::default(); - unsafe { fmpq_abs(&mut abs_entry.value, &entry) }; + unsafe { fmpq_abs(&mut abs_entry.value, entry) }; // compare maximum to absolute value of entry and keep larger one if unsafe { fmpq_cmp(&max.value, &abs_entry.value) } < 0 { max = abs_entry; From 519eff7ce1fa90bf52de72f7ee17ae4d6508da62 Mon Sep 17 00:00:00 2001 From: Marvin Beckmann Date: Mon, 27 Jul 2026 10:19:12 +0200 Subject: [PATCH 3/6] start procedure to embed flint3-sys instead of flint-sys (for beter cross-platform compatibility) --- Cargo.toml | 2 +- src/integer/mat_poly_over_z.rs | 2 +- src/integer/mat_poly_over_z/arithmetic/add.rs | 2 +- src/integer/mat_poly_over_z/arithmetic/mul.rs | 2 +- .../mat_poly_over_z/arithmetic/mul_scalar.rs | 2 +- src/integer/mat_poly_over_z/arithmetic/sub.rs | 2 +- src/integer/mat_poly_over_z/cmp.rs | 2 +- src/integer/mat_poly_over_z/concat.rs | 2 +- src/integer/mat_poly_over_z/default.rs | 2 +- src/integer/mat_poly_over_z/evaluate.rs | 2 +- src/integer/mat_poly_over_z/get.rs | 7 ++- src/integer/mat_poly_over_z/ownership.rs | 2 +- src/integer/mat_poly_over_z/properties.rs | 2 +- src/integer/mat_poly_over_z/reduce.rs | 2 +- src/integer/mat_poly_over_z/set.rs | 6 +-- src/integer/mat_poly_over_z/tensor.rs | 2 +- src/integer/mat_poly_over_z/trace.rs | 2 +- src/integer/mat_poly_over_z/transpose.rs | 2 +- .../mat_poly_over_z/unsafe_functions.rs | 6 +-- .../mat_poly_over_z/vector/dot_product.rs | 2 +- src/integer/mat_z.rs | 2 +- src/integer/mat_z/arithmetic/add.rs | 2 +- src/integer/mat_z/arithmetic/div.rs | 4 +- src/integer/mat_z/arithmetic/modulo.rs | 2 +- src/integer/mat_z/arithmetic/mul.rs | 6 +-- src/integer/mat_z/arithmetic/mul_scalar.rs | 4 +- src/integer/mat_z/arithmetic/sub.rs | 4 +- src/integer/mat_z/basis_reductions.rs | 2 +- src/integer/mat_z/cmp.rs | 2 +- src/integer/mat_z/concat.rs | 2 +- src/integer/mat_z/default.rs | 2 +- src/integer/mat_z/determinant.rs | 2 +- src/integer/mat_z/forms.rs | 4 +- src/integer/mat_z/get.rs | 7 ++- src/integer/mat_z/inverse.rs | 2 +- src/integer/mat_z/ownership.rs | 2 +- src/integer/mat_z/properties.rs | 2 +- src/integer/mat_z/set.rs | 6 +-- src/integer/mat_z/tensor.rs | 2 +- src/integer/mat_z/trace.rs | 2 +- src/integer/mat_z/transpose.rs | 2 +- src/integer/mat_z/unsafe_functions.rs | 6 +-- src/integer/mat_z/vector/dot_product.rs | 2 +- src/integer/mat_z/vector/norm.rs | 2 +- src/integer/poly_over_z.rs | 2 +- src/integer/poly_over_z/arithmetic/add.rs | 2 +- src/integer/poly_over_z/arithmetic/modulo.rs | 2 +- src/integer/poly_over_z/arithmetic/mul.rs | 2 +- .../poly_over_z/arithmetic/mul_scalar.rs | 8 ++- src/integer/poly_over_z/arithmetic/sub.rs | 4 +- src/integer/poly_over_z/cmp.rs | 2 +- src/integer/poly_over_z/default.rs | 2 +- src/integer/poly_over_z/dot_product.rs | 4 +- src/integer/poly_over_z/evaluate.rs | 2 +- src/integer/poly_over_z/fmpz_poly_helpers.rs | 19 +++---- src/integer/poly_over_z/from.rs | 2 +- src/integer/poly_over_z/get.rs | 2 +- src/integer/poly_over_z/ownership.rs | 2 +- src/integer/poly_over_z/properties.rs | 2 +- src/integer/poly_over_z/set.rs | 2 +- src/integer/poly_over_z/to_string.rs | 2 +- src/integer/poly_over_z/unsafe_functions.rs | 6 +-- src/integer/z.rs | 2 +- src/integer/z/arithmetic/add.rs | 7 +-- src/integer/z/arithmetic/div.rs | 2 +- src/integer/z/arithmetic/logarithm.rs | 2 +- src/integer/z/arithmetic/modulo.rs | 2 +- src/integer/z/arithmetic/mul.rs | 7 +-- src/integer/z/arithmetic/pow.rs | 2 +- src/integer/z/arithmetic/root.rs | 2 +- src/integer/z/arithmetic/sub.rs | 10 ++-- src/integer/z/cmp.rs | 2 +- src/integer/z/fmpz_helpers.rs | 8 +-- src/integer/z/from.rs | 10 ++-- src/integer/z/gcd.rs | 2 +- src/integer/z/lcm.rs | 2 +- src/integer/z/logic/bit_and.rs | 2 +- src/integer/z/logic/bit_or.rs | 2 +- src/integer/z/logic/bit_xor.rs | 2 +- src/integer/z/logic/complement.rs | 2 +- src/integer/z/ownership.rs | 4 +- src/integer/z/properties.rs | 7 ++- src/integer/z/to_string.rs | 2 +- src/integer/z/unsafe_functions.rs | 4 +- .../arithmetic/add.rs | 2 +- .../arithmetic/mul.rs | 5 +- .../arithmetic/sub.rs | 2 +- .../arithmetic/mul_scalar.rs | 2 +- .../mat_polynomial_ring_zq/concat.rs | 2 +- .../mat_polynomial_ring_zq/get.rs | 4 +- .../mat_polynomial_ring_zq/reduce.rs | 2 +- .../mat_polynomial_ring_zq/set.rs | 6 +-- .../mat_polynomial_ring_zq/tensor.rs | 2 +- .../mat_polynomial_ring_zq/transpose.rs | 2 +- .../unsafe_functions.rs | 2 +- .../vector/dot_product.rs | 2 +- src/integer_mod_q/mat_zq.rs | 2 +- src/integer_mod_q/mat_zq/arithmetic/add.rs | 4 +- src/integer_mod_q/mat_zq/arithmetic/mul.rs | 3 +- .../mat_zq/arithmetic/mul_scalar.rs | 5 +- src/integer_mod_q/mat_zq/arithmetic/sub.rs | 4 +- src/integer_mod_q/mat_zq/cmp.rs | 2 +- src/integer_mod_q/mat_zq/concat.rs | 2 +- src/integer_mod_q/mat_zq/default.rs | 2 +- src/integer_mod_q/mat_zq/from.rs | 2 +- src/integer_mod_q/mat_zq/get.rs | 11 ++-- src/integer_mod_q/mat_zq/inverse.rs | 2 +- src/integer_mod_q/mat_zq/ownership.rs | 2 +- src/integer_mod_q/mat_zq/properties.rs | 5 +- src/integer_mod_q/mat_zq/set.rs | 14 ++--- src/integer_mod_q/mat_zq/tensor.rs | 2 +- src/integer_mod_q/mat_zq/trace.rs | 2 +- src/integer_mod_q/mat_zq/transpose.rs | 2 +- src/integer_mod_q/mat_zq/unsafe_functions.rs | 7 ++- .../mat_zq/vector/dot_product.rs | 2 +- src/integer_mod_q/mat_zq/vector/norm.rs | 2 +- src/integer_mod_q/modulus.rs | 2 +- src/integer_mod_q/modulus/cmp.rs | 6 +-- src/integer_mod_q/modulus/fmpz_helpers.rs | 2 +- src/integer_mod_q/modulus/from.rs | 6 +-- src/integer_mod_q/modulus/get.rs | 2 +- src/integer_mod_q/modulus/ownership.rs | 6 +-- src/integer_mod_q/modulus/properties.rs | 2 +- src/integer_mod_q/modulus/to_string.rs | 2 +- src/integer_mod_q/modulus/unsafe_functions.rs | 12 ++--- .../modulus_polynomial_ring_zq/get.rs | 2 +- .../modulus_polynomial_ring_zq/ownership.rs | 2 +- .../ntt_basis_polynomial_ring_zq/inv_ntt.rs | 8 ++- .../ntt_basis_polynomial_ring_zq/ntt.rs | 5 +- .../ntt_polynomial_ring_zq/arithmetic/add.rs | 2 +- .../ntt_polynomial_ring_zq/arithmetic/mul.rs | 2 +- .../ntt_polynomial_ring_zq/arithmetic/sub.rs | 2 +- src/integer_mod_q/poly_over_zq.rs | 2 +- .../poly_over_zq/arithmetic/add.rs | 2 +- .../poly_over_zq/arithmetic/mul.rs | 2 +- .../poly_over_zq/arithmetic/mul_scalar.rs | 2 +- .../poly_over_zq/arithmetic/sub.rs | 2 +- src/integer_mod_q/poly_over_zq/cmp.rs | 2 +- src/integer_mod_q/poly_over_zq/dot_product.rs | 4 +- src/integer_mod_q/poly_over_zq/evaluate.rs | 2 +- src/integer_mod_q/poly_over_zq/from.rs | 4 +- src/integer_mod_q/poly_over_zq/get.rs | 4 +- src/integer_mod_q/poly_over_zq/ownership.rs | 6 +-- src/integer_mod_q/poly_over_zq/properties.rs | 5 +- src/integer_mod_q/poly_over_zq/set.rs | 2 +- src/integer_mod_q/poly_over_zq/to_string.rs | 2 +- .../poly_over_zq/unsafe_functions.rs | 15 +++--- src/integer_mod_q/polynomial_ring_zq/get.rs | 2 +- src/integer_mod_q/polynomial_ring_zq/set.rs | 2 +- .../polynomial_ring_zq/unsafe_functions.rs | 2 +- src/integer_mod_q/z_q/arithmetic/add.rs | 5 +- src/integer_mod_q/z_q/arithmetic/mul.rs | 5 +- src/integer_mod_q/z_q/arithmetic/pow.rs | 2 +- src/integer_mod_q/z_q/arithmetic/sub.rs | 5 +- src/integer_mod_q/z_q/fmpz_mod_helpers.rs | 4 +- src/integer_mod_q/z_q/properties.rs | 2 +- src/integer_mod_q/z_q/reduce.rs | 2 +- src/integer_mod_q/z_q/unsafe_functions.rs | 2 +- src/macros/unsafe_passthrough.rs | 52 +++++++++---------- src/rational/mat_q.rs | 2 +- src/rational/mat_q/arithmetic/add.rs | 2 +- src/rational/mat_q/arithmetic/div_scalar.rs | 2 +- src/rational/mat_q/arithmetic/mul.rs | 2 +- src/rational/mat_q/arithmetic/mul_scalar.rs | 2 +- src/rational/mat_q/arithmetic/sub.rs | 2 +- src/rational/mat_q/cmp.rs | 2 +- src/rational/mat_q/concat.rs | 2 +- src/rational/mat_q/default.rs | 2 +- src/rational/mat_q/determinant.rs | 2 +- src/rational/mat_q/from.rs | 2 +- src/rational/mat_q/get.rs | 6 +-- src/rational/mat_q/gso.rs | 2 +- src/rational/mat_q/inverse.rs | 2 +- src/rational/mat_q/ownership.rs | 2 +- src/rational/mat_q/properties.rs | 2 +- src/rational/mat_q/set.rs | 6 +-- src/rational/mat_q/tensor.rs | 2 +- src/rational/mat_q/trace.rs | 2 +- src/rational/mat_q/transpose.rs | 2 +- src/rational/mat_q/unsafe_functions.rs | 6 +-- src/rational/mat_q/vector/dot_product.rs | 2 +- src/rational/mat_q/vector/norm.rs | 2 +- src/rational/poly_over_q.rs | 2 +- src/rational/poly_over_q/arithmetic/add.rs | 2 +- .../poly_over_q/arithmetic/div_scalar.rs | 2 +- src/rational/poly_over_q/arithmetic/exp.rs | 2 +- src/rational/poly_over_q/arithmetic/mul.rs | 2 +- .../poly_over_q/arithmetic/mul_scalar.rs | 2 +- src/rational/poly_over_q/arithmetic/sub.rs | 2 +- src/rational/poly_over_q/cmp.rs | 2 +- src/rational/poly_over_q/default.rs | 2 +- src/rational/poly_over_q/dot_product.rs | 4 +- src/rational/poly_over_q/evaluate.rs | 2 +- src/rational/poly_over_q/from.rs | 2 +- src/rational/poly_over_q/get.rs | 2 +- src/rational/poly_over_q/ownership.rs | 6 +-- src/rational/poly_over_q/properties.rs | 2 +- src/rational/poly_over_q/set.rs | 2 +- src/rational/poly_over_q/to_string.rs | 2 +- src/rational/poly_over_q/unsafe_functions.rs | 6 +-- src/rational/q.rs | 2 +- src/rational/q/arithmetic/add.rs | 2 +- src/rational/q/arithmetic/div.rs | 2 +- src/rational/q/arithmetic/exp.rs | 4 +- src/rational/q/arithmetic/logarithm.rs | 2 +- src/rational/q/arithmetic/mul.rs | 2 +- src/rational/q/arithmetic/pow.rs | 2 +- src/rational/q/arithmetic/sub.rs | 2 +- src/rational/q/cmp.rs | 6 +-- src/rational/q/default.rs | 2 +- src/rational/q/from.rs | 14 ++--- src/rational/q/get.rs | 2 +- src/rational/q/ownership.rs | 6 +-- src/rational/q/properties.rs | 2 +- src/rational/q/rounding.rs | 6 +-- src/rational/q/to_string.rs | 2 +- src/rational/q/unsafe_functions.rs | 4 +- src/traits.rs | 2 +- src/utils/factorization.rs | 2 +- src/utils/factorization/default.rs | 2 +- src/utils/factorization/from.rs | 2 +- src/utils/factorization/ownership.rs | 2 +- src/utils/factorization/refine.rs | 2 +- src/utils/sample/discrete_gauss.rs | 2 +- src/utils/sample/uniform.rs | 2 +- 225 files changed, 361 insertions(+), 413 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 15f088bf..6810d631 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ autobenches = false [dependencies] criterion = { version = "0.8", features = ["html_reports"] } -flint-sys = "0.9.0" libc = "0" paste = "1" rand = "0.10" @@ -27,6 +26,7 @@ thiserror = "2" lazy_static = "1" probability = "0.20" derive_more = { version = "2.1", features = ["display"] } +flint3-sys = { version="3.6.0", features=["gmp-mpfr-sys"]} [profile.bench] debug = true diff --git a/src/integer/mat_poly_over_z.rs b/src/integer/mat_poly_over_z.rs index 3b9a4846..a36536cd 100644 --- a/src/integer/mat_poly_over_z.rs +++ b/src/integer/mat_poly_over_z.rs @@ -10,7 +10,7 @@ //! This implementation uses the [FLINT](https://flintlib.org/) library. use crate::utils::parse::partial_string; -use flint_sys::fmpz_types::fmpz_poly_mat_struct; +use flint3_sys::fmpz_poly_mat_struct; use std::fmt; mod arithmetic; diff --git a/src/integer/mat_poly_over_z/arithmetic/add.rs b/src/integer/mat_poly_over_z/arithmetic/add.rs index cd61bad8..d3b05a14 100644 --- a/src/integer/mat_poly_over_z/arithmetic/add.rs +++ b/src/integer/mat_poly_over_z/arithmetic/add.rs @@ -15,7 +15,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_add; +use flint3_sys::fmpz_poly_mat_add; use std::ops::{Add, AddAssign}; impl AddAssign<&MatPolyOverZ> for MatPolyOverZ { diff --git a/src/integer/mat_poly_over_z/arithmetic/mul.rs b/src/integer/mat_poly_over_z/arithmetic/mul.rs index 8fd14875..c5c80223 100644 --- a/src/integer/mat_poly_over_z/arithmetic/mul.rs +++ b/src/integer/mat_poly_over_z/arithmetic/mul.rs @@ -15,7 +15,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_borrowed_to_owned, arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_mul_KS; +use flint3_sys::fmpz_poly_mat_mul_KS; use std::ops::Mul; impl Mul for &MatPolyOverZ { diff --git a/src/integer/mat_poly_over_z/arithmetic/mul_scalar.rs b/src/integer/mat_poly_over_z/arithmetic/mul_scalar.rs index 854b9c46..236ef292 100644 --- a/src/integer/mat_poly_over_z/arithmetic/mul_scalar.rs +++ b/src/integer/mat_poly_over_z/arithmetic/mul_scalar.rs @@ -18,7 +18,7 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_scalar_mul_fmpz, fmpz_poly_mat_scalar_mul_fmpz_poly}; +use flint3_sys::{fmpz_poly_mat_scalar_mul_fmpz, fmpz_poly_mat_scalar_mul_fmpz_poly}; use std::ops::{Mul, MulAssign}; impl Mul<&Z> for &MatPolyOverZ { diff --git a/src/integer/mat_poly_over_z/arithmetic/sub.rs b/src/integer/mat_poly_over_z/arithmetic/sub.rs index 14ae732d..ce507929 100644 --- a/src/integer/mat_poly_over_z/arithmetic/sub.rs +++ b/src/integer/mat_poly_over_z/arithmetic/sub.rs @@ -16,7 +16,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_sub; +use flint3_sys::fmpz_poly_mat_sub; use std::ops::{Sub, SubAssign}; impl SubAssign<&MatPolyOverZ> for MatPolyOverZ { diff --git a/src/integer/mat_poly_over_z/cmp.rs b/src/integer/mat_poly_over_z/cmp.rs index dce27278..6cb18c60 100644 --- a/src/integer/mat_poly_over_z/cmp.rs +++ b/src/integer/mat_poly_over_z/cmp.rs @@ -15,7 +15,7 @@ use crate::{ macros::compare_base::compare_base_default, traits::CompareBase, }; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_equal; +use flint3_sys::fmpz_poly_mat_equal; impl PartialEq for MatPolyOverZ { /// Checks if two matrices over [`PolyOverZ`](crate::integer::PolyOverZ) are equal. Used by the `==` and `!=` operators. diff --git a/src/integer/mat_poly_over_z/concat.rs b/src/integer/mat_poly_over_z/concat.rs index ea3e248e..6c8eea5a 100644 --- a/src/integer/mat_poly_over_z/concat.rs +++ b/src/integer/mat_poly_over_z/concat.rs @@ -13,7 +13,7 @@ use crate::{ error::MathError, traits::{Concatenate, MatrixDimensions}, }; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_concat_horizontal, fmpz_poly_mat_concat_vertical}; +use flint3_sys::{fmpz_poly_mat_concat_horizontal, fmpz_poly_mat_concat_vertical}; impl Concatenate for &MatPolyOverZ { type Output = MatPolyOverZ; diff --git a/src/integer/mat_poly_over_z/default.rs b/src/integer/mat_poly_over_z/default.rs index 03a7601c..c73fd0bd 100644 --- a/src/integer/mat_poly_over_z/default.rs +++ b/src/integer/mat_poly_over_z/default.rs @@ -10,7 +10,7 @@ use super::MatPolyOverZ; use crate::utils::index::evaluate_indices; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_init, fmpz_poly_mat_one}; +use flint3_sys::{fmpz_poly_mat_init, fmpz_poly_mat_one}; use std::{fmt::Display, mem::MaybeUninit}; impl MatPolyOverZ { diff --git a/src/integer/mat_poly_over_z/evaluate.rs b/src/integer/mat_poly_over_z/evaluate.rs index 57ff46c4..89ea654e 100644 --- a/src/integer/mat_poly_over_z/evaluate.rs +++ b/src/integer/mat_poly_over_z/evaluate.rs @@ -7,7 +7,7 @@ use crate::{ integer::{MatZ, Z}, traits::{Evaluate, MatrixDimensions}, }; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_evaluate_fmpz; +use flint3_sys::fmpz_poly_mat_evaluate_fmpz; impl> Evaluate for MatPolyOverZ { /// Evaluates a [`MatPolyOverZ`] on a given input entrywise. diff --git a/src/integer/mat_poly_over_z/get.rs b/src/integer/mat_poly_over_z/get.rs index 95b6e3d9..8e864bef 100644 --- a/src/integer/mat_poly_over_z/get.rs +++ b/src/integer/mat_poly_over_z/get.rs @@ -13,13 +13,12 @@ use crate::{ integer::PolyOverZ, traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}, }; -use flint_sys::{ - fmpz_poly::fmpz_poly_set, - fmpz_poly_mat::{ +use flint3_sys::{ + fmpz_poly_set, fmpz_poly_struct, + { fmpz_poly_mat_entry, fmpz_poly_mat_init_set, fmpz_poly_mat_window_clear, fmpz_poly_mat_window_init, }, - fmpz_types::fmpz_poly_struct, }; use std::mem::MaybeUninit; diff --git a/src/integer/mat_poly_over_z/ownership.rs b/src/integer/mat_poly_over_z/ownership.rs index c33cae20..675517d2 100644 --- a/src/integer/mat_poly_over_z/ownership.rs +++ b/src/integer/mat_poly_over_z/ownership.rs @@ -13,7 +13,7 @@ use super::MatPolyOverZ; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_clear, fmpz_poly_mat_set}; +use flint3_sys::{fmpz_poly_mat_clear, fmpz_poly_mat_set}; impl Clone for MatPolyOverZ { /// Clones the given element and returns a deep clone of the [`MatPolyOverZ`] element. diff --git a/src/integer/mat_poly_over_z/properties.rs b/src/integer/mat_poly_over_z/properties.rs index 124fbb66..8592560a 100644 --- a/src/integer/mat_poly_over_z/properties.rs +++ b/src/integer/mat_poly_over_z/properties.rs @@ -14,7 +14,7 @@ use crate::{ integer::Z, traits::{MatrixDimensions, MatrixGetEntry}, }; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_is_one, fmpz_poly_mat_is_zero, fmpz_poly_mat_rank}; +use flint3_sys::{fmpz_poly_mat_is_one, fmpz_poly_mat_is_zero, fmpz_poly_mat_rank}; impl MatPolyOverZ { /// Checks if a [`MatPolyOverZ`] is a identity matrix, i.e. diff --git a/src/integer/mat_poly_over_z/reduce.rs b/src/integer/mat_poly_over_z/reduce.rs index f3e994da..f0c808a7 100644 --- a/src/integer/mat_poly_over_z/reduce.rs +++ b/src/integer/mat_poly_over_z/reduce.rs @@ -15,7 +15,7 @@ use crate::{ integer::{PolyOverZ, poly_over_z::fmpz_poly_helpers::reduce_fmpz_poly_by_poly_over_z}, traits::MatrixDimensions, }; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_entry; +use flint3_sys::fmpz_poly_mat_entry; impl MatPolyOverZ { /// Entrywise reduces a matrix of polynomials by a polynomial `modulus`. diff --git a/src/integer/mat_poly_over_z/set.rs b/src/integer/mat_poly_over_z/set.rs index b4bc608a..963dd9c9 100644 --- a/src/integer/mat_poly_over_z/set.rs +++ b/src/integer/mat_poly_over_z/set.rs @@ -16,12 +16,12 @@ use crate::{ traits::{MatrixDimensions, MatrixSetEntry, MatrixSetSubmatrix, MatrixSwaps}, utils::index::{evaluate_index_for_vector, evaluate_indices_for_matrix}, }; -use flint_sys::{ - fmpz_poly::{fmpz_poly_set, fmpz_poly_swap}, - fmpz_poly_mat::{ +use flint3_sys::{ + { fmpz_poly_mat_entry, fmpz_poly_mat_set, fmpz_poly_mat_window_clear, fmpz_poly_mat_window_init, }, + {fmpz_poly_set, fmpz_poly_swap}, }; use std::{fmt::Display, mem::MaybeUninit}; diff --git a/src/integer/mat_poly_over_z/tensor.rs b/src/integer/mat_poly_over_z/tensor.rs index dc473d8f..5d8bb30b 100644 --- a/src/integer/mat_poly_over_z/tensor.rs +++ b/src/integer/mat_poly_over_z/tensor.rs @@ -13,7 +13,7 @@ use crate::{ integer::PolyOverZ, traits::{MatrixDimensions, MatrixGetEntry, Tensor}, }; -use flint_sys::{fmpz_poly::fmpz_poly_mul, fmpz_poly_mat::fmpz_poly_mat_entry}; +use flint3_sys::{fmpz_poly_mat_entry, fmpz_poly_mul}; impl Tensor for MatPolyOverZ { /// Computes the tensor product of `self` with `other`. diff --git a/src/integer/mat_poly_over_z/trace.rs b/src/integer/mat_poly_over_z/trace.rs index 807fe4a5..86bb62ac 100644 --- a/src/integer/mat_poly_over_z/trace.rs +++ b/src/integer/mat_poly_over_z/trace.rs @@ -8,7 +8,7 @@ //! This module contains the implementation of the `trace` function. -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_trace; +use flint3_sys::fmpz_poly_mat_trace; use super::MatPolyOverZ; use crate::{error::MathError, integer::PolyOverZ, traits::MatrixDimensions}; diff --git a/src/integer/mat_poly_over_z/transpose.rs b/src/integer/mat_poly_over_z/transpose.rs index 1d949485..8046d155 100644 --- a/src/integer/mat_poly_over_z/transpose.rs +++ b/src/integer/mat_poly_over_z/transpose.rs @@ -10,7 +10,7 @@ use super::MatPolyOverZ; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_transpose; +use flint3_sys::fmpz_poly_mat_transpose; impl MatPolyOverZ { /// Returns the transposed form of the given matrix, i.e. rows get transformed to columns diff --git a/src/integer/mat_poly_over_z/unsafe_functions.rs b/src/integer/mat_poly_over_z/unsafe_functions.rs index 272065ab..9f7a24e1 100644 --- a/src/integer/mat_poly_over_z/unsafe_functions.rs +++ b/src/integer/mat_poly_over_z/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::MatPolyOverZ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::{fmpz_poly_mat::fmpz_poly_mat_clear, fmpz_types::fmpz_poly_mat_struct}; +use flint3_sys::{fmpz_poly_mat_clear, fmpz_poly_mat_struct}; unsafe_getter!(MatPolyOverZ, matrix, fmpz_poly_mat_struct); unsafe_setter!( @@ -25,7 +25,7 @@ unsafe_setter!( mod test_get_fmpz_poly_mat_struct { use super::MatPolyOverZ; use crate::{integer::PolyOverZ, traits::MatrixGetEntry}; - use flint_sys::{fmpz_poly::fmpz_poly_set, fmpz_poly_mat::fmpz_poly_mat_entry}; + use flint3_sys::{fmpz_poly_mat_entry, fmpz_poly_set}; use std::str::FromStr; /// Checks availability of the getter for [`MatPolyOverZ::matrix`] @@ -51,7 +51,7 @@ mod test_get_fmpz_poly_mat_struct { mod test_set_fmpz_poly_mat_struct { use super::MatPolyOverZ; use crate::{integer::PolyOverZ, traits::MatrixGetEntry}; - use flint_sys::fmpz_poly_mat::fmpz_poly_mat_init; + use flint3_sys::fmpz_poly_mat_init; use std::{mem::MaybeUninit, str::FromStr}; /// Checks availability of the setter for [`MatPolyOverZ::matrix`] diff --git a/src/integer/mat_poly_over_z/vector/dot_product.rs b/src/integer/mat_poly_over_z/vector/dot_product.rs index 02b8c543..d79ef5d9 100644 --- a/src/integer/mat_poly_over_z/vector/dot_product.rs +++ b/src/integer/mat_poly_over_z/vector/dot_product.rs @@ -11,7 +11,7 @@ use crate::error::MathError; use crate::integer::{MatPolyOverZ, PolyOverZ}; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly::{fmpz_poly_add, fmpz_poly_mul}; +use flint3_sys::{fmpz_poly_add, fmpz_poly_mul}; impl MatPolyOverZ { /// Returns the dot product of two vectors of type [`MatPolyOverZ`]. diff --git a/src/integer/mat_z.rs b/src/integer/mat_z.rs index e836d753..f0e97c1e 100644 --- a/src/integer/mat_z.rs +++ b/src/integer/mat_z.rs @@ -10,7 +10,7 @@ //! This implementation uses the [FLINT](https://flintlib.org/) library. use crate::utils::parse::partial_string; -use flint_sys::fmpz_types::fmpz_mat_struct; +use flint3_sys::fmpz_mat_struct; use std::fmt; mod arithmetic; diff --git a/src/integer/mat_z/arithmetic/add.rs b/src/integer/mat_z/arithmetic/add.rs index 3b1f19cf..66e7231f 100644 --- a/src/integer/mat_z/arithmetic/add.rs +++ b/src/integer/mat_z/arithmetic/add.rs @@ -15,7 +15,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_mat::fmpz_mat_add; +use flint3_sys::fmpz_mat_add; use std::ops::{Add, AddAssign}; impl AddAssign<&MatZ> for MatZ { diff --git a/src/integer/mat_z/arithmetic/div.rs b/src/integer/mat_z/arithmetic/div.rs index 940b9360..ecbe2e96 100644 --- a/src/integer/mat_z/arithmetic/div.rs +++ b/src/integer/mat_z/arithmetic/div.rs @@ -15,8 +15,8 @@ use crate::macros::arithmetics::{ }; use crate::rational::MatQ; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::fmpq_mat_set_fmpz_mat_div_fmpz; -use flint_sys::fmpz_mat::fmpz_mat_scalar_divexact_fmpz; +use flint3_sys::fmpq_mat_set_fmpz_mat_div_fmpz; +use flint3_sys::fmpz_mat_scalar_divexact_fmpz; use std::ops::Div; impl MatZ { diff --git a/src/integer/mat_z/arithmetic/modulo.rs b/src/integer/mat_z/arithmetic/modulo.rs index 748cf460..9a173952 100644 --- a/src/integer/mat_z/arithmetic/modulo.rs +++ b/src/integer/mat_z/arithmetic/modulo.rs @@ -18,7 +18,7 @@ use crate::{ }, traits::MatrixDimensions, }; -use flint_sys::{fmpz::fmpz_mod, fmpz_mat::fmpz_mat_entry, fmpz_mod::fmpz_mod_set_fmpz}; +use flint3_sys::{fmpz_mat_entry, fmpz_mod, fmpz_mod_set_fmpz}; use std::ops::Rem; impl Rem<&Z> for &MatZ { diff --git a/src/integer/mat_z/arithmetic/mul.rs b/src/integer/mat_z/arithmetic/mul.rs index ae30430b..1bb3843b 100644 --- a/src/integer/mat_z/arithmetic/mul.rs +++ b/src/integer/mat_z/arithmetic/mul.rs @@ -16,9 +16,9 @@ use crate::macros::arithmetics::{ }; use crate::rational::MatQ; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::fmpq_mat_mul_r_fmpz_mat; -use flint_sys::fmpz_mat::fmpz_mat_mul; -use flint_sys::fmpz_mod_mat::_fmpz_mod_mat_reduce; +use flint3_sys::_fmpz_mod_mat_reduce; +use flint3_sys::fmpq_mat_mul_r_fmpz_mat; +use flint3_sys::fmpz_mat_mul; use std::ops::Mul; impl Mul for &MatZ { diff --git a/src/integer/mat_z/arithmetic/mul_scalar.rs b/src/integer/mat_z/arithmetic/mul_scalar.rs index 3de882f4..1f8eaca4 100644 --- a/src/integer/mat_z/arithmetic/mul_scalar.rs +++ b/src/integer/mat_z/arithmetic/mul_scalar.rs @@ -19,9 +19,7 @@ use crate::macros::arithmetics::{ use crate::macros::for_others::implement_for_others; use crate::rational::{MatQ, Q}; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_mat::{ - fmpz_mat_scalar_mul_fmpz, fmpz_mat_scalar_mul_si, fmpz_mat_scalar_mul_ui, -}; +use flint3_sys::{fmpz_mat_scalar_mul_fmpz, fmpz_mat_scalar_mul_si, fmpz_mat_scalar_mul_ui}; use std::ops::{Mul, MulAssign}; impl Mul<&Z> for &MatZ { diff --git a/src/integer/mat_z/arithmetic/sub.rs b/src/integer/mat_z/arithmetic/sub.rs index 95983186..bc57818d 100644 --- a/src/integer/mat_z/arithmetic/sub.rs +++ b/src/integer/mat_z/arithmetic/sub.rs @@ -17,8 +17,8 @@ use crate::macros::arithmetics::{ }; use crate::rational::MatQ; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_mat::fmpz_mat_sub; -use flint_sys::fmpz_mod_mat::_fmpz_mod_mat_reduce; +use flint3_sys::_fmpz_mod_mat_reduce; +use flint3_sys::fmpz_mat_sub; use std::ops::{Sub, SubAssign}; impl SubAssign<&MatZ> for MatZ { diff --git a/src/integer/mat_z/basis_reductions.rs b/src/integer/mat_z/basis_reductions.rs index 604d9ac5..66bd50eb 100644 --- a/src/integer/mat_z/basis_reductions.rs +++ b/src/integer/mat_z/basis_reductions.rs @@ -10,7 +10,7 @@ use super::MatZ; use crate::{rational::Q, traits::MatrixDimensions}; -use flint_sys::fmpz_mat::{fmpz_mat_is_reduced, fmpz_mat_lll_storjohann}; +use flint3_sys::{fmpz_mat_is_reduced, fmpz_mat_lll_storjohann}; impl MatZ { /// Performs the (modified Storjohann) LLL algorithm on the matrix `self`. diff --git a/src/integer/mat_z/cmp.rs b/src/integer/mat_z/cmp.rs index 682abd16..81b0481d 100644 --- a/src/integer/mat_z/cmp.rs +++ b/src/integer/mat_z/cmp.rs @@ -10,7 +10,7 @@ use super::MatZ; use crate::{integer::Z, macros::compare_base::compare_base_default, traits::CompareBase}; -use flint_sys::fmpz_mat::fmpz_mat_equal; +use flint3_sys::fmpz_mat_equal; impl PartialEq for MatZ { /// Checks if two [`MatZ`] instances are equal. Used by the `==` and `!=` operators. diff --git a/src/integer/mat_z/concat.rs b/src/integer/mat_z/concat.rs index 6521fab9..f8084a5d 100644 --- a/src/integer/mat_z/concat.rs +++ b/src/integer/mat_z/concat.rs @@ -13,7 +13,7 @@ use crate::{ error::MathError, traits::{Concatenate, MatrixDimensions}, }; -use flint_sys::fmpz_mat::{fmpz_mat_concat_horizontal, fmpz_mat_concat_vertical}; +use flint3_sys::{fmpz_mat_concat_horizontal, fmpz_mat_concat_vertical}; impl Concatenate for &MatZ { type Output = MatZ; diff --git a/src/integer/mat_z/default.rs b/src/integer/mat_z/default.rs index 7e8e345b..117147e0 100644 --- a/src/integer/mat_z/default.rs +++ b/src/integer/mat_z/default.rs @@ -10,7 +10,7 @@ use super::MatZ; use crate::utils::index::evaluate_indices; -use flint_sys::fmpz_mat::{fmpz_mat_init, fmpz_mat_one}; +use flint3_sys::{fmpz_mat_init, fmpz_mat_one}; use std::{fmt::Display, mem::MaybeUninit}; impl MatZ { diff --git a/src/integer/mat_z/determinant.rs b/src/integer/mat_z/determinant.rs index 969404d1..fd1d4065 100644 --- a/src/integer/mat_z/determinant.rs +++ b/src/integer/mat_z/determinant.rs @@ -10,7 +10,7 @@ use super::MatZ; use crate::{error::MathError, integer::Z, traits::MatrixDimensions}; -use flint_sys::fmpz_mat::fmpz_mat_det; +use flint3_sys::fmpz_mat_det; impl MatZ { /// Returns the determinant of the matrix or an error if diff --git a/src/integer/mat_z/forms.rs b/src/integer/mat_z/forms.rs index 54d70808..220a7529 100644 --- a/src/integer/mat_z/forms.rs +++ b/src/integer/mat_z/forms.rs @@ -11,9 +11,7 @@ use super::MatZ; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_mat::{ - fmpz_mat_hnf_transform, fmpz_mat_is_in_hnf, fmpz_mat_is_in_snf, fmpz_mat_snf, -}; +use flint3_sys::{fmpz_mat_hnf_transform, fmpz_mat_is_in_hnf, fmpz_mat_is_in_snf, fmpz_mat_snf}; impl MatZ { /// Computes the Hermite normal form of `self` along with diff --git a/src/integer/mat_z/get.rs b/src/integer/mat_z/get.rs index 85c00c4c..0a6e8dd4 100644 --- a/src/integer/mat_z/get.rs +++ b/src/integer/mat_z/get.rs @@ -13,10 +13,9 @@ use crate::{ integer::Z, traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}, }; -use flint_sys::{ - flint::fmpz, - fmpz::fmpz_init_set, - fmpz_mat::{fmpz_mat_entry, fmpz_mat_init_set, fmpz_mat_window_clear, fmpz_mat_window_init}, +use flint3_sys::{ + fmpz, fmpz_init_set, + {fmpz_mat_entry, fmpz_mat_init_set, fmpz_mat_window_clear, fmpz_mat_window_init}, }; use std::mem::MaybeUninit; diff --git a/src/integer/mat_z/inverse.rs b/src/integer/mat_z/inverse.rs index 39eb0e28..b778d29c 100644 --- a/src/integer/mat_z/inverse.rs +++ b/src/integer/mat_z/inverse.rs @@ -10,7 +10,7 @@ use super::MatZ; use crate::{rational::MatQ, traits::MatrixDimensions}; -use flint_sys::fmpq_mat::fmpq_mat_inv; +use flint3_sys::fmpq_mat_inv; impl MatZ { /// Returns the inverse of the matrix if it exists (is square and diff --git a/src/integer/mat_z/ownership.rs b/src/integer/mat_z/ownership.rs index 978d95af..f72ba68f 100644 --- a/src/integer/mat_z/ownership.rs +++ b/src/integer/mat_z/ownership.rs @@ -14,7 +14,7 @@ use crate::traits::MatrixDimensions; use super::MatZ; -use flint_sys::fmpz_mat::{fmpz_mat_clear, fmpz_mat_set}; +use flint3_sys::{fmpz_mat_clear, fmpz_mat_set}; impl Clone for MatZ { /// Clones the given element and returns a deep clone of the [`MatZ`] element. diff --git a/src/integer/mat_z/properties.rs b/src/integer/mat_z/properties.rs index dcfbf72b..2cfc432d 100644 --- a/src/integer/mat_z/properties.rs +++ b/src/integer/mat_z/properties.rs @@ -13,7 +13,7 @@ use crate::{ integer::Z, traits::{MatrixDimensions, MatrixGetEntry}, }; -use flint_sys::fmpz_mat::{fmpz_mat_is_one, fmpz_mat_is_square, fmpz_mat_is_zero, fmpz_mat_rank}; +use flint3_sys::{fmpz_mat_is_one, fmpz_mat_is_square, fmpz_mat_is_zero, fmpz_mat_rank}; impl MatZ { /// Checks if a [`MatZ`] is the identity matrix. diff --git a/src/integer/mat_z/set.rs b/src/integer/mat_z/set.rs index a2c25f3a..527150fb 100644 --- a/src/integer/mat_z/set.rs +++ b/src/integer/mat_z/set.rs @@ -15,12 +15,12 @@ use crate::{ traits::{MatrixDimensions, MatrixSetEntry, MatrixSetSubmatrix, MatrixSwaps}, utils::index::{evaluate_index_for_vector, evaluate_indices_for_matrix}, }; -use flint_sys::{ - fmpz::{fmpz_set, fmpz_swap}, - fmpz_mat::{ +use flint3_sys::{ + { fmpz_mat_entry, fmpz_mat_invert_cols, fmpz_mat_invert_rows, fmpz_mat_set, fmpz_mat_swap_cols, fmpz_mat_swap_rows, fmpz_mat_window_clear, fmpz_mat_window_init, }, + {fmpz_set, fmpz_swap}, }; use std::{fmt::Display, mem::MaybeUninit, ptr::null_mut}; diff --git a/src/integer/mat_z/tensor.rs b/src/integer/mat_z/tensor.rs index 72757807..8d8aec90 100644 --- a/src/integer/mat_z/tensor.rs +++ b/src/integer/mat_z/tensor.rs @@ -10,7 +10,7 @@ use super::MatZ; use crate::traits::{MatrixDimensions, Tensor}; -use flint_sys::fmpz_mat::fmpz_mat_kronecker_product; +use flint3_sys::fmpz_mat_kronecker_product; impl Tensor for MatZ { /// Computes the tensor product of `self` with `other`. diff --git a/src/integer/mat_z/trace.rs b/src/integer/mat_z/trace.rs index 7d05dc3b..5b33f325 100644 --- a/src/integer/mat_z/trace.rs +++ b/src/integer/mat_z/trace.rs @@ -8,7 +8,7 @@ //! This module contains the implementation of the `trace` function. -use flint_sys::fmpz_mat::fmpz_mat_trace; +use flint3_sys::fmpz_mat_trace; use super::MatZ; use crate::{error::MathError, integer::Z, traits::MatrixDimensions}; diff --git a/src/integer/mat_z/transpose.rs b/src/integer/mat_z/transpose.rs index df999225..1610db63 100644 --- a/src/integer/mat_z/transpose.rs +++ b/src/integer/mat_z/transpose.rs @@ -11,7 +11,7 @@ use crate::traits::MatrixDimensions; use super::MatZ; -use flint_sys::fmpz_mat::fmpz_mat_transpose; +use flint3_sys::fmpz_mat_transpose; impl MatZ { /// Returns the transposed form of the given matrix, i.e. rows get transformed to columns diff --git a/src/integer/mat_z/unsafe_functions.rs b/src/integer/mat_z/unsafe_functions.rs index 038f51c0..76909159 100644 --- a/src/integer/mat_z/unsafe_functions.rs +++ b/src/integer/mat_z/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::MatZ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::{fmpz_mat::fmpz_mat_clear, fmpz_types::fmpz_mat_struct}; +use flint3_sys::{fmpz_mat_clear, fmpz_mat_struct}; unsafe_getter!(MatZ, matrix, fmpz_mat_struct); unsafe_setter!(MatZ, matrix, fmpz_mat_struct, fmpz_mat_clear); @@ -20,7 +20,7 @@ unsafe_setter!(MatZ, matrix, fmpz_mat_struct, fmpz_mat_clear); mod test_get_fmpz_mat_struct { use super::MatZ; use crate::{integer::Z, traits::MatrixGetEntry}; - use flint_sys::{flint::fmpz, fmpz::fmpz_set, fmpz_mat::fmpz_mat_entry}; + use flint3_sys::{fmpz, fmpz_mat_entry, fmpz_set}; use std::str::FromStr; /// Checks availability of the getter for [`MatZ::matrix`] @@ -46,7 +46,7 @@ mod test_get_fmpz_mat_struct { mod test_set_fmpz_mat_struct { use super::MatZ; use crate::{integer::Z, traits::MatrixGetEntry}; - use flint_sys::fmpz_mat::fmpz_mat_init; + use flint3_sys::fmpz_mat_init; use std::{mem::MaybeUninit, str::FromStr}; /// Checks availability of the setter for [`MatZ::matrix`] diff --git a/src/integer/mat_z/vector/dot_product.rs b/src/integer/mat_z/vector/dot_product.rs index d32af460..b51337c1 100644 --- a/src/integer/mat_z/vector/dot_product.rs +++ b/src/integer/mat_z/vector/dot_product.rs @@ -11,7 +11,7 @@ use crate::error::MathError; use crate::integer::{MatZ, Z}; use crate::traits::MatrixDimensions; -use flint_sys::fmpz::fmpz_addmul; +use flint3_sys::fmpz_addmul; impl MatZ { /// Returns the dot product of two vectors of type [`MatZ`]. diff --git a/src/integer/mat_z/vector/norm.rs b/src/integer/mat_z/vector/norm.rs index 74fc52eb..0a60d07c 100644 --- a/src/integer/mat_z/vector/norm.rs +++ b/src/integer/mat_z/vector/norm.rs @@ -16,7 +16,7 @@ use crate::{ rational::Q, traits::MatrixDimensions, }; -use flint_sys::fmpz::fmpz_addmul; +use flint3_sys::fmpz_addmul; impl MatZ { /// Returns the squared Euclidean norm or squared 2-norm of the given (row or column) vector diff --git a/src/integer/poly_over_z.rs b/src/integer/poly_over_z.rs index e30cc073..d4009c00 100644 --- a/src/integer/poly_over_z.rs +++ b/src/integer/poly_over_z.rs @@ -10,7 +10,7 @@ //! [`Z`](crate::integer::Z) //! This implementation uses the [FLINT](https://flintlib.org/) library. -use flint_sys::fmpz_types::fmpz_poly_struct; +use flint3_sys::fmpz_poly_struct; use std::fmt; mod arithmetic; diff --git a/src/integer/poly_over_z/arithmetic/add.rs b/src/integer/poly_over_z/arithmetic/add.rs index 7250b9bf..d69bd367 100644 --- a/src/integer/poly_over_z/arithmetic/add.rs +++ b/src/integer/poly_over_z/arithmetic/add.rs @@ -14,7 +14,7 @@ use crate::macros::arithmetics::{ arithmetic_assign_trait_borrowed_to_owned, arithmetic_trait_borrowed_to_owned, arithmetic_trait_mixed_borrowed_owned, }; -use flint_sys::{fmpz::fmpz_add, fmpz_poly::fmpz_poly_add}; +use flint3_sys::{fmpz_add, fmpz_poly_add}; use std::ops::{Add, AddAssign}; impl AddAssign<&PolyOverZ> for PolyOverZ { diff --git a/src/integer/poly_over_z/arithmetic/modulo.rs b/src/integer/poly_over_z/arithmetic/modulo.rs index 686d94ad..0ba383b0 100644 --- a/src/integer/poly_over_z/arithmetic/modulo.rs +++ b/src/integer/poly_over_z/arithmetic/modulo.rs @@ -17,7 +17,7 @@ use crate::{ for_others::implement_for_others, }, }; -use flint_sys::fmpz_poly::fmpz_poly_scalar_mod_fmpz; +use flint3_sys::fmpz_poly_scalar_mod_fmpz; use std::ops::Rem; impl Rem<&Z> for &PolyOverZ { diff --git a/src/integer/poly_over_z/arithmetic/mul.rs b/src/integer/poly_over_z/arithmetic/mul.rs index 9a3ab9b2..8c6067fd 100644 --- a/src/integer/poly_over_z/arithmetic/mul.rs +++ b/src/integer/poly_over_z/arithmetic/mul.rs @@ -13,7 +13,7 @@ use crate::macros::arithmetics::{ arithmetic_assign_trait_borrowed_to_owned, arithmetic_trait_borrowed_to_owned, arithmetic_trait_mixed_borrowed_owned, }; -use flint_sys::fmpz_poly::fmpz_poly_mul; +use flint3_sys::fmpz_poly_mul; use std::ops::{Mul, MulAssign}; impl MulAssign<&PolyOverZ> for PolyOverZ { diff --git a/src/integer/poly_over_z/arithmetic/mul_scalar.rs b/src/integer/poly_over_z/arithmetic/mul_scalar.rs index bd5e0bbd..91fd16f0 100644 --- a/src/integer/poly_over_z/arithmetic/mul_scalar.rs +++ b/src/integer/poly_over_z/arithmetic/mul_scalar.rs @@ -18,11 +18,9 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::rational::{PolyOverQ, Q}; -use flint_sys::fmpq_poly::fmpq_poly_scalar_mul_fmpq; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_scalar_mul_fmpz; -use flint_sys::fmpz_poly::{ - fmpz_poly_scalar_mul_fmpz, fmpz_poly_scalar_mul_si, fmpz_poly_scalar_mul_ui, -}; +use flint3_sys::fmpq_poly_scalar_mul_fmpq; +use flint3_sys::fmpz_mod_poly_scalar_mul_fmpz; +use flint3_sys::{fmpz_poly_scalar_mul_fmpz, fmpz_poly_scalar_mul_si, fmpz_poly_scalar_mul_ui}; use std::ops::{Mul, MulAssign}; impl Mul<&Z> for &PolyOverZ { diff --git a/src/integer/poly_over_z/arithmetic/sub.rs b/src/integer/poly_over_z/arithmetic/sub.rs index fb4fcbad..97895795 100644 --- a/src/integer/poly_over_z/arithmetic/sub.rs +++ b/src/integer/poly_over_z/arithmetic/sub.rs @@ -17,9 +17,7 @@ use crate::{ }, rational::PolyOverQ, }; -use flint_sys::{ - fmpq_poly::fmpq_poly_sub, fmpz_mod_poly::fmpz_mod_poly_sub, fmpz_poly::fmpz_poly_sub, -}; +use flint3_sys::{fmpq_poly_sub, fmpz_mod_poly_sub, fmpz_poly_sub}; use std::ops::{Sub, SubAssign}; impl SubAssign<&PolyOverZ> for PolyOverZ { diff --git a/src/integer/poly_over_z/cmp.rs b/src/integer/poly_over_z/cmp.rs index 527e34a1..975d229b 100644 --- a/src/integer/poly_over_z/cmp.rs +++ b/src/integer/poly_over_z/cmp.rs @@ -10,7 +10,7 @@ //! This uses the traits from [`std::cmp`]. use crate::{integer::Z, traits::CompareBase}; -use flint_sys::fmpz_poly::fmpz_poly_equal; +use flint3_sys::fmpz_poly_equal; use super::PolyOverZ; diff --git a/src/integer/poly_over_z/default.rs b/src/integer/poly_over_z/default.rs index 609d2740..583ae2ef 100644 --- a/src/integer/poly_over_z/default.rs +++ b/src/integer/poly_over_z/default.rs @@ -9,7 +9,7 @@ //! Default value for a [`PolyOverZ`]. use super::PolyOverZ; -use flint_sys::fmpz_poly::fmpz_poly_init; +use flint3_sys::fmpz_poly_init; use std::mem::MaybeUninit; impl Default for PolyOverZ { diff --git a/src/integer/poly_over_z/dot_product.rs b/src/integer/poly_over_z/dot_product.rs index 0b20b35a..66cdee82 100644 --- a/src/integer/poly_over_z/dot_product.rs +++ b/src/integer/poly_over_z/dot_product.rs @@ -10,8 +10,8 @@ use crate::integer::PolyOverZ; use crate::{error::MathError, integer::Z}; -use flint_sys::fmpz::{fmpz_add, fmpz_mul}; -use flint_sys::fmpz_poly::fmpz_poly_get_coeff_fmpz; +use flint3_sys::fmpz_poly_get_coeff_fmpz; +use flint3_sys::{fmpz_add, fmpz_mul}; impl PolyOverZ { /// Returns the dot product of two polynomials of type [`PolyOverZ`]. diff --git a/src/integer/poly_over_z/evaluate.rs b/src/integer/poly_over_z/evaluate.rs index 52925d59..b50fb672 100644 --- a/src/integer/poly_over_z/evaluate.rs +++ b/src/integer/poly_over_z/evaluate.rs @@ -12,7 +12,7 @@ use super::PolyOverZ; use crate::{integer::Z, rational::Q, traits::Evaluate}; -use flint_sys::fmpz_poly::{fmpz_poly_evaluate_fmpq, fmpz_poly_evaluate_fmpz}; +use flint3_sys::{fmpz_poly_evaluate_fmpq, fmpz_poly_evaluate_fmpz}; impl> Evaluate for PolyOverZ { /// Evaluates a [`PolyOverZ`] on a given input. diff --git a/src/integer/poly_over_z/fmpz_poly_helpers.rs b/src/integer/poly_over_z/fmpz_poly_helpers.rs index 91bbab06..9a815f29 100644 --- a/src/integer/poly_over_z/fmpz_poly_helpers.rs +++ b/src/integer/poly_over_z/fmpz_poly_helpers.rs @@ -9,13 +9,10 @@ //! This module contains helpful functions on [`fmpz_poly_struct`]. use super::PolyOverZ; -use flint_sys::{ - flint::fmpz, - fmpz::{fmpz_is_one, fmpz_is_zero, fmpz_submul, fmpz_zero}, - fmpz_mod::fmpz_mod_set_fmpz, - fmpz_mod_types::{fmpz_mod_ctx_struct, fmpz_mod_poly_struct}, - fmpz_poly::_fmpz_poly_normalise, - fmpz_types::fmpz_poly_struct, +use flint3_sys::{ + _fmpz_poly_normalise, fmpz, fmpz_mod_set_fmpz, fmpz_poly_struct, + {fmpz_is_one, fmpz_is_zero, fmpz_submul, fmpz_zero}, + {fmpz_mod_ctx_struct, fmpz_mod_poly_struct}, }; use std::cmp::min; @@ -94,7 +91,7 @@ pub(crate) unsafe fn reduce_fmpz_poly_by_poly_over_z( /// integer::{MatPolyOverZ, fmpz_poly_helpers::reduce_fmpz_poly_by_fmpz_poly_sparse}, /// integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq}, /// }; -/// use flint_sys::{fmpz_poly::_fmpz_poly_normalise, fmpz_poly_mat::fmpz_poly_mat_entry}; +/// use flint3_sys::{_fmpz_poly_normalise, fmpz_poly_mat::fmpz_poly_mat_entry}; /// use std::str::FromStr; /// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap(); /// let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap(); @@ -163,7 +160,7 @@ pub(crate) unsafe fn reduce_fmpz_poly_by_fmpz_mod_poly_sparse( /// integer::{MatPolyOverZ, fmpz_poly_helpers::reduce_fmpz_poly_by_fmpz_poly_sparse}, /// integer_mod_q::{ModulusPolynomialRingZq}, /// }; -/// use flint_sys::{fmpz_poly::_fmpz_poly_normalise, fmpz_poly_mat::fmpz_poly_mat_entry}; +/// use flint3_sys::{_fmpz_poly_normalise, fmpz_poly_mat::fmpz_poly_mat_entry}; /// use std::str::FromStr; /// /// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap(); @@ -257,7 +254,7 @@ mod test_reduce_fmpz_poly_by_fmpz_poly { integer::{MatPolyOverZ, fmpz_poly_helpers::reduce_fmpz_poly_by_fmpz_poly_sparse}, integer_mod_q::ModulusPolynomialRingZq, }; - use flint_sys::{fmpz_poly::_fmpz_poly_normalise, fmpz_poly_mat::fmpz_poly_mat_entry}; + use flint3_sys::{_fmpz_poly_normalise, fmpz_poly_mat_entry}; use std::str::FromStr; /// Ensures that the doc test example works. @@ -294,7 +291,7 @@ mod test_reduce_fmpz_poly_by_fmpz_mod_poly { integer::{MatPolyOverZ, fmpz_poly_helpers::reduce_fmpz_poly_by_fmpz_poly_sparse}, integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq}, }; - use flint_sys::{fmpz_poly::_fmpz_poly_normalise, fmpz_poly_mat::fmpz_poly_mat_entry}; + use flint3_sys::{_fmpz_poly_normalise, fmpz_poly_mat_entry}; use std::str::FromStr; /// Ensures that the doc test example works. diff --git a/src/integer/poly_over_z/from.rs b/src/integer/poly_over_z/from.rs index 6000dd7f..ddb39954 100644 --- a/src/integer/poly_over_z/from.rs +++ b/src/integer/poly_over_z/from.rs @@ -16,7 +16,7 @@ use crate::{ integer::Z, traits::AsInteger, }; -use flint_sys::fmpz_poly::{fmpz_poly_set_fmpz, fmpz_poly_set_str}; +use flint3_sys::{fmpz_poly_set_fmpz, fmpz_poly_set_str}; use std::{ffi::CString, str::FromStr}; impl FromStr for PolyOverZ { diff --git a/src/integer/poly_over_z/get.rs b/src/integer/poly_over_z/get.rs index bf1071e9..69fd8e70 100644 --- a/src/integer/poly_over_z/get.rs +++ b/src/integer/poly_over_z/get.rs @@ -10,7 +10,7 @@ use super::PolyOverZ; use crate::{integer::Z, traits::GetCoefficient}; -use flint_sys::fmpz_poly::{fmpz_poly_degree, fmpz_poly_get_coeff_fmpz}; +use flint3_sys::{fmpz_poly_degree, fmpz_poly_get_coeff_fmpz}; impl GetCoefficient for PolyOverZ { /// Returns the coefficient of a polynomial [`PolyOverZ`] as a [`Z`]. diff --git a/src/integer/poly_over_z/ownership.rs b/src/integer/poly_over_z/ownership.rs index 8dbdbf62..48855cb6 100644 --- a/src/integer/poly_over_z/ownership.rs +++ b/src/integer/poly_over_z/ownership.rs @@ -12,7 +12,7 @@ //! The explicit functions contain the documentation. use super::PolyOverZ; -use flint_sys::fmpz_poly::{fmpz_poly_clear, fmpz_poly_set}; +use flint3_sys::{fmpz_poly_clear, fmpz_poly_set}; impl Clone for PolyOverZ { /// Clones the given element and returns a deep clone of the [`PolyOverZ`] element. diff --git a/src/integer/poly_over_z/properties.rs b/src/integer/poly_over_z/properties.rs index 12a6a952..42fddc02 100644 --- a/src/integer/poly_over_z/properties.rs +++ b/src/integer/poly_over_z/properties.rs @@ -9,7 +9,7 @@ //! This module includes functionality about properties of [`PolyOverZ`] instances. use super::PolyOverZ; -use flint_sys::fmpz_poly::{fmpz_poly_degree, fmpz_poly_is_one}; +use flint3_sys::{fmpz_poly_degree, fmpz_poly_is_one}; impl PolyOverZ { /// Checks if a [`PolyOverZ`] is the constant polynomial with coefficient `1`. diff --git a/src/integer/poly_over_z/set.rs b/src/integer/poly_over_z/set.rs index 742494d1..f7a9a67e 100644 --- a/src/integer/poly_over_z/set.rs +++ b/src/integer/poly_over_z/set.rs @@ -10,7 +10,7 @@ use super::PolyOverZ; use crate::{integer::Z, traits::SetCoefficient}; -use flint_sys::fmpz_poly::fmpz_poly_set_coeff_fmpz; +use flint3_sys::fmpz_poly_set_coeff_fmpz; impl> SetCoefficient for PolyOverZ { /// Sets the coefficient of a polynomial [`PolyOverZ`]. diff --git a/src/integer/poly_over_z/to_string.rs b/src/integer/poly_over_z/to_string.rs index 5ae06ebe..a97d7820 100644 --- a/src/integer/poly_over_z/to_string.rs +++ b/src/integer/poly_over_z/to_string.rs @@ -14,7 +14,7 @@ use super::PolyOverZ; use crate::macros::for_others::implement_for_owned; use core::fmt; -use flint_sys::fmpz_poly::fmpz_poly_get_str; +use flint3_sys::fmpz_poly_get_str; use std::ffi::CStr; impl From<&PolyOverZ> for String { diff --git a/src/integer/poly_over_z/unsafe_functions.rs b/src/integer/poly_over_z/unsafe_functions.rs index 71676cc1..431673a6 100644 --- a/src/integer/poly_over_z/unsafe_functions.rs +++ b/src/integer/poly_over_z/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::PolyOverZ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::{fmpz_poly::fmpz_poly_clear, fmpz_types::fmpz_poly_struct}; +use flint3_sys::{fmpz_poly_clear, fmpz_poly_struct}; unsafe_getter!(PolyOverZ, poly, fmpz_poly_struct); unsafe_setter!(PolyOverZ, poly, fmpz_poly_struct, fmpz_poly_clear); @@ -19,7 +19,7 @@ unsafe_setter!(PolyOverZ, poly, fmpz_poly_struct, fmpz_poly_clear); #[cfg(test)] mod test_get_fmpz_poly_struct { use super::PolyOverZ; - use flint_sys::{flint::fmpz, fmpz_poly::fmpz_poly_set_fmpz}; + use flint3_sys::{fmpz, fmpz_poly_set_fmpz}; /// Checks availability of the getter for [`PolyOverZ::poly`] /// and its ability to be modified. @@ -40,7 +40,7 @@ mod test_get_fmpz_poly_struct { #[cfg(test)] mod test_set_fmpz_poly_struct { use super::PolyOverZ; - use flint_sys::fmpz_poly::fmpz_poly_init; + use flint3_sys::fmpz_poly_init; use std::mem::MaybeUninit; /// Checks availability of the setter for [`PolyOverZ::poly`] diff --git a/src/integer/z.rs b/src/integer/z.rs index 9b287c7b..fd420dc8 100644 --- a/src/integer/z.rs +++ b/src/integer/z.rs @@ -9,7 +9,7 @@ //! `Z` is a type for integers with arbitrary length. //! This implementation uses the [FLINT](https://flintlib.org/) library. -use flint_sys::flint::fmpz; +use flint3_sys::fmpz; use std::fmt; mod arithmetic; diff --git a/src/integer/z/arithmetic/add.rs b/src/integer/z/arithmetic/add.rs index 5f5cbae5..ada09588 100644 --- a/src/integer/z/arithmetic/add.rs +++ b/src/integer/z/arithmetic/add.rs @@ -19,11 +19,8 @@ use crate::{ }, rational::Q, }; -use flint_sys::{ - flint::fmpz, - fmpq::fmpq_add_fmpz, - fmpz::{fmpz_add, fmpz_add_si, fmpz_add_ui}, - fmpz_mod::fmpz_mod_add_fmpz, +use flint3_sys::{ + fmpq_add_fmpz, fmpz, fmpz_mod_add_fmpz, {fmpz_add, fmpz_add_si, fmpz_add_ui}, }; use std::ops::{Add, AddAssign}; diff --git a/src/integer/z/arithmetic/div.rs b/src/integer/z/arithmetic/div.rs index da151fad..e89c5153 100644 --- a/src/integer/z/arithmetic/div.rs +++ b/src/integer/z/arithmetic/div.rs @@ -14,7 +14,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, }; use crate::rational::Q; -use flint_sys::fmpz::{fmpz_cdiv_q, fmpz_fdiv_q, fmpz_tdiv_qr}; +use flint3_sys::{fmpz_cdiv_q, fmpz_fdiv_q, fmpz_tdiv_qr}; use std::ops::Div; impl Z { diff --git a/src/integer/z/arithmetic/logarithm.rs b/src/integer/z/arithmetic/logarithm.rs index e2eb7c51..1267d838 100644 --- a/src/integer/z/arithmetic/logarithm.rs +++ b/src/integer/z/arithmetic/logarithm.rs @@ -9,7 +9,7 @@ //! Implementations to call the logarithm on a [`Z`] integer. use crate::{error::MathError, integer::Z, rational::Q}; -use flint_sys::fmpz::{fmpz_clog, fmpz_dlog, fmpz_flog}; +use flint3_sys::{fmpz_clog, fmpz_dlog, fmpz_flog}; impl Z { /// Computes the logarithm of a natural number (i.e. an integer greater than `0`) diff --git a/src/integer/z/arithmetic/modulo.rs b/src/integer/z/arithmetic/modulo.rs index 41f5cddc..cbcf3854 100644 --- a/src/integer/z/arithmetic/modulo.rs +++ b/src/integer/z/arithmetic/modulo.rs @@ -8,7 +8,7 @@ //! Implementation of the [`Rem`] trait for [`Z`] values. -use flint_sys::{fmpz::fmpz_mod, fmpz_mod::fmpz_mod_set_fmpz}; +use flint3_sys::{fmpz_mod, fmpz_mod_set_fmpz}; use super::super::Z; use crate::{ diff --git a/src/integer/z/arithmetic/mul.rs b/src/integer/z/arithmetic/mul.rs index 0b208add..8899fbfd 100644 --- a/src/integer/z/arithmetic/mul.rs +++ b/src/integer/z/arithmetic/mul.rs @@ -18,11 +18,8 @@ use crate::{ }, rational::Q, }; -use flint_sys::{ - flint::fmpz, - fmpq::fmpq_mul_fmpz, - fmpz::{fmpz_mul, fmpz_mul_si, fmpz_mul_ui}, - fmpz_mod::fmpz_mod_mul_fmpz, +use flint3_sys::{ + fmpq_mul_fmpz, fmpz, fmpz_mod_mul_fmpz, {fmpz_mul, fmpz_mul_si, fmpz_mul_ui}, }; use std::ops::{Mul, MulAssign}; diff --git a/src/integer/z/arithmetic/pow.rs b/src/integer/z/arithmetic/pow.rs index e3d0a72c..2e9ca8f0 100644 --- a/src/integer/z/arithmetic/pow.rs +++ b/src/integer/z/arithmetic/pow.rs @@ -9,7 +9,7 @@ //! This module provides an implementation of the [`Pow`] trait for [`Z`]. use crate::{error::MathError, integer::Z, traits::Pow}; -use flint_sys::fmpz::fmpz_pow_fmpz; +use flint3_sys::fmpz_pow_fmpz; impl> Pow for Z { type Output = Z; diff --git a/src/integer/z/arithmetic/root.rs b/src/integer/z/arithmetic/root.rs index 373ecd92..8ba92fe6 100644 --- a/src/integer/z/arithmetic/root.rs +++ b/src/integer/z/arithmetic/root.rs @@ -9,7 +9,7 @@ //! This module provides implementations for calculating roots on [`Z`]. use crate::{error::MathError, integer::Z, rational::Q}; -use flint_sys::fmpz::fmpz_sqrtrem; +use flint3_sys::fmpz_sqrtrem; impl Z { /// Calculate the square root with a fixed precision. diff --git a/src/integer/z/arithmetic/sub.rs b/src/integer/z/arithmetic/sub.rs index 0925ca1b..045c3745 100644 --- a/src/integer/z/arithmetic/sub.rs +++ b/src/integer/z/arithmetic/sub.rs @@ -18,11 +18,9 @@ use crate::{ }, rational::Q, }; -use flint_sys::{ - flint::{fmpq, fmpz}, - fmpq::{fmpq_set_fmpz_frac, fmpq_sub}, - fmpz::{fmpz_sub, fmpz_sub_si, fmpz_sub_ui}, - fmpz_mod::fmpz_mod_sub_fmpz, +use flint3_sys::{ + fmpz_mod_sub_fmpz, {fmpq, fmpz}, {fmpq_set_fmpz_frac, fmpq_sub}, + {fmpz_sub, fmpz_sub_si, fmpz_sub_ui}, }; use std::ops::{Sub, SubAssign}; @@ -131,7 +129,7 @@ impl Sub<&Q> for &Z { /// ``` fn sub(self, other: &Q) -> Self::Output { let mut out = Q::default(); - let mut fmpq_1 = fmpq::default(); + let mut fmpq_1 = default(); unsafe { fmpq_set_fmpz_frac(&mut fmpq_1, &self.value, &1) } unsafe { fmpq_sub(&mut out.value, &fmpq_1, &other.value); diff --git a/src/integer/z/cmp.rs b/src/integer/z/cmp.rs index 458689d0..6c15cf93 100644 --- a/src/integer/z/cmp.rs +++ b/src/integer/z/cmp.rs @@ -11,7 +11,7 @@ use super::Z; use crate::{integer_mod_q::Modulus, macros::for_others::implement_for_others}; -use flint_sys::fmpz::{fmpz_cmp, fmpz_equal}; +use flint3_sys::{fmpz_cmp, fmpz_equal}; use std::cmp::Ordering; impl PartialEq for Z { diff --git a/src/integer/z/fmpz_helpers.rs b/src/integer/z/fmpz_helpers.rs index f4f1566d..3e7f9fd4 100644 --- a/src/integer/z/fmpz_helpers.rs +++ b/src/integer/z/fmpz_helpers.rs @@ -10,8 +10,8 @@ use super::Z; use crate::traits::AsInteger; -use flint_sys::flint::fmpz; -use flint_sys::fmpz::{ +use flint3_sys::fmpz; +use flint3_sys::{ fmpz_abs, fmpz_cmpabs, fmpz_init_set, fmpz_init_set_si, fmpz_init_set_ui, fmpz_sub, fmpz_swap, }; @@ -26,7 +26,7 @@ use flint_sys::fmpz::{ /// /// # Examples /// ```compile_fail -/// use flint_sys::fmpz::fmpz; +/// use flint3_sys::fmpz; /// use qfall_math::integer::{fmpz_helpers::find_max_abs, Z}; /// /// let fmpz_vec = vec![fmpz(0), fmpz(-13), fmpz(10)]; @@ -61,7 +61,7 @@ pub(crate) fn find_max_abs(fmpz_vector: &Vec) -> Z { /// /// # Examples /// ```compile_fail -/// use flint_sys::fmpz::fmpz; +/// use flint3_sys::fmpz; /// use qfall_math::integer::fmpz_helpers::distance; /// /// let a = fmpz(1); diff --git a/src/integer/z/from.rs b/src/integer/z/from.rs index 1307c026..66ed117e 100644 --- a/src/integer/z/from.rs +++ b/src/integer/z/from.rs @@ -17,8 +17,8 @@ use crate::{ macros::for_others::implement_empty_trait_owned_ref, traits::AsInteger, }; -use flint_sys::flint::fmpz; -use flint_sys::fmpz::{fmpz_get_si, fmpz_get_ui, fmpz_init_set, fmpz_set_str, fmpz_setbit}; +use flint3_sys::fmpz; +use flint3_sys::{fmpz_get_si, fmpz_get_ui, fmpz_init_set, fmpz_set_str, fmpz_setbit}; use std::{ffi::CString, str::FromStr}; impl Z { @@ -44,7 +44,7 @@ impl Z { /// ``` /// ```compile_fail /// use qfall_math::integer::Z; - /// use flint_sys::fmpz::{fmpz, fmpz_clear}; + /// use flint3_sys::{fmpz, fmpz_clear}; /// /// let value = fmpz(0); /// @@ -75,7 +75,7 @@ impl Z { /// # Examples /// ```compile_fail /// use qfall_math::integer::Z; - /// use flint_sys::fmpz::fmpz; + /// use flint3_sys::fmpz; /// /// let value = fmpz(0); /// @@ -774,7 +774,7 @@ mod test_from_str_b { #[cfg(test)] mod test_from_fmpz { use super::Z; - use flint_sys::{flint::fmpz, fmpz::fmpz_set_ui}; + use flint3_sys::{fmpz, fmpz_set_ui}; /// Ensure that `from_fmpz` is available for small and large numbers #[test] diff --git a/src/integer/z/gcd.rs b/src/integer/z/gcd.rs index 59eaca2a..0fdba032 100644 --- a/src/integer/z/gcd.rs +++ b/src/integer/z/gcd.rs @@ -11,7 +11,7 @@ use super::Z; use crate::traits::{Gcd, Xgcd}; -use flint_sys::fmpz::{fmpz_gcd, fmpz_xgcd}; +use flint3_sys::{fmpz_gcd, fmpz_xgcd}; impl> Gcd for Z { type Output = Z; diff --git a/src/integer/z/lcm.rs b/src/integer/z/lcm.rs index 9c1b5378..bdb458a2 100644 --- a/src/integer/z/lcm.rs +++ b/src/integer/z/lcm.rs @@ -10,7 +10,7 @@ use super::Z; use crate::traits::Lcm; -use flint_sys::fmpz::fmpz_lcm; +use flint3_sys::fmpz_lcm; impl> Lcm for Z { type Output = Z; diff --git a/src/integer/z/logic/bit_and.rs b/src/integer/z/logic/bit_and.rs index 258beebf..5d3e69c8 100644 --- a/src/integer/z/logic/bit_and.rs +++ b/src/integer/z/logic/bit_and.rs @@ -15,7 +15,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpz::fmpz_and; +use flint3_sys::fmpz_and; use std::ops::BitAnd; impl BitAnd for &Z { diff --git a/src/integer/z/logic/bit_or.rs b/src/integer/z/logic/bit_or.rs index b6262ff2..2ef4aa48 100644 --- a/src/integer/z/logic/bit_or.rs +++ b/src/integer/z/logic/bit_or.rs @@ -15,7 +15,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpz::fmpz_or; +use flint3_sys::fmpz_or; use std::ops::BitOr; impl BitOr for &Z { diff --git a/src/integer/z/logic/bit_xor.rs b/src/integer/z/logic/bit_xor.rs index 48a63ebe..4b7ae2c0 100644 --- a/src/integer/z/logic/bit_xor.rs +++ b/src/integer/z/logic/bit_xor.rs @@ -15,7 +15,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpz::fmpz_xor; +use flint3_sys::fmpz_xor; use std::ops::BitXor; impl BitXor for &Z { diff --git a/src/integer/z/logic/complement.rs b/src/integer/z/logic/complement.rs index 7dc1bbd5..1e7afcbb 100644 --- a/src/integer/z/logic/complement.rs +++ b/src/integer/z/logic/complement.rs @@ -9,7 +9,7 @@ //! This module contains an implementation to compute the bit-wise complement. use crate::integer::Z; -use flint_sys::fmpz::fmpz_complement; +use flint3_sys::fmpz_complement; impl Z { /// Outputs the bit-wise complement of `self`. diff --git a/src/integer/z/ownership.rs b/src/integer/z/ownership.rs index e0a97359..f1a93b83 100644 --- a/src/integer/z/ownership.rs +++ b/src/integer/z/ownership.rs @@ -12,8 +12,8 @@ //! The explicit functions contain the documentation. use super::Z; -use flint_sys::flint::fmpz; -use flint_sys::fmpz::{fmpz_clear, fmpz_init_set}; +use flint3_sys::fmpz; +use flint3_sys::{fmpz_clear, fmpz_init_set}; impl Clone for Z { /// Clones the given element and returns a deep clone of the [`Z`] element. diff --git a/src/integer/z/properties.rs b/src/integer/z/properties.rs index dc5432df..90c4114d 100644 --- a/src/integer/z/properties.rs +++ b/src/integer/z/properties.rs @@ -10,10 +10,9 @@ use super::Z; use crate::rational::Q; -use flint_sys::{ - flint::fmpq, - fmpq::fmpq_inv, - fmpz::{ +use flint3_sys::{ + fmpq, fmpq_inv, + { fmpz_abs, fmpz_bits, fmpz_is_one, fmpz_is_perfect_power, fmpz_is_prime, fmpz_is_zero, fmpz_tstbit, }, diff --git a/src/integer/z/to_string.rs b/src/integer/z/to_string.rs index c7bc94ca..cc4bd7aa 100644 --- a/src/integer/z/to_string.rs +++ b/src/integer/z/to_string.rs @@ -14,7 +14,7 @@ use super::Z; use crate::{error::MathError, macros::for_others::implement_for_owned}; use core::fmt; -use flint_sys::fmpz::{fmpz_bits, fmpz_get_str, fmpz_tstbit}; +use flint3_sys::{fmpz_bits, fmpz_get_str, fmpz_tstbit}; use std::{ffi::CStr, ptr::null_mut, string::FromUtf8Error}; impl From<&Z> for String { diff --git a/src/integer/z/unsafe_functions.rs b/src/integer/z/unsafe_functions.rs index d21caeb5..bb0f6a0c 100644 --- a/src/integer/z/unsafe_functions.rs +++ b/src/integer/z/unsafe_functions.rs @@ -13,7 +13,7 @@ use crate::{ integer::Z, macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}, }; -use flint_sys::{flint::fmpz, fmpz::fmpz_clear}; +use flint3_sys::{fmpz, fmpz_clear}; unsafe_getter!(Z, value, fmpz); unsafe_setter!(Z, value, fmpz, fmpz_clear); @@ -38,7 +38,7 @@ mod test_get_fmpz { #[cfg(test)] mod test_set_fmpz { use super::Z; - use flint_sys::flint::fmpz; + use flint3_sys::fmpz; /// Checks availability of the setter for [`Z::value`] /// and its ability to modify [`Z`]. diff --git a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/add.rs b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/add.rs index 0b2265b8..3de52f26 100644 --- a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/add.rs +++ b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/add.rs @@ -17,7 +17,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod::fmpz_mod_add_fmpz; +use flint3_sys::fmpz_mod_add_fmpz; use std::ops::{Add, AddAssign}; impl Add for &MatNTTPolynomialRingZq { diff --git a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs index 4915a32d..e14bfc4a 100644 --- a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs +++ b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/mul.rs @@ -16,10 +16,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::{ - fmpz_mod::{fmpz_mod_add_fmpz, fmpz_mod_mul}, - fmpz_mod_types::fmpz_mod_ctx, -}; +use flint3_sys::{fmpz_mod_add_fmpz, fmpz_mod_ctx, fmpz_mod_mul}; use std::ops::Mul; impl Mul for &MatNTTPolynomialRingZq { diff --git a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/sub.rs b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/sub.rs index 2e57a151..2986ea26 100644 --- a/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/sub.rs +++ b/src/integer_mod_q/mat_ntt_polynomial_ring_zq/arithmetic/sub.rs @@ -17,7 +17,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod::fmpz_mod_sub_fmpz; +use flint3_sys::fmpz_mod_sub_fmpz; use std::ops::{Sub, SubAssign}; impl Sub for &MatNTTPolynomialRingZq { diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/arithmetic/mul_scalar.rs b/src/integer_mod_q/mat_polynomial_ring_zq/arithmetic/mul_scalar.rs index 0ffdbf10..9a8980c7 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/arithmetic/mul_scalar.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/arithmetic/mul_scalar.rs @@ -18,7 +18,7 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::traits::{CompareBase, MatrixDimensions}; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_scalar_mul_fmpz, fmpz_poly_mat_scalar_mul_fmpz_poly}; +use flint3_sys::{fmpz_poly_mat_scalar_mul_fmpz, fmpz_poly_mat_scalar_mul_fmpz_poly}; use std::ops::{Mul, MulAssign}; impl Mul<&Z> for &MatPolynomialRingZq { diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/concat.rs b/src/integer_mod_q/mat_polynomial_ring_zq/concat.rs index ffd67546..cf858856 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/concat.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/concat.rs @@ -14,7 +14,7 @@ use crate::{ integer::MatPolyOverZ, traits::{CompareBase, Concatenate, MatrixDimensions}, }; -use flint_sys::fmpz_poly_mat::{fmpz_poly_mat_concat_horizontal, fmpz_poly_mat_concat_vertical}; +use flint3_sys::{fmpz_poly_mat_concat_horizontal, fmpz_poly_mat_concat_vertical}; impl Concatenate for &MatPolynomialRingZq { type Output = MatPolynomialRingZq; diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/get.rs b/src/integer_mod_q/mat_polynomial_ring_zq/get.rs index 5443d53b..16a80fd5 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/get.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/get.rs @@ -14,7 +14,7 @@ use crate::{ integer_mod_q::{ModulusPolynomialRingZq, PolynomialRingZq}, traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}, }; -use flint_sys::{fmpz_poly_mat::fmpz_poly_mat_entry, fmpz_types::fmpz_poly_struct}; +use flint3_sys::{fmpz_poly_mat_entry, fmpz_poly_struct}; impl MatPolynomialRingZq { /// Returns the modulus of the matrix as a [`ModulusPolynomialRingZq`]. @@ -768,7 +768,7 @@ mod test_get_submatrix { mod test_collect_entries { use crate::integer::{MatPolyOverZ, PolyOverZ}; use crate::integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq}; - use flint_sys::fmpz_poly::fmpz_poly_set; + use flint3_sys::fmpz_poly_set; use std::str::FromStr; const LARGE_PRIME: u64 = u64::MAX - 58; diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs b/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs index 1a77c7c7..605a3d5c 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs @@ -18,7 +18,7 @@ use super::MatPolynomialRingZq; use crate::{ integer::fmpz_poly_helpers::reduce_fmpz_poly_by_fmpz_mod_poly_sparse, traits::MatrixDimensions, }; -use flint_sys::{fmpz_poly::fmpz_poly_length, fmpz_poly_mat::fmpz_poly_mat_entry}; +use flint3_sys::{fmpz_poly_length, fmpz_poly_mat_entry}; impl MatPolynomialRingZq { /// This function manually applies the modulus diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/set.rs b/src/integer_mod_q/mat_polynomial_ring_zq/set.rs index 38d602d5..95aeb5ee 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/set.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/set.rs @@ -13,10 +13,10 @@ use crate::integer_mod_q::PolynomialRingZq; use crate::macros::for_others::implement_for_owned; use crate::traits::{MatrixSetSubmatrix, MatrixSwaps}; use crate::{error::MathError, integer::PolyOverZ, traits::MatrixSetEntry}; -use flint_sys::fmpz_poly_mat::{ - fmpz_poly_mat_set, fmpz_poly_mat_window_clear, fmpz_poly_mat_window_init, +use flint3_sys::{ + fmpz_poly_mat_entry, fmpz_poly_mat_set, fmpz_poly_mat_window_clear, fmpz_poly_mat_window_init, + fmpz_poly_set, }; -use flint_sys::{fmpz_poly::fmpz_poly_set, fmpz_poly_mat::fmpz_poly_mat_entry}; use std::fmt::Display; use std::mem::MaybeUninit; diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/tensor.rs b/src/integer_mod_q/mat_polynomial_ring_zq/tensor.rs index f866148d..292eae2c 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/tensor.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/tensor.rs @@ -14,7 +14,7 @@ use crate::{ integer::PolyOverZ, traits::{CompareBase, MatrixDimensions, MatrixGetEntry, Tensor}, }; -use flint_sys::{fmpz_poly::fmpz_poly_mul, fmpz_poly_mat::fmpz_poly_mat_entry}; +use flint3_sys::{fmpz_poly_mat_entry, fmpz_poly_mul}; impl Tensor for MatPolynomialRingZq { /// Computes the tensor product of `self` with `other`. diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/transpose.rs b/src/integer_mod_q/mat_polynomial_ring_zq/transpose.rs index 1428a695..835ab371 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/transpose.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/transpose.rs @@ -10,7 +10,7 @@ use super::MatPolynomialRingZq; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly_mat::fmpz_poly_mat_transpose; +use flint3_sys::fmpz_poly_mat_transpose; impl MatPolynomialRingZq { /// Returns the transposed form of the given matrix, i.e. rows get transformed to columns diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs b/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs index 85fadbdc..6b8650bf 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/unsafe_functions.rs @@ -10,7 +10,7 @@ //! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe. use super::MatPolynomialRingZq; use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect}; -use flint_sys::fmpz_types::fmpz_poly_mat_struct; +use flint3_sys::fmpz_poly_mat_struct; unsafe_getter_indirect!( MatPolynomialRingZq, diff --git a/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs b/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs index 1327c71d..a748853f 100644 --- a/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs +++ b/src/integer_mod_q/mat_polynomial_ring_zq/vector/dot_product.rs @@ -12,7 +12,7 @@ use crate::error::MathError; use crate::integer::PolyOverZ; use crate::integer_mod_q::{MatPolynomialRingZq, PolynomialRingZq}; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_poly::fmpz_poly_mul; +use flint3_sys::fmpz_poly_mul; impl MatPolynomialRingZq { /// Returns the dot product of two vectors of type [`MatPolynomialRingZq`]. diff --git a/src/integer_mod_q/mat_zq.rs b/src/integer_mod_q/mat_zq.rs index 35cefecc..e6139f48 100644 --- a/src/integer_mod_q/mat_zq.rs +++ b/src/integer_mod_q/mat_zq.rs @@ -14,7 +14,7 @@ // values. The end-user should be unable to obtain a non-reduced value. use crate::{integer::debug_fmpz_mat_struct, integer_mod_q::Modulus, utils::parse::partial_string}; -use flint_sys::fmpz_mod_types::fmpz_mod_mat_struct; +use flint3_sys::fmpz_mod_mat_struct; use std::fmt; mod arithmetic; diff --git a/src/integer_mod_q/mat_zq/arithmetic/add.rs b/src/integer_mod_q/mat_zq/arithmetic/add.rs index 3168039d..9f44eeb1 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/add.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/add.rs @@ -16,8 +16,8 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, arithmetic_trait_reverse, }; use crate::traits::{CompareBase, MatrixDimensions}; -use flint_sys::fmpz_mat::fmpz_mat_add; -use flint_sys::fmpz_mod_mat::{_fmpz_mod_mat_reduce, fmpz_mod_mat_add}; +use flint3_sys::fmpz_mat_add; +use flint3_sys::{_fmpz_mod_mat_reduce, fmpz_mod_mat_add}; use std::ops::{Add, AddAssign}; impl AddAssign<&MatZq> for MatZq { diff --git a/src/integer_mod_q/mat_zq/arithmetic/mul.rs b/src/integer_mod_q/mat_zq/arithmetic/mul.rs index f197aea0..f4b36f80 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/mul.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/mul.rs @@ -15,8 +15,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_borrowed_to_owned, arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::{CompareBase, MatrixDimensions}; -use flint_sys::fmpz_mat::fmpz_mat_mul; -use flint_sys::fmpz_mod_mat::{_fmpz_mod_mat_reduce, fmpz_mod_mat_mul}; +use flint3_sys::{_fmpz_mod_mat_reduce, fmpz_mat_mul, fmpz_mod_mat_mul}; use std::ops::Mul; impl Mul for &MatZq { diff --git a/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs b/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs index dd8f45d1..db7ec934 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/mul_scalar.rs @@ -19,9 +19,8 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::traits::{CompareBase, MatrixDimensions}; -use flint_sys::flint::fmpz; -use flint_sys::fmpz_mod_mat::{ - fmpz_mod_mat_scalar_mul_fmpz, fmpz_mod_mat_scalar_mul_si, fmpz_mod_mat_scalar_mul_ui, +use flint3_sys::{ + fmpz, fmpz_mod_mat_scalar_mul_fmpz, fmpz_mod_mat_scalar_mul_si, fmpz_mod_mat_scalar_mul_ui, }; use std::ops::{Mul, MulAssign}; diff --git a/src/integer_mod_q/mat_zq/arithmetic/sub.rs b/src/integer_mod_q/mat_zq/arithmetic/sub.rs index 6da701f3..d9a26b3d 100644 --- a/src/integer_mod_q/mat_zq/arithmetic/sub.rs +++ b/src/integer_mod_q/mat_zq/arithmetic/sub.rs @@ -16,8 +16,8 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::{CompareBase, MatrixDimensions}; -use flint_sys::fmpz_mat::fmpz_mat_sub; -use flint_sys::fmpz_mod_mat::{_fmpz_mod_mat_reduce, fmpz_mod_mat_sub}; +use flint3_sys::fmpz_mat_sub; +use flint3_sys::{_fmpz_mod_mat_reduce, fmpz_mod_mat_sub}; use std::ops::{Sub, SubAssign}; impl SubAssign<&MatZq> for MatZq { diff --git a/src/integer_mod_q/mat_zq/cmp.rs b/src/integer_mod_q/mat_zq/cmp.rs index fb0aaee5..337a5955 100644 --- a/src/integer_mod_q/mat_zq/cmp.rs +++ b/src/integer_mod_q/mat_zq/cmp.rs @@ -16,7 +16,7 @@ use crate::{ macros::compare_base::{compare_base_default, compare_base_get_mod, compare_base_impl}, traits::CompareBase, }; -use flint_sys::fmpz_mat::fmpz_mat_equal; +use flint3_sys::fmpz_mat_equal; impl PartialEq for MatZq { /// Checks if two [`MatZq`] instances are equal. Used by the `==` and `!=` operators. diff --git a/src/integer_mod_q/mat_zq/concat.rs b/src/integer_mod_q/mat_zq/concat.rs index 2dbd2562..75da20d1 100644 --- a/src/integer_mod_q/mat_zq/concat.rs +++ b/src/integer_mod_q/mat_zq/concat.rs @@ -13,7 +13,7 @@ use crate::{ error::MathError, traits::{CompareBase, Concatenate, MatrixDimensions}, }; -use flint_sys::fmpz_mod_mat::{fmpz_mod_mat_concat_horizontal, fmpz_mod_mat_concat_vertical}; +use flint3_sys::{fmpz_mod_mat_concat_horizontal, fmpz_mod_mat_concat_vertical}; impl Concatenate for &MatZq { type Output = MatZq; diff --git a/src/integer_mod_q/mat_zq/default.rs b/src/integer_mod_q/mat_zq/default.rs index 97f305a0..d2a4cfe0 100644 --- a/src/integer_mod_q/mat_zq/default.rs +++ b/src/integer_mod_q/mat_zq/default.rs @@ -10,7 +10,7 @@ use super::MatZq; use crate::{integer_mod_q::Modulus, utils::index::evaluate_indices}; -use flint_sys::fmpz_mod_mat::{fmpz_mod_mat_init, fmpz_mod_mat_one}; +use flint3_sys::{fmpz_mod_mat_init, fmpz_mod_mat_one}; use std::{fmt::Display, mem::MaybeUninit}; impl MatZq { diff --git a/src/integer_mod_q/mat_zq/from.rs b/src/integer_mod_q/mat_zq/from.rs index d8abed39..b0663092 100644 --- a/src/integer_mod_q/mat_zq/from.rs +++ b/src/integer_mod_q/mat_zq/from.rs @@ -22,7 +22,7 @@ use crate::{ parse::{matrix_from_utf8_fill_bytes, parse_matrix_string}, }, }; -use flint_sys::{fmpz_mat::fmpz_mat_set, fmpz_mod_mat::_fmpz_mod_mat_reduce}; +use flint3_sys::{_fmpz_mod_mat_reduce, fmpz_mat_set}; use std::{fmt::Display, str::FromStr}; impl FromStr for MatZq { diff --git a/src/integer_mod_q/mat_zq/get.rs b/src/integer_mod_q/mat_zq/get.rs index 374b80b2..09871ac9 100644 --- a/src/integer_mod_q/mat_zq/get.rs +++ b/src/integer_mod_q/mat_zq/get.rs @@ -14,14 +14,9 @@ use crate::{ integer_mod_q::{Modulus, Zq, fmpz_mod_helpers::length}, traits::{AsInteger, MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix, MatrixSetEntry}, }; -use flint_sys::{ - flint::fmpz, - fmpz::fmpz_init_set, - fmpz_mat::fmpz_mat_set, - fmpz_mod_mat::{ - fmpz_mod_mat_entry, fmpz_mod_mat_init_set, fmpz_mod_mat_window_clear, - fmpz_mod_mat_window_init, - }, +use flint3_sys::{ + fmpz, fmpz_init_set, fmpz_mat_set, fmpz_mod_mat_entry, fmpz_mod_mat_init_set, + fmpz_mod_mat_window_clear, fmpz_mod_mat_window_init, }; use std::mem::MaybeUninit; diff --git a/src/integer_mod_q/mat_zq/inverse.rs b/src/integer_mod_q/mat_zq/inverse.rs index 794c6442..ead9a093 100644 --- a/src/integer_mod_q/mat_zq/inverse.rs +++ b/src/integer_mod_q/mat_zq/inverse.rs @@ -13,7 +13,7 @@ use crate::{ integer::Z, traits::{Concatenate, Gcd, MatrixDimensions, MatrixSetSubmatrix, MatrixSwaps}, }; -use flint_sys::fmpz_mod_mat::fmpz_mod_mat_rref; +use flint3_sys::fmpz_mod_mat_rref; impl MatZq { /// Returns the inverse of the matrix if it exists (is square and diff --git a/src/integer_mod_q/mat_zq/ownership.rs b/src/integer_mod_q/mat_zq/ownership.rs index ae565c9e..dc655438 100644 --- a/src/integer_mod_q/mat_zq/ownership.rs +++ b/src/integer_mod_q/mat_zq/ownership.rs @@ -13,7 +13,7 @@ use super::MatZq; use crate::traits::MatrixDimensions; -use flint_sys::fmpz_mod_mat::{fmpz_mod_mat_clear, fmpz_mod_mat_init_set}; +use flint3_sys::{fmpz_mod_mat_clear, fmpz_mod_mat_init_set}; impl Clone for MatZq { /// Clones the given element and returns a deep clone of the [`MatZq`] element. diff --git a/src/integer_mod_q/mat_zq/properties.rs b/src/integer_mod_q/mat_zq/properties.rs index 514dbd05..14710ea7 100644 --- a/src/integer_mod_q/mat_zq/properties.rs +++ b/src/integer_mod_q/mat_zq/properties.rs @@ -13,9 +13,8 @@ use crate::{ integer::Z, traits::{MatrixDimensions, MatrixGetEntry}, }; -use flint_sys::{ - fmpz_mat::fmpz_mat_is_one, - fmpz_mod_mat::{fmpz_mod_mat_is_square, fmpz_mod_mat_is_zero}, +use flint3_sys::{ + fmpz_mat_is_one, {fmpz_mod_mat_is_square, fmpz_mod_mat_is_zero}, }; impl MatZq { diff --git a/src/integer_mod_q/mat_zq/set.rs b/src/integer_mod_q/mat_zq/set.rs index dfa6f4d5..9a4e59b6 100644 --- a/src/integer_mod_q/mat_zq/set.rs +++ b/src/integer_mod_q/mat_zq/set.rs @@ -16,16 +16,16 @@ use crate::{ traits::{MatrixDimensions, MatrixSetEntry, MatrixSetSubmatrix, MatrixSwaps}, utils::index::{evaluate_index_for_vector, evaluate_indices_for_matrix}, }; -use flint_sys::{ - fmpz::fmpz_swap, - fmpz_mat::{ - fmpz_mat_entry, fmpz_mat_invert_cols, fmpz_mat_invert_rows, fmpz_mat_swap_cols, - fmpz_mat_swap_rows, - }, - fmpz_mod_mat::{ +use flint3_sys::{ + fmpz_swap, + { _fmpz_mod_mat_reduce, fmpz_mod_mat_set, fmpz_mod_mat_set_entry, fmpz_mod_mat_window_clear, fmpz_mod_mat_window_init, }, + { + fmpz_mat_entry, fmpz_mat_invert_cols, fmpz_mat_invert_rows, fmpz_mat_swap_cols, + fmpz_mat_swap_rows, + }, }; use std::{fmt::Display, mem::MaybeUninit, ptr::null_mut}; diff --git a/src/integer_mod_q/mat_zq/tensor.rs b/src/integer_mod_q/mat_zq/tensor.rs index ae742a4d..875e24a8 100644 --- a/src/integer_mod_q/mat_zq/tensor.rs +++ b/src/integer_mod_q/mat_zq/tensor.rs @@ -13,7 +13,7 @@ use crate::{ error::MathError, traits::{CompareBase, MatrixDimensions, Tensor}, }; -use flint_sys::{fmpz_mat::fmpz_mat_kronecker_product, fmpz_mod_mat::_fmpz_mod_mat_reduce}; +use flint3_sys::{_fmpz_mod_mat_reduce, fmpz_mat_kronecker_product}; impl Tensor for MatZq { /// Computes the tensor product of `self` with `other`. diff --git a/src/integer_mod_q/mat_zq/trace.rs b/src/integer_mod_q/mat_zq/trace.rs index 6053bd7a..243140c9 100644 --- a/src/integer_mod_q/mat_zq/trace.rs +++ b/src/integer_mod_q/mat_zq/trace.rs @@ -8,7 +8,7 @@ //! This module contains the implementation of the `trace` function. -use flint_sys::fmpz_mod_mat::fmpz_mod_mat_trace; +use flint3_sys::fmpz_mod_mat_trace; use super::MatZq; use crate::{error::MathError, integer_mod_q::Zq, traits::MatrixDimensions}; diff --git a/src/integer_mod_q/mat_zq/transpose.rs b/src/integer_mod_q/mat_zq/transpose.rs index 4c11538e..e43d1dc1 100644 --- a/src/integer_mod_q/mat_zq/transpose.rs +++ b/src/integer_mod_q/mat_zq/transpose.rs @@ -11,7 +11,7 @@ use crate::traits::*; use super::MatZq; -use flint_sys::fmpz_mat::fmpz_mat_transpose; +use flint3_sys::fmpz_mat_transpose; impl MatZq { /// Returns the transposed form of the given matrix, i.e. rows get transformed to columns diff --git a/src/integer_mod_q/mat_zq/unsafe_functions.rs b/src/integer_mod_q/mat_zq/unsafe_functions.rs index fc242b01..f39b1394 100644 --- a/src/integer_mod_q/mat_zq/unsafe_functions.rs +++ b/src/integer_mod_q/mat_zq/unsafe_functions.rs @@ -13,9 +13,8 @@ use super::MatZq; use crate::macros::unsafe_passthrough::{ unsafe_getter, unsafe_getter_indirect, unsafe_setter, unsafe_setter_indirect, }; -use flint_sys::{ - fmpz_mat::fmpz_mat_clear, - fmpz_mod_types::{fmpz_mod_ctx, fmpz_mod_mat_struct}, +use flint3_sys::{ + fmpz_mat_clear, {fmpz_mod_ctx, fmpz_mod_mat_struct}, }; unsafe_getter!(MatZq, matrix, fmpz_mod_mat_struct); @@ -49,7 +48,7 @@ mod test_get_fmpz_mod_mat_struct { mod test_set_fmpz_mod_mat_struct { use super::MatZq; use crate::integer_mod_q::Modulus; - use flint_sys::fmpz_mod_mat::fmpz_mod_mat_init; + use flint3_sys::fmpz_mod_mat_init; use std::{mem::MaybeUninit, str::FromStr}; /// Checks availability of the setter for [`MatZq::matrix`] diff --git a/src/integer_mod_q/mat_zq/vector/dot_product.rs b/src/integer_mod_q/mat_zq/vector/dot_product.rs index f11fa978..ac1dd296 100644 --- a/src/integer_mod_q/mat_zq/vector/dot_product.rs +++ b/src/integer_mod_q/mat_zq/vector/dot_product.rs @@ -14,7 +14,7 @@ use crate::{ integer_mod_q::{MatZq, Zq}, traits::{CompareBase, MatrixDimensions}, }; -use flint_sys::fmpz::fmpz_addmul; +use flint3_sys::fmpz_addmul; impl MatZq { /// Returns the dot product of two vectors of type [`MatZq`]. diff --git a/src/integer_mod_q/mat_zq/vector/norm.rs b/src/integer_mod_q/mat_zq/vector/norm.rs index dcf99e9e..f62817d5 100644 --- a/src/integer_mod_q/mat_zq/vector/norm.rs +++ b/src/integer_mod_q/mat_zq/vector/norm.rs @@ -17,7 +17,7 @@ use crate::{ rational::Q, traits::{AsInteger, MatrixDimensions}, }; -use flint_sys::fmpz::fmpz_addmul; +use flint3_sys::fmpz_addmul; impl MatZq { /// Returns the squared Euclidean norm or squared 2-norm of the given (row or column) vector diff --git a/src/integer_mod_q/modulus.rs b/src/integer_mod_q/modulus.rs index 29ca3490..4ad59697 100644 --- a/src/integer_mod_q/modulus.rs +++ b/src/integer_mod_q/modulus.rs @@ -15,7 +15,7 @@ //! This implementation uses the [FLINT](https://flintlib.org/) library. use crate::integer::debug_fmpz; -use flint_sys::{flint::nmod_t, fmpz_mod_types::fmpz_mod_ctx}; +use flint3_sys::{fmpz_mod_ctx, nmod_t}; use std::{fmt, rc::Rc}; mod cmp; diff --git a/src/integer_mod_q/modulus/cmp.rs b/src/integer_mod_q/modulus/cmp.rs index 75fb415f..5ed43e07 100644 --- a/src/integer_mod_q/modulus/cmp.rs +++ b/src/integer_mod_q/modulus/cmp.rs @@ -16,11 +16,11 @@ use crate::{ integer::Z, macros::for_others::{implement_for_others, implement_trait_reverse}, }; -use flint_sys::fmpz::{fmpz_cmp, fmpz_equal}; +use flint3_sys::{fmpz_cmp, fmpz_equal}; use std::cmp::Ordering; impl PartialEq for Modulus { - /// Compares the two [`fmpz`](flint_sys::flint::fmpz) structs hiding behind the + /// Compares the two [`fmpz`](flint3_sys::fmpz) structs hiding behind the /// given [`Modulus`] instances to check whether the given [`Modulus`] instances /// have the same value. /// @@ -41,7 +41,7 @@ impl PartialEq for Modulus { /// ``` fn eq(&self, other: &Self) -> bool { unsafe { - 1 == flint_sys::fmpz::fmpz_equal( + 1 == flint3_sys::fmpz_equal( &self.modulus.n[0], &other.get_fmpz_mod_ctx_struct().to_owned().n[0], ) diff --git a/src/integer_mod_q/modulus/fmpz_helpers.rs b/src/integer_mod_q/modulus/fmpz_helpers.rs index eec00f1c..9ebcd013 100644 --- a/src/integer_mod_q/modulus/fmpz_helpers.rs +++ b/src/integer_mod_q/modulus/fmpz_helpers.rs @@ -10,7 +10,7 @@ use super::Modulus; use crate::traits::AsInteger; -use flint_sys::{flint::fmpz, fmpz::fmpz_init_set}; +use flint3_sys::{fmpz, fmpz_init_set}; unsafe impl AsInteger for Modulus { /// Documentation at [`AsInteger::into_fmpz`] diff --git a/src/integer_mod_q/modulus/from.rs b/src/integer_mod_q/modulus/from.rs index 7002779c..3d71364e 100644 --- a/src/integer_mod_q/modulus/from.rs +++ b/src/integer_mod_q/modulus/from.rs @@ -14,10 +14,8 @@ use super::Modulus; use crate::{ error::MathError, integer::Z, macros::for_others::implement_empty_trait_owned_ref, traits::*, }; -use flint_sys::{ - flint::fmpz, - fmpz::{fmpz_clear, fmpz_cmp_si}, - fmpz_mod::fmpz_mod_ctx_init, +use flint3_sys::{ + fmpz, fmpz_mod_ctx_init, {fmpz_clear, fmpz_cmp_si}, }; use std::{mem::MaybeUninit, rc::Rc, str::FromStr}; diff --git a/src/integer_mod_q/modulus/get.rs b/src/integer_mod_q/modulus/get.rs index 99ab1c24..8efc910a 100644 --- a/src/integer_mod_q/modulus/get.rs +++ b/src/integer_mod_q/modulus/get.rs @@ -9,7 +9,7 @@ //! Implementations to get information about a [`Modulus`]. use super::Modulus; -use flint_sys::fmpz_mod_types::fmpz_mod_ctx_struct; +use flint3_sys::fmpz_mod_ctx_struct; impl Modulus { /// Returns the [`fmpz_mod_ctx_struct`] of a modulus and is only used internally. diff --git a/src/integer_mod_q/modulus/ownership.rs b/src/integer_mod_q/modulus/ownership.rs index 11aa94c8..dc183191 100644 --- a/src/integer_mod_q/modulus/ownership.rs +++ b/src/integer_mod_q/modulus/ownership.rs @@ -12,12 +12,12 @@ //! The explicit functions contain the documentation. use super::Modulus; -use flint_sys::fmpz_mod::fmpz_mod_ctx_clear; +use flint3_sys::fmpz_mod_ctx_clear; use std::rc::Rc; impl Clone for Modulus { /// Clones the given element and returns another cloned reference - /// to the [`fmpz_mod_ctx`](flint_sys::fmpz_mod_types::fmpz_mod_ctx) element. + /// to the [`fmpz_mod_ctx`](flint3_sys::fmpz_mod_ctx) element. /// /// # Examples /// ``` @@ -35,7 +35,7 @@ impl Clone for Modulus { } impl Drop for Modulus { - /// Drops the given reference to the [`fmpz_mod_ctx`](flint_sys::fmpz_mod_types::fmpz_mod_ctx) element + /// Drops the given reference to the [`fmpz_mod_ctx`](flint3_sys::fmpz_mod_types::fmpz_mod_ctx) element /// and frees the allocated memory if no references are left. /// /// # Examples diff --git a/src/integer_mod_q/modulus/properties.rs b/src/integer_mod_q/modulus/properties.rs index 38268fee..3cf2cae1 100644 --- a/src/integer_mod_q/modulus/properties.rs +++ b/src/integer_mod_q/modulus/properties.rs @@ -10,7 +10,7 @@ //! This includes checks such as primeness. use super::Modulus; -use flint_sys::fmpz::fmpz_is_prime; +use flint3_sys::fmpz_is_prime; impl Modulus { /// Checks if a [`Modulus`] is prime. diff --git a/src/integer_mod_q/modulus/to_string.rs b/src/integer_mod_q/modulus/to_string.rs index 2fd64c87..1e7adf03 100644 --- a/src/integer_mod_q/modulus/to_string.rs +++ b/src/integer_mod_q/modulus/to_string.rs @@ -14,7 +14,7 @@ use super::Modulus; use crate::macros::for_others::implement_for_owned; use core::fmt; -use flint_sys::fmpz::fmpz_get_str; +use flint3_sys::fmpz_get_str; use std::{ffi::CStr, ptr::null_mut}; impl From<&Modulus> for String { diff --git a/src/integer_mod_q/modulus/unsafe_functions.rs b/src/integer_mod_q/modulus/unsafe_functions.rs index 5dc1e2f4..c5fa0257 100644 --- a/src/integer_mod_q/modulus/unsafe_functions.rs +++ b/src/integer_mod_q/modulus/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::Modulus; use crate::macros::unsafe_passthrough::unsafe_getter_mod; -use flint_sys::{fmpz_mod::fmpz_mod_ctx_clear, fmpz_mod_types::fmpz_mod_ctx}; +use flint3_sys::{fmpz_mod_ctx, fmpz_mod_ctx_clear}; unsafe_getter_mod!(Modulus, modulus, fmpz_mod_ctx); @@ -21,12 +21,12 @@ impl Modulus { /// Parameters: /// - `flint_struct`: value to set the attribute to /// - /// **WARNING:** The set struct is part of [`flint_sys`]. + /// **WARNING:** The set struct is part of [`flint3_sys`]. /// Any changes to this object are unsafe and may introduce memory leaks. /// Please be aware that most moduli are shared across multiple instances and all /// modifications of this struct will affect any other instance with a reference to this object. /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) @@ -37,10 +37,10 @@ impl Modulus { /// that might be used in the future. The memory of the old `modulus` is freed /// using this function. /// - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn set_fmpz_mod_ctx(&mut self, flint_struct: fmpz_mod_ctx) { let ptr = std::rc::Rc::as_ptr(&self.modulus) as *mut _; let modulus = unsafe { &mut *ptr }; @@ -80,7 +80,7 @@ mod test_get_fmpz_mod_ctx { #[cfg(test)] mod test_set_fmpz_mod_ctx { use super::Modulus; - use flint_sys::fmpz_mod::fmpz_mod_ctx_init; + use flint3_sys::fmpz_mod_ctx_init; use std::mem::MaybeUninit; /// Checks availability of the setter for [`Modulus::modulus`] diff --git a/src/integer_mod_q/modulus_polynomial_ring_zq/get.rs b/src/integer_mod_q/modulus_polynomial_ring_zq/get.rs index 38620987..94de41fe 100644 --- a/src/integer_mod_q/modulus_polynomial_ring_zq/get.rs +++ b/src/integer_mod_q/modulus_polynomial_ring_zq/get.rs @@ -13,7 +13,7 @@ use crate::{ integer_mod_q::{Modulus, ModulusPolynomialRingZq, PolyOverZq, Zq}, traits::GetCoefficient, }; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_get_coeff_fmpz; +use flint3_sys::fmpz_mod_poly_get_coeff_fmpz; impl GetCoefficient for ModulusPolynomialRingZq { /// Returns the coefficient of a polynomial [`ModulusPolynomialRingZq`] as a [`Zq`]. diff --git a/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs b/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs index 095ef591..c0362bb0 100644 --- a/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs +++ b/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs @@ -16,7 +16,7 @@ use std::rc::Rc; impl Clone for ModulusPolynomialRingZq { /// Clones the given element and returns another cloned reference - /// to the [`fq_ctx_struct`](flint_sys::fq_types::fq_ctx_struct) element. + /// to the [`fq_ctx_struct`](flint3_sys::fq_types::fq_ctx_struct) element. /// /// # Examples /// ``` diff --git a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs index c1b80e0e..2627450a 100644 --- a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs +++ b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/inv_ntt.rs @@ -18,11 +18,9 @@ use crate::{ integer_mod_q::{Modulus, PolyOverZq}, utils::index::bit_reverse_permutation, }; -use flint_sys::{ - fmpz::fmpz_swap, - fmpz_mod::{fmpz_mod_add, fmpz_mod_mul, fmpz_mod_sub_fmpz}, - fmpz_mod_poly::fmpz_mod_poly_set_coeff_fmpz, - fmpz_mod_types::fmpz_mod_ctx, +use flint3_sys::{ + fmpz_mod_ctx, fmpz_mod_poly_set_coeff_fmpz, fmpz_swap, + {fmpz_mod_add, fmpz_mod_mul, fmpz_mod_sub_fmpz}, }; impl NTTBasisPolynomialRingZq { diff --git a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs index d2040211..157c892c 100644 --- a/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs +++ b/src/integer_mod_q/ntt_basis_polynomial_ring_zq/ntt.rs @@ -19,9 +19,8 @@ use crate::{ traits::GetCoefficient, utils::index::bit_reverse_permutation, }; -use flint_sys::{ - fmpz_mod::{fmpz_mod_add, fmpz_mod_mul, fmpz_mod_sub}, - fmpz_mod_types::fmpz_mod_ctx, +use flint3_sys::{ + fmpz_mod_ctx, {fmpz_mod_add, fmpz_mod_mul, fmpz_mod_sub}, }; impl NTTBasisPolynomialRingZq { diff --git a/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/add.rs b/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/add.rs index dbced900..a066405c 100644 --- a/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/add.rs +++ b/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/add.rs @@ -17,7 +17,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod::fmpz_mod_add; +use flint3_sys::fmpz_mod_add; use std::ops::{Add, AddAssign}; impl Add for &NTTPolynomialRingZq { diff --git a/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/mul.rs b/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/mul.rs index a12ae5a3..88eedfee 100644 --- a/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/mul.rs +++ b/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/mul.rs @@ -17,7 +17,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod::fmpz_mod_mul; +use flint3_sys::fmpz_mod_mul; use std::ops::{Mul, MulAssign}; impl Mul for &NTTPolynomialRingZq { diff --git a/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/sub.rs b/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/sub.rs index 0b19ba4e..19db8fcd 100644 --- a/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/sub.rs +++ b/src/integer_mod_q/ntt_polynomial_ring_zq/arithmetic/sub.rs @@ -17,7 +17,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod::fmpz_mod_sub; +use flint3_sys::fmpz_mod_sub; use std::ops::{Sub, SubAssign}; impl Sub for &NTTPolynomialRingZq { diff --git a/src/integer_mod_q/poly_over_zq.rs b/src/integer_mod_q/poly_over_zq.rs index 167a84fa..a635177a 100644 --- a/src/integer_mod_q/poly_over_zq.rs +++ b/src/integer_mod_q/poly_over_zq.rs @@ -15,7 +15,7 @@ // values. The end-user should be unable to obtain a non-reduced value. use super::modulus::Modulus; -use flint_sys::fmpz_mod_types::fmpz_mod_poly_struct; +use flint3_sys::fmpz_mod_poly_struct; use std::fmt; mod arithmetic; diff --git a/src/integer_mod_q/poly_over_zq/arithmetic/add.rs b/src/integer_mod_q/poly_over_zq/arithmetic/add.rs index a38fad09..d2c0ec39 100644 --- a/src/integer_mod_q/poly_over_zq/arithmetic/add.rs +++ b/src/integer_mod_q/poly_over_zq/arithmetic/add.rs @@ -18,7 +18,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_add; +use flint3_sys::fmpz_mod_poly_add; use std::{ ops::{Add, AddAssign}, str::FromStr, diff --git a/src/integer_mod_q/poly_over_zq/arithmetic/mul.rs b/src/integer_mod_q/poly_over_zq/arithmetic/mul.rs index 50ad79d4..f05688de 100644 --- a/src/integer_mod_q/poly_over_zq/arithmetic/mul.rs +++ b/src/integer_mod_q/poly_over_zq/arithmetic/mul.rs @@ -19,7 +19,7 @@ use crate::{ traits::CompareBase, }; use core::panic; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_mul; +use flint3_sys::fmpz_mod_poly_mul; use std::{ ops::{Mul, MulAssign}, str::FromStr, diff --git a/src/integer_mod_q/poly_over_zq/arithmetic/mul_scalar.rs b/src/integer_mod_q/poly_over_zq/arithmetic/mul_scalar.rs index 09061baa..2a3edb46 100644 --- a/src/integer_mod_q/poly_over_zq/arithmetic/mul_scalar.rs +++ b/src/integer_mod_q/poly_over_zq/arithmetic/mul_scalar.rs @@ -19,7 +19,7 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::traits::CompareBase; -use flint_sys::fmpz_mod_poly::{fmpz_mod_poly_scalar_mul_fmpz, fmpz_mod_poly_scalar_mul_ui}; +use flint3_sys::{fmpz_mod_poly_scalar_mul_fmpz, fmpz_mod_poly_scalar_mul_ui}; use std::ops::{Mul, MulAssign}; impl Mul<&Z> for &PolyOverZq { diff --git a/src/integer_mod_q/poly_over_zq/arithmetic/sub.rs b/src/integer_mod_q/poly_over_zq/arithmetic/sub.rs index 821c2d26..1d1facf3 100644 --- a/src/integer_mod_q/poly_over_zq/arithmetic/sub.rs +++ b/src/integer_mod_q/poly_over_zq/arithmetic/sub.rs @@ -19,7 +19,7 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_sub; +use flint3_sys::fmpz_mod_poly_sub; use std::{ ops::{Sub, SubAssign}, str::FromStr, diff --git a/src/integer_mod_q/poly_over_zq/cmp.rs b/src/integer_mod_q/poly_over_zq/cmp.rs index 947f8a9f..1825c9ce 100644 --- a/src/integer_mod_q/poly_over_zq/cmp.rs +++ b/src/integer_mod_q/poly_over_zq/cmp.rs @@ -17,7 +17,7 @@ use crate::{ macros::compare_base::{compare_base_default, compare_base_get_mod, compare_base_impl}, traits::CompareBase, }; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_equal; +use flint3_sys::fmpz_mod_poly_equal; impl PartialEq for PolyOverZq { /// Checks if two polynomials over [`Zq`](crate::integer_mod_q::Zq) are equal. diff --git a/src/integer_mod_q/poly_over_zq/dot_product.rs b/src/integer_mod_q/poly_over_zq/dot_product.rs index eb8fd389..3ab8accb 100644 --- a/src/integer_mod_q/poly_over_zq/dot_product.rs +++ b/src/integer_mod_q/poly_over_zq/dot_product.rs @@ -11,8 +11,8 @@ use crate::integer_mod_q::{PolyOverZq, Zq}; use crate::traits::CompareBase; use crate::{error::MathError, integer::Z}; -use flint_sys::fmpz_mod::{fmpz_mod_add, fmpz_mod_mul}; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_get_coeff_fmpz; +use flint3_sys::fmpz_mod_poly_get_coeff_fmpz; +use flint3_sys::{fmpz_mod_add, fmpz_mod_mul}; impl PolyOverZq { /// Returns the dot product of two polynomials of type [`PolyOverZq`]. diff --git a/src/integer_mod_q/poly_over_zq/evaluate.rs b/src/integer_mod_q/poly_over_zq/evaluate.rs index 78e45947..d32f721b 100644 --- a/src/integer_mod_q/poly_over_zq/evaluate.rs +++ b/src/integer_mod_q/poly_over_zq/evaluate.rs @@ -18,7 +18,7 @@ use crate::{ macros::for_others::implement_for_owned, traits::{CompareBase, Evaluate}, }; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_evaluate_fmpz; +use flint3_sys::fmpz_mod_poly_evaluate_fmpz; impl> Evaluate for PolyOverZq { /// Evaluates a [`PolyOverZq`] on a given input that implements [`Into`]. diff --git a/src/integer_mod_q/poly_over_zq/from.rs b/src/integer_mod_q/poly_over_zq/from.rs index 2d05a7e7..26dc6dd8 100644 --- a/src/integer_mod_q/poly_over_zq/from.rs +++ b/src/integer_mod_q/poly_over_zq/from.rs @@ -16,9 +16,7 @@ use crate::{ integer_mod_q::{ModulusPolynomialRingZq, PolyOverZq, Zq, modulus::Modulus}, macros::for_others::implement_for_owned, }; -use flint_sys::fmpz_mod_poly::{ - fmpz_mod_poly_init, fmpz_mod_poly_set_coeff_fmpz, fmpz_mod_poly_set_fmpz_poly, -}; +use flint3_sys::{fmpz_mod_poly_init, fmpz_mod_poly_set_coeff_fmpz, fmpz_mod_poly_set_fmpz_poly}; use std::{mem::MaybeUninit, str::FromStr}; impl> From for PolyOverZq { diff --git a/src/integer_mod_q/poly_over_zq/get.rs b/src/integer_mod_q/poly_over_zq/get.rs index accc5bd1..c78052d4 100644 --- a/src/integer_mod_q/poly_over_zq/get.rs +++ b/src/integer_mod_q/poly_over_zq/get.rs @@ -14,9 +14,7 @@ use crate::{ integer_mod_q::{Modulus, Zq}, traits::GetCoefficient, }; -use flint_sys::fmpz_mod_poly::{ - fmpz_mod_poly_degree, fmpz_mod_poly_get_coeff_fmpz, fmpz_mod_poly_get_fmpz_poly, -}; +use flint3_sys::{fmpz_mod_poly_degree, fmpz_mod_poly_get_coeff_fmpz, fmpz_mod_poly_get_fmpz_poly}; impl GetCoefficient for PolyOverZq { /// Returns the coefficient of a polynomial [`PolyOverZq`] as a [`Zq`]. diff --git a/src/integer_mod_q/poly_over_zq/ownership.rs b/src/integer_mod_q/poly_over_zq/ownership.rs index 90943e7c..c9a63d9f 100644 --- a/src/integer_mod_q/poly_over_zq/ownership.rs +++ b/src/integer_mod_q/poly_over_zq/ownership.rs @@ -13,9 +13,7 @@ use super::PolyOverZq; use crate::integer::PolyOverZ; -use flint_sys::fmpz_mod_poly::{ - fmpz_mod_poly_clear, fmpz_mod_poly_init, fmpz_mod_poly_set_fmpz_poly, -}; +use flint3_sys::{fmpz_mod_poly_clear, fmpz_mod_poly_init, fmpz_mod_poly_set_fmpz_poly}; use std::{mem::MaybeUninit, str::FromStr}; impl Clone for PolyOverZq { @@ -129,7 +127,7 @@ mod test_drop { use std::{collections::HashSet, str::FromStr}; /// Creates and drops a [`PolyOverZq`] object, and outputs - /// the storage point in memory of that [`fmpz_mod_poly`](flint_sys::fmpz_mod_poly::fmpz_mod_poly_t) struct + /// the storage point in memory of that [`fmpz_mod_poly`](flint3_sys::fmpz_mod_poly::fmpz_mod_poly_t) struct fn create_and_drop_modulus() -> (i64, i64) { let a = PolyOverZq::from_str(&format!("2 {} -2 mod {}", i64::MAX, u64::MAX)).unwrap(); diff --git a/src/integer_mod_q/poly_over_zq/properties.rs b/src/integer_mod_q/poly_over_zq/properties.rs index 5347a510..e78252d1 100644 --- a/src/integer_mod_q/poly_over_zq/properties.rs +++ b/src/integer_mod_q/poly_over_zq/properties.rs @@ -10,9 +10,8 @@ //! This includes checks such as reducibility. use super::PolyOverZq; -use flint_sys::{ - fmpz_mod_poly::{fmpz_mod_poly_degree, fmpz_mod_poly_is_one}, - fmpz_mod_poly_factor::fmpz_mod_poly_is_irreducible, +use flint3_sys::{ + fmpz_mod_poly_is_irreducible, {fmpz_mod_poly_degree, fmpz_mod_poly_is_one}, }; impl PolyOverZq { diff --git a/src/integer_mod_q/poly_over_zq/set.rs b/src/integer_mod_q/poly_over_zq/set.rs index 641c49f2..3aeb675b 100644 --- a/src/integer_mod_q/poly_over_zq/set.rs +++ b/src/integer_mod_q/poly_over_zq/set.rs @@ -12,7 +12,7 @@ use super::PolyOverZq; use crate::{ integer::Z, integer_mod_q::Zq, macros::for_others::implement_for_owned, traits::SetCoefficient, }; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_set_coeff_fmpz; +use flint3_sys::fmpz_mod_poly_set_coeff_fmpz; impl> SetCoefficient for PolyOverZq { /// Sets the coefficient of a polynomial [`PolyOverZq`]. diff --git a/src/integer_mod_q/poly_over_zq/to_string.rs b/src/integer_mod_q/poly_over_zq/to_string.rs index 324fd90b..6a6b17d2 100644 --- a/src/integer_mod_q/poly_over_zq/to_string.rs +++ b/src/integer_mod_q/poly_over_zq/to_string.rs @@ -13,7 +13,7 @@ use super::PolyOverZq; use crate::{integer::PolyOverZ, macros::for_others::implement_for_owned}; -use flint_sys::fmpz_mod_poly::fmpz_mod_poly_get_fmpz_poly; +use flint3_sys::fmpz_mod_poly_get_fmpz_poly; use std::fmt; impl From<&PolyOverZq> for String { diff --git a/src/integer_mod_q/poly_over_zq/unsafe_functions.rs b/src/integer_mod_q/poly_over_zq/unsafe_functions.rs index b5127faf..08e93138 100644 --- a/src/integer_mod_q/poly_over_zq/unsafe_functions.rs +++ b/src/integer_mod_q/poly_over_zq/unsafe_functions.rs @@ -13,10 +13,7 @@ use super::PolyOverZq; use crate::macros::unsafe_passthrough::{ unsafe_getter, unsafe_getter_indirect, unsafe_setter_indirect, }; -use flint_sys::{ - fmpz_mod_poly::fmpz_mod_poly_clear, fmpz_mod_types::fmpz_mod_ctx, - fmpz_mod_types::fmpz_mod_poly_struct, -}; +use flint3_sys::{fmpz_mod_ctx, fmpz_mod_poly_clear, fmpz_mod_poly_struct}; unsafe_getter!(PolyOverZq, poly, fmpz_mod_poly_struct); unsafe_getter_indirect!(PolyOverZq, modulus, get_fmpz_mod_ctx, fmpz_mod_ctx); @@ -27,7 +24,7 @@ impl PolyOverZq { /// Parameters: /// - `flint_struct`: value to set the attribute to /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) @@ -38,10 +35,10 @@ impl PolyOverZq { /// that might be used in the future. The memory of the old struct is freed /// using this function. /// - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn set_fmpz_mod_poly_struct(&mut self, flint_struct: fmpz_mod_poly_struct) { unsafe { fmpz_mod_poly_clear(&mut self.poly, self.modulus.get_fmpz_mod_ctx_struct()) }; @@ -53,7 +50,7 @@ unsafe_setter_indirect!(PolyOverZq, modulus, set_fmpz_mod_ctx, fmpz_mod_ctx); #[cfg(test)] mod test_get_fmpz_mod_poly_struct { use super::PolyOverZq; - use flint_sys::fmpz_mod_poly::fmpz_mod_poly_set_ui; + use flint3_sys::fmpz_mod_poly_set_ui; /// Checks availability of the getter for [`PolyOverZq::poly`] /// and its ability to be modified. @@ -74,7 +71,7 @@ mod test_get_fmpz_mod_poly_struct { mod test_set_fmpz_mod_poly_struct { use super::PolyOverZq; use crate::integer_mod_q::Modulus; - use flint_sys::fmpz_mod_poly::fmpz_mod_poly_init; + use flint3_sys::fmpz_mod_poly_init; use std::mem::MaybeUninit; /// Checks availability of the setter for [`PolyOverZq::poly`] diff --git a/src/integer_mod_q/polynomial_ring_zq/get.rs b/src/integer_mod_q/polynomial_ring_zq/get.rs index d083f827..4b2841e4 100644 --- a/src/integer_mod_q/polynomial_ring_zq/get.rs +++ b/src/integer_mod_q/polynomial_ring_zq/get.rs @@ -14,7 +14,7 @@ use crate::{ integer_mod_q::{ModulusPolynomialRingZq, Zq}, traits::GetCoefficient, }; -use flint_sys::fmpz_poly::{fmpz_poly_degree, fmpz_poly_get_coeff_fmpz}; +use flint3_sys::{fmpz_poly_degree, fmpz_poly_get_coeff_fmpz}; impl GetCoefficient for PolynomialRingZq { /// Returns the coefficient of a [`PolynomialRingZq`] as a [`Zq`]. diff --git a/src/integer_mod_q/polynomial_ring_zq/set.rs b/src/integer_mod_q/polynomial_ring_zq/set.rs index 01e16cc9..1012a950 100644 --- a/src/integer_mod_q/polynomial_ring_zq/set.rs +++ b/src/integer_mod_q/polynomial_ring_zq/set.rs @@ -12,7 +12,7 @@ use super::PolynomialRingZq; use crate::{ integer::Z, integer_mod_q::Zq, macros::for_others::implement_for_owned, traits::SetCoefficient, }; -use flint_sys::fmpz_poly::fmpz_poly_set_coeff_fmpz; +use flint3_sys::fmpz_poly_set_coeff_fmpz; impl> SetCoefficient for PolynomialRingZq { /// Sets the coefficient of a [`PolynomialRingZq`] element. diff --git a/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs b/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs index 8017923f..daeef080 100644 --- a/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs +++ b/src/integer_mod_q/polynomial_ring_zq/unsafe_functions.rs @@ -10,7 +10,7 @@ //! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe. use super::PolynomialRingZq; use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect}; -use flint_sys::fmpz_types::fmpz_poly_struct; +use flint3_sys::fmpz_poly_struct; unsafe_getter_indirect!( PolynomialRingZq, diff --git a/src/integer_mod_q/z_q/arithmetic/add.rs b/src/integer_mod_q/z_q/arithmetic/add.rs index 8ee53ea9..90a07ea7 100644 --- a/src/integer_mod_q/z_q/arithmetic/add.rs +++ b/src/integer_mod_q/z_q/arithmetic/add.rs @@ -19,9 +19,8 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::{ - flint::fmpz, - fmpz_mod::{fmpz_mod_add, fmpz_mod_add_fmpz, fmpz_mod_add_si, fmpz_mod_add_ui}, +use flint3_sys::{ + fmpz, {fmpz_mod_add, fmpz_mod_add_fmpz, fmpz_mod_add_si, fmpz_mod_add_ui}, }; use std::ops::{Add, AddAssign}; diff --git a/src/integer_mod_q/z_q/arithmetic/mul.rs b/src/integer_mod_q/z_q/arithmetic/mul.rs index 7cec8c6e..ba5ff579 100644 --- a/src/integer_mod_q/z_q/arithmetic/mul.rs +++ b/src/integer_mod_q/z_q/arithmetic/mul.rs @@ -19,9 +19,8 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::{ - flint::fmpz, - fmpz_mod::{fmpz_mod_mul, fmpz_mod_mul_fmpz, fmpz_mod_mul_si, fmpz_mod_mul_ui}, +use flint3_sys::{ + fmpz, {fmpz_mod_mul, fmpz_mod_mul_fmpz, fmpz_mod_mul_si, fmpz_mod_mul_ui}, }; use std::ops::{Mul, MulAssign}; diff --git a/src/integer_mod_q/z_q/arithmetic/pow.rs b/src/integer_mod_q/z_q/arithmetic/pow.rs index 70412721..84751268 100644 --- a/src/integer_mod_q/z_q/arithmetic/pow.rs +++ b/src/integer_mod_q/z_q/arithmetic/pow.rs @@ -9,7 +9,7 @@ //! This module provides an implementation of the [`Pow`] trait for [`Zq`]. use crate::{error::MathError, integer::Z, integer_mod_q::Zq, traits::Pow}; -use flint_sys::fmpz_mod::fmpz_mod_pow_fmpz; +use flint3_sys::fmpz_mod_pow_fmpz; impl> Pow for Zq { type Output = Zq; diff --git a/src/integer_mod_q/z_q/arithmetic/sub.rs b/src/integer_mod_q/z_q/arithmetic/sub.rs index 2fac9b5c..f18e3a74 100644 --- a/src/integer_mod_q/z_q/arithmetic/sub.rs +++ b/src/integer_mod_q/z_q/arithmetic/sub.rs @@ -19,9 +19,8 @@ use crate::{ }, traits::CompareBase, }; -use flint_sys::{ - flint::fmpz, - fmpz_mod::{fmpz_mod_sub, fmpz_mod_sub_fmpz, fmpz_mod_sub_si, fmpz_mod_sub_ui}, +use flint3_sys::{ + fmpz, {fmpz_mod_sub, fmpz_mod_sub_fmpz, fmpz_mod_sub_si, fmpz_mod_sub_ui}, }; use std::ops::{Sub, SubAssign}; diff --git a/src/integer_mod_q/z_q/fmpz_mod_helpers.rs b/src/integer_mod_q/z_q/fmpz_mod_helpers.rs index 1f5c877c..14ddf706 100644 --- a/src/integer_mod_q/z_q/fmpz_mod_helpers.rs +++ b/src/integer_mod_q/z_q/fmpz_mod_helpers.rs @@ -13,7 +13,7 @@ use crate::{ integer::{Z, fmpz_helpers::distance}, traits::AsInteger, }; -use flint_sys::flint::fmpz; +use flint3_sys::fmpz; const ZERO_FMPZ: fmpz = 0; @@ -25,7 +25,7 @@ const ZERO_FMPZ: fmpz = 0; /// /// # Examples /// ```compile_fail -/// use flint_sys::fmpz::fmpz; +/// use flint3_sys::fmpz; /// use qfall_math::integer_mod_q::fmpz_mod_helpers::length; /// /// let modulus = fmpz(15); diff --git a/src/integer_mod_q/z_q/properties.rs b/src/integer_mod_q/z_q/properties.rs index 6c3deb0d..2ba5d983 100644 --- a/src/integer_mod_q/z_q/properties.rs +++ b/src/integer_mod_q/z_q/properties.rs @@ -10,7 +10,7 @@ use super::Zq; use crate::traits::Pow; -use flint_sys::{fmpz::fmpz_is_zero, fmpz_mod::fmpz_mod_is_one}; +use flint3_sys::{fmpz_is_zero, fmpz_mod_is_one}; impl Zq { /// Returns the inverse of `self` as a fresh [`Zq`] instance. diff --git a/src/integer_mod_q/z_q/reduce.rs b/src/integer_mod_q/z_q/reduce.rs index 10925668..8ed0b0cd 100644 --- a/src/integer_mod_q/z_q/reduce.rs +++ b/src/integer_mod_q/z_q/reduce.rs @@ -14,7 +14,7 @@ // hence no reduction is performed in the check. use super::Zq; -use flint_sys::fmpz_mod::fmpz_mod_set_fmpz; +use flint3_sys::fmpz_mod_set_fmpz; impl Zq { /// This function manually applies the diff --git a/src/integer_mod_q/z_q/unsafe_functions.rs b/src/integer_mod_q/z_q/unsafe_functions.rs index 8bbc6dc0..bc9f291a 100644 --- a/src/integer_mod_q/z_q/unsafe_functions.rs +++ b/src/integer_mod_q/z_q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::Zq; use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect}; -use flint_sys::{flint::fmpz, fmpz_mod_types::fmpz_mod_ctx}; +use flint3_sys::{fmpz, fmpz_mod_ctx}; unsafe_getter_indirect!(Zq, value, get_fmpz, fmpz); unsafe_getter_indirect!(Zq, modulus, get_fmpz_mod_ctx, fmpz_mod_ctx); diff --git a/src/macros/unsafe_passthrough.rs b/src/macros/unsafe_passthrough.rs index cd0c9e15..6427058a 100644 --- a/src/macros/unsafe_passthrough.rs +++ b/src/macros/unsafe_passthrough.rs @@ -7,14 +7,14 @@ // Mozilla Foundation. See . //! This module implements macros which are used to implement functions, -//! which provide public access to [`flint_sys`] structs and require to be unsafe. +//! which provide public access to [`flint3_sys`] structs and require to be unsafe. /// Implements a getter-function for a field in a struct. /// /// Input parameters: /// - `struct`: the struct for which the getter is implemented (e.g. [`Z`](crate::integer::Z), ...). /// - `attribute_name`: the name of the field (e.g. `value`, ...). -/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint_sys::fmpz::fmpz)) +/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint3_sys::fmpz)) /// /// Returns the Implementation code for the given $struct with the signature: /// ```impl $struct``` @@ -24,20 +24,20 @@ macro_rules! unsafe_getter { paste::paste! { #[doc = "Returns a mutable reference to the field `" $attribute_name "` of type [`" $attribute_type "`]."] /// - /// **WARNING:** The returned struct is part of [`flint_sys`]. + /// **WARNING:** The returned struct is part of [`flint3_sys`]. /// Any changes to this object are unsafe and may introduce memory leaks. /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) /// to provide this feature in the future. /// /// # Safety - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn [](&mut self) -> &mut $attribute_type { &mut self.$attribute_name } @@ -53,7 +53,7 @@ macro_rules! unsafe_getter { /// Input parameters: /// - `struct`: the struct for which the getter is implemented (e.g. [`Z`](crate::integer::Z), ...). /// - `attribute_name`: the name of the field (e.g. `value`, ...). -/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint_sys::fmpz::fmpz)) +/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint3_sys::fmpz)) /// /// Returns the Implementation code for the given $struct with the signature: /// ```impl $struct``` @@ -63,22 +63,22 @@ macro_rules! unsafe_getter_mod { paste::paste! { #[doc = "Returns a mutable reference to the field `" $attribute_name "` of type [`" $attribute_type "`]."] /// - /// **WARNING:** The returned struct is part of [`flint_sys`]. + /// **WARNING:** The returned struct is part of [`flint3_sys`]. /// Any changes to this object are unsafe and may introduce memory leaks. /// Please be aware that most moduli are shared across multiple instances and all /// modifications of this struct will affect any other instance with a reference to this object. /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) /// to provide this feature in the future. /// /// # Safety - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn [](&mut self) -> &mut $attribute_type { let ptr = std::rc::Rc::as_ptr(&self.$attribute_name) as *mut $attribute_type; unsafe { &mut *ptr } @@ -95,8 +95,8 @@ macro_rules! unsafe_getter_mod { /// - `struct`: the struct for which the getter is implemented (e.g. [`Z`](crate::integer::Z), ...). /// - `attribute_name`: the name of the field (e.g. `value`, ...). /// - `function_name`: the name of the function, which is called to gather -/// the [`flint_sys`] struct (e.g. [crate::integer::Z::get_fmpz]) -/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint_sys::fmpz::fmpz)) +/// the [`flint3_sys`] struct (e.g. [crate::integer::Z::get_fmpz]) +/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint3_sys::fmpz)) /// /// Returns the Implementation code for the given $struct with the signature: /// ```impl $struct``` @@ -106,23 +106,23 @@ macro_rules! unsafe_getter_indirect { paste::paste! { #[doc = "Returns a mutable reference to the underlying [`" $attribute_type "`] by calling `" $function_name "` on `" $attribute_name "`."] /// - /// **WARNING:** The returned struct is part of [`flint_sys`]. + /// **WARNING:** The returned struct is part of [`flint3_sys`]. /// Any changes to this object are unsafe and may introduce memory leaks. /// In case you are calling this function to a modulus struct, /// please be aware that most moduli are shared across multiple instances and all /// modifications of this struct will affect any other instance with a reference to this object. /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) /// to provide this feature in the future. /// /// # Safety - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn [](&mut self) -> &mut $attribute_type { unsafe { self.$attribute_name.$function_name() } } @@ -140,7 +140,7 @@ pub(crate) use unsafe_getter_mod; /// Input parameters: /// - `struct`: the struct for which the setter is implemented (e.g. [`Z`](crate::integer::Z), ...). /// - `attribute_name`: the name of the field (e.g. `value`, ...). -/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint_sys::fmpz::fmpz)) +/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint3_sys::fmpz)) /// /// Returns the Implementation code for the given $struct with the signature: /// ```impl $struct``` @@ -153,7 +153,7 @@ macro_rules! unsafe_setter { /// Parameters: /// - `flint_struct`: value to set the attribute to /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) @@ -164,10 +164,10 @@ macro_rules! unsafe_setter { /// that might be used in the future. The memory of the old struct is freed /// using this function. /// - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn [](&mut self, flint_struct: $attribute_type) { unsafe { $clear_function(&mut self.$attribute_name) }; @@ -185,8 +185,8 @@ macro_rules! unsafe_setter { /// - `struct`: the struct for which the setter is implemented (e.g. [`Z`](crate::integer::Z), ...). /// - `attribute_name`: the name of the field (e.g. `value`, ...). /// - `function_name`: the name of the function, which is called to gather -/// the [`flint_sys`] struct (e.g. [crate::integer::Z::set_fmpz]) -/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint_sys::fmpz::fmpz)) +/// the [`flint3_sys`] struct (e.g. [crate::integer::Z::set_fmpz]) +/// - `attribute_type`: the struct resp. type of the field (e.g. [`fmpz`](flint3_sys::fmpz)) /// /// Returns the Implementation code for the given $struct with the signature: /// ```impl $struct``` @@ -199,7 +199,7 @@ macro_rules! unsafe_setter_indirect { /// Parameters: /// - `flint_struct`: value to set the attribute to /// - /// This function is a passthrough to enable users of this library to use [`flint_sys`] + /// This function is a passthrough to enable users of this library to use [`flint3_sys`] /// and with that [FLINT](https://flintlib.org/) functions that might not be covered in our library yet. /// If this is the case, please consider contributing to this open-source project /// by opening a Pull Request at [qfall_math](https://github.com/qfall/math) @@ -210,10 +210,10 @@ macro_rules! unsafe_setter_indirect { /// that might be used in the future. The memory of the old struct is freed /// using this function. /// - /// Any [`flint_sys`] struct and function is part of a FFI to the C-library `FLINT`. + /// Any [`flint3_sys`] struct and function is part of a FFI to the C-library `FLINT`. /// As `FLINT` is a C-library, it does not provide all memory safety features /// that Rust and our Wrapper provide. - /// Thus, using functions of [`flint_sys`] can introduce memory leaks. + /// Thus, using functions of [`flint3_sys`] can introduce memory leaks. pub unsafe fn [](&mut self, flint_struct: $attribute_type) { unsafe { self.$attribute_name.$function_name(flint_struct) } } diff --git a/src/rational/mat_q.rs b/src/rational/mat_q.rs index 699bf2c4..d8a39f2a 100644 --- a/src/rational/mat_q.rs +++ b/src/rational/mat_q.rs @@ -14,7 +14,7 @@ // values. The end-user should be unable to obtain a non-reduced value. use crate::utils::parse::partial_string; -use flint_sys::fmpq_types::fmpq_mat_struct; +use flint3_sys::fmpq_mat_struct; use std::fmt; mod arithmetic; diff --git a/src/rational/mat_q/arithmetic/add.rs b/src/rational/mat_q/arithmetic/add.rs index 7fc011be..8e008d23 100644 --- a/src/rational/mat_q/arithmetic/add.rs +++ b/src/rational/mat_q/arithmetic/add.rs @@ -16,7 +16,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, arithmetic_trait_reverse, }; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::fmpq_mat_add; +use flint3_sys::fmpq_mat_add; use std::ops::{Add, AddAssign}; impl AddAssign<&MatQ> for MatQ { diff --git a/src/rational/mat_q/arithmetic/div_scalar.rs b/src/rational/mat_q/arithmetic/div_scalar.rs index 805c46de..eafe9fab 100644 --- a/src/rational/mat_q/arithmetic/div_scalar.rs +++ b/src/rational/mat_q/arithmetic/div_scalar.rs @@ -20,7 +20,7 @@ use crate::{ rational::{MatQ, Q}, traits::MatrixDimensions, }; -use flint_sys::fmpq_mat::fmpq_mat_scalar_div_fmpz; +use flint3_sys::fmpq_mat_scalar_div_fmpz; use std::ops::{Div, DivAssign, MulAssign}; impl Div<&Z> for &MatQ { diff --git a/src/rational/mat_q/arithmetic/mul.rs b/src/rational/mat_q/arithmetic/mul.rs index 80a2715a..c700d2f1 100644 --- a/src/rational/mat_q/arithmetic/mul.rs +++ b/src/rational/mat_q/arithmetic/mul.rs @@ -15,7 +15,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_borrowed_to_owned, arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::{MatrixDimensions, MatrixSetEntry}; -use flint_sys::fmpq_mat::{fmpq_mat_mul, fmpq_mat_mul_fmpz_mat}; +use flint3_sys::{fmpq_mat_mul, fmpq_mat_mul_fmpz_mat}; use std::ops::Mul; impl Mul for &MatQ { diff --git a/src/rational/mat_q/arithmetic/mul_scalar.rs b/src/rational/mat_q/arithmetic/mul_scalar.rs index 670f80d4..1a7d7f6f 100644 --- a/src/rational/mat_q/arithmetic/mul_scalar.rs +++ b/src/rational/mat_q/arithmetic/mul_scalar.rs @@ -18,7 +18,7 @@ use crate::macros::arithmetics::{ use crate::macros::for_others::implement_for_others; use crate::rational::Q; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::{fmpq_mat_scalar_mul_fmpq, fmpq_mat_scalar_mul_fmpz}; +use flint3_sys::{fmpq_mat_scalar_mul_fmpq, fmpq_mat_scalar_mul_fmpz}; use std::ops::{Mul, MulAssign}; impl Mul<&Z> for &MatQ { diff --git a/src/rational/mat_q/arithmetic/sub.rs b/src/rational/mat_q/arithmetic/sub.rs index fb294ec9..9b32e694 100644 --- a/src/rational/mat_q/arithmetic/sub.rs +++ b/src/rational/mat_q/arithmetic/sub.rs @@ -16,7 +16,7 @@ use crate::macros::arithmetics::{ arithmetic_trait_mixed_borrowed_owned, }; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::fmpq_mat_sub; +use flint3_sys::fmpq_mat_sub; use std::ops::{Sub, SubAssign}; impl SubAssign<&MatQ> for MatQ { diff --git a/src/rational/mat_q/cmp.rs b/src/rational/mat_q/cmp.rs index a9dbfdd5..79b69b23 100644 --- a/src/rational/mat_q/cmp.rs +++ b/src/rational/mat_q/cmp.rs @@ -15,7 +15,7 @@ use crate::{ rational::Q, traits::{CompareBase, MatrixDimensions, MatrixGetEntry}, }; -use flint_sys::fmpq_mat::{fmpq_mat_equal, fmpq_mat_set_fmpz_mat_div_fmpz}; +use flint3_sys::{fmpq_mat_equal, fmpq_mat_set_fmpz_mat_div_fmpz}; impl PartialEq for MatQ { /// Checks if two [`MatQ`] instances are equal. Used by the `==` and `!=` operators. diff --git a/src/rational/mat_q/concat.rs b/src/rational/mat_q/concat.rs index d5563174..2813b051 100644 --- a/src/rational/mat_q/concat.rs +++ b/src/rational/mat_q/concat.rs @@ -13,7 +13,7 @@ use crate::{ error::MathError, traits::{Concatenate, MatrixDimensions}, }; -use flint_sys::fmpq_mat::{fmpq_mat_concat_horizontal, fmpq_mat_concat_vertical}; +use flint3_sys::{fmpq_mat_concat_horizontal, fmpq_mat_concat_vertical}; impl Concatenate for &MatQ { type Output = MatQ; diff --git a/src/rational/mat_q/default.rs b/src/rational/mat_q/default.rs index 4f320c25..08fc76cc 100644 --- a/src/rational/mat_q/default.rs +++ b/src/rational/mat_q/default.rs @@ -10,7 +10,7 @@ use super::MatQ; use crate::utils::index::evaluate_indices; -use flint_sys::fmpq_mat::{fmpq_mat_init, fmpq_mat_one}; +use flint3_sys::{fmpq_mat_init, fmpq_mat_one}; use std::{fmt::Display, mem::MaybeUninit}; impl MatQ { diff --git a/src/rational/mat_q/determinant.rs b/src/rational/mat_q/determinant.rs index 6387ad10..3ce8d153 100644 --- a/src/rational/mat_q/determinant.rs +++ b/src/rational/mat_q/determinant.rs @@ -10,7 +10,7 @@ use super::MatQ; use crate::{error::MathError, rational::Q, traits::MatrixDimensions}; -use flint_sys::fmpq_mat::fmpq_mat_det; +use flint3_sys::fmpq_mat_det; impl MatQ { /// Returns the determinant of the matrix or an error if diff --git a/src/rational/mat_q/from.rs b/src/rational/mat_q/from.rs index 64e72ba2..1b21d6d0 100644 --- a/src/rational/mat_q/from.rs +++ b/src/rational/mat_q/from.rs @@ -19,7 +19,7 @@ use crate::{ traits::{MatrixDimensions, MatrixSetEntry}, utils::{dimensions::find_matrix_dimensions, parse::parse_matrix_string}, }; -use flint_sys::fmpq_mat::fmpq_mat_set_fmpz_mat; +use flint3_sys::fmpq_mat_set_fmpz_mat; use std::str::FromStr; impl FromStr for MatQ { diff --git a/src/rational/mat_q/get.rs b/src/rational/mat_q/get.rs index fb865696..b4ee9c49 100644 --- a/src/rational/mat_q/get.rs +++ b/src/rational/mat_q/get.rs @@ -11,8 +11,8 @@ use super::MatQ; use crate::rational::Q; use crate::traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}; -use flint_sys::fmpq_mat::{fmpq_mat_init_set, fmpq_mat_window_clear, fmpq_mat_window_init}; -use flint_sys::{flint::fmpq, fmpq::fmpq_set, fmpq_mat::fmpq_mat_entry}; +use flint3_sys::{fmpq_mat_init_set, fmpq_mat_window_clear, fmpq_mat_window_init}; +use flint3_sys::{fmpq, fmpq_set, fmpq_mat_entry}; use std::mem::MaybeUninit; impl MatrixDimensions for MatQ { @@ -217,7 +217,7 @@ impl MatQ { for j in 0..num_cols { // efficiently get entry without cloning the entry itself let entry = unsafe { - flint_sys::fmpq::fmpq_get_d(fmpq_mat_entry(&self.matrix, i as i64, j as i64)) + flint3_sys::fmpq_get_d(fmpq_mat_entry(&self.matrix, i as i64, j as i64)) }; row.push(entry); } diff --git a/src/rational/mat_q/gso.rs b/src/rational/mat_q/gso.rs index 987dd817..4bae26dc 100644 --- a/src/rational/mat_q/gso.rs +++ b/src/rational/mat_q/gso.rs @@ -10,7 +10,7 @@ use super::MatQ; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::fmpq_mat_gso; +use flint3_sys::fmpq_mat_gso; impl MatQ { /// Computes the Gram-Schmidt Orthogonalization of the matrix and returns a [`MatQ`] with the corresponding matrix. diff --git a/src/rational/mat_q/inverse.rs b/src/rational/mat_q/inverse.rs index 67b59577..9c79b9a1 100644 --- a/src/rational/mat_q/inverse.rs +++ b/src/rational/mat_q/inverse.rs @@ -10,7 +10,7 @@ use super::MatQ; use crate::traits::MatrixDimensions; -use flint_sys::fmpq_mat::fmpq_mat_inv; +use flint3_sys::fmpq_mat_inv; impl MatQ { /// Returns the inverse of the matrix if it exists (is square and diff --git a/src/rational/mat_q/ownership.rs b/src/rational/mat_q/ownership.rs index a08ce938..5f788b7e 100644 --- a/src/rational/mat_q/ownership.rs +++ b/src/rational/mat_q/ownership.rs @@ -14,7 +14,7 @@ use crate::traits::MatrixDimensions; use super::MatQ; -use flint_sys::fmpq_mat::{fmpq_mat_clear, fmpq_mat_set}; +use flint3_sys::{fmpq_mat_clear, fmpq_mat_set}; impl Clone for MatQ { /// Clones the given element and returns a deep clone of the given [`MatQ`] element. diff --git a/src/rational/mat_q/properties.rs b/src/rational/mat_q/properties.rs index 244f3c37..8dc8ca21 100644 --- a/src/rational/mat_q/properties.rs +++ b/src/rational/mat_q/properties.rs @@ -10,7 +10,7 @@ use super::MatQ; use crate::traits::{MatrixDimensions, MatrixGetEntry}; -use flint_sys::fmpq_mat::{fmpq_mat_is_one, fmpq_mat_is_square, fmpq_mat_is_zero}; +use flint3_sys::{fmpq_mat_is_one, fmpq_mat_is_square, fmpq_mat_is_zero}; impl MatQ { /// Checks if a [`MatQ`] is the identity matrix. diff --git a/src/rational/mat_q/set.rs b/src/rational/mat_q/set.rs index 294211eb..fa0cfc57 100644 --- a/src/rational/mat_q/set.rs +++ b/src/rational/mat_q/set.rs @@ -14,9 +14,9 @@ use crate::{ traits::{MatrixDimensions, MatrixSetEntry, MatrixSetSubmatrix, MatrixSwaps}, utils::index::{evaluate_index_for_vector, evaluate_indices_for_matrix}, }; -use flint_sys::{ - fmpq::{fmpq_set, fmpq_swap}, - fmpq_mat::{ +use flint3_sys::{ + {fmpq_set, fmpq_swap}, + { fmpq_mat_entry, fmpq_mat_invert_cols, fmpq_mat_invert_rows, fmpq_mat_set, fmpq_mat_swap_cols, fmpq_mat_swap_rows, fmpq_mat_window_clear, fmpq_mat_window_init, }, diff --git a/src/rational/mat_q/tensor.rs b/src/rational/mat_q/tensor.rs index ff7cc98f..2f2ca5e2 100644 --- a/src/rational/mat_q/tensor.rs +++ b/src/rational/mat_q/tensor.rs @@ -8,7 +8,7 @@ //! This module contains the implementation of the `tensor` product. -use flint_sys::fmpq_mat::fmpq_mat_kronecker_product; +use flint3_sys::fmpq_mat_kronecker_product; use super::MatQ; use crate::traits::{MatrixDimensions, Tensor}; diff --git a/src/rational/mat_q/trace.rs b/src/rational/mat_q/trace.rs index 6170ffcb..f61b9e9e 100644 --- a/src/rational/mat_q/trace.rs +++ b/src/rational/mat_q/trace.rs @@ -8,7 +8,7 @@ //! This module contains the implementation of the `trace` function. -use flint_sys::fmpq_mat::fmpq_mat_trace; +use flint3_sys::fmpq_mat_trace; use super::MatQ; use crate::{error::MathError, rational::Q, traits::MatrixDimensions}; diff --git a/src/rational/mat_q/transpose.rs b/src/rational/mat_q/transpose.rs index 0419b4ba..6022115e 100644 --- a/src/rational/mat_q/transpose.rs +++ b/src/rational/mat_q/transpose.rs @@ -11,7 +11,7 @@ use crate::traits::*; use super::MatQ; -use flint_sys::fmpq_mat::fmpq_mat_transpose; +use flint3_sys::fmpq_mat_transpose; impl MatQ { /// Returns the transposed form of the given matrix, i.e. rows get transformed to columns diff --git a/src/rational/mat_q/unsafe_functions.rs b/src/rational/mat_q/unsafe_functions.rs index 12cde237..2231b091 100644 --- a/src/rational/mat_q/unsafe_functions.rs +++ b/src/rational/mat_q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::MatQ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::{fmpq_mat::fmpq_mat_clear, fmpq_types::fmpq_mat_struct}; +use flint3_sys::{fmpq_mat_clear, fmpq_mat_struct}; unsafe_getter!(MatQ, matrix, fmpq_mat_struct); @@ -21,7 +21,7 @@ unsafe_setter!(MatQ, matrix, fmpq_mat_struct, fmpq_mat_clear); mod test_get_fmpq_mat_struct { use super::MatQ; use crate::{rational::Q, traits::MatrixGetEntry}; - use flint_sys::{fmpq::fmpq_set, fmpq_mat::fmpq_mat_entry}; + use flint3_sys::{fmpq_mat_entry, fmpq_set}; use std::str::FromStr; /// Checks availability of the getter for [`MatQ::matrix`] @@ -47,7 +47,7 @@ mod test_get_fmpq_mat_struct { mod test_set_fmpq_mat_struct { use super::MatQ; use crate::{rational::Q, traits::MatrixGetEntry}; - use flint_sys::fmpq_mat::fmpq_mat_init; + use flint3_sys::fmpq_mat_init; use std::{mem::MaybeUninit, str::FromStr}; /// Checks availability of the setter for [`MatQ::matrix`] diff --git a/src/rational/mat_q/vector/dot_product.rs b/src/rational/mat_q/vector/dot_product.rs index d8dfea89..83261c0e 100644 --- a/src/rational/mat_q/vector/dot_product.rs +++ b/src/rational/mat_q/vector/dot_product.rs @@ -11,7 +11,7 @@ use crate::error::MathError; use crate::rational::{MatQ, Q}; use crate::traits::MatrixDimensions; -use flint_sys::fmpq::fmpq_addmul; +use flint3_sys::fmpq_addmul; impl MatQ { /// Returns the dot product of two vectors of type [`MatQ`]. diff --git a/src/rational/mat_q/vector/norm.rs b/src/rational/mat_q/vector/norm.rs index 917ecfba..9349462c 100644 --- a/src/rational/mat_q/vector/norm.rs +++ b/src/rational/mat_q/vector/norm.rs @@ -11,7 +11,7 @@ use super::super::MatQ; use crate::{error::MathError, rational::Q, traits::MatrixDimensions}; -use flint_sys::fmpq::{fmpq_abs, fmpq_addmul, fmpq_cmp}; +use flint3_sys::{fmpq_abs, fmpq_addmul, fmpq_cmp}; impl MatQ { /// Returns the squared Euclidean norm or squared 2-norm of the given (row or column) vector diff --git a/src/rational/poly_over_q.rs b/src/rational/poly_over_q.rs index b98e827d..2240008a 100644 --- a/src/rational/poly_over_q.rs +++ b/src/rational/poly_over_q.rs @@ -16,7 +16,7 @@ // non-reduced value. use crate::integer::debug_fmpz; -use flint_sys::fmpq_types::fmpq_poly_struct; +use flint3_sys::fmpq_poly_struct; use std::fmt; mod arithmetic; diff --git a/src/rational/poly_over_q/arithmetic/add.rs b/src/rational/poly_over_q/arithmetic/add.rs index c2188cb7..d75aa84d 100644 --- a/src/rational/poly_over_q/arithmetic/add.rs +++ b/src/rational/poly_over_q/arithmetic/add.rs @@ -16,7 +16,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, arithmetic_trait_reverse, }, }; -use flint_sys::fmpq_poly::fmpq_poly_add; +use flint3_sys::fmpq_poly_add; use std::ops::{Add, AddAssign}; impl AddAssign<&PolyOverQ> for PolyOverQ { diff --git a/src/rational/poly_over_q/arithmetic/div_scalar.rs b/src/rational/poly_over_q/arithmetic/div_scalar.rs index 84c97ce6..e80c7bbc 100644 --- a/src/rational/poly_over_q/arithmetic/div_scalar.rs +++ b/src/rational/poly_over_q/arithmetic/div_scalar.rs @@ -16,7 +16,7 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::rational::Q; -use flint_sys::fmpq_poly::{ +use flint3_sys::{ fmpq_poly_scalar_div_fmpq, fmpq_poly_scalar_div_fmpz, fmpq_poly_scalar_div_si, fmpq_poly_scalar_div_ui, }; diff --git a/src/rational/poly_over_q/arithmetic/exp.rs b/src/rational/poly_over_q/arithmetic/exp.rs index e2706a3b..61dff47f 100644 --- a/src/rational/poly_over_q/arithmetic/exp.rs +++ b/src/rational/poly_over_q/arithmetic/exp.rs @@ -9,7 +9,7 @@ //! Implementations to approximate the exponential function using a [`PolyOverQ`] polynomial. use crate::rational::PolyOverQ; -use flint_sys::fmpq_poly::fmpq_poly_exp_series; +use flint3_sys::fmpq_poly_exp_series; use std::str::FromStr; impl PolyOverQ { diff --git a/src/rational/poly_over_q/arithmetic/mul.rs b/src/rational/poly_over_q/arithmetic/mul.rs index e4625be2..460eccd7 100644 --- a/src/rational/poly_over_q/arithmetic/mul.rs +++ b/src/rational/poly_over_q/arithmetic/mul.rs @@ -16,7 +16,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, arithmetic_trait_reverse, }, }; -use flint_sys::fmpq_poly::fmpq_poly_mul; +use flint3_sys::fmpq_poly_mul; use std::ops::{Mul, MulAssign}; impl MulAssign<&PolyOverQ> for PolyOverQ { diff --git a/src/rational/poly_over_q/arithmetic/mul_scalar.rs b/src/rational/poly_over_q/arithmetic/mul_scalar.rs index cb71490b..bb1ec745 100644 --- a/src/rational/poly_over_q/arithmetic/mul_scalar.rs +++ b/src/rational/poly_over_q/arithmetic/mul_scalar.rs @@ -17,7 +17,7 @@ use crate::macros::arithmetics::{ }; use crate::macros::for_others::implement_for_others; use crate::rational::Q; -use flint_sys::fmpq_poly::{ +use flint3_sys::{ fmpq_poly_scalar_mul_fmpq, fmpq_poly_scalar_mul_fmpz, fmpq_poly_scalar_mul_si, fmpq_poly_scalar_mul_ui, }; diff --git a/src/rational/poly_over_q/arithmetic/sub.rs b/src/rational/poly_over_q/arithmetic/sub.rs index 0dbc610f..fa2d6248 100644 --- a/src/rational/poly_over_q/arithmetic/sub.rs +++ b/src/rational/poly_over_q/arithmetic/sub.rs @@ -16,7 +16,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpq_poly::fmpq_poly_sub; +use flint3_sys::fmpq_poly_sub; use std::ops::{Sub, SubAssign}; impl SubAssign<&PolyOverQ> for PolyOverQ { diff --git a/src/rational/poly_over_q/cmp.rs b/src/rational/poly_over_q/cmp.rs index a6c51540..86d63452 100644 --- a/src/rational/poly_over_q/cmp.rs +++ b/src/rational/poly_over_q/cmp.rs @@ -16,7 +16,7 @@ use crate::{ rational::Q, traits::{CompareBase, GetCoefficient}, }; -use flint_sys::fmpq_poly::fmpq_poly_equal; +use flint3_sys::fmpq_poly_equal; impl PartialEq for PolyOverQ { /// Checks if two polynomials over [`Q`](crate::rational::Q) are equal. Used by the `==` and `!=` operators. diff --git a/src/rational/poly_over_q/default.rs b/src/rational/poly_over_q/default.rs index 39e27fb8..779347f6 100644 --- a/src/rational/poly_over_q/default.rs +++ b/src/rational/poly_over_q/default.rs @@ -9,7 +9,7 @@ //! Default value for a [`PolyOverQ`]. use super::PolyOverQ; -use flint_sys::fmpq_poly::fmpq_poly_init; +use flint3_sys::fmpq_poly_init; use std::mem::MaybeUninit; impl Default for PolyOverQ { diff --git a/src/rational/poly_over_q/dot_product.rs b/src/rational/poly_over_q/dot_product.rs index d3e94a3d..3d5973d4 100644 --- a/src/rational/poly_over_q/dot_product.rs +++ b/src/rational/poly_over_q/dot_product.rs @@ -10,8 +10,8 @@ use crate::error::MathError; use crate::rational::{PolyOverQ, Q}; -use flint_sys::fmpq::{fmpq_add, fmpq_mul}; -use flint_sys::fmpq_poly::fmpq_poly_get_coeff_fmpq; +use flint3_sys::fmpq_poly_get_coeff_fmpq; +use flint3_sys::{fmpq_add, fmpq_mul}; impl PolyOverQ { /// Returns the dot product of two polynomials of type [`PolyOverQ`]. diff --git a/src/rational/poly_over_q/evaluate.rs b/src/rational/poly_over_q/evaluate.rs index de7fc8f4..102d27f8 100644 --- a/src/rational/poly_over_q/evaluate.rs +++ b/src/rational/poly_over_q/evaluate.rs @@ -12,7 +12,7 @@ use super::PolyOverQ; use crate::{rational::Q, traits::Evaluate}; -use flint_sys::fmpq_poly::fmpq_poly_evaluate_fmpq; +use flint3_sys::fmpq_poly_evaluate_fmpq; impl> Evaluate for PolyOverQ { /// Evaluates a [`PolyOverQ`] on a given input. diff --git a/src/rational/poly_over_q/from.rs b/src/rational/poly_over_q/from.rs index 9bd01ecf..0aadea07 100644 --- a/src/rational/poly_over_q/from.rs +++ b/src/rational/poly_over_q/from.rs @@ -17,7 +17,7 @@ use crate::{ macros::for_others::implement_for_owned, rational::Q, }; -use flint_sys::fmpq_poly::{ +use flint3_sys::{ fmpq_poly_canonicalise, fmpq_poly_set_fmpq, fmpq_poly_set_fmpz_poly, fmpq_poly_set_str, }; use std::{ffi::CString, str::FromStr}; diff --git a/src/rational/poly_over_q/get.rs b/src/rational/poly_over_q/get.rs index f810faaf..20c8c6b7 100644 --- a/src/rational/poly_over_q/get.rs +++ b/src/rational/poly_over_q/get.rs @@ -10,7 +10,7 @@ use super::PolyOverQ; use crate::{rational::Q, traits::GetCoefficient}; -use flint_sys::fmpq_poly::{fmpq_poly_degree, fmpq_poly_get_coeff_fmpq}; +use flint3_sys::{fmpq_poly_degree, fmpq_poly_get_coeff_fmpq}; impl GetCoefficient for PolyOverQ { /// Returns the coefficient of a polynomial [`PolyOverQ`] as a [`Q`]. diff --git a/src/rational/poly_over_q/ownership.rs b/src/rational/poly_over_q/ownership.rs index 20b54880..5a2ae1de 100644 --- a/src/rational/poly_over_q/ownership.rs +++ b/src/rational/poly_over_q/ownership.rs @@ -12,7 +12,7 @@ //! The explicit functions contain the documentation. use super::PolyOverQ; -use flint_sys::fmpq_poly::{fmpq_poly_clear, fmpq_poly_init, fmpq_poly_set}; +use flint3_sys::{fmpq_poly_clear, fmpq_poly_init, fmpq_poly_set}; use std::mem::MaybeUninit; // The use of [`PolyOverQ`] should be thread safe because @@ -25,7 +25,7 @@ unsafe impl Sync for PolyOverQ {} impl Clone for PolyOverQ { /// Clones the given [`PolyOverQ`] element by returning a deep clone, - /// storing two separately stored [fmpz](flint_sys::flint::fmpz) values + /// storing two separately stored [fmpz](flint3_sys::fmpz) values /// for `nominator` and `denominator` in memory. /// /// # Examples @@ -143,7 +143,7 @@ mod test_drop { use std::{collections::HashSet, str::FromStr}; /// Creates and drops a [`PolyOverQ`] object, and outputs - /// the storage point in memory of that [`fmpq_poly`](flint_sys::fmpz_mod_poly::fmpz_mod_poly_t) struct + /// the storage point in memory of that [`fmpq_poly`](flint3_sys::fmpz_mod_poly::fmpz_mod_poly_t) struct fn create_and_drop_modulus() -> (i64, i64, i64) { let a = PolyOverQ::from_str(&format!("2 {}/1 -2/-3", i64::MAX)).unwrap(); diff --git a/src/rational/poly_over_q/properties.rs b/src/rational/poly_over_q/properties.rs index e43e5c85..58ca792d 100644 --- a/src/rational/poly_over_q/properties.rs +++ b/src/rational/poly_over_q/properties.rs @@ -8,7 +8,7 @@ //! This module includes functionality about properties of [`PolyOverQ`] instances. -use flint_sys::fmpq_poly::{fmpq_poly_degree, fmpq_poly_is_one}; +use flint3_sys::{fmpq_poly_degree, fmpq_poly_is_one}; use super::PolyOverQ; diff --git a/src/rational/poly_over_q/set.rs b/src/rational/poly_over_q/set.rs index 480a6cd7..ce63e4e8 100644 --- a/src/rational/poly_over_q/set.rs +++ b/src/rational/poly_over_q/set.rs @@ -10,7 +10,7 @@ use super::PolyOverQ; use crate::{rational::Q, traits::SetCoefficient}; -use flint_sys::fmpq_poly::fmpq_poly_set_coeff_fmpq; +use flint3_sys::fmpq_poly_set_coeff_fmpq; impl> SetCoefficient for PolyOverQ { /// Sets the coefficient of a polynomial [`PolyOverQ`]. diff --git a/src/rational/poly_over_q/to_string.rs b/src/rational/poly_over_q/to_string.rs index aa09355d..d9fdfed0 100644 --- a/src/rational/poly_over_q/to_string.rs +++ b/src/rational/poly_over_q/to_string.rs @@ -14,7 +14,7 @@ use super::PolyOverQ; use crate::{macros::for_others::implement_for_owned, traits::GetCoefficient}; use core::fmt; -use flint_sys::fmpq_poly::fmpq_poly_get_str; +use flint3_sys::fmpq_poly_get_str; use std::ffi::CStr; impl From<&PolyOverQ> for String { diff --git a/src/rational/poly_over_q/unsafe_functions.rs b/src/rational/poly_over_q/unsafe_functions.rs index 7e5cf37d..8d35fd15 100644 --- a/src/rational/poly_over_q/unsafe_functions.rs +++ b/src/rational/poly_over_q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::PolyOverQ; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::{fmpq_poly::fmpq_poly_clear, fmpq_types::fmpq_poly_struct}; +use flint3_sys::{fmpq_poly_clear, fmpq_poly_struct}; unsafe_getter!(PolyOverQ, poly, fmpq_poly_struct); @@ -21,7 +21,7 @@ unsafe_setter!(PolyOverQ, poly, fmpq_poly_struct, fmpq_poly_clear); mod test_get_fmpq_poly_struct { use super::PolyOverQ; use crate::rational::Q; - use flint_sys::fmpq_poly::fmpq_poly_set_coeff_fmpq; + use flint3_sys::fmpq_poly_set_coeff_fmpq; /// Checks availability of the getter for [`PolyOverQ::poly`] /// and its ability to be modified. @@ -42,7 +42,7 @@ mod test_get_fmpq_poly_struct { #[cfg(test)] mod test_set_fmpq_poly_struct { use super::PolyOverQ; - use flint_sys::fmpq_poly::fmpq_poly_init; + use flint3_sys::fmpq_poly_init; use std::mem::MaybeUninit; /// Checks availability of the setter for [`PolyOverQ::poly`] diff --git a/src/rational/q.rs b/src/rational/q.rs index 8d68831c..47ca6f9e 100644 --- a/src/rational/q.rs +++ b/src/rational/q.rs @@ -14,7 +14,7 @@ // values. The end-user should be unable to obtain a non-reduced value. use crate::integer::debug_fmpz; -use flint_sys::flint::fmpq; +use flint3_sys::fmpq; use std::fmt; mod arithmetic; diff --git a/src/rational/q/arithmetic/add.rs b/src/rational/q/arithmetic/add.rs index 253ba94a..6a524dce 100644 --- a/src/rational/q/arithmetic/add.rs +++ b/src/rational/q/arithmetic/add.rs @@ -17,7 +17,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpq::{fmpq_add, fmpq_add_fmpz, fmpq_add_si, fmpq_add_ui}; +use flint3_sys::{fmpq_add, fmpq_add_fmpz, fmpq_add_si, fmpq_add_ui}; use std::ops::{Add, AddAssign}; impl AddAssign<&Q> for Q { diff --git a/src/rational/q/arithmetic/div.rs b/src/rational/q/arithmetic/div.rs index 0066aaf5..a720325d 100644 --- a/src/rational/q/arithmetic/div.rs +++ b/src/rational/q/arithmetic/div.rs @@ -18,7 +18,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpq::{fmpq_div, fmpq_div_fmpz, fmpq_is_zero}; +use flint3_sys::{fmpq_div, fmpq_div_fmpz, fmpq_is_zero}; use std::ops::{Div, DivAssign}; impl DivAssign<&Q> for Q { diff --git a/src/rational/q/arithmetic/exp.rs b/src/rational/q/arithmetic/exp.rs index e3d9b095..74413c2a 100644 --- a/src/rational/q/arithmetic/exp.rs +++ b/src/rational/q/arithmetic/exp.rs @@ -12,7 +12,7 @@ use crate::{ rational::{PolyOverQ, Q}, traits::Evaluate, }; -use flint_sys::fmpq::fmpq_mul_2exp; +use flint3_sys::fmpq_mul_2exp; impl Q { /// Computes `e^self`. @@ -83,7 +83,7 @@ impl Q { #[cfg(test)] mod test_exp { use super::*; - use flint_sys::fmpz::fmpz_get_d_2exp; + use flint3_sys::fmpz_get_d_2exp; /// Ensure that `e^0 = 1`. #[test] diff --git a/src/rational/q/arithmetic/logarithm.rs b/src/rational/q/arithmetic/logarithm.rs index 99aadf30..130d046c 100644 --- a/src/rational/q/arithmetic/logarithm.rs +++ b/src/rational/q/arithmetic/logarithm.rs @@ -9,7 +9,7 @@ //! Implementations to call the logarithm on a [`Q`] integer. use crate::{error::MathError, integer::Z, rational::Q}; -use flint_sys::fmpz::fmpz_dlog; +use flint3_sys::fmpz_dlog; impl Q { /// Computes the natural logarithm of a positive rational number diff --git a/src/rational/q/arithmetic/mul.rs b/src/rational/q/arithmetic/mul.rs index 54c7ad22..de3dff61 100644 --- a/src/rational/q/arithmetic/mul.rs +++ b/src/rational/q/arithmetic/mul.rs @@ -17,7 +17,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpq::{fmpq_mul, fmpq_mul_fmpz, fmpq_mul_si, fmpq_mul_ui}; +use flint3_sys::{fmpq_mul, fmpq_mul_fmpz, fmpq_mul_si, fmpq_mul_ui}; use std::ops::{Mul, MulAssign}; impl MulAssign<&Q> for Q { diff --git a/src/rational/q/arithmetic/pow.rs b/src/rational/q/arithmetic/pow.rs index d5fc10be..4cf1fc53 100644 --- a/src/rational/q/arithmetic/pow.rs +++ b/src/rational/q/arithmetic/pow.rs @@ -9,7 +9,7 @@ //! This module provides an implementation of the [`Pow`] trait for [`Q`]. use crate::{error::MathError, integer::Z, rational::Q, traits::Pow}; -use flint_sys::fmpq::fmpq_pow_fmpz; +use flint3_sys::fmpq_pow_fmpz; impl> Pow for Q { type Output = Q; diff --git a/src/rational/q/arithmetic/sub.rs b/src/rational/q/arithmetic/sub.rs index 3918af76..e68e24d6 100644 --- a/src/rational/q/arithmetic/sub.rs +++ b/src/rational/q/arithmetic/sub.rs @@ -17,7 +17,7 @@ use crate::{ arithmetic_trait_mixed_borrowed_owned, }, }; -use flint_sys::fmpq::{fmpq_sub, fmpq_sub_fmpz, fmpq_sub_si, fmpq_sub_ui}; +use flint3_sys::{fmpq_sub, fmpq_sub_fmpz, fmpq_sub_si, fmpq_sub_ui}; use std::ops::{Sub, SubAssign}; impl SubAssign<&Q> for Q { diff --git a/src/rational/q/cmp.rs b/src/rational/q/cmp.rs index 21d0bfb3..4ed781a6 100644 --- a/src/rational/q/cmp.rs +++ b/src/rational/q/cmp.rs @@ -15,9 +15,9 @@ use crate::{ integer_mod_q::Modulus, macros::for_others::{implement_for_others, implement_trait_reverse}, }; -use flint_sys::{ - fmpq::{fmpq_cmp, fmpq_equal}, - fmpz::fmpz_equal, +use flint3_sys::{ + {fmpq_cmp, fmpq_equal}, + fmpz_equal, }; use std::cmp::Ordering; diff --git a/src/rational/q/default.rs b/src/rational/q/default.rs index 9f242b2a..1b345b9d 100644 --- a/src/rational/q/default.rs +++ b/src/rational/q/default.rs @@ -9,7 +9,7 @@ //! Define default values for [`Q`]. use super::Q; -use flint_sys::flint::fmpq; +use flint3_sys::fmpq; impl Default for Q { /// Returns an instantiation of [`Q`] with value `0/1`. diff --git a/src/rational/q/from.rs b/src/rational/q/from.rs index 917160a3..11c99da0 100644 --- a/src/rational/q/from.rs +++ b/src/rational/q/from.rs @@ -17,10 +17,10 @@ use crate::{ macros::from::{from_trait, from_type}, traits::{AsInteger, Pow}, }; -use flint_sys::{ - flint::fmpq, - fmpq::{fmpq_canonicalise, fmpq_clear, fmpq_get_d, fmpq_set_str}, - fmpz::{fmpz_init_set, fmpz_is_zero}, +use flint3_sys::{ + fmpq, + {fmpq_canonicalise, fmpq_clear, fmpq_get_d, fmpq_set_str}, + {fmpz_init_set, fmpz_is_zero}, }; use std::{ffi::CString, str::FromStr}; @@ -61,7 +61,7 @@ impl Q { // -52 because the mantissa is 52 bit long exponent -= 1023 + 52; let shift = match exponent { - // This could be optimized with `fmpz_lshift_mpn` once it is part of flint_sys. + // This could be optimized with `fmpz_lshift_mpn` once it is part of flint3_sys. e if e >= 1 => Q::from(2).pow(e).unwrap(), e => Q::from((1, 2)).pow(e.abs()).unwrap(), }; @@ -252,8 +252,8 @@ impl FromStr for Q { return Err(StringConversionError::InvalidStringToQInput(s.to_owned()))?; } - // `fmpq::default()` returns the value `0/0` - let mut value = fmpq::default(); + // `default()` returns the value `0/0` + let mut value = default(); let c_string = CString::new(s)?; diff --git a/src/rational/q/get.rs b/src/rational/q/get.rs index abb1cb13..b098c7a1 100644 --- a/src/rational/q/get.rs +++ b/src/rational/q/get.rs @@ -10,7 +10,7 @@ use super::Q; use crate::integer::Z; -use flint_sys::fmpz::fmpz_init_set; +use flint3_sys::fmpz_init_set; impl Q { /// Returns the denominator diff --git a/src/rational/q/ownership.rs b/src/rational/q/ownership.rs index 0ee25a44..cb70b9b2 100644 --- a/src/rational/q/ownership.rs +++ b/src/rational/q/ownership.rs @@ -12,11 +12,11 @@ //! The explicit functions contain the documentation. use super::Q; -use flint_sys::fmpq::{fmpq_clear, fmpq_set}; +use flint3_sys::{fmpq_clear, fmpq_set}; impl Clone for Q { /// Clones the given element and returns another cloned reference - /// to the [`fmpq`](flint_sys::flint::fmpq) element. + /// to the [`fmpq`](flint3_sys::fmpq) element. /// /// # Examples /// ``` @@ -34,7 +34,7 @@ impl Clone for Q { } impl Drop for Q { - /// Drops the given reference to the [`fmpq`](flint_sys::flint::fmpq) element + /// Drops the given reference to the [`fmpq`](flint3_sys::fmpq) element /// and frees the allocated memory if no references are left. /// /// # Examples diff --git a/src/rational/q/properties.rs b/src/rational/q/properties.rs index 628de9f5..8556fa10 100644 --- a/src/rational/q/properties.rs +++ b/src/rational/q/properties.rs @@ -9,7 +9,7 @@ //! This module includes functionality about properties of [`Q`] instances. use super::Q; -use flint_sys::fmpq::{fmpq_abs, fmpq_inv, fmpq_is_one, fmpq_is_zero}; +use flint3_sys::{fmpq_abs, fmpq_inv, fmpq_is_one, fmpq_is_zero}; impl Q { /// Returns the given [`Q`] instance with its absolute value. diff --git a/src/rational/q/rounding.rs b/src/rational/q/rounding.rs index 3cef514b..63c77269 100644 --- a/src/rational/q/rounding.rs +++ b/src/rational/q/rounding.rs @@ -10,9 +10,9 @@ use super::Q; use crate::{error::MathError, integer::Z, traits::Distance}; -use flint_sys::{ - fmpq::{fmpq_sgn, fmpq_simplest_between}, - fmpz::{fmpz_cdiv_q, fmpz_fdiv_q}, +use flint3_sys::{ + {fmpq_sgn, fmpq_simplest_between}, + {fmpz_cdiv_q, fmpz_fdiv_q}, }; impl Q { diff --git a/src/rational/q/to_string.rs b/src/rational/q/to_string.rs index 9eb62f25..895dc931 100644 --- a/src/rational/q/to_string.rs +++ b/src/rational/q/to_string.rs @@ -14,7 +14,7 @@ use super::Q; use crate::macros::for_others::implement_for_owned; use core::fmt; -use flint_sys::fmpq::fmpq_get_str; +use flint3_sys::fmpq_get_str; use std::{ffi::CStr, ptr::null_mut}; impl From<&Q> for String { diff --git a/src/rational/q/unsafe_functions.rs b/src/rational/q/unsafe_functions.rs index 94c7c2e3..1abbd35b 100644 --- a/src/rational/q/unsafe_functions.rs +++ b/src/rational/q/unsafe_functions.rs @@ -11,7 +11,7 @@ use super::Q; use crate::macros::unsafe_passthrough::{unsafe_getter, unsafe_setter}; -use flint_sys::{flint::fmpq, fmpq::fmpq_clear}; +use flint3_sys::{fmpq, fmpq_clear}; unsafe_getter!(Q, value, fmpq); @@ -39,7 +39,7 @@ mod test_get_fmpq { #[cfg(test)] mod test_set_fmpq { use super::Q; - use flint_sys::flint::fmpq; + use flint3_sys::fmpq; /// Checks availability of the setter for [`Q::value`] /// and its ability to modify [`Q`]. diff --git a/src/traits.rs b/src/traits.rs index 95d47451..18022969 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -15,7 +15,7 @@ use crate::{ error::MathError, utils::index::{evaluate_index, evaluate_index_for_vector, evaluate_indices_for_matrix}, }; -use flint_sys::flint::fmpz; +use flint3_sys::fmpz; use std::fmt::Display; /// Is implemented by every type where a base-check might be needed. diff --git a/src/utils/factorization.rs b/src/utils/factorization.rs index 33afa776..0159c5db 100644 --- a/src/utils/factorization.rs +++ b/src/utils/factorization.rs @@ -9,7 +9,7 @@ //! This module contains the type [`Factorization`], which is a factorized //! (or partly factorized) representation of integers with arbitrary length. -use flint_sys::fmpz_types::fmpz_factor_struct; +use flint3_sys::fmpz_factor_struct; use std::fmt; mod default; diff --git a/src/utils/factorization/default.rs b/src/utils/factorization/default.rs index 6093ece5..039e1d54 100644 --- a/src/utils/factorization/default.rs +++ b/src/utils/factorization/default.rs @@ -9,7 +9,7 @@ //! Default values for a [`Factorization`]. use super::Factorization; -use flint_sys::fmpz_factor::fmpz_factor_init; +use flint3_sys::fmpz_factor_init; use std::mem::MaybeUninit; impl Default for Factorization { diff --git a/src/utils/factorization/from.rs b/src/utils/factorization/from.rs index 2367150d..754305a9 100644 --- a/src/utils/factorization/from.rs +++ b/src/utils/factorization/from.rs @@ -10,7 +10,7 @@ use super::Factorization; use crate::integer::Z; -use flint_sys::fmpz_factor::{_fmpz_factor_append, fmpz_factor_get_fmpz}; +use flint3_sys::{_fmpz_factor_append, fmpz_factor_get_fmpz}; impl> From for Factorization { /// Convert an integer into a [`Factorization`]. diff --git a/src/utils/factorization/ownership.rs b/src/utils/factorization/ownership.rs index 9cf666d8..f256155f 100644 --- a/src/utils/factorization/ownership.rs +++ b/src/utils/factorization/ownership.rs @@ -9,7 +9,7 @@ //! Implementations for factorizations of [`Z`](crate::integer::Z) values. use super::Factorization; -use flint_sys::fmpz_factor::fmpz_factor_clear; +use flint3_sys::fmpz_factor_clear; impl Drop for Factorization { /// Drops the given [`Factorization`] value and frees the allocated memory. diff --git a/src/utils/factorization/refine.rs b/src/utils/factorization/refine.rs index 3552a9f9..248825e3 100644 --- a/src/utils/factorization/refine.rs +++ b/src/utils/factorization/refine.rs @@ -9,7 +9,7 @@ //! Implementations for Factorizations of [`Z`](crate::integer::Z) values. use super::Factorization; -use flint_sys::fmpz_factor::fmpz_factor_refine; +use flint3_sys::fmpz_factor_refine; impl Factorization { /// Allows to refine a partial factorization of type [`Factorization`] to a more diff --git a/src/utils/sample/discrete_gauss.rs b/src/utils/sample/discrete_gauss.rs index 5a3db1f7..bcc34009 100644 --- a/src/utils/sample/discrete_gauss.rs +++ b/src/utils/sample/discrete_gauss.rs @@ -606,7 +606,7 @@ mod test_sample_d { integer::{MatZ, Z}, rational::{MatQ, Q}, }; - use flint_sys::fmpz_mat::fmpz_mat_hnf; + use flint3_sys::fmpz_mat_hnf; use std::str::FromStr; /// Ensures that the doc-test compiles and runs properly. diff --git a/src/utils/sample/uniform.rs b/src/utils/sample/uniform.rs index 0ed051f8..a773f984 100644 --- a/src/utils/sample/uniform.rs +++ b/src/utils/sample/uniform.rs @@ -10,7 +10,7 @@ //! uniform random distribution. use crate::{error::MathError, integer::Z}; -use flint_sys::fmpz::{fmpz_addmul_ui, fmpz_set_ui}; +use flint3_sys::{fmpz_addmul_ui, fmpz_set_ui}; use rand::{Rng, rngs::ThreadRng}; /// Enables uniformly random sampling a [`Z`] in `[0, interval_size)`. From 3b78f1d3c6a2f84487250a825a63085a3d832bc0 Mon Sep 17 00:00:00 2001 From: Marvin Beckmann Date: Sun, 2 Aug 2026 08:35:57 +0200 Subject: [PATCH 4/6] make two default calls for fmpq explicit --- src/integer/z/arithmetic/sub.rs | 2 +- src/rational/q/from.rs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/integer/z/arithmetic/sub.rs b/src/integer/z/arithmetic/sub.rs index 045c3745..88fef43d 100644 --- a/src/integer/z/arithmetic/sub.rs +++ b/src/integer/z/arithmetic/sub.rs @@ -129,7 +129,7 @@ impl Sub<&Q> for &Z { /// ``` fn sub(self, other: &Q) -> Self::Output { let mut out = Q::default(); - let mut fmpq_1 = default(); + let mut fmpq_1 = fmpq::default(); unsafe { fmpq_set_fmpz_frac(&mut fmpq_1, &self.value, &1) } unsafe { fmpq_sub(&mut out.value, &fmpq_1, &other.value); diff --git a/src/rational/q/from.rs b/src/rational/q/from.rs index 11c99da0..82d22b1e 100644 --- a/src/rational/q/from.rs +++ b/src/rational/q/from.rs @@ -18,9 +18,7 @@ use crate::{ traits::{AsInteger, Pow}, }; use flint3_sys::{ - fmpq, - {fmpq_canonicalise, fmpq_clear, fmpq_get_d, fmpq_set_str}, - {fmpz_init_set, fmpz_is_zero}, + fmpq, {fmpq_canonicalise, fmpq_clear, fmpq_get_d, fmpq_set_str}, {fmpz_init_set, fmpz_is_zero}, }; use std::{ffi::CString, str::FromStr}; @@ -253,7 +251,7 @@ impl FromStr for Q { } // `default()` returns the value `0/0` - let mut value = default(); + let mut value = fmpq::default(); let c_string = CString::new(s)?; From 33281a0dbd37859c91bb664dc00f80cbb14c9513 Mon Sep 17 00:00:00 2001 From: jnsiemer Date: Mon, 3 Aug 2026 11:46:47 +0100 Subject: [PATCH 5/6] Fix docs --- src/integer_mod_q/modulus/ownership.rs | 2 +- src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs | 2 +- src/rational/mat_q/get.rs | 2 +- src/rational/mat_q/set.rs | 2 +- src/rational/q/cmp.rs | 3 +-- src/rational/q/rounding.rs | 3 +-- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/integer_mod_q/modulus/ownership.rs b/src/integer_mod_q/modulus/ownership.rs index dc183191..af90708b 100644 --- a/src/integer_mod_q/modulus/ownership.rs +++ b/src/integer_mod_q/modulus/ownership.rs @@ -35,7 +35,7 @@ impl Clone for Modulus { } impl Drop for Modulus { - /// Drops the given reference to the [`fmpz_mod_ctx`](flint3_sys::fmpz_mod_types::fmpz_mod_ctx) element + /// Drops the given reference to the [`fmpz_mod_ctx`](flint3_sys::fmpz_mod_ctx) element /// and frees the allocated memory if no references are left. /// /// # Examples diff --git a/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs b/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs index c0362bb0..6770b2f9 100644 --- a/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs +++ b/src/integer_mod_q/modulus_polynomial_ring_zq/ownership.rs @@ -16,7 +16,7 @@ use std::rc::Rc; impl Clone for ModulusPolynomialRingZq { /// Clones the given element and returns another cloned reference - /// to the [`fq_ctx_struct`](flint3_sys::fq_types::fq_ctx_struct) element. + /// to the [`fq_ctx_struct`](flint3_sys::fq_ctx_struct) element. /// /// # Examples /// ``` diff --git a/src/rational/mat_q/get.rs b/src/rational/mat_q/get.rs index b4ee9c49..9faf492d 100644 --- a/src/rational/mat_q/get.rs +++ b/src/rational/mat_q/get.rs @@ -11,8 +11,8 @@ use super::MatQ; use crate::rational::Q; use crate::traits::{MatrixDimensions, MatrixGetEntry, MatrixGetSubmatrix}; +use flint3_sys::{fmpq, fmpq_mat_entry, fmpq_set}; use flint3_sys::{fmpq_mat_init_set, fmpq_mat_window_clear, fmpq_mat_window_init}; -use flint3_sys::{fmpq, fmpq_set, fmpq_mat_entry}; use std::mem::MaybeUninit; impl MatrixDimensions for MatQ { diff --git a/src/rational/mat_q/set.rs b/src/rational/mat_q/set.rs index fa0cfc57..294d5837 100644 --- a/src/rational/mat_q/set.rs +++ b/src/rational/mat_q/set.rs @@ -15,11 +15,11 @@ use crate::{ utils::index::{evaluate_index_for_vector, evaluate_indices_for_matrix}, }; use flint3_sys::{ - {fmpq_set, fmpq_swap}, { fmpq_mat_entry, fmpq_mat_invert_cols, fmpq_mat_invert_rows, fmpq_mat_set, fmpq_mat_swap_cols, fmpq_mat_swap_rows, fmpq_mat_window_clear, fmpq_mat_window_init, }, + {fmpq_set, fmpq_swap}, }; use std::{fmt::Display, mem::MaybeUninit, ptr::null_mut}; diff --git a/src/rational/q/cmp.rs b/src/rational/q/cmp.rs index 4ed781a6..faa27ab8 100644 --- a/src/rational/q/cmp.rs +++ b/src/rational/q/cmp.rs @@ -16,8 +16,7 @@ use crate::{ macros::for_others::{implement_for_others, implement_trait_reverse}, }; use flint3_sys::{ - {fmpq_cmp, fmpq_equal}, - fmpz_equal, + fmpz_equal, {fmpq_cmp, fmpq_equal}, }; use std::cmp::Ordering; diff --git a/src/rational/q/rounding.rs b/src/rational/q/rounding.rs index 63c77269..f244d55e 100644 --- a/src/rational/q/rounding.rs +++ b/src/rational/q/rounding.rs @@ -11,8 +11,7 @@ use super::Q; use crate::{error::MathError, integer::Z, traits::Distance}; use flint3_sys::{ - {fmpq_sgn, fmpq_simplest_between}, - {fmpz_cdiv_q, fmpz_fdiv_q}, + {fmpq_sgn, fmpq_simplest_between}, {fmpz_cdiv_q, fmpz_fdiv_q}, }; impl Q { From 22cedc6d9dcee5996a9212d1245b60c2398c4447 Mon Sep 17 00:00:00 2001 From: jnsiemer Date: Mon, 3 Aug 2026 13:23:32 +0100 Subject: [PATCH 6/6] Make clippy happy --- src/integer/poly_over_z/from.rs | 2 +- src/integer/z/from.rs | 2 +- src/integer_mod_q/mat_zq/inverse.rs | 5 ++--- src/integer_mod_q/z_q/from.rs | 2 +- src/rational/q/from.rs | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/integer/poly_over_z/from.rs b/src/integer/poly_over_z/from.rs index ddb39954..44920695 100644 --- a/src/integer/poly_over_z/from.rs +++ b/src/integer/poly_over_z/from.rs @@ -69,7 +69,7 @@ impl FromStr for PolyOverZ { // We only have to check it once, because for every other position it checks // whether there is only one space. if !s_trimmed.contains(" ") { - return Err(StringConversionError::InvalidStringToPolyMissingWhitespace( + Err(StringConversionError::InvalidStringToPolyMissingWhitespace( s.to_owned(), ))?; }; diff --git a/src/integer/z/from.rs b/src/integer/z/from.rs index 66ed117e..c2b70f68 100644 --- a/src/integer/z/from.rs +++ b/src/integer/z/from.rs @@ -120,7 +120,7 @@ impl Z { } if s.contains(char::is_whitespace) { - return Err(StringConversionError::InvalidStringToZInput(s.to_owned()))?; + Err(StringConversionError::InvalidStringToZInput(s.to_owned()))?; } // since |value| = |0| < 62 bits, we do not need to free the allocated space manually diff --git a/src/integer_mod_q/mat_zq/inverse.rs b/src/integer_mod_q/mat_zq/inverse.rs index ead9a093..978544fe 100644 --- a/src/integer_mod_q/mat_zq/inverse.rs +++ b/src/integer_mod_q/mat_zq/inverse.rs @@ -51,10 +51,9 @@ impl MatZq { // Use solve for all unit vectors. for i in 0..dimensions { - if let Some(column_i) = self.solve_gaussian_elimination(&e_i) { + { + let column_i = self.solve_gaussian_elimination(&e_i)?; inverse.set_column(i, &column_i, 0).unwrap(); - } else { - return None; } if i != dimensions - 1 { diff --git a/src/integer_mod_q/z_q/from.rs b/src/integer_mod_q/z_q/from.rs index 74024ee9..8791310a 100644 --- a/src/integer_mod_q/z_q/from.rs +++ b/src/integer_mod_q/z_q/from.rs @@ -121,7 +121,7 @@ impl FromStr for Zq { fn from_str(s: &str) -> Result { let input_split: Vec<&str> = s.split("mod").collect(); if input_split.len() != 2 { - return Err(StringConversionError::InvalidStringToZqInput(s.to_owned()))?; + Err(StringConversionError::InvalidStringToZqInput(s.to_owned()))?; } // instantiate both parts of Zq element diff --git a/src/rational/q/from.rs b/src/rational/q/from.rs index 82d22b1e..7fd20c92 100644 --- a/src/rational/q/from.rs +++ b/src/rational/q/from.rs @@ -247,7 +247,7 @@ impl FromStr for Q { /// if the provided string has `0` as the denominator. fn from_str(s: &str) -> Result { if s.contains(char::is_whitespace) { - return Err(StringConversionError::InvalidStringToQInput(s.to_owned()))?; + Err(StringConversionError::InvalidStringToQInput(s.to_owned()))?; } // `default()` returns the value `0/0` @@ -264,7 +264,7 @@ impl FromStr for Q { // since value is set to `0`, if an error occurs, we do not need to free // the allocated space manually if -1 == unsafe { fmpq_set_str(&mut value, c_string.as_ptr(), 10) } { - return Err(StringConversionError::InvalidStringToQInput(s.to_owned()))?; + Err(StringConversionError::InvalidStringToQInput(s.to_owned()))?; }; // canonical form is expected by other functions