1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
//! Auto-generated module
//!
//! š¤ Generated with [SplitRS](https://github.com/cool-japan/splitrs)
use crateFloat;
use crate;
use ;
/// SIMD-accelerated inverse square root: 1/sqrt(x)
///
/// Computes the reciprocal of the square root for each element.
/// This operation is fundamental in graphics and physics simulations.
///
/// # Arguments
/// * `a` - Input values (should be positive)
///
/// # Returns
/// Array of 1/sqrt(x) values
/// - Returns INFINITY for x = 0
/// - Returns NaN for x < 0
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::rsqrt_simd;
///
/// let x = array![1.0_f64, 4.0, 9.0, 16.0];
///
/// let result = rsqrt_simd::<f64>(&x.view());
/// assert!((result[0] - 1.0).abs() < 1e-14); // 1/sqrt(1) = 1
/// assert!((result[1] - 0.5).abs() < 1e-14); // 1/sqrt(4) = 0.5
/// assert!((result[2] - 1.0/3.0).abs() < 1e-14); // 1/sqrt(9) = 1/3
/// assert!((result[3] - 0.25).abs() < 1e-14); // 1/sqrt(16) = 0.25
/// ```
///
/// # Use Cases
/// - Vector normalization: v_normalized = v * rsqrt(dot(v, v))
/// - Quaternion normalization in 3D graphics
/// - Inverse distance weighting
/// - Fast approximate physics simulations
/// SIMD-accelerated simultaneous sin and cos computation
///
/// Computes both sine and cosine of each element in a single pass.
/// This is more efficient than calling sin and cos separately because
/// many implementations can compute both with minimal additional overhead.
///
/// # Arguments
/// * `a` - Input angles in radians
///
/// # Returns
/// Tuple of (sin_array, cos_array)
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::sincos_simd;
/// use std::f64::consts::PI;
///
/// let x = array![0.0_f64, PI/6.0, PI/4.0, PI/2.0];
///
/// let (sin_result, cos_result) = sincos_simd::<f64>(&x.view());
/// assert!((sin_result[0] - 0.0).abs() < 1e-14); // sin(0) = 0
/// assert!((cos_result[0] - 1.0).abs() < 1e-14); // cos(0) = 1
/// assert!((sin_result[1] - 0.5).abs() < 1e-14); // sin(Ļ/6) = 0.5
/// assert!((sin_result[3] - 1.0).abs() < 1e-14); // sin(Ļ/2) = 1
/// assert!(cos_result[3].abs() < 1e-14); // cos(Ļ/2) ā 0
/// ```
///
/// # Use Cases
/// - Rotation matrices (need both sin and cos)
/// - Complex number operations: e^(iĪø) = cos(Īø) + iĀ·sin(Īø)
/// - Fourier transform calculations
/// - Wave simulations
/// - Animation and interpolation (circular motion)
/// SIMD-accelerated numerically stable exp(x) - 1
///
/// Computes exp(x) - 1 accurately for small x values where the direct
/// calculation `exp(x) - 1` would suffer from catastrophic cancellation.
/// For |x| < 1e-10, the result is approximately x (Taylor expansion).
///
/// # Arguments
/// * `a` - Input values
///
/// # Returns
/// Array of exp(x) - 1 values
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::expm1_simd;
///
/// let x = array![0.0_f64, 1e-15, 1.0, -1.0];
///
/// let result = expm1_simd::<f64>(&x.view());
/// // exp(0) - 1 = 0
/// assert!((result[0] - 0.0).abs() < 1e-14);
/// // For small x: exp(x) - 1 ā x
/// assert!((result[1] - 1e-15).abs() < 1e-29);
/// // exp(1) - 1 ā 1.718
/// assert!((result[2] - (1.0_f64.exp() - 1.0)).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Financial calculations (compound interest for small rates)
/// - Numerical integration (avoiding cancellation errors)
/// - Statistical distributions (Poisson, exponential)
/// - Machine learning (softplus: log(1 + exp(x)))
/// SIMD-accelerated numerically stable ln(1 + x)
///
/// Computes ln(1 + x) accurately for small x values where the direct
/// calculation `(1 + x).ln()` would suffer from catastrophic cancellation.
/// For |x| < 1e-10, the result is approximately x - x²/2 (Taylor expansion).
///
/// # Arguments
/// * `a` - Input values (should be > -1)
///
/// # Returns
/// Array of ln(1 + x) values
/// - Returns -ā for x = -1
/// - Returns NaN for x < -1
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::log1p_simd;
///
/// let x = array![0.0_f64, 1e-15, 1.0, -0.5];
///
/// let result = log1p_simd::<f64>(&x.view());
/// // ln(1 + 0) = 0
/// assert!((result[0] - 0.0).abs() < 1e-14);
/// // For small x: ln(1 + x) ā x
/// assert!((result[1] - 1e-15).abs() < 1e-29);
/// // ln(2) ā 0.693
/// assert!((result[2] - 2.0_f64.ln()).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Log-probability calculations (log(1 - p) for small p)
/// - Numerical integration
/// - Statistical distributions
/// - Machine learning (binary cross-entropy: -yĀ·log(p) - (1-y)Ā·log(1-p))
/// SIMD-accelerated element-wise clipping (clamping)
///
/// Clips (limits) each element to be within [min_val, max_val].
/// Values below min_val become min_val, values above max_val become max_val.
///
/// # Arguments
/// * `a` - Input array
/// * `min_val` - Minimum value (lower bound)
/// * `max_val` - Maximum value (upper bound)
///
/// # Returns
/// Array with values clipped to [min_val, max_val]
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::clip_simd;
///
/// let x = array![-2.0_f64, -1.0, 0.0, 1.0, 2.0, 3.0];
///
/// let result = clip_simd::<f64>(&x.view(), 0.0, 1.0);
/// assert!((result[0] - 0.0).abs() < 1e-14); // -2 clipped to 0
/// assert!((result[2] - 0.0).abs() < 1e-14); // 0 unchanged
/// assert!((result[3] - 1.0).abs() < 1e-14); // 1 unchanged
/// assert!((result[5] - 1.0).abs() < 1e-14); // 3 clipped to 1
/// ```
///
/// # Use Cases
/// - Gradient clipping in neural networks
/// - Image processing (pixel value clamping)
/// - Bounded optimization
/// - Data normalization preprocessing
/// SIMD-accelerated cumulative sum (prefix sum)
///
/// Computes the cumulative sum of elements. `result[i] = sum(a[0..=i])`
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Array of cumulative sums
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::cumsum_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0, 4.0, 5.0];
///
/// let result = cumsum_simd::<f64>(&x.view());
/// assert!((result[0] - 1.0).abs() < 1e-14); // 1
/// assert!((result[1] - 3.0).abs() < 1e-14); // 1+2
/// assert!((result[2] - 6.0).abs() < 1e-14); // 1+2+3
/// assert!((result[3] - 10.0).abs() < 1e-14); // 1+2+3+4
/// assert!((result[4] - 15.0).abs() < 1e-14); // 1+2+3+4+5
/// ```
///
/// # Use Cases
/// - Computing CDF from PDF
/// - Running totals and statistics
/// - Parallel prefix algorithms
/// - Integral image computation
/// SIMD-accelerated cumulative product
///
/// Computes the cumulative product of elements. `result[i] = product(a[0..=i])`
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Array of cumulative products
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::cumprod_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0, 4.0];
///
/// let result = cumprod_simd::<f64>(&x.view());
/// assert!((result[0] - 1.0).abs() < 1e-14); // 1
/// assert!((result[1] - 2.0).abs() < 1e-14); // 1*2
/// assert!((result[2] - 6.0).abs() < 1e-14); // 1*2*3
/// assert!((result[3] - 24.0).abs() < 1e-14); // 1*2*3*4 = 4!
/// ```
///
/// # Use Cases
/// - Computing factorials and permutations
/// - Product of survival probabilities
/// - Chain rule in automatic differentiation
/// - Compound interest calculations
/// SIMD-accelerated first-order difference
///
/// Computes the first-order finite difference: `result[i] = a[i+1] - a[i]`
/// The output has length n-1 for input of length n.
///
/// # Arguments
/// * `a` - Input array (length >= 2)
///
/// # Returns
/// Array of differences (length n-1)
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::{array, Array1};
/// use scirs2_core::ndarray_ext::elementwise::diff_simd;
///
/// let x = array![1.0_f64, 3.0, 6.0, 10.0, 15.0];
///
/// let result = diff_simd::<f64>(&x.view());
/// assert_eq!(result.len(), 4); // n-1 elements
/// assert!((result[0] - 2.0).abs() < 1e-14); // 3-1
/// assert!((result[1] - 3.0).abs() < 1e-14); // 6-3
/// assert!((result[2] - 4.0).abs() < 1e-14); // 10-6
/// assert!((result[3] - 5.0).abs() < 1e-14); // 15-10
/// ```
///
/// # Use Cases
/// - Numerical differentiation
/// - Detecting changes in time series
/// - Computing gradients
/// - Edge detection in signal processing
/// SIMD-accelerated variance computation
///
/// Computes the sample variance: Var(x) = sum((x - mean)²) / (n-1)
/// Uses Bessel's correction for unbiased estimation.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Sample variance of the array
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::variance_simd;
///
/// let x = array![2.0_f64, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0];
/// let var = variance_simd::<f64>(&x.view());
/// // Sample variance: sum of squared deviations = 32, n = 8
/// // var = 32 / (8-1) = 32/7 ā 4.571
/// let expected = 32.0 / 7.0;
/// assert!((var - expected).abs() < 1e-10);
/// ```
///
/// # Use Cases
/// - Statistical analysis
/// - Quality control (process capability)
/// - Risk assessment (financial variance)
/// - Feature scaling (standardization)
/// SIMD-accelerated standard deviation computation
///
/// Computes the sample standard deviation: std = sqrt(sample_variance)
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Sample standard deviation
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::std_simd;
///
/// let x = array![2.0_f64, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0];
/// let s = std_simd::<f64>(&x.view());
/// // Sample std = sqrt(sample variance) = sqrt(32/7) ā 2.138
/// let expected = (32.0_f64 / 7.0).sqrt();
/// assert!((s - expected).abs() < 1e-10);
/// ```
///
/// # Use Cases
/// - Volatility measurement in finance
/// - Error analysis in experiments
/// - Gaussian distribution parameters
/// - Confidence interval calculations
/// SIMD-accelerated array sum
///
/// Computes the sum of all elements in the array.
/// Uses Kahan summation for improved numerical accuracy.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Sum of all elements
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::sum_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0, 4.0, 5.0];
/// let s = sum_simd::<f64>(&x.view());
/// assert!((s - 15.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Computing totals
/// - Mean calculation component
/// - Probability mass functions
/// - Integration approximation
/// SIMD-accelerated array mean
///
/// Computes the arithmetic mean: mean = sum(x) / n
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Arithmetic mean of elements
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::mean_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0, 4.0, 5.0];
/// let m = mean_simd::<f64>(&x.view());
/// assert!((m - 3.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Central tendency measurement
/// - Batch normalization (compute running mean)
/// - Signal averaging
/// - Expected value estimation
/// SIMD-accelerated weighted sum
///
/// Computes sum(values * weights).
///
/// # Arguments
/// * `values` - Values array
/// * `weights` - Weights array (same length as values)
///
/// # Returns
/// Weighted sum
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::weighted_sum_simd;
///
/// let values = array![10.0_f64, 20.0, 30.0];
/// let weights = array![0.2_f64, 0.3, 0.5];
/// let ws = weighted_sum_simd::<f64>(&values.view(), &weights.view());
/// // 10*0.2 + 20*0.3 + 30*0.5 = 2 + 6 + 15 = 23
/// assert!((ws - 23.0).abs() < 1e-10);
/// ```
///
/// # Use Cases
/// - Portfolio valuation
/// - Weighted regression
/// - Attention mechanism scores
/// - Signal filtering
/// SIMD-accelerated weighted mean
///
/// Computes sum(values * weights) / sum(weights).
///
/// # Arguments
/// * `values` - Values array
/// * `weights` - Weights array (same length as values)
///
/// # Returns
/// Weighted mean
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::weighted_mean_simd;
///
/// let values = array![10.0_f64, 20.0, 30.0];
/// let weights = array![1.0_f64, 2.0, 2.0];
/// let wm = weighted_mean_simd::<f64>(&values.view(), &weights.view());
/// // (10*1 + 20*2 + 30*2) / (1+2+2) = (10+40+60)/5 = 22
/// assert!((wm - 22.0).abs() < 1e-10);
/// ```
///
/// # Use Cases
/// - Grade point average calculation
/// - Portfolio weighted return
/// - Weighted sentiment analysis
/// - Attention-weighted representations
/// SIMD-accelerated maximum element
///
/// Finds the maximum value in the array.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Maximum element value
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::max_element_simd;
///
/// let x = array![3.0_f64, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];
/// let max = max_element_simd::<f64>(&x.view());
/// assert!((max - 9.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Finding peak values
/// - Range calculation
/// - Normalization (min-max scaling)
/// - Softmax numerator stability
/// SIMD-accelerated minimum element
///
/// Finds the minimum value in the array.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Minimum element value
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::min_element_simd;
///
/// let x = array![3.0_f64, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];
/// let min = min_element_simd::<f64>(&x.view());
/// assert!((min - 1.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Finding minimum values
/// - Range calculation
/// - Clipping lower bounds
/// - Outlier detection
/// SIMD-accelerated argmax (index of maximum)
///
/// Returns the index of the maximum element.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Some(index) of maximum element, or None if array is empty
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::argmax_simd;
///
/// let x = array![3.0_f64, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];
/// let idx = argmax_simd::<f64>(&x.view());
/// assert_eq!(idx, Some(5)); // x[5] = 9.0 is the maximum
/// ```
///
/// # Use Cases
/// - Classification prediction (class with highest probability)
/// - Finding optimal parameters
/// - Greedy selection algorithms
/// - Winner-take-all networks
/// SIMD-accelerated argmin (index of minimum)
///
/// Returns the index of the minimum element.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Some(index) of minimum element, or None if array is empty
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::argmin_simd;
///
/// let x = array![3.0_f64, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];
/// let idx = argmin_simd::<f64>(&x.view());
/// assert_eq!(idx, Some(1)); // x[1] = 1.0 is the minimum (first occurrence)
/// ```
///
/// # Use Cases
/// - Finding nearest neighbors
/// - Minimum loss selection
/// - Optimal path finding
/// - Resource allocation
/// SIMD-accelerated sum of squares
///
/// Computes sum(x²) efficiently.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Sum of squared elements
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::sum_squares_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0, 4.0];
/// let ss = sum_squares_simd::<f64>(&x.view());
/// // 1 + 4 + 9 + 16 = 30
/// assert!((ss - 30.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - L2 norm calculation (sqrt of sum of squares)
/// - Mean squared error
/// - Variance computation
/// - Energy of signal
/// SIMD-accelerated sum of cubes
///
/// Computes sum(x³) efficiently.
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Sum of cubed elements
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::sum_cubes_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0];
/// let sc = sum_cubes_simd::<f64>(&x.view());
/// // 1 + 8 + 27 = 36
/// assert!((sc - 36.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Higher-order moment calculation
/// - Skewness estimation
/// - Cubic interpolation
/// - Power sum computation
/// SIMD-accelerated log-sum-exp
///
/// Computes log(sum(exp(x))) in a numerically stable way.
/// Uses the identity: log(sum(exp(x))) = max(x) + log(sum(exp(x - max(x))))
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// Log of sum of exponentials
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::log_sum_exp_simd;
///
/// let x = array![1.0_f64, 2.0, 3.0];
/// let lse = log_sum_exp_simd::<f64>(&x.view());
/// // log(e^1 + e^2 + e^3) ā 3.407
/// let expected = (1.0_f64.exp() + 2.0_f64.exp() + 3.0_f64.exp()).ln();
/// assert!((lse - expected).abs() < 1e-10);
/// ```
///
/// # Use Cases
/// - Softmax denominator
/// - Log-probability computations
/// - Partition function in statistical mechanics
/// - Evidence lower bound (ELBO) in VAEs
/// SIMD-accelerated L2 norm (Euclidean norm)
///
/// Computes ||x||ā = sqrt(sum(x²))
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// L2 (Euclidean) norm
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::norm_simd;
///
/// let x = array![3.0_f64, 4.0];
/// let n = norm_simd::<f64>(&x.view());
/// // sqrt(9 + 16) = 5
/// assert!((n - 5.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Vector magnitude
/// - Normalization preprocessing
/// - Regularization penalty
/// - Gradient clipping
/// SIMD-accelerated L1 norm (Manhattan norm)
///
/// Computes ||x||ā = sum(|x|)
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// L1 (Manhattan) norm
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::norm_l1_simd;
///
/// let x = array![1.0_f64, -2.0, 3.0, -4.0];
/// let n = norm_l1_simd::<f64>(&x.view());
/// // |1| + |-2| + |3| + |-4| = 10
/// assert!((n - 10.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Sparse regularization (LASSO)
/// - Robust statistics
/// - Compressed sensing
/// - Feature selection
/// SIMD-accelerated L-infinity norm (Chebyshev/max norm)
///
/// Computes ||x||ā = max(|x|)
///
/// # Arguments
/// * `a` - Input array
///
/// # Returns
/// L-infinity (max) norm
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::norm_linf_simd;
///
/// let x = array![1.0_f64, -5.0, 3.0, -2.0];
/// let n = norm_linf_simd::<f64>(&x.view());
/// // max(|1|, |-5|, |3|, |-2|) = 5
/// assert!((n - 5.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Gradient clipping by max norm
/// - Adversarial robustness (Lā perturbations)
/// - Convergence criteria
/// - Worst-case analysis
/// SIMD-accelerated Euclidean distance
///
/// Computes ||a - b||ā = sqrt(sum((a - b)²))
///
/// # Arguments
/// * `a` - First vector
/// * `b` - Second vector
///
/// # Returns
/// Euclidean distance between vectors
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::distance_euclidean_simd;
///
/// let a = array![0.0_f64, 0.0];
/// let b = array![3.0_f64, 4.0];
/// let d = distance_euclidean_simd::<f64>(&a.view(), &b.view());
/// assert!((d - 5.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - K-means clustering
/// - Nearest neighbor search
/// - Physical distance measurement
/// - Embedding similarity
/// SIMD-accelerated Manhattan distance
///
/// Computes sum(|a - b|)
///
/// # Arguments
/// * `a` - First vector
/// * `b` - Second vector
///
/// # Returns
/// Manhattan (L1) distance between vectors
///
/// # Examples
/// ```
/// use scirs2_core::ndarray::array;
/// use scirs2_core::ndarray_ext::elementwise::distance_manhattan_simd;
///
/// let a = array![1.0_f64, 2.0, 3.0];
/// let b = array![4.0_f64, 0.0, 3.0];
/// let d = distance_manhattan_simd::<f64>(&a.view(), &b.view());
/// // |1-4| + |2-0| + |3-3| = 3 + 2 + 0 = 5
/// assert!((d - 5.0).abs() < 1e-14);
/// ```
///
/// # Use Cases
/// - Grid-based path finding
/// - Robust distance metric
/// - Taxicab geometry
/// - Feature comparison