Skip to content

Commit

Permalink
Add parallel sorting and parallel bulk-selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r committed Apr 13, 2023
1 parent e1c00a1 commit cb4ad3e
Show file tree
Hide file tree
Showing 12 changed files with 2,962 additions and 54 deletions.
37 changes: 34 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.58.0
toolchain: 1.60.0
profile: minimal
components: rustfmt, rust-docs, clippy
override: true
Expand All @@ -32,6 +32,16 @@ jobs:
with:
command: test
args: --no-default-features
- name: test-rayon
uses: actions-rs/cargo@v1
with:
command: test
args: --features rayon --
par::merge_sort::test::stably_sorted
par::quick_sort::test::sorted
par::partition::test::at_indices
env:
QUICKCHECK_GENERATOR_SIZE: 1000000
- name: clippy
uses: actions-rs/cargo@v1
with:
Expand All @@ -51,6 +61,11 @@ jobs:
with:
command: doc
args: --no-default-features
- name: doc-rayon
uses: actions-rs/cargo@v1
with:
command: doc
args: --features rayon
- name: fmt
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -82,6 +97,16 @@ jobs:
with:
command: test
args: --no-default-features
- name: test-rayon
uses: actions-rs/cargo@v1
with:
command: test
args: --features rayon --
par::merge_sort::test::stably_sorted
par::quick_sort::test::sorted
par::partition::test::at_indices
env:
QUICKCHECK_GENERATOR_SIZE: 1000000
- name: clippy
uses: actions-rs/cargo@v1
with:
Expand All @@ -107,6 +132,13 @@ jobs:
args: --no-default-features
env:
RUSTDOCFLAGS: "--cfg docsrs"
- name: doc-rayon
uses: actions-rs/cargo@v1
with:
command: doc
args: --features rayon
env:
RUSTDOCFLAGS: "--cfg docsrs"
- name: fmt
uses: actions-rs/cargo@v1
with:
Expand All @@ -116,5 +148,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: miri
args: test
if: ${{ false }}
args: test -- Slice1Ext
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ndarray-slice"
version = "0.2.1"
rust-version = "1.58"
version = "0.2.2"
rust-version = "1.60"
edition = "2021"
authors = ["Rouven Spreckels <[email protected]>"]
description = """Fast and robust slice-based algorithms (e.g., sorting, selection, search)
Expand Down Expand Up @@ -37,15 +37,18 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
ndarray = { version = "0.15.6", default-features = false }
rayon = { version = "1.7.0", optional = true }

[dev-dependencies]
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
rand = "0.8.5"

[features]
default = ["std"]
alloc = []
std = ["alloc", "ndarray/std"]
rayon = ["dep:rayon", "ndarray/rayon", "std"]

[profile.test]
opt-level = 2
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
[License]: https://img.shields.io/badge/License-MIT%20OR%20Apache--2.0-blue.svg

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

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

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

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

// Instead, sorting is specifically implemented for non-contiguous mutable (sub)views.
// Instead, sorting is specifically implemented for non-contiguous
// mutable (sub)views.
column.sort_unstable();

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

## Features

* `alloc`: Enables stable `sort`/`sort_by`/`sort_by_key`. Enabled by `std`.
* `std`: Enables stable `sort_by_cached_key`. Enabled by default.
* `alloc` for stable `sort`/`sort_by`/`sort_by_key`. Enabled by `std`.
* `std` for stable `sort_by_cached_key`. Enabled by `default` or `rayon`.
* `rayon` for parallel `par_sort*`/`par_select_many_nth_unstable*`.

# License

Expand Down
6 changes: 6 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 0.2.2 (2023-04-13)

* Add `rayon` feature for parallel sorting and parallel bulk-selection.
* Guarantee that bulk-selected elements are in the order of their indices.
* Half recursive branching of bulk-selection via tail call elimination.

# Version 0.2.1 (2023-04-08)

* Update docs.
Expand Down
Loading

0 comments on commit cb4ad3e

Please sign in to comment.