Skip to content

Commit cb4ad3e

Browse files
committed
Add parallel sorting and parallel bulk-selection.
1 parent e1c00a1 commit cb4ad3e

File tree

12 files changed

+2962
-54
lines changed

12 files changed

+2962
-54
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: toolchain
1515
uses: actions-rs/toolchain@v1
1616
with:
17-
toolchain: 1.58.0
17+
toolchain: 1.60.0
1818
profile: minimal
1919
components: rustfmt, rust-docs, clippy
2020
override: true
@@ -32,6 +32,16 @@ jobs:
3232
with:
3333
command: test
3434
args: --no-default-features
35+
- name: test-rayon
36+
uses: actions-rs/cargo@v1
37+
with:
38+
command: test
39+
args: --features rayon --
40+
par::merge_sort::test::stably_sorted
41+
par::quick_sort::test::sorted
42+
par::partition::test::at_indices
43+
env:
44+
QUICKCHECK_GENERATOR_SIZE: 1000000
3545
- name: clippy
3646
uses: actions-rs/cargo@v1
3747
with:
@@ -51,6 +61,11 @@ jobs:
5161
with:
5262
command: doc
5363
args: --no-default-features
64+
- name: doc-rayon
65+
uses: actions-rs/cargo@v1
66+
with:
67+
command: doc
68+
args: --features rayon
5469
- name: fmt
5570
uses: actions-rs/cargo@v1
5671
with:
@@ -82,6 +97,16 @@ jobs:
8297
with:
8398
command: test
8499
args: --no-default-features
100+
- name: test-rayon
101+
uses: actions-rs/cargo@v1
102+
with:
103+
command: test
104+
args: --features rayon --
105+
par::merge_sort::test::stably_sorted
106+
par::quick_sort::test::sorted
107+
par::partition::test::at_indices
108+
env:
109+
QUICKCHECK_GENERATOR_SIZE: 1000000
85110
- name: clippy
86111
uses: actions-rs/cargo@v1
87112
with:
@@ -107,6 +132,13 @@ jobs:
107132
args: --no-default-features
108133
env:
109134
RUSTDOCFLAGS: "--cfg docsrs"
135+
- name: doc-rayon
136+
uses: actions-rs/cargo@v1
137+
with:
138+
command: doc
139+
args: --features rayon
140+
env:
141+
RUSTDOCFLAGS: "--cfg docsrs"
110142
- name: fmt
111143
uses: actions-rs/cargo@v1
112144
with:
@@ -116,5 +148,4 @@ jobs:
116148
uses: actions-rs/cargo@v1
117149
with:
118150
command: miri
119-
args: test
120-
if: ${{ false }}
151+
args: test -- Slice1Ext

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ndarray-slice"
3-
version = "0.2.1"
4-
rust-version = "1.58"
3+
version = "0.2.2"
4+
rust-version = "1.60"
55
edition = "2021"
66
authors = ["Rouven Spreckels <[email protected]>"]
77
description = """Fast and robust slice-based algorithms (e.g., sorting, selection, search)
@@ -37,15 +37,18 @@ rustdoc-args = ["--cfg", "docsrs"]
3737

3838
[dependencies]
3939
ndarray = { version = "0.15.6", default-features = false }
40+
rayon = { version = "1.7.0", optional = true }
4041

4142
[dev-dependencies]
4243
quickcheck = "1.0.3"
4344
quickcheck_macros = "1.0.0"
45+
rand = "0.8.5"
4446

4547
[features]
4648
default = ["std"]
4749
alloc = []
4850
std = ["alloc", "ndarray/std"]
51+
rayon = ["dep:rayon", "ndarray/rayon", "std"]
4952

5053
[profile.test]
5154
opt-level = 2

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
[License]: https://img.shields.io/badge/License-MIT%20OR%20Apache--2.0-blue.svg
1616

1717
Fast and robust slice-based algorithms (e.g., [sorting], [selection], [search]) for
18-
non-contiguous (sub)views into *n*-dimensional arrays. Reimplements algorithms in [`slice`] for
19-
[`ndarray`] with arbitrary memory layout (e.g., non-contiguous).
18+
non-contiguous (sub)views into *n*-dimensional arrays. Reimplements algorithms in [`slice`] and
19+
[`rayon::slice`] for [`ndarray`] with arbitrary memory layout (e.g., non-contiguous).
2020

2121
[`slice`]: https://doc.rust-lang.org/std/primitive.slice.html
22+
[`rayon::slice`]: https://docs.rs/rayon/latest/rayon/slice/index.html
2223
[`ndarray`]: https://docs.rs/ndarray
2324

2425
## Example
@@ -38,11 +39,12 @@ let mut v = arr2(&[[-5, 4, 1, -3, 2], // row 0, axis 0
3839
// Mutable subview into the last column.
3940
let mut column = v.column_mut(4);
4041

41-
// Due to row-major memory layout, columns are non-contiguous and hence cannot be sorted by
42-
// viewing them as mutable slices.
42+
// Due to row-major memory layout, columns are non-contiguous
43+
// and hence cannot be sorted by viewing them as mutable slices.
4344
assert_eq!(column.as_slice_mut(), None);
4445

45-
// Instead, sorting is specifically implemented for non-contiguous mutable (sub)views.
46+
// Instead, sorting is specifically implemented for non-contiguous
47+
// mutable (sub)views.
4648
column.sort_unstable();
4749

4850
assert!(v == arr2(&[[-5, 4, 1, -3, -1],
@@ -87,8 +89,9 @@ See the [release history](RELEASES.md) to keep track of the development.
8789

8890
## Features
8991

90-
* `alloc`: Enables stable `sort`/`sort_by`/`sort_by_key`. Enabled by `std`.
91-
* `std`: Enables stable `sort_by_cached_key`. Enabled by default.
92+
* `alloc` for stable `sort`/`sort_by`/`sort_by_key`. Enabled by `std`.
93+
* `std` for stable `sort_by_cached_key`. Enabled by `default` or `rayon`.
94+
* `rayon` for parallel `par_sort*`/`par_select_many_nth_unstable*`.
9295

9396
# License
9497

RELEASES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Version 0.2.2 (2023-04-13)
2+
3+
* Add `rayon` feature for parallel sorting and parallel bulk-selection.
4+
* Guarantee that bulk-selected elements are in the order of their indices.
5+
* Half recursive branching of bulk-selection via tail call elimination.
6+
17
# Version 0.2.1 (2023-04-08)
28

39
* Update docs.

0 commit comments

Comments
 (0)