quantrs2_device/process_tomography/
fallback.rs

1//! Fallback implementations when SciRS2 is not available
2
3use scirs2_core::ndarray::{Array1, Array2, ArrayView1, ArrayView2};
4
5/// Fallback statistical mean calculation
6pub const fn mean(_data: &ArrayView1<f64>) -> Result<f64, String> {
7    Ok(0.0)
8}
9
10/// Fallback standard deviation calculation
11pub const fn std(_data: &ArrayView1<f64>, _ddof: i32) -> Result<f64, String> {
12    Ok(1.0)
13}
14
15/// Fallback Pearson correlation calculation
16pub const fn pearsonr(
17    _x: &ArrayView1<f64>,
18    _y: &ArrayView1<f64>,
19    _alt: &str,
20) -> Result<(f64, f64), String> {
21    Ok((0.0, 0.5))
22}
23
24/// Fallback matrix trace calculation
25pub const fn trace(_matrix: &ArrayView2<f64>) -> Result<f64, String> {
26    Ok(1.0)
27}
28
29/// Fallback matrix inversion
30pub fn inv(_matrix: &ArrayView2<f64>) -> Result<Array2<f64>, String> {
31    Ok(Array2::eye(2))
32}
33
34/// Fallback optimization result
35pub struct OptimizeResult {
36    pub x: Array1<f64>,
37    pub fun: f64,
38    pub success: bool,
39    pub nit: usize,
40}
41
42/// Fallback optimization function
43pub fn minimize(
44    _func: fn(&Array1<f64>) -> f64,
45    _x0: &Array1<f64>,
46    _method: &str,
47) -> Result<OptimizeResult, String> {
48    Ok(OptimizeResult {
49        x: Array1::zeros(2),
50        fun: 0.0,
51        success: true,
52        nit: 0,
53    })
54}
55
56/// Fallback eigenvalue decomposition
57pub fn eig(
58    _matrix: &ArrayView2<f64>,
59) -> Result<
60    (
61        Array1<scirs2_core::Complex64>,
62        Array2<scirs2_core::Complex64>,
63    ),
64    String,
65> {
66    let eigenvalues = Array1::from_vec(vec![
67        scirs2_core::Complex64::new(1.0, 0.0),
68        scirs2_core::Complex64::new(0.0, 0.0),
69    ]);
70    let eigenvectors = Array2::from_shape_vec(
71        (2, 2),
72        vec![
73            scirs2_core::Complex64::new(1.0, 0.0),
74            scirs2_core::Complex64::new(0.0, 0.0),
75            scirs2_core::Complex64::new(0.0, 0.0),
76            scirs2_core::Complex64::new(1.0, 0.0),
77        ],
78    )
79    .map_err(|e| format!("Array creation error: {e}"))?;
80
81    Ok((eigenvalues, eigenvectors))
82}
83
84/// Fallback matrix determinant calculation
85pub const fn det(_matrix: &ArrayView2<f64>) -> Result<f64, String> {
86    Ok(1.0)
87}
88
89/// Fallback QR decomposition
90pub fn qr(_matrix: &ArrayView2<f64>) -> Result<(Array2<f64>, Array2<f64>), String> {
91    Ok((Array2::eye(2), Array2::eye(2)))
92}
93
94/// Fallback SVD decomposition
95pub fn svd(_matrix: &ArrayView2<f64>) -> Result<(Array2<f64>, Array1<f64>, Array2<f64>), String> {
96    Ok((Array2::eye(2), Array1::ones(2), Array2::eye(2)))
97}
98
99/// Fallback matrix norm calculation
100pub const fn matrix_norm(_matrix: &ArrayView2<f64>, _ord: Option<&str>) -> Result<f64, String> {
101    Ok(1.0)
102}
103
104/// Fallback Cholesky decomposition
105pub fn cholesky(_matrix: &ArrayView2<f64>) -> Result<Array2<f64>, String> {
106    Ok(Array2::eye(2))
107}
108
109/// Fallback variance calculation
110pub const fn var(_data: &ArrayView1<f64>, _ddof: i32) -> Result<f64, String> {
111    Ok(1.0)
112}
113
114/// Fallback correlation coefficient calculation
115pub fn corrcoef(_x: &ArrayView1<f64>, _y: &ArrayView1<f64>) -> Result<Array2<f64>, String> {
116    Ok(Array2::eye(2))
117}
118
119/// Fallback Spearman correlation calculation
120pub const fn spearmanr(
121    _x: &ArrayView1<f64>,
122    _y: &ArrayView1<f64>,
123    _alternative: &str,
124) -> Result<(f64, f64), String> {
125    Ok((0.0, 0.5))
126}
127
128/// Fallback t-test (one sample)
129pub const fn ttest_1samp(
130    _a: &ArrayView1<f64>,
131    _popmean: f64,
132    _alternative: &str,
133) -> Result<TTestResult, String> {
134    Ok(TTestResult {
135        statistic: 0.0,
136        pvalue: 0.5,
137    })
138}
139
140/// Fallback t-test (independent samples)
141pub const fn ttest_ind(
142    _a: &ArrayView1<f64>,
143    _b: &ArrayView1<f64>,
144    _alternative: &str,
145) -> Result<TTestResult, String> {
146    Ok(TTestResult {
147        statistic: 0.0,
148        pvalue: 0.5,
149    })
150}
151
152/// Fallback Kolmogorov-Smirnov 2-sample test
153pub const fn ks_2samp(
154    _data1: &ArrayView1<f64>,
155    _data2: &ArrayView1<f64>,
156    _alternative: &str,
157) -> Result<KSTestResult, String> {
158    Ok(KSTestResult {
159        statistic: 0.0,
160        pvalue: 0.5,
161    })
162}
163
164/// Fallback Shapiro-Wilk test
165pub const fn shapiro_wilk(_data: &ArrayView1<f64>) -> Result<SWTestResult, String> {
166    Ok(SWTestResult {
167        statistic: 0.95,
168        pvalue: 0.1,
169    })
170}
171
172/// T-test result structure
173#[derive(Debug, Clone)]
174pub struct TTestResult {
175    pub statistic: f64,
176    pub pvalue: f64,
177}
178
179/// Kolmogorov-Smirnov test result structure
180#[derive(Debug, Clone)]
181pub struct KSTestResult {
182    pub statistic: f64,
183    pub pvalue: f64,
184}
185
186/// Shapiro-Wilk test result structure
187#[derive(Debug, Clone)]
188pub struct SWTestResult {
189    pub statistic: f64,
190    pub pvalue: f64,
191}
192
193/// Alternative hypothesis type
194#[derive(Debug, Clone)]
195pub enum Alternative {
196    TwoSided,
197    Less,
198    Greater,
199}
200
201/// Distribution types and functions
202pub mod distributions {
203    use super::*;
204
205    /// Normal distribution functions
206    pub mod norm {
207        /// Normal PDF
208        pub const fn pdf(_x: f64, _loc: f64, _scale: f64) -> f64 {
209            0.4
210        }
211
212        /// Normal CDF
213        pub const fn cdf(_x: f64, _loc: f64, _scale: f64) -> f64 {
214            0.5
215        }
216
217        /// Normal PPF (inverse CDF)
218        pub const fn ppf(_q: f64, _loc: f64, _scale: f64) -> f64 {
219            0.0
220        }
221    }
222
223    /// Chi-squared distribution functions
224    pub mod chi2 {
225        /// Chi-squared PDF
226        pub const fn pdf(_x: f64, _df: f64) -> f64 {
227            0.1
228        }
229
230        /// Chi-squared CDF
231        pub const fn cdf(_x: f64, _df: f64) -> f64 {
232            0.5
233        }
234
235        /// Chi-squared PPF
236        pub const fn ppf(_q: f64, _df: f64) -> f64 {
237            1.0
238        }
239    }
240
241    /// Gamma distribution functions
242    pub mod gamma {
243        /// Gamma PDF
244        pub const fn pdf(_x: f64, _a: f64, _scale: f64) -> f64 {
245            0.2
246        }
247
248        /// Gamma CDF
249        pub const fn cdf(_x: f64, _a: f64, _scale: f64) -> f64 {
250            0.5
251        }
252
253        /// Gamma PPF
254        pub const fn ppf(_q: f64, _a: f64, _scale: f64) -> f64 {
255            1.0
256        }
257    }
258}
259
260/// Graph analysis fallback functions
261pub mod graph {
262    use super::*;
263
264    /// Fallback betweenness centrality
265    pub fn betweenness_centrality(_graph: &Array2<f64>) -> Result<Array1<f64>, String> {
266        Ok(Array1::ones(2))
267    }
268
269    /// Fallback closeness centrality
270    pub fn closeness_centrality(_graph: &Array2<f64>) -> Result<Array1<f64>, String> {
271        Ok(Array1::ones(2))
272    }
273
274    /// Fallback minimum spanning tree
275    pub fn minimum_spanning_tree(_graph: &Array2<f64>) -> Result<Array2<f64>, String> {
276        Ok(Array2::eye(2))
277    }
278
279    /// Fallback shortest path
280    pub fn shortest_path(
281        _graph: &Array2<f64>,
282        _start: usize,
283        _end: usize,
284    ) -> Result<Vec<usize>, String> {
285        Ok(vec![0, 1])
286    }
287
288    /// Fallback strongly connected components
289    pub fn strongly_connected_components(_graph: &Array2<f64>) -> Result<Vec<Vec<usize>>, String> {
290        Ok(vec![vec![0], vec![1]])
291    }
292
293    /// Graph structure placeholder
294    pub struct Graph {
295        pub adjacency_matrix: Array2<f64>,
296    }
297
298    impl Graph {
299        pub const fn new(adjacency_matrix: Array2<f64>) -> Self {
300            Self { adjacency_matrix }
301        }
302    }
303}