Week 3

Laying out the groundwork …. Hello everyone, hope this blog finds you well.

This week was the beginning of the core implementations of this project. We started out with writing the build instructions for our project in CMake, but focussed majorly on bindings for the numpy module.

Aim :

My aim for this week was to learn how to write build instructions for C++ projects. Coming from a python heavy skillset, I was not comfortable at first but I slowly picked up CMake through some online videos. Following that I was trying to setup pybind11 locally, I played around with it and tried out small projects to get a feel for writing python bindings.

Work :

I raised the following pull requests this week.

  • PR#6 : Ndarray Implementation

    In this pull request I could implement around 75% of the requested numpy featureset with pybind11 headers.

    These are the current issues with numpy as present.

    • Some stuff in our pocketpy backend works differently from pure python, so they may cause divergence in future.
    • This implementation is done with original pybind11, so I still need to test with pocketpy pybind and let mentors know if there are any issues.
    • I have only supported integer int32 and floating float64 datatypes as of now.
  • PR#7 : Add numpy sub-namespace and some refactoring

    In this pull request, I have added a sub namespace named numpy to my pkpy namespace because my class declaration was conflicting with an inner name in pocketpy.

  • PR#8 : Remove template specialization from code to make it compatible with GCC

    This was a necessary change to make my code work on all compiler platforms, currently it was failing with certian GCC versions.
    I was trying to specialize a member template function as follows -

    template <>
    auto binary_operator_add_impl(const float_& other) const {
      xt::xarray<float_> result = xt::cast<float_>(_array) + other;
      return ndarray<float_>(result);
    }
    

    According to the C++ standard, this is fine. However, unfortunately, GCC hasn’t implemented this feature for about 10 years. I used if constexpr to replace template specialization, as they generally can achieve the same goal in this case.

  • PR#10 : Allow ndarray of scalar

    This edge case is now supported.

    >>> import numpy_bindings as np
    >>> a = np.array(3.14)
    >>> print(a)
     3.14
    
  • PR#11 : Support the __eq__ operator and refactoring existing return types.

    This operator is now supported.

    def assert_equal(a, b):
      assert (a.__eq__(b)).all()
    

I reviewed and merged the following pull request this week.

  • PR#9 : some fix

    There were still some errors with GCC and function overloading, which my co mentee fixed with a cheap trick.

Future Work :

In the upcoming week, I need to learn frameworks like pytest to write pythonic tests for my numpy API and google test to check robustness of pocketpy pybind.

Address

Mumbai, Maharashtra, India