quantrs2_core/
simd_ops_stubs.rs

1//! Temporary SIMD operations stubs to replace scirs2_core::simd_ops
2//! TODO: Replace with scirs2_core when regex dependency issue is fixed
3
4use scirs2_core::ndarray::{Array1, ArrayView1};
5use scirs2_core::Complex64;
6
7/// Trait for SIMD operations on f64
8pub trait SimdF64 {
9    fn simd_add(self, other: f64) -> f64;
10    fn simd_sub(self, other: f64) -> f64;
11    fn simd_mul(self, other: f64) -> f64;
12    fn simd_scalar_mul(view: &ArrayView1<f64>, scalar: f64) -> Array1<f64>;
13    fn simd_add_arrays(a: &ArrayView1<f64>, b: &ArrayView1<f64>) -> Array1<f64>;
14    fn simd_sub_arrays(a: &ArrayView1<f64>, b: &ArrayView1<f64>) -> Array1<f64>;
15    fn simd_mul_arrays(a: &ArrayView1<f64>, b: &ArrayView1<f64>) -> Array1<f64>;
16    fn simd_sum(slice: &[f64]) -> f64;
17    fn simd_sum_array(a: &ArrayView1<f64>) -> f64;
18}
19
20impl SimdF64 for f64 {
21    #[inline]
22    fn simd_add(self, other: f64) -> f64 {
23        self + other
24    }
25
26    #[inline]
27    fn simd_sub(self, other: f64) -> f64 {
28        self - other
29    }
30
31    #[inline]
32    fn simd_mul(self, other: f64) -> f64 {
33        self * other
34    }
35
36    #[inline]
37    fn simd_scalar_mul(view: &ArrayView1<f64>, scalar: f64) -> Array1<f64> {
38        view.mapv(|x| x * scalar)
39    }
40
41    #[inline]
42    fn simd_add_arrays(a: &ArrayView1<f64>, b: &ArrayView1<f64>) -> Array1<f64> {
43        a + b
44    }
45
46    #[inline]
47    fn simd_sub_arrays(a: &ArrayView1<f64>, b: &ArrayView1<f64>) -> Array1<f64> {
48        a - b
49    }
50
51    #[inline]
52    fn simd_mul_arrays(a: &ArrayView1<f64>, b: &ArrayView1<f64>) -> Array1<f64> {
53        a * b
54    }
55
56    #[inline]
57    fn simd_sum(slice: &[f64]) -> f64 {
58        slice.iter().sum()
59    }
60
61    #[inline]
62    fn simd_sum_array(a: &ArrayView1<f64>) -> f64 {
63        a.sum()
64    }
65}
66
67/// Trait for SIMD operations on Complex64
68pub trait SimdComplex64 {
69    fn simd_add(self, other: Complex64) -> Complex64;
70    fn simd_sub(self, other: Complex64) -> Complex64;
71    fn simd_mul(self, other: Complex64) -> Complex64;
72    fn simd_scalar_mul(self, scalar: Complex64) -> Complex64;
73    fn simd_sum(slice: &[Complex64]) -> Complex64;
74}
75
76impl SimdComplex64 for Complex64 {
77    #[inline]
78    fn simd_add(self, other: Complex64) -> Complex64 {
79        self + other
80    }
81
82    #[inline]
83    fn simd_sub(self, other: Complex64) -> Complex64 {
84        self - other
85    }
86
87    #[inline]
88    fn simd_mul(self, other: Complex64) -> Complex64 {
89        self * other
90    }
91
92    #[inline]
93    fn simd_scalar_mul(self, scalar: Complex64) -> Complex64 {
94        self * scalar
95    }
96
97    #[inline]
98    fn simd_sum(slice: &[Complex64]) -> Complex64 {
99        slice.iter().sum()
100    }
101}