Skip to main content

Cython interface to parallel sorting routines

Project description

parallel-sort

Test build PyPI version

This module provides a simple Cython interface to parallel sorting algorithms available in C++. It provides functions for in-place and out-of-place sorts, as well as indirect sorting (aka. "argsort").

By default it requires a C++17-capable compiler, and will use the standard std::sortroutine with the parallel execution policy introduced in that standard. For older compilers without C++17 support, the GNU Parallel Mode sorting routines may be used instead.

Usage

import parallel_sort
import numpy as np

x = np.random.random(size=10000)

x_sorted = parallel_sort.sort(x)

assert np.all(np.diff(x) >= 0) # x is now sorted

Note that these routines are "unstable" sorts, meaning that the ordering of equal elements in the original array is not guaranteed to be preserved.

Installing

Requirements: numpy, C++17-capable g++, Cython (only for installation from source).

On Linux, installing from wheel via pip should "just work":

pip install parallel_sort

On Mac, it is important to ensure that gcc is used to compile the module rather than the default Apple-provided clang, which can be done by prefixing the install command with CC=$(brew --prefix gcc)/bin/gcc-13 (substituting your gcc version as appropriate).

GNU Parallel Mode option

For older compilers that do not support C++17, the module can use the GNU Parallel Mode library instead. To build without C++17, clone the repository and set use_cxx17 = False in setup.py. Then run:

pip install -e .

to compile and install the module.

Note for Apple Silicon Macs

If the module builds OK, but importing it fails with an error "undefined reference to aarch64_ldadd4_acq_rel", try rebuilding with the following command

CFLAGS=-mno-outline-atomics CC=$(brew --prefix gcc)/bin/gcc-13 pip install --no-cache-dir -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parallel-sort-0.2.0.tar.gz (197.0 kB view hashes)

Uploaded Source

Built Distributions

parallel_sort-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl (2.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

parallel_sort-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl (2.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

parallel_sort-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl (2.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

parallel_sort-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl (2.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

parallel_sort-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl (2.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.28+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page