Skip to content

Commit 0709be5

Browse files
committed
Restore unsafe-passthrough
1 parent f97b6a8 commit 0709be5

File tree

7 files changed

+65
-9
lines changed

7 files changed

+65
-9
lines changed

src/integer_mod_q/mat_polynomial_ring_zq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod sort;
3131
mod tensor;
3232
mod to_string;
3333
mod transpose;
34+
mod unsafe_functions;
3435
mod vector;
3536

3637
/// [`MatPolynomialRingZq`] is a matrix with entries of type [`PolynomialRingZq`](crate::integer_mod_q::PolynomialRingZq).

src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl MatPolynomialRingZq {
4040
pub(crate) fn reduce(&mut self) {
4141
for row_num in 0..self.matrix.get_num_rows() {
4242
for column_num in 0..self.matrix.get_num_columns() {
43-
self.reduce_entry(row_num, column_num);
43+
unsafe { self.reduce_entry(row_num, column_num) };
4444
}
4545
}
4646
}
@@ -62,9 +62,9 @@ impl MatPolynomialRingZq {
6262
/// let poly_mat = MatPolyOverZ::from_str("[[4 -1 0 1 1, 1 42],[0, 2 1 2]]").unwrap();
6363
/// let mut poly_ring_mat = MatPolynomialRingZq::from((&poly_mat, &modulus));
6464
///
65-
/// poly_ring_mat.reduce_entry(0, 0)
65+
/// unsafe { poly_ring_mat.reduce_entry(0, 0) };
6666
/// ```
67-
pub(crate) fn reduce_entry(&mut self, row: i64, column: i64) {
67+
pub(crate) unsafe fn reduce_entry(&mut self, row: i64, column: i64) {
6868
let entry = unsafe { fmpz_poly_mat_entry(&self.matrix.matrix, row, column) };
6969
if (unsafe { *entry }).length > 0 {
7070
unsafe {

src/integer_mod_q/mat_polynomial_ring_zq/tensor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ unsafe fn set_matrix_window_mul(
154154
),
155155
&scalar.poly,
156156
fmpz_poly_mat_entry(&matrix.matrix.matrix, i_other, j_other),
157-
)
157+
);
158+
out.reduce_entry(
159+
row_left * rows_other + i_other,
160+
column_upper * columns_other + j_other,
161+
);
158162
}
159-
out.reduce_entry(
160-
row_left * rows_other + i_other,
161-
column_upper * columns_other + j_other,
162-
);
163163
}
164164
}
165165
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright © 2025 Niklas Siemer
2+
//
3+
// This file is part of qFALL-math.
4+
//
5+
// qFALL-math is free software: you can redistribute it and/or modify it under
6+
// the terms of the Mozilla Public License Version 2.0 as published by the
7+
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
8+
9+
//! This module contains public functions that enable access to underlying
10+
//! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe.
11+
use super::MatPolynomialRingZq;
12+
use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect};
13+
use flint_sys::fmpz_poly_mat::fmpz_poly_mat_struct;
14+
15+
unsafe_getter_indirect!(
16+
MatPolynomialRingZq,
17+
matrix,
18+
get_fmpz_poly_mat_struct,
19+
fmpz_poly_mat_struct
20+
);
21+
22+
unsafe_setter_indirect!(
23+
MatPolynomialRingZq,
24+
matrix,
25+
set_fmpz_poly_mat_struct,
26+
fmpz_poly_mat_struct
27+
);

src/integer_mod_q/polynomial_ring_zq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod reduce;
3333
mod sample;
3434
mod set;
3535
mod to_string;
36+
mod unsafe_functions;
3637

3738
/// [`PolynomialRingZq`] represents polynomials over the finite field
3839
/// [`PolyOverZq`](crate::integer_mod_q::PolyOverZq)/f(X) where f(X) is a polynomial over [`Zq`](super::Zq).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright © 2025 Niklas Siemer
2+
//
3+
// This file is part of qFALL-math.
4+
//
5+
// qFALL-math is free software: you can redistribute it and/or modify it under
6+
// the terms of the Mozilla Public License Version 2.0 as published by the
7+
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
8+
9+
//! This module contains public functions that enable access to underlying
10+
//! [FLINT](https://flintlib.org/) structs. Therefore, they require to be unsafe.
11+
use super::PolynomialRingZq;
12+
use crate::macros::unsafe_passthrough::{unsafe_getter_indirect, unsafe_setter_indirect};
13+
use flint_sys::fmpz_poly::fmpz_poly_struct;
14+
15+
unsafe_getter_indirect!(
16+
PolynomialRingZq,
17+
poly,
18+
get_fmpz_poly_struct,
19+
fmpz_poly_struct
20+
);
21+
22+
unsafe_setter_indirect!(
23+
PolynomialRingZq,
24+
poly,
25+
set_fmpz_poly_struct,
26+
fmpz_poly_struct
27+
);

src/utils/reduce.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// the terms of the Mozilla Public License Version 2.0 as published by the
77
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
88

9-
//! Implementations to reduce a [`MatPolynomialRingZq`] with the
9+
//! Implementations to reduce a [`MatPolynomialRingZq`](crate::integer_mod_q::MatPolynomialRingZq) with the
1010
//! [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq).
1111
//! Only contains internal functions for reductions.
1212

0 commit comments

Comments
 (0)