My GSoC Journey - Part 3
Coding Begins!
So, now that I got to know the Gnuastro community a bit and had discussed the plan of attack with my mentor it was time to start with the actual coding.
Week 1
As planned, I started with the building the extension module for Cosmic Calculator(cosmiccal) library. A simple Python extension Module should be structed as:
The cosmical library was chosen as a starting point because it contained only 6 functions and solely dealt with doubles, ints, and floats. Consequently, there wasn’t yet a requirement for a NumPy Converter. It was pretty straight forward to create wrappers for these functions by following the aforementioned structure. The setup.py
script for building and installing these modules was created at the following stage. For this, I followed the Python Extension documentation’s advice and utilised distutils
, which offers two crucial functions:
-
distutils.core.Extension which is used to describe a
C/C++
extension. - distutils.core.setup the frontman in actually building and compiling the modules.
After this, the commands to build and install these modules were simply:
python3 setup.py build
python3 setup.py install
Week 2
At our subsequent meeting, my mentor confirmed my work, and we both agreed that the next step should be to write the NumPy converter so that this may be expanded to include the other library modules as well.
Week 2 was a little light on work because I was out of town for a few days. However, the most of my reading time was devoted to learning about the NumPy C-API
and how it connected with the Python C-API
.
I discovered that a NumPy array’s primary container object was the PyArrayObject
, and its PyTypeObject
was the PyArray_Type
. Therefore, in order for any PyObject
to be regarded as a NumPy Array, it has to fulfil these two requirements.
The API itself offered functions that allowed any generic array type data container to be converted into PyArray_Type
or one of its subclasses. For creating the converter, I would always turn to these!