Week 7
Mid-term evaluation approaching …. Hello everyone, hope this blog finds you well.
This week was indeed a heavy week as far as project planning and code discussion was concerned. I managed to submit requested code submissions before the deadline and my mentor @blueloveTH was satisfied with the work.
Aim :
My aim for this week was to get my code compatible with pocketpy pybind and prepare a wokring demo for my mentors.
Work :
This is the demo I prepared for my mentors. The frontend is at a basic stage but that will be improved as soon as the backend is ready.
How to run numpy module programs with gsoc-2024-dev pybind11
Prepare a python code file with the numpy operations you want to run.
For example : Let’s try 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_main.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
I made the following pull requests this week -
-
PR#30 : Refactor some functions into properties
The pull request makes
dtype
,ndim
,shape
,size
as readonly properties instead of member functions. I had to use the def_readonly_property label from pybind11 to ensure it. -
PR#31 : Make print inline with numpy
The pull request fixes the following bug -
>>> a = np.array([1, 2, 3]) >>> a
# cpython's numpy array([1, 2, 3])
# ours ndarray( {1, 2, 3} )
- PR#32 : Remove xoptional headers
- PR#33 : Removed unrequired data convertors
- PR#34 : Remove xjson from xtl headers as well
Future Work :
In this upcoming week, we will start work after the mid term evaluation. I am pretty confident that I will pass this evaluation. Following that we need to reduce disk space required for the project and start working on all the numpy dtypes.