2024-07-06 17:36:51 +00:00
|
|
|
//! Configuration of module. Here, we can choose to compile for 32-bits or
|
|
|
|
//! 64-bit floating point values as basic data storage and computation size.
|
|
|
|
//! Default is f64.
|
2023-12-20 20:20:10 +00:00
|
|
|
//!
|
2023-11-22 13:40:16 +00:00
|
|
|
|
2023-12-20 20:20:10 +00:00
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(feature="f64")] {
|
2024-07-06 17:36:51 +00:00
|
|
|
/// Floating-point value, compile time option to make it either f32, or
|
|
|
|
/// f64.
|
2023-12-20 20:20:10 +00:00
|
|
|
pub type Flt = f64;
|
2023-12-28 22:49:25 +00:00
|
|
|
/// Ratio between circumference and diameter of a circle
|
2023-12-20 20:20:10 +00:00
|
|
|
pub const pi: Flt = std::f64::consts::PI;
|
2024-08-15 11:10:40 +00:00
|
|
|
|
2024-09-28 12:22:35 +00:00
|
|
|
|
2023-12-20 20:20:10 +00:00
|
|
|
}
|
|
|
|
else if #[cfg(feature="f32")] {
|
2023-12-28 22:49:25 +00:00
|
|
|
/// Floating-point value, compile time option to make it either f32, or f64
|
2023-12-20 20:20:10 +00:00
|
|
|
pub type Flt = f32;
|
2023-12-28 22:49:25 +00:00
|
|
|
/// Ratio between circumference and diameter of a circle
|
2023-12-20 20:20:10 +00:00
|
|
|
pub const pi: Flt = std::f32::consts::PI;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::compile_error!("feature should be f32 or f64");
|
|
|
|
}
|
|
|
|
}
|
2023-12-13 10:02:06 +00:00
|
|
|
|
2024-04-19 12:09:32 +00:00
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(feature = "python-bindings")] {
|
2024-09-28 12:22:35 +00:00
|
|
|
pub use numpy::{IntoPyArray,PyArray, PyArray1, PyArray2, PyArray3, PyArrayDyn, PyArrayLike1,
|
|
|
|
PyArrayLike2,PyArrayLike3,PyReadonlyArrayDyn, convert::ToPyArray};
|
2024-04-19 12:09:32 +00:00
|
|
|
pub use pyo3::prelude::*;
|
2024-05-01 13:25:26 +00:00
|
|
|
pub use pyo3::exceptions::PyValueError;
|
2024-04-19 12:09:32 +00:00
|
|
|
pub use pyo3::{pymodule, types::PyModule, PyResult};
|
2024-05-01 13:25:26 +00:00
|
|
|
pub use pyo3::anyhow::*;
|
|
|
|
pub use pyo3;
|
|
|
|
|
2024-08-11 09:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pub use ndarray::prelude::*;
|
2024-08-19 18:23:29 +00:00
|
|
|
pub use ndarray::{Array1, Array2, ArrayView1, ArrayViewMut1};
|
2024-04-19 12:09:32 +00:00
|
|
|
|
2024-08-11 09:58:50 +00:00
|
|
|
pub use ndarray::Zip;
|
2024-05-01 13:25:26 +00:00
|
|
|
use num::complex::Complex;
|
2024-07-09 22:23:34 +00:00
|
|
|
pub use num::complex::ComplexFloat;
|
2024-04-19 12:09:32 +00:00
|
|
|
|
|
|
|
/// View into 1D array of floats
|
2024-08-11 09:58:50 +00:00
|
|
|
#[allow(dead_code)]
|
2024-04-19 12:09:32 +00:00
|
|
|
pub type VdView<'a> = ArrayView1<'a, Flt>;
|
|
|
|
|
|
|
|
/// View into 1D array of complex floats
|
2024-08-11 09:58:50 +00:00
|
|
|
#[allow(dead_code)]
|
2024-04-19 12:09:32 +00:00
|
|
|
pub type VcView<'a> = ArrayView1<'a, Cflt>;
|
|
|
|
|
2023-12-13 10:02:06 +00:00
|
|
|
/// Complex number floating point
|
2023-11-22 13:40:16 +00:00
|
|
|
pub type Cflt = Complex<Flt>;
|
|
|
|
|
2024-04-19 12:09:32 +00:00
|
|
|
/// Complex unit sqrt(-1)
|
|
|
|
pub const I: Cflt = Cflt::new(0., 1.);
|
|
|
|
|
|
|
|
/// (Owning) Vector of floating point values
|
2023-11-22 13:40:16 +00:00
|
|
|
pub type Vd = Vec<Flt>;
|
2024-04-19 12:09:32 +00:00
|
|
|
|
|
|
|
/// (Owning) Vector of complex floating point values
|
2023-11-22 13:40:16 +00:00
|
|
|
pub type Vc = Vec<Cflt>;
|
|
|
|
|
2023-12-28 22:49:25 +00:00
|
|
|
/// 1D array of floats
|
2023-11-29 06:20:13 +00:00
|
|
|
pub type Dcol = Array1<Flt>;
|
2024-04-19 12:09:32 +00:00
|
|
|
|
2023-12-28 22:49:25 +00:00
|
|
|
/// 1D array of complex floats
|
2023-11-29 06:20:13 +00:00
|
|
|
pub type Ccol = Array1<Cflt>;
|
|
|
|
|
2023-12-28 22:49:25 +00:00
|
|
|
/// 2D array of floats
|
2023-11-22 13:40:16 +00:00
|
|
|
pub type Dmat = Array2<Flt>;
|
2024-07-06 17:36:51 +00:00
|
|
|
|
2023-12-28 22:49:25 +00:00
|
|
|
/// 2D array of complex floats
|
2023-11-22 13:40:16 +00:00
|
|
|
pub type Cmat = Array2<Cflt>;
|
2024-05-01 13:25:26 +00:00
|
|
|
|
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(feature = "python-bindings")] {
|
|
|
|
|
|
|
|
/// 1D array of T as returned from Rust to Numpy
|
|
|
|
pub type PyArr1<'py, T> = Bound<'py, PyArray<T, ndarray::Dim<[usize; 1]>>>;
|
2024-07-06 17:36:51 +00:00
|
|
|
|
2024-05-01 13:25:26 +00:00
|
|
|
/// 1D array Floats returned from Rust to Numpy
|
|
|
|
pub type PyArr1Flt<'py> = PyArr1<'py, Flt>;
|
|
|
|
|
|
|
|
/// 1D array of Complex returned from Rust to Numpy
|
|
|
|
pub type PyArr1Cflt<'py> = PyArr1<'py, Cflt>;
|
|
|
|
|
2024-07-06 17:36:51 +00:00
|
|
|
}}
|