basic_dsp_matrix/general/
statistics.rs

1use super::*;
2use crate::IntoFixedLength;
3
4impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsOps<T> for MatrixMxN<V, S, T>
5where
6    V: StatisticsOps<Statistics<T>, Result = Statistics<T>>,
7{
8    type Result = Vec<Statistics<T>>;
9
10    fn statistics(&self) -> Vec<Statistics<T>> {
11        let mut result = Vec::with_capacity(self.col_len());
12        for v in self.rows() {
13            let res = v.statistics();
14            result.push(res);
15        }
16
17        result
18    }
19}
20
21impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsSplitOps<T> for MatrixMxN<V, S, T>
22where
23    V: StatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
24{
25    type Result = Vec<StatsVec<Statistics<T>>>;
26
27    fn statistics_split(&self, len: usize) -> ScalarResult<Vec<StatsVec<Statistics<T>>>> {
28        let mut result = Vec::with_capacity(self.col_len());
29        for v in self.rows() {
30            let res = v.statistics_split(len)?;
31            result.push(res);
32        }
33
34        Ok(result)
35    }
36}
37
38impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsOps<T> for Matrix2xN<V, S, T>
39where
40    V: StatisticsOps<Statistics<T>, Result = Statistics<T>>,
41{
42    type Result = [Statistics<T>; 2];
43
44    fn statistics(&self) -> Self::Result {
45        let mut result = Vec::with_capacity(self.col_len());
46        for v in self.rows() {
47            let res = v.statistics();
48            result.push(res);
49        }
50
51        result.into_fixed_length()
52    }
53}
54
55impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsSplitOps<T> for Matrix2xN<V, S, T>
56where
57    V: StatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
58{
59    type Result = [StatsVec<Statistics<T>>; 2];
60
61    fn statistics_split(&self, len: usize) -> ScalarResult<Self::Result> {
62        let mut result = Vec::with_capacity(self.col_len());
63        for v in self.rows() {
64            let res = v.statistics_split(len)?;
65            result.push(res);
66        }
67
68        Ok(result.into_fixed_length())
69    }
70}
71
72impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsOps<T> for Matrix3xN<V, S, T>
73where
74    V: StatisticsOps<Statistics<T>, Result = Statistics<T>>,
75{
76    type Result = [Statistics<T>; 3];
77
78    fn statistics(&self) -> Self::Result {
79        let mut result = Vec::with_capacity(self.col_len());
80        for v in self.rows() {
81            let res = v.statistics();
82            result.push(res);
83        }
84
85        result.into_fixed_length()
86    }
87}
88
89impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsSplitOps<T> for Matrix3xN<V, S, T>
90where
91    V: StatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
92{
93    type Result = [StatsVec<Statistics<T>>; 3];
94
95    fn statistics_split(&self, len: usize) -> ScalarResult<Self::Result> {
96        let mut result = Vec::with_capacity(self.col_len());
97        for v in self.rows() {
98            let res = v.statistics_split(len)?;
99            result.push(res);
100        }
101
102        Ok(result.into_fixed_length())
103    }
104}
105
106impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsOps<T> for Matrix4xN<V, S, T>
107where
108    V: StatisticsOps<Statistics<T>, Result = Statistics<T>>,
109{
110    type Result = [Statistics<T>; 4];
111
112    fn statistics(&self) -> Self::Result {
113        let mut result = Vec::with_capacity(self.col_len());
114        for v in self.rows() {
115            let res = v.statistics();
116            result.push(res);
117        }
118
119        result.into_fixed_length()
120    }
121}
122
123impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> StatisticsSplitOps<T> for Matrix4xN<V, S, T>
124where
125    V: StatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
126{
127    type Result = [StatsVec<Statistics<T>>; 4];
128
129    fn statistics_split(&self, len: usize) -> ScalarResult<Self::Result> {
130        let mut result = Vec::with_capacity(self.col_len());
131        for v in self.rows() {
132            let res = v.statistics_split(len)?;
133            result.push(res);
134        }
135
136        Ok(result.into_fixed_length())
137    }
138}
139
140impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> SumOps<Vec<T>> for MatrixMxN<V, S, T>
141where
142    V: SumOps<T>,
143{
144    fn sum(&self) -> Vec<T> {
145        let mut result = Vec::with_capacity(self.col_len());
146        for v in self.rows() {
147            let res = v.sum();
148            result.push(res);
149        }
150
151        result
152    }
153
154    fn sum_sq(&self) -> Vec<T> {
155        let mut result = Vec::with_capacity(self.col_len());
156        for v in self.rows() {
157            let res = v.sum_sq();
158            result.push(res);
159        }
160
161        result
162    }
163}
164
165impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> SumOps<[T; 2]> for Matrix2xN<V, S, T>
166where
167    V: SumOps<T>,
168{
169    fn sum(&self) -> [T; 2] {
170        let mut result = Vec::with_capacity(self.col_len());
171        for v in self.rows() {
172            let res = v.sum();
173            result.push(res);
174        }
175
176        result.into_fixed_length()
177    }
178
179    fn sum_sq(&self) -> [T; 2] {
180        let mut result = Vec::with_capacity(self.col_len());
181        for v in self.rows() {
182            let res = v.sum_sq();
183            result.push(res);
184        }
185
186        result.into_fixed_length()
187    }
188}
189
190impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> SumOps<[T; 3]> for Matrix2xN<V, S, T>
191where
192    V: SumOps<T>,
193{
194    fn sum(&self) -> [T; 3] {
195        let mut result = Vec::with_capacity(self.col_len());
196        for v in self.rows() {
197            let res = v.sum();
198            result.push(res);
199        }
200
201        result.into_fixed_length()
202    }
203
204    fn sum_sq(&self) -> [T; 3] {
205        let mut result = Vec::with_capacity(self.col_len());
206        for v in self.rows() {
207            let res = v.sum_sq();
208            result.push(res);
209        }
210
211        result.into_fixed_length()
212    }
213}
214
215impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> SumOps<[T; 4]> for Matrix2xN<V, S, T>
216where
217    V: SumOps<T>,
218{
219    fn sum(&self) -> [T; 4] {
220        let mut result = Vec::with_capacity(self.col_len());
221        for v in self.rows() {
222            let res = v.sum();
223            result.push(res);
224        }
225
226        result.into_fixed_length()
227    }
228
229    fn sum_sq(&self) -> [T; 4] {
230        let mut result = Vec::with_capacity(self.col_len());
231        for v in self.rows() {
232            let res = v.sum_sq();
233            result.push(res);
234        }
235
236        result.into_fixed_length()
237    }
238}
239
240impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsOps<T> for MatrixMxN<V, S, T>
241where
242    V: PreciseStatisticsOps<Statistics<T>, Result = Statistics<T>>,
243{
244    type Result = Vec<Statistics<T>>;
245
246    fn statistics_prec(&self) -> Vec<Statistics<T>> {
247        let mut result = Vec::with_capacity(self.col_len());
248        for v in self.rows() {
249            let res = v.statistics_prec();
250            result.push(res);
251        }
252
253        result
254    }
255}
256
257impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsSplitOps<T> for MatrixMxN<V, S, T>
258where
259    V: PreciseStatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
260{
261    type Result = Vec<StatsVec<Statistics<T>>>;
262
263    fn statistics_split_prec(&self, len: usize) -> ScalarResult<Vec<StatsVec<Statistics<T>>>> {
264        let mut result = Vec::with_capacity(self.col_len());
265        for v in self.rows() {
266            let res = v.statistics_split_prec(len)?;
267            result.push(res);
268        }
269
270        Ok(result)
271    }
272}
273
274impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsOps<T> for Matrix2xN<V, S, T>
275where
276    V: PreciseStatisticsOps<Statistics<T>, Result = Statistics<T>>,
277{
278    type Result = [Statistics<T>; 2];
279
280    fn statistics_prec(&self) -> Self::Result {
281        let mut result = Vec::with_capacity(self.col_len());
282        for v in self.rows() {
283            let res = v.statistics_prec();
284            result.push(res);
285        }
286
287        result.into_fixed_length()
288    }
289}
290
291impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsSplitOps<T> for Matrix2xN<V, S, T>
292where
293    V: PreciseStatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
294{
295    type Result = [StatsVec<Statistics<T>>; 2];
296
297    fn statistics_split_prec(&self, len: usize) -> ScalarResult<Self::Result> {
298        let mut result = Vec::with_capacity(self.col_len());
299        for v in self.rows() {
300            let res = v.statistics_split_prec(len)?;
301            result.push(res);
302        }
303
304        Ok(result.into_fixed_length())
305    }
306}
307
308impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsOps<T> for Matrix3xN<V, S, T>
309where
310    V: PreciseStatisticsOps<Statistics<T>, Result = Statistics<T>>,
311{
312    type Result = [Statistics<T>; 3];
313
314    fn statistics_prec(&self) -> Self::Result {
315        let mut result = Vec::with_capacity(self.col_len());
316        for v in self.rows() {
317            let res = v.statistics_prec();
318            result.push(res);
319        }
320
321        result.into_fixed_length()
322    }
323}
324
325impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsSplitOps<T> for Matrix3xN<V, S, T>
326where
327    V: PreciseStatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
328{
329    type Result = [StatsVec<Statistics<T>>; 3];
330
331    fn statistics_split_prec(&self, len: usize) -> ScalarResult<Self::Result> {
332        let mut result = Vec::with_capacity(self.col_len());
333        for v in self.rows() {
334            let res = v.statistics_split_prec(len)?;
335            result.push(res);
336        }
337
338        Ok(result.into_fixed_length())
339    }
340}
341
342impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsOps<T> for Matrix4xN<V, S, T>
343where
344    V: PreciseStatisticsOps<Statistics<T>, Result = Statistics<T>>,
345{
346    type Result = [Statistics<T>; 4];
347
348    fn statistics_prec(&self) -> Self::Result {
349        let mut result = Vec::with_capacity(self.col_len());
350        for v in self.rows() {
351            let res = v.statistics_prec();
352            result.push(res);
353        }
354
355        result.into_fixed_length()
356    }
357}
358
359impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber> PreciseStatisticsSplitOps<T> for Matrix4xN<V, S, T>
360where
361    V: PreciseStatisticsSplitOps<Statistics<T>, Result = StatsVec<Statistics<T>>>,
362{
363    type Result = [StatsVec<Statistics<T>>; 4];
364
365    fn statistics_split_prec(&self, len: usize) -> ScalarResult<Self::Result> {
366        let mut result = Vec::with_capacity(self.col_len());
367        for v in self.rows() {
368            let res = v.statistics_split_prec(len)?;
369            result.push(res);
370        }
371
372        Ok(result.into_fixed_length())
373    }
374}
375
376impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber, O: RealNumber> PreciseSumOps<Vec<O>>
377    for MatrixMxN<V, S, T>
378where
379    V: PreciseSumOps<O>,
380{
381    fn sum_prec(&self) -> Vec<O> {
382        let mut result = Vec::with_capacity(self.col_len());
383        for v in self.rows() {
384            let res = v.sum_prec();
385            result.push(res);
386        }
387
388        result
389    }
390
391    fn sum_sq_prec(&self) -> Vec<O> {
392        let mut result = Vec::with_capacity(self.col_len());
393        for v in self.rows() {
394            let res = v.sum_sq_prec();
395            result.push(res);
396        }
397
398        result
399    }
400}
401
402impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber, O: RealNumber> PreciseSumOps<[O; 2]>
403    for Matrix2xN<V, S, T>
404where
405    V: PreciseSumOps<O>,
406{
407    fn sum_prec(&self) -> [O; 2] {
408        let mut result = Vec::with_capacity(self.col_len());
409        for v in self.rows() {
410            let res = v.sum_prec();
411            result.push(res);
412        }
413
414        result.into_fixed_length()
415    }
416
417    fn sum_sq_prec(&self) -> [O; 2] {
418        let mut result = Vec::with_capacity(self.col_len());
419        for v in self.rows() {
420            let res = v.sum_sq_prec();
421            result.push(res);
422        }
423
424        result.into_fixed_length()
425    }
426}
427
428impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber, O: RealNumber> PreciseSumOps<[O; 3]>
429    for Matrix3xN<V, S, T>
430where
431    V: PreciseSumOps<O>,
432{
433    fn sum_prec(&self) -> [O; 3] {
434        let mut result = Vec::with_capacity(self.col_len());
435        for v in self.rows() {
436            let res = v.sum_prec();
437            result.push(res);
438        }
439
440        result.into_fixed_length()
441    }
442
443    fn sum_sq_prec(&self) -> [O; 3] {
444        let mut result = Vec::with_capacity(self.col_len());
445        for v in self.rows() {
446            let res = v.sum_sq_prec();
447            result.push(res);
448        }
449
450        result.into_fixed_length()
451    }
452}
453
454impl<S: ToSlice<T>, V: Vector<T>, T: RealNumber, O: RealNumber> PreciseSumOps<[O; 4]>
455    for Matrix4xN<V, S, T>
456where
457    V: PreciseSumOps<O>,
458{
459    fn sum_prec(&self) -> [O; 4] {
460        let mut result = Vec::with_capacity(self.col_len());
461        for v in self.rows() {
462            let res = v.sum_prec();
463            result.push(res);
464        }
465
466        result.into_fixed_length()
467    }
468
469    fn sum_sq_prec(&self) -> [O; 4] {
470        let mut result = Vec::with_capacity(self.col_len());
471        for v in self.rows() {
472            let res = v.sum_sq_prec();
473            result.push(res);
474        }
475
476        result.into_fixed_length()
477    }
478}