A fast math and neural network library for Python and C++
Project description
Credits
Thanks to @NervousNullPtr for his help on the library. He and I collaborate to provide the best user experience possible, as well as to produce innovative new ideas and faster, more efficient code.
Why Use Librapid?
In short, LibRapid aims to allow for faster mathematical calculations, including multidimensional arrays, machine learning and arbitrary-precision arithmetic. LibRapid also includes some helper functions to reduce dependencies, such as basic colour manipulation and access to console properties. The entire library is highly optimised and supports GPU calculations where applicable.
How it Works
LibRapid is a highly-optimised C++ (and CUDA) library, which can be found at ./src/librapid
. The C++ library is
interfaced with Python using PyBind11, meaning very little performance is lost
between the C++ backend and Python frontend of the library. LibRapid also makes use of some
of Agner Fog's libraries and optimisations to accelerate low-level functions and increase
performance.
LibRapid also aims to provide a consistent interface between the C++ and Python libraries, allowing you to use the library comprehensively in both languages without having to trawl through two sets of documentation.
Please note that the Python interface has been adjusted slightly from the C++ interface to provide a more "pythonic" feel without reducing the overall functionality.
Installing LibRapid
Python
To install LibRapid as a Python library, simply run pip install librapid
in the command line. Hopefully, there will be precompiled wheels available for your operating system and python version, meaning you will not need a C++ compiler to install it (if this is not the case, a modern C++ compiler will be required).
Note
Occasionally, the pip
binary version of LibRapid will cause a segfault
error. This is a known bug we are trying to fix, but in the meantime, you can run pip install librapid --no-binary librapid
.
Building from Source
To enable CUDA support, to use your own BLAS library or to get a (potentially) more optimised install of the library, you will have to build LibRapid from source:
git clone https://github.com/LibRapid/librapid.git --recursive
cd librapid
pip install . -vvv
C++
To use the library in C++, you have a few options. The first option is to download the .zip
file for librapid, copy +
paste all of the source and header files and add them all to your project.
You can also use librapid in your CMake
projects by either using the FetchContent
feature, or by adding the librapid
subdirectory.
Using FetchContent
:
# CMake
add_executable(MyApp myapp.cpp)
include(FetchContent)
FetchContent_Declare(librapid GIT_REPOSITORY https://github.com/librapid/librapid.git)
FetchContent_MakeAvailable(librapid)
target_link_libraries(MyApp librapid)
Or using add_subdirectory
:
# Command line
git clone https://github.com/librapid/librapid.git --recursive
# CMake
add_executable(MyApp myapp.cpp)
add_subdirectory(librapid)
target_link_libraries(MyApp librapid)
Documentation
Viewing Online
Documentation can be found online here on ReadTheDocs.
Building from Source
If you would like to build it yourself, you will need to install the required software:
# Command line
pip install -r docs/requirements
You will also need to install a recent version of Doxygen, which you can find here
To build the documentation, open a command line window in the docs
directory and run make html
. You can then
open the file docs/build/html/index.html
in a web-browser to view the documentation.
Performance
LibRapid has highly optimised functions and routines, meaning your code will be faster as a result. Nearly all functions
exceed the performance of NumPy and equivalent libraries. Functions are also being
optimised further all the time. Anything slower than NumPy
is considered a bug, and LibRapid developers will attempt to
optimise it until they are satisfied with the performance.
Both the C++ and Python libraries are designed to work with any CBLAS compatible library, such as ATLAS or OpenBLAS, though will be fully functional without one, using built-in, but slower, routines.
Parallel Code
LibRapid is designed to use multiple threads to run code faster. The number of threads used for these operations will default to the number of threads available on the system, however this may end up leading to slower code when the number of threads exceeds 12-16. To set the number of threads, use the following functions:
// C++
librapid::setNumThreads(<num>); // Set threads to <num>. <num> must be a positive integer.
librapid::getNumThreads(); // Get the number of threads. If OpenMP was not found, it returns 1.
# Python
librapid.setNumThreads(<num>); # Set threads to <num>. <num> must be a positive integer.
librapid.getNumThreads(); # Get the number of threads. If OpenMP was not found, it returns 1.
The CMakeLists.txt
file will attempt to find a BLAS installation automatically, though it may fail if the files are
not strucutred correctly (see below).
If you build LibRapid from source, it will automatically search some specific directories for a BLAS install, though if one is not found, BLAS will not be linked and internal routines will be used instead. Please note that the BLAS install must have the following file structure:
blas-dir
├── include
| └── cblas.h
├── lib
| └── your-blas-lib.lib
└── bin (Only on Windows)
└── your-blas-dll.dll
Recommended Setup for Optimal Performance
The recommended BLAS library to use is OpenBLAS
, though it is very slow and tedious to build (especially on Windows).
For this reason, pre-built binaries are provided which are optimised for most processors and architectures. To download
these, go to https://github.com/LibRapid/librapid/actions and select the most recent build (don't worry if it failed!).
Scroll down to the bottom of the page and download the .zip
file for your operating system:
OpenBLAS on macos-latest : MacOS
OpenBLAS on ubuntu-latest : All GNU+Linux Distributions
OpenBLAS on windows-latest : Windows
Unzip this and put the contents in
C:/opt/OpenBLAS
on Windows, or/opt/OpenBLAS
on Unix-like Operating Systems.
The directory structure should look similar to this (example on Windows):
<root directory> # C:/, /, etc.
└── opt
├── bin
│ └── openblas.dll
├── include
│ └── openblas
│ ├── cblas.h
│ ├── f77blas.h
│ ├── lapack.h
│ ├── lapacke.h
│ ├── lapacke_config.h
│ ├── lapacke_example_aux.h
│ ├── lapacke_mangling.h
│ ├── lapacke_utils.h
│ ├── openblas
│ │ └── lapacke_mangling.h
│ └── openblas_config.h
├── lib
│ ├── openblas.lib
│ └── pkgconfig
│ └── openblas.pc
└── share
└── cmake
└── OpenBLAS
├── OpenBLASConfig.cmake
├── OpenBLASConfigVersion.cmake
├── OpenBLASTargets-release.cmake
└── OpenBLASTargets.cmake
With OpenBLAS set up in this way, LibRapid will automatically find and use it, whether you're in C++ or building from source for Python. This will (most likely) also give the best performance for the library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for librapid-0.3.6-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7ff7b8cb5ba58ffe962ef4b8252b5f2cd10aa03d1d8f037264cf178b743f90a |
|
MD5 | 1318f7a4366f7859c3ba99265ebc24a0 |
|
BLAKE2b-256 | 60cf0c2e1706b1b2562bccf53e713f6dc38ffa4a9951d51dd6796c9c3cd4aa94 |
Hashes for librapid-0.3.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c88d758d3e524415c729a15b72dfb04726f41cf00283566c29233036bac54a3 |
|
MD5 | 367f93eda23e1a794b31c4986eb1ef29 |
|
BLAKE2b-256 | 2ebb5fbdf03620d910ee5f8067d59b0a687c85092d89bcc2c710e6f6a42cce48 |
Hashes for librapid-0.3.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac6b1921e1d253ed97ccf4fc8c584736f57ac4c3b16d73a48871c55676981fa |
|
MD5 | 28b7bc7c3244156e9b405d59535a3962 |
|
BLAKE2b-256 | 436097d39786e5fe1ae8e713ede0f09533ef2a18703038a4034a44f959faf186 |
Hashes for librapid-0.3.6-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 596d3464aaf27693a218902ebe98b0fb38f1d5fdd166f0d98f39f142281edfa9 |
|
MD5 | 64b22f9d7710460704fa2fe96e60d1f5 |
|
BLAKE2b-256 | 50905d711293614f77ec58f22ea84797c273499e2e978067065e02519fed77da |
Hashes for librapid-0.3.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baa2a4c5a7db5de14552c1c6392857e162610021b4d716be94246ef7e0a41bce |
|
MD5 | c5622a1f92a79f1a96c7137b8e6a0ad9 |
|
BLAKE2b-256 | 98db5031fad37a395eb21160c8ad31c7c193434b61485262f1c46c8e9017ef5c |
Hashes for librapid-0.3.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5184de131737dc3620b8f19144ab14e654c9b42bd313b31844b4b7d756e19e42 |
|
MD5 | c7f485a5727b565379372781c1e082b9 |
|
BLAKE2b-256 | bf8b2b1e017a81d20334db37e93e8bfc1788f9b5c75084a71859b831f9740234 |
Hashes for librapid-0.3.6-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf99da7c94d1254ec5d6eb6e3d2238be91ab44328634fbb446e991abd7d46cc |
|
MD5 | 6851b00a0f9e9d87abfcf9022e1a7641 |
|
BLAKE2b-256 | 3556ec761da296221baa77b4154f5270ccc40b7f71bb5e8f72eb8abacb16e2b2 |
Hashes for librapid-0.3.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b502507943e4d3c83e115dec0d83c9cc126c63a721790ff88a6bd907b461ecb |
|
MD5 | 8c87bde214b9f8fc4d3b2ba602878bd8 |
|
BLAKE2b-256 | 3ef1601b5e79f0733fe6c290021c71e18881199d378b310341f928faa3402c07 |
Hashes for librapid-0.3.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a02eeb90ca6d69a572b4cecb0c2e8067a6f9376b7b1c427020b7d16019eaa2 |
|
MD5 | 2847e662d5d53486a8ff89e71ea82e47 |
|
BLAKE2b-256 | c565a4c4362666c1bc54619256e9bf3862bfa2a378e47b92855c7b208e7a2766 |
Hashes for librapid-0.3.6-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e88f62af5a3b3557ad8e0694d97d4e6ec618e8eff17bd85c3aa2a800924aaade |
|
MD5 | 676ff8d24debee1f71c065364f05f3fc |
|
BLAKE2b-256 | 76b7af2387544fe4f12989ef3adcbb85185ed3ee3be9cf208b8f39aab0345be9 |
Hashes for librapid-0.3.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cdac92d547d01dcc0b48e17d575c80825ee7118190d11414f26c6b2bc53f688 |
|
MD5 | 0581c0c95dac58120f536d51fada7d22 |
|
BLAKE2b-256 | 0c0f9263f414ca4a84a0662e77c93c5de921a4a07929aa4f848146a1fdfd6123 |
Hashes for librapid-0.3.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72271906114a001cab6140f19646dac4048966ed5237addfa48176f17940773e |
|
MD5 | 5dfed7c5110a3c699ee1f1002e57cd0f |
|
BLAKE2b-256 | 374e68939dd3df40a07eccaf55b826cd3cc07eb475d48d560a4bd0532515781c |
Hashes for librapid-0.3.6-cp36-cp36m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81739fb61df241894ea6c49f45bb9273a362df3e3e6e10f06df524044a839d75 |
|
MD5 | cf93b087c9058eb83eefc3458382fb39 |
|
BLAKE2b-256 | 982bdd9bb19b7b50d7925b65e8c63d40d28a8dfdf6839b5b0ada03a7107d86f6 |
Hashes for librapid-0.3.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6ff0cef3bc47f36fca3b10df34cd527b2e2ef4bc59f3ce9fbb7c88c98512781 |
|
MD5 | cd0b5ad81834a055440ffb14426458d6 |
|
BLAKE2b-256 | 3f9eee660c87d9b78d37deb1437b7553977c2ad1ad88e5861c5468e1d53dd1ef |
Hashes for librapid-0.3.6-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5e146400c2dbf1c4654b7aec83bfbc24386f08a309efc008d7c26e5694c2470 |
|
MD5 | e013c261cba1fb6d71700a3f1458f012 |
|
BLAKE2b-256 | de5eb18b7a3c8bb9c4941d99f94bba834e1f82b2bd6092748ed5423ef09ead73 |