Giter VIP home page Giter VIP logo

ndarray's Introduction

NDArray: Numpy style arrays for C++

A common scenario which arrises in scientific and high performance computing is the need to conduct calculations or simulations in faster, lower level languages such as C++, and then load results into a higher level language such as python to conduct analysis on the results. Depending on the type and amount of data, it can be difficult and time consuming to write this data to a file in a specific format, making sure it is consisten, then writing a second python implementation to reliably read such data. If storing as raw text however, this can lead to long load times, and large data files.

Currently, there are few small and complete C++ libraries to complete this task. The xtensor library is a very good option, and I do recommend it. However, it is a large library which is likely much more than many need, especially in smaller projects. If you are working on a larger project and need more NumPy magic than this library provides, I do recommend that you check it out here. It likely has everything you are looking for.

I have written the NDArray template library, a minimal implementation of Numpy style arrays for C++, as a smaller alternative to xtensor. These arrays can be multi-dimensional, and reshaped like Numpy arrays. Indexing can be done either with a vector, or as variadic parammeters, both using the () operator. Access to the data using the linear index is also permitted via the [] operator.

It is also possible to load/save data from/to a .npy binary file. This allows for fast and easy access to the data in python (as well as many other languages). While the template container can be used to store any array of any type, the load and save methods are only valid for the following templates:

  • NDArray<char>
  • NDArray<unsigned char>
  • NDArray<uint16_t>
  • NDArray<uint32_t>
  • NDArray<uint64_t>
  • NDArray<int16_t>
  • NDArray<int32_t>
  • NDArray<int64_t>
  • NDArray<float>
  • NDArray<double>
  • NDArray<std::complex<float>>
  • NDArray<std::complex<double>>

This is due to the fact that only certain numeric types are allowed by Numpy. Attempting to save a NDArray templated for a different type will result in and exception being thrown. Python and Numpy allow for the storing of raw Python objects in .npy files, but the loading of such files into a C++ program with this library will also result in an exception.

Usage

To be written soon...

Install

This is a single file, header-only library. Just place the ndarray.hpp file in your projects include directory, inorder to include it for use.

ndarray's People

Contributors

hunterbelanger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.