Fix for the handling of array sizes. We were assuming that all the input arrays
had the same shapes, but actually they could differ.