lambdaworks_math/fft/
errors.rs1use core::fmt::Display;
2
3use crate::field::errors::FieldError;
4
5#[cfg(feature = "cuda")]
6use lambdaworks_gpu::cuda::abstractions::errors::CudaError;
7
8#[derive(Debug)]
9pub enum FFTError {
10 RootOfUnityError(u64),
11 InputError(usize),
12 OrderError(u64),
13 DomainSizeError(usize),
14 #[cfg(feature = "cuda")]
15 CudaError(CudaError),
16}
17
18impl Display for FFTError {
19 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
20 match self {
21 FFTError::RootOfUnityError(_) => write!(f, "Could not calculate root of unity"),
22 FFTError::InputError(v) => {
23 write!(f, "Input length is {v}, which is not a power of two")
24 }
25 FFTError::OrderError(v) => {
26 write!(f, "Order should be less than or equal to 63, but is {v}")
27 }
28 FFTError::DomainSizeError(_) => {
29 write!(f, "Domain size exceeds two adicity of the field")
30 }
31 #[cfg(feature = "cuda")]
32 FFTError::CudaError(_) => {
33 write!(f, "A CUDA related error has ocurred")
34 }
35 }
36 }
37}
38
39#[cfg(feature = "std")]
40impl std::error::Error for FFTError {
41 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
42 match self {
43 #[cfg(feature = "cuda")]
44 FFTError::CudaError(_) => Some(e),
45 _ => None,
46 }
47 }
48}
49
50#[cfg(feature = "cuda")]
51impl From<CudaError> for FFTError {
52 fn from(error: CudaError) -> Self {
53 Self::CudaError(error)
54 }
55}
56
57impl From<FieldError> for FFTError {
58 fn from(error: FieldError) -> Self {
59 match error {
60 FieldError::DivisionByZero => {
61 panic!("Can't divide by zero during FFT");
62 }
63 FieldError::InvZeroError => {
64 panic!("Can't calculate inverse of zero during FFT");
65 }
66 FieldError::RootOfUnityError(order) => FFTError::RootOfUnityError(order),
67 }
68 }
69}