|
|
1 سال پیش | |
|---|---|---|
| .. | ||
| include | 1 سال پیش | |
| src | 1 سال پیش | |
| tests | 1 سال پیش | |
| README.md | 1 سال پیش | |
| numpy.pyi | 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)
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;
}
Build the project at root to generate the executable at build/gsoc2024.
cmake -B build
cmake --build build
Now run the executable to get the output.
|base| gsoc-2024-dev ±|main ✗|→ build/gsoc2024
4950