@@ -24,7 +24,7 @@ non-contiguous (sub)views into *n*-dimensional arrays. Reimplements algorithms i
24
24
## Example
25
25
26
26
``` rust
27
- use ndarray_slice :: {Slice1Ext , ndarray :: arr2};
27
+ use ndarray_slice :: {ndarray :: arr2, Slice1Ext };
28
28
29
29
// 2-dimensional array of 4 rows and 5 columns.
30
30
let mut v = arr2 (& [[- 5 , 4 , 1 , - 3 , 2 ], // row 0, axis 0
@@ -43,7 +43,7 @@ let mut column = v.column_mut(4);
43
43
assert_eq! (column . as_slice_mut (), None );
44
44
45
45
// Instead, sorting is specifically implemented for non-contiguous mutable (sub)views.
46
- column . sort ();
46
+ column . sort_unstable ();
47
47
48
48
assert! (v == arr2 (& [[- 5 , 4 , 1 , - 3 , - 1 ],
49
49
[ 8 , 3 , 2 , 4 , 2 ],
@@ -55,13 +55,17 @@ assert!(v == arr2(&[[-5, 4, 1, -3, -1],
55
55
56
56
## Current Implementation
57
57
58
- Complexities where * n* is the length of the (sub)view.
58
+ Complexities where * n* is the length of the (sub)view and * m* the count of indices to select.
59
+
60
+ | Resource | Complexity | Sorting (stable) | Sorting (unstable) | Selection (unstable) | Bulk Selection (unstable) |
61
+ | ----------| ------------| ------------------| ---------------------| --------------------------| ---------------------------|
62
+ | Time | Best | * O* (* n* ) | * O* (* n* ) | * O* (* n* ) | * O* (* n* log * m* ) |
63
+ | Time | Expected | * O* (* n* log * n* ) | * O* (* n* log * n* ) | * O* (* n* ) | * O* (* n* log * m* ) |
64
+ | Time | Worst | * O* (* n* log * n* ) | * O* (* n* log * n* ) | * O* (* n* log * n* ) | * O* (* n* log * n* log * m* ) |
65
+ | Space | Best | * O* (1) | * O* (1) | * O* (1) | * O* (* m* ) |
66
+ | Space | Expected | * O* (* n* /2) | * O* (log * n* ) | * O* (log * n* ) | * O* (* m* +log * n* ) |
67
+ | Spoce | Worst | * O* (* n* /2) | * O* (log * n* ) | * O* (log * n* ) | * O* (* m* +log * n* ) |
59
68
60
- | Algorithm | Stable | Allocation | Recursive | Average | Worse-Case |
61
- | -----------| ------- | ------------| -----------| ----------| -------------------|
62
- | Sorting | yes | yes | no | * O* (* n* ) | * O* (* n* log(* n* )) |
63
- | Sorting | no | no | yes | * O* (* n* ) | * O* (* n* log(* n* )) |
64
- | Selection | no | no | no | * O* (* n* ) | * O* (* n* log(* n* )) |
65
69
66
70
[ sorting ] : https://en.wikipedia.org/wiki/Sorting_algorithm
67
71
[ selection ] : https://en.wikipedia.org/wiki/Selection_algorithm
@@ -73,7 +77,7 @@ Complexities where *n* is the length of the (sub)view.
73
77
74
78
## Roadmap
75
79
76
- * Lower worst-case complexity from * O* (* n* log( * n* ) ) to * O* (* n* ) for selection algorithms.
80
+ * Lower worst-case time complexity from * O* (* n* log * n* ) to * O* (* n* ) for selection algorithms.
77
81
* Add ` SliceExt ` trait for * n* -dimensional array or (sub)view with methods expecting ` Axis ` as
78
82
their first argument. Comparing methods will always be suffixed with ` _by ` or ` _by_key `
79
83
defining how to compare multi-dimensional elements (e.g., columns) along the provided axis
0 commit comments