C++ numpy-like template-based array implementation.
Implements multiple flavours of a N-dimensional array in a minimalistic way.
Static array is std::array-based implementation, in which the element type and array size are fixed and determined at compile time. This implies stack array storage.
In dynamic array only the element type is known at compile time. This implies heap array storage.
Implements a diagonal array view on another array. Only diagonal's number is stored.
Implements an identity array. Only the shape is stored.
Implements an N-dimensional array with the same value in every cell. Only the shape and the value is stored.
Implements a view on another array. Only a set of indexes (in case of boolean indexed array) or set of ranges (in case of sliced and subset arrays), or their combination is stored.
Any C++20-compatible compiler:
- gcc 10 or higher
- clang 6 or higher
- Visual Studio 2019 or higher
git clone https://github.com/mgorshkov/np.git
mkdir build && cd build
cmake ..
cmake --build .
mkdir build && cd build
cmake ..
cmake --build . --config Release
cmake --build . --target doc
Open np/build/doc/html/index.html in your browser.
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=~/np_install
cmake --build . --target install
#include <iostream>
#include <np/Creators.hpp>
int main(int, char **) {
// PI number calculation with Monte-Carlo method
using namespace np;
Size size = 10000000;
auto rx = random::rand(size);
auto ry = random::rand(size);
auto dist = rx * rx + ry * ry;
auto inside = (dist["dist<1"]).size();
std::cout << "PI=" << 4 * static_cast<double>(inside) / size;
return 0;
}
- Clone the repo
git clone https://github.com/mgorshkov/np.git
- cd samples/monte-carlo
cd samples/monte-carlo
- Make build dir
mkdir -p build-release && cd build-release
- Configure cmake
cmake -DCMAKE_BUILD_TYPE=Release ..
- Build
cmake --build .
cmake --build . --config Release
- Run the app
$./monte_carlo
PI=3.14158
- Methods from pandas library on top of NP library: https://github.com/mgorshkov/pd
- Scientific methods on top of NP library: https://github.com/mgorshkov/scipy
- ML Methods from scikit-learn library: https://github.com/mgorshkov/sklearn