joaosferreira's Blog

Week 8 Check-in

Published: 07/29/2020

What did you do this week?

This week I started a new PR that adds multimethods for indexing routines. The multimethods added so far are the following:

Genenating index arrays

  • indices
  • ix_
  • ravel_multi_index
  • unravel_index
  • diag_indices
  • diag_indices_from
  • mask_indices
  • tril_indices
  • tril_indices_from
  • triu_indices
  • triu_indices_from

I also finished the two PRs from the previous week, one that adds multimethods for mathematical functions and another for functional programming routines. As mentioned in my last blog post, this week I also managed to merge another PR that picks up on work previously done by one of my mentors. This PR extended the overriding of classes to other backends, more specifically, to Dask and Sparse.

What is coming up next?

I will continue the PR started this week by adding more multimethods that target indexing routines. This should be mostly writing default implementations for the new multimethods. Depending on how this goes I might also start a new PR that picks up on work previously started by one of my mentors on adding multimethods for NumPy's random module.

Did you get stuck anywhere?

There were no blocks this week, only one test that I could not understand why it was failing. Turns out that uarray, the backend mechanism behind unumpy, was calling the default implementations after these failed in a given backend with the arguments previously marked for dispatching not being coerced into array types. This was fixed on the uarray side by one of my mentors by skipping this last call to the defaults under certain conditions.

View Blog Post

Week 7 Check-in

Published: 07/21/2020

What did you do this week?

I started a new PR that adds multimethods for functional programming routines. The multimethods added are the following:

  • apply_along_axis
  • apply_over_axes
  • frompyfunc
  • piecewise

Other work done this week was mainly adding default implementations to a previous PR that adds multimethods for mathematical functions. I've also managed to finally pick up the work started by one of my mentors that adds an overriding class (this was discussed in previous blog posts). This was done by adding the function overriden_class to both Dask and Sparse backends.

What is coming up next?

Next week I will be starting a new PR that adds multimethods for indexing routines and also patch up the ongoing PRs from this week. I will also try to open a new PR that branches off from this one and adds the work done this week on the overriding class. When this is merged it will enable me to add some mutlimethods that I've been holding off like nan_to_num and real_if_close.

Did you get stuck anywhere?

Trying to understand NumPy's implementations for some mathematical functions like unwrap and interp to implement their defaults was a bit difficult at first but I managed to self unblock. I haven't previously looked at NumPy's code for help on writing defaults but this week I found it to be very helpful although it can also be confusing sometimes (and can feel like cheating). I still didn't fully understand unwraps's implementation though.

View Blog Post

Week 6 Check-in

Published: 07/15/2020

What did you do this week?

I started a new PR that adds multimethods for mathematical functions. The multimethods that were added are the following:

Trigonometric functions

  • degrees
  • radians
  • unwrap


  • around (and its aliase round_)
  • fix

Sums, products, differences

  • cumprod
  • cumsum
  • nancumprod
  • nancumsum
  • ediff1d
  • cross
  • trapz

Other special functions

  • i0
  • sinc

Arithmetic operations

  • float_power

Handling complex numbers

  • angle
  • real
  • imag
  • conjugate


  • convolve
  • clip
  • nan_to_num
  • real_if_close
  • interp

I've also concluded the PR on array manipulation routines from previous weeks which still had some unresolved issues. It turns out that this week's work was mostly spent patching up the previous PR and less working on the new one unfortunately. This ended up delaying the new PR a bit but since the new one already added quite a few multimethods the schedule is unaffected.

What is coming up next?

Continuing the new PR by adding default implementations to the appropriate multimethods and starting a new PR that adds multimethods for functional programming routines. I already did some offline prototyping of default implementations for mathematical functions, the more easy ones at least. The more difficult ones (e.g., unwrap, convolve and interp) should be the focus of that part of next week's work.

Did you get stuck anywhere?

There were no major blocks this week. The only issue was the somewhat precedence that the older PR had which prevented the newer one to advance. For example, both PRs had failing tests in the XND backend so this backend was removed (the project is not maintained anymore) in the older PR. Since this has now been merged the newer PR can now receive those changes that fix its failing tests.

View Blog Post

Week 5 Check-in

Published: 07/07/2020

What did you do this week?

I continued the PR started in the previous week by adding more multimethods for array manipulation. The following multimethods were added:

Tiling arrays

  • tile
  • repeat

Adding and removing elements

  • delete
  • insert
  • append
  • resize
  • trim_zeros

Rearranging elements

  • flip
  • fliplr
  • flipud
  • reshape
  • roll
  • rot90

Most of the work was adding default implementations for the above multimethods which relied heavily on array slicing. Contrary to what I mentioned in my last blog post, not much time was dedicated to writing overriden_class for other backends so I will try to compensate in the next weeks.

What is coming up next?

As described in my proposal's timeline I'll be starting a new PR that adds multimethods for mathematical functions. This will be the focus of this week's work as some of these multimethods are also needed by sangyx, another GSoC student working on uarray. He is working on the udiff library that uses uarray and unumpy for automatic differentiation. To avoid getting in his way I will try to finish this PR as soon as possible.

Did you get stuck anywhere?

There were times when I didn't know exactly how to implement a specific default but this was easily overcome with the help of my mentors who would point me in the right direction. Asking for help sooner rather than later has proven to be invaluable. Looking back I think there were no major blocks this week.

View Blog Post

Week 4 Check-in

Published: 06/30/2020

What did you do this week?

I started a PR that adds multimethods for array manipulation routines. I'll name the multimethods according to the NumPy docs sectioning:

Basic operations

  • copyto

Changing number of dimensions

  • expand_dims
  • squeeze

Changing kind of array

  • asfarray
  • asfortranarray
  • asarray_chkfinite
  • require

Joining arrays

  • dstack

Splitting arrays

  • split
  • array_split
  • dsplit
  • hsplit
  • vsplit

As mentioned in my last blog post, this week I also started reviewing a PR that implements metaclasses from which classes in unumpy instantiate. They are used to override these classes with ones from the backend being used through a property method called overriden_class. Currently only the NumPy backend has this method but I've been trying to implement it in other backends as well.

What is coming up next?

The current PR should last one more week since I'll continue to add more multimethods for array manipulation routines. I will also be working on adding overriden_class to other backends as I've been doing this past week.

Did you get stuck anywhere?

I think the only place I got stuck was trying to implement overriden_class for other backends. To be more specific, I tried implementing it in the Dask backend first and foremost, however, this backend is different since it uses another backend internally. From my understanding this causes that some classes might have to be overridden by the inner backend and others by Dask itself. With that said, I might need help later on with this issue. In general, I feel that this metaclasses feature has been the most challenging part of my project so far. Although this wasn't initially included in my proposal and can be considered extra work I welcome the challenge and hope that my mentors keep entrusting me more of these features. Also, given that the semester is almost ending I start having more free time on my hands to tackle these problems which is what I want.

View Blog Post