Week 1

Let’s Start Coding …. Hello everyone, hope this blog finds you well.

As the coding period of Google Summer Of Code’24 commenced on May 27th, I have also parallely started my work for Week 1.

Aim :

My purpose for this week was to discuss and concretize the structure of the project. I needed to go through xtensor documentation in detail and validate using it as a backend for implementing the numpy module. It was an eventful week involving some research, discussing issues with my mentors and interacting with developers from the xtensor-stack community.

Work :

This week I corrected the project file structure first. We had already linked a branch of pocketpy while initializing the repository on github. I missed that with git clone because git treats it as a submodule, which needs to be manually updated. Once I cloned the linked branch, we no longer needed the pocketpy header added in PR#2. This realization saved me from adding about 17k lines of unnecessary code.
I made the following Pull Requests for this task :

  • Commit 225accb - Update README.md
  • PR #3 - Modify the Numpy project file structure.

Following that I worked on making a ndarray wrapper for pocketpy on xarray, a well defined xtensor container.
I made the following Pull Request for this task :

  • PR #4 - Add ndarray implementation to numpy.hpp using xtensor support.

Let us go through this Pull Request in breif -

  • Plan to support all dtypes and corresponding precision types : As you would be aware that numpy has multiple numerical dtypes and each of those types has a set of precision types. Supporting all these types is essential for our module. But since we are writing code in C++, we don’t have the precision types at hand and have to design them using existing C++ types. For that I used the cstdint library. It’s header is a type support library header, providing fixed width integer types and part of C numeric limits interface.

    As you can see in the code we could support all the the following numpy dtypes.

      include <cstdint>
    
      using int8 = int8_t;
      using int16 = int16_t;
      using int32 = int32_t;
      using int64 = int64_t;
      using uint8 = uint8_t;
      using uint16 = uint16_t;
      using uint32 = uint32_t;
      using uint64 = uint64_t;
      using int_ = int32;
      using float32 = float;
      using float64 = double;
      using float_ = float64;
      using bool_ = bool;
      using complex64 = std::complex<float32>;
      using complex128 = std::complex<float64>;
      using complex_ = complex128;
      using string = std::string;
    
  • Constructor for our ndarray class : So through this Pull Request we are able to map xtensor xarray to pocketpy ndarray as
    xt::xarray<int> arr = {{1, 2}, {3, 4}}; to pkpy::ndarray<int> arr {{1, 2}, {3, 4}};

    xtensor allows initialization of containers upto 5 dimensional arrays. That is a great advantage we have over using NumCpp which was targeted earlier. I have

  • Implementing numpy routines : I used the numpy.pyi typing file as inspiration here.
    As of now I have added the following categories in the numpy.hpp file.

    1. Dunder methods.
    2. Properties.
    3. Member methods.
      a. Boolean Operations
      b. Aggregation
      c. Shape Manipulation
      d. Seaching and Sorting
      e. Miscellaneous

    4. Factory functions.
      a. Array Creation
      b. Trigonometry
      c. Exponentiation
      d. Miscellaneous

Future Work :

In the upcoming week, I would like to get this pull request merged after thorough discussion with my mentors.

Address

Mumbai, Maharashtra, India