1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::field::errors::FieldError;
use thiserror::Error;

#[cfg(feature = "metal")]
use lambdaworks_gpu::metal::abstractions::errors::MetalError;

#[cfg(feature = "cuda")]
use lambdaworks_gpu::cuda::abstractions::errors::CudaError;

#[derive(Debug, Error)]
pub enum FFTError {
    #[error("Could not calculate root of unity")]
    RootOfUnityError(u64),
    #[error("Input length is {0}, which is not a power of two")]
    InputError(usize),
    #[error("Order should be less than or equal to 63, but is {0}")]
    OrderError(u64),
    #[cfg(feature = "metal")]
    #[error("A Metal related error has ocurred")]
    MetalError(#[from] MetalError),
    #[cfg(feature = "cuda")]
    #[error("A CUDA related error has ocurred")]
    CudaError(#[from] CudaError),
}

impl From<FieldError> for FFTError {
    fn from(error: FieldError) -> Self {
        match error {
            FieldError::DivisionByZero => {
                panic!("Can't divide by zero during FFT");
            }
            FieldError::RootOfUnityError(order) => FFTError::RootOfUnityError(order),
        }
    }
}