akielaries / openGPMP

Hardware Accelerated General Purpose Mathematics Package
https://akielaries.github.io/openGPMP/
MIT License
8 stars 3 forks source link
computational-mathematics cpp linear-algebra machine-learning number-theory opengpmp simd

Version PyPi Codacy Badge license codecov clones openGPMP

Overview

openGPMP is an open-source, multi-threaded, mathematics package written in C++, C, Fortran and Assembly with no runtime dependencies. The primary focus in Number Theory and Cryptographic algorithms, Linear Algebra, Calculus, Statistics, and Machine Learning concepts, and more. openGPMP aims to serve as a warehouse and one-stop shop for mathematical operations. Additional acceleration methods are featured for optional use and installation via OpenCL and CUDA. By default, SIMD intrinsics will be used for the supported platforms.

Look in the samples folder for examples on how to use some of openGPMP's functionalities and the in-depth documentation.

Installation

C++ (source)

Requirements

Build

Clone the repository or download the codebase from a release:

# clone repo
$ git clone git@github.com:akielaries/openGPMP.git
$ cd openGPMP

Create a build directory and configure with CMake:

$ mkdir build && cd build
$ cmake -S ../

Note For now, OSX requires GCC for compilation

Install the compiled static library and headers:

$ make
$ sudo make install

Note Keep the build directory for easy uninstallation.

Python (pygpmp)

To install the Python interface, use the pip package manager and run the following, pip install pygpmp. Additional hardware support is available with SWIG as a dependency for the pip installation.

From source

Building the Python pip wheel from source is easy as well. Run the following:

# install dependencies
$ pip install -r requirements.txt
# create CMake files in py_build dir
$ cmake -B py_build -DBUILD_PYGPMP=ON
# install
$ pip install .

Julia (gpmp.jl)

Note In progress The Julia interface is built with the help of wrapit.

tinygpmp

Note In progress tinygpmp targets low-voltage, resource-constrained devices and is currently aiming to support AVR series MCUs, STM32 chips, and other embedded devices.

tinygpmp can be built using the following CMake options:

    * `-DTINYGPMP_AVR=ON` ***todo***
    * `-DTINYGPMP_ARM32=ON` ***todo***
    * `-DTINYGPMP_DYN=ON` ***todo***
    * `-DTINYGPMP_STAT=ON` ***todo***

Uninstall

To uninstall files related to openGPMP, simply run the following:

# enter the build dir from installation
$ cd build
$ sudo make uninstall

Modules

During early stages, modules will be developed in breadth while focusing on depth in later stages of the PRE-V1.0.0 phase. The modules below are all in progress.

  1. Core (utilities & common interfaces)
  2. Arithmetic
  3. Calculus
  4. Discrete Mathematics
  5. Linear Algebra
  6. Machine/Deep Learning
  7. Number Theory
  8. Complex
  9. Statistics
  10. Optimization

For more details view the project documentation.

Examples

View the simple examples on how to use some of the modules in different languages here.

# clone the repo and enter the samples dir
$ git clone git@github.com:akielaries/openGPMP.git 
$ cd samples
# compile an example and link against openGPMP
$ g++ cpp/linreg.cpp -lopenGPMP -o example
$ ./example

Example C++ driver file for running Caesar Cipher & Mono-Alphabetic Substitution Keyword cipher:

#include <iostream>
#include <string>
// include the number theory module header
#include <openGPMP/nt.hpp>

int main() {
    // declare CIPHER class obj
    gpmp::Cipher cc;

    /* CAESAR CIPHER */
    std::string text0 = "Plaintext";
    int shift_key_0 = 5;
    std::string hashtext_0 = cc.caesar(text0, shift_key_0);
    std::cout << "Hashtext0 = " << hashtext_0 << std::endl;

    /* TESTING MONOALPHABETIC SUBSTITUION KEYWORD CIPHER */
    std::string shift_key_2 = "Computer";
    std::string text2 = "Password";
    // encode the plaintext
    std::string encoded_text = cc.keyword_encode(shift_key_2);
    // call the cipher function
    std::string hashtext_2 = cc.keyword(text2 , encoded_text);

    std::cout << "Hashtext2 = " << hashtext_2 << std::endl;

    return 0;
}

A Python example showing the same functionalities.

>>> from pygpmp import nt
>>> c = nt.Cipher()
>>> text0 = c.caesar('Plaintext', 5)
>>> print(text0)
Uqfnsyjcy
>>> 
>>> text1 = c.caesar('ATTACKATONCE', 4)
>>> print(text1)
EXXEGOEXSRGI
>>> 
>>> text = "Password"
>>> shift = "Computer"
>>> encoded_text = c.keyword_encode(shift);
>>> hashtext = c.keyword(text, encoded_text);
>>> print(hashtext)
JCNNWILP

Why?

The rationale/why behind this project is mostly because I find high performance & numerical computing, low level programming, computational mathematics, C, C++, Fortran, Assembly, Julia, etc, etc all interesting. As far as usability and practicality, that may become more solidified with more contributors and time spent but I do aim to design and implement the project with real-world usage as a focus...