#![allow(clippy::excessive_precision)]
#![deny(clippy::unwrap_used)]
#![cfg_attr(
all(feature = "fcma", target_arch = "aarch64"),
feature(stdarch_neon_fcma)
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(all(target_arch = "x86_64", feature = "avx"))]
mod avx;
mod cwt_executor;
mod cwt_filter;
#[cfg(feature = "scalogram")]
mod drawing;
mod err;
mod factory;
mod freqs;
mod mla;
#[cfg(all(target_arch = "aarch64", feature = "neon"))]
mod neon;
mod sample;
mod scale_bounds;
mod scales;
mod spetrum_arith;
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), feature = "sse"))]
mod sse;
mod wavelets;
#[cfg(feature = "scalogram")]
#[cfg_attr(docsrs, doc(cfg(feature = "scalogram")))]
use crate::drawing::{draw_scalogram_color_impl_f32, draw_scalogram_color_impl_f64};
use crate::factory::create_cwt;
use crate::freqs::scale_to_frequencies_impl;
pub use cwt_filter::CwtWavelet;
#[cfg(feature = "scalogram")]
#[cfg_attr(docsrs, doc(cfg(feature = "scalogram")))]
pub use drawing::Colormap;
pub use err::ScaletError;
use num_complex::Complex;
use std::sync::Arc;
pub use wavelets::{CmhatWavelet, GaborWavelet, HhhatWavelet, MorletWavelet};
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
pub struct CwtOptions {
pub scale_type: ScaleType,
pub nv: usize,
pub l1_norm: bool,
}
impl Default for CwtOptions {
fn default() -> Self {
Self {
nv: 32,
scale_type: ScaleType::Log,
l1_norm: true,
}
}
}
pub trait CwtExecutor<T> {
fn execute(&self, input: &[T]) -> Result<Vec<Vec<Complex<T>>>, ScaletError>;
fn execute_complex(&self, input: &[Complex<T>]) -> Result<Vec<Vec<Complex<T>>>, ScaletError>;
fn length(&self) -> usize;
fn view_scales(&self) -> &[T];
}
pub struct Scalet {}
impl Scalet {
pub fn make_morlet_f32(
length: usize,
options: CwtOptions,
) -> Result<Arc<dyn CwtExecutor<f32> + Send + Sync>, ScaletError> {
create_cwt(
Arc::new(MorletWavelet::default()),
length,
options.scale_type,
options,
)
}
pub fn make_morlet_f64(
length: usize,
options: CwtOptions,
) -> Result<Arc<dyn CwtExecutor<f64> + Send + Sync>, ScaletError> {
create_cwt(
Arc::new(MorletWavelet::default()),
length,
options.scale_type,
options,
)
}
pub fn make_cwt_f32(
wavelet: Arc<dyn CwtWavelet<f32> + Send + Sync>,
length: usize,
options: CwtOptions,
) -> Result<Arc<dyn CwtExecutor<f32> + Send + Sync>, ScaletError> {
create_cwt(wavelet, length, options.scale_type, options)
}
pub fn make_cwt_f64(
wavelet: Arc<dyn CwtWavelet<f64> + Send + Sync>,
length: usize,
options: CwtOptions,
) -> Result<Arc<dyn CwtExecutor<f64> + Send + Sync>, ScaletError> {
create_cwt(wavelet, length, options.scale_type, options)
}
pub fn scales_to_frequencies_f32(
wavelet: Arc<dyn CwtWavelet<f32> + Send + Sync>,
scales: &[f32],
filter_length: usize,
sampling_frequency: f32,
) -> Result<Vec<f32>, ScaletError> {
scale_to_frequencies_impl(wavelet, scales, sampling_frequency, filter_length)
}
pub fn scales_to_frequencies_f64(
wavelet: Arc<dyn CwtWavelet<f64> + Send + Sync>,
scales: &[f64],
filter_length: usize,
sampling_frequency: f64,
) -> Result<Vec<f64>, ScaletError> {
scale_to_frequencies_impl(wavelet, scales, sampling_frequency, filter_length)
}
#[cfg(feature = "scalogram")]
#[cfg_attr(docsrs, doc(cfg(feature = "scalogram")))]
pub fn draw_scalogram_color_f32(
coeffs: &[Vec<Complex<f32>>],
out_width: usize,
out_height: usize,
colormap: Colormap,
) -> Result<Vec<u8>, ScaletError> {
draw_scalogram_color_impl_f32(coeffs, out_width, out_height, colormap)
}
#[cfg(feature = "scalogram")]
#[cfg_attr(docsrs, doc(cfg(feature = "scalogram")))]
pub fn draw_scalogram_color_f64(
coeffs: &[Vec<Complex<f64>>],
out_width: usize,
out_height: usize,
colormap: Colormap,
) -> Result<Vec<u8>, ScaletError> {
draw_scalogram_color_impl_f64(coeffs, out_width, out_height, colormap)
}
}
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum ScaleType {
Log,
Linear,
}