Skip to content

Commit 42c3a5e

Browse files
committed
added schoolbook convolution
1 parent f9bc0e9 commit 42c3a5e

5 files changed

Lines changed: 22 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "feanor-math"
3-
version = "3.5.16"
3+
version = "3.5.17"
44
edition = "2024"
55
authors = ["Simon Pohmann <simon@pohmann.de>"]
66

src/algorithms/convolution/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,22 @@ impl<R: ?Sized + RingBase, A: Allocator> ConvolutionAlgorithm<R> for KaratsubaAl
396396
fn supports_ring<S: RingStore<Type = R> + Copy>(&self, _ring: S) -> bool { true }
397397
}
398398

399+
/// Very simple schoolbook convolution algorithm.
400+
pub struct SchoolbookConvolution;
401+
402+
impl<R: ?Sized + RingBase> ConvolutionAlgorithm<R> for SchoolbookConvolution {
403+
fn supports_ring<S: RingStore<Type = R> + Copy>(&self, _ring: S) -> bool { true }
404+
405+
fn compute_convolution<S, V1, V2>(&self, lhs: V1, rhs: V2, dst: &mut [<R as RingBase>::Element], ring: S)
406+
where
407+
S: RingStore<Type = R> + Copy,
408+
V1: VectorView<<R as RingBase>::Element>,
409+
V2: VectorView<<R as RingBase>::Element>,
410+
{
411+
naive_assign_mul::<_, _, _, _, true>(dst, lhs, rhs, ring)
412+
}
413+
}
414+
399415
/// Trait to allow rings to customize the parameters with which [`KaratsubaAlgorithm`] will
400416
/// compute convolutions over the ring.
401417
#[stability::unstable(feature = "enable")]
@@ -447,14 +463,16 @@ fn bench_karatsuba_mul(bencher: &mut test::Bencher) {
447463
});
448464
}
449465

466+
#[test]
467+
fn test_schoolbook_convolution() { generic_tests::test_convolution(SchoolbookConvolution, StaticRing::<i64>::RING, 1); }
468+
450469
#[allow(missing_docs)]
451470
#[cfg(any(test, feature = "generic_tests"))]
452471
pub mod generic_tests {
453472
use std::cmp::min;
454473

455474
use super::*;
456475
use crate::homomorphism::*;
457-
use crate::ring::*;
458476

459477
pub fn test_convolution<C, R>(convolution: C, ring: R, scale: El<R>)
460478
where

src/algorithms/fft/factor_fft.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ use crate::algorithms::fft::bluestein::BluesteinFFT;
408408
#[cfg(test)]
409409
use crate::algorithms::unity_root::*;
410410
#[cfg(test)]
411-
use crate::rings::zn::ZnRingStore;
412-
#[cfg(test)]
413411
use crate::rings::zn::zn_64;
414412
#[cfg(test)]
415413
use crate::rings::zn::zn_static::{Fp, Zn};

src/computation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ where
240240
self.executor.finished.store(true, Ordering::Relaxed);
241241
self.executor.abort.store(Some(Box::new(abort)), Ordering::AcqRel);
242242
};
243-
self.controller.join(
243+
_ = self.controller.join(
244244
|controller| {
245245
if self.executor.finished.load(Ordering::Relaxed) {
246246
return;

0 commit comments

Comments
 (0)