Skip to content

mat: disallow zero dimension results

Sebastien Binet requested to merge mat/zero-panic into master

Created by: kortschak

Please take a look.

I would have liked to add a zero-size check in the construction functions for each of these types. But there are a number of places (particularly in list_test.go) that use calls to New*(0,... (list_test can special-case 0 and just return the type, which would be better anyway since we say the zero value is usable). The approach here covers the majority of cases though (note that it does not catch stack and augment with one zero and one non-zero dimensioned input - this is arguably OK).

The io routines do not panic, since the user cannot know prior to reading whether the data are zero.

I'd like to be able to differentiate zero values that the user has made from zero values that we've incorrectly passed into a routine and panic harder in the latter case, but this doesn't seem easily doable. I may come back to it.

I have also added in missing negative dimension checks where needed.

Updates #442 (closed).

Merge request reports