Anurag Bhat 86b4fc623c Merge numpy to pocketpy (#303) 1 rok pred
..
include 86b4fc623c Merge numpy to pocketpy (#303) 1 rok pred
src 86b4fc623c Merge numpy to pocketpy (#303) 1 rok pred
tests 86b4fc623c Merge numpy to pocketpy (#303) 1 rok pred
README.md 86b4fc623c Merge numpy to pocketpy (#303) 1 rok pred
numpy.pyi 86b4fc623c Merge numpy to pocketpy (#303) 1 rok pred

README.md

numpy

How to run numpy module programs with gsoc-2024-dev pybind11

  1. Prepare the python code file with the numpy operations you want to run. \ \ For example : let's try out numpy arange function in test_numpy.py

    import numpy_bindings as np
      
    def test_arange(n):
      a = np.arange(n)
      print(a.sum())
      
    test_arange(100)
    
  2. Read the script and execute it in test_numpy.cpp.

    #include <pybind11/embed.h>
    #include <fstream>
    #include <sstream>
    #include <string>
      
    namespace py = pybind11;
    using namespace pybind11;
      
    int main() {
      py::scoped_interpreter guard{};
      std::ifstream file("test_numpy.py");
      std::stringstream buffer;
      buffer << file.rdbuf();
      std::string script = buffer.str();
      py::exec(script);
      
      return 0;
    }
    
  3. Build the project at root to generate the executable at build/gsoc2024.

    cmake -B build
    cmake --build build
    
  4. Now run the executable to get the output.

    |base| gsoc-2024-dev ±|main ✗|→ build/gsoc2024 
    4950