ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

Encode expected/actual info in ShapeError

Open bluss opened this issue 4 years ago • 2 comments
trafficstars

Add a (limited) way to add specific information to a ShapeError

Admittedly wonky, but maybe worthwhile.

Result<(), ShapeError> used to be 1 byte, and with this change it expands to 16 bytes (2 usize on 64-bit).

The remaining 15 bytes are used for optimistically packing as much of extra info into the error message as possible.

For example we can store expected/actual index for errors (for example index out of bounds or axis out of bounds, these are not so commonly handled with ShapeError).

With this change it is supported:

  • Expected/actual index with 7 bytes per index
  • Expected/actual shape with 7-14 bytes per shape supports storing shapes with one or two bytes (< 256²) per dimension, with limited ndim.

bluss avatar Mar 29 '21 18:03 bluss

I guess I needed to experiment with this no-alloc approach. This is a good starting point for also experimenting with an error in a Box, which also does fine on microbenchmarks. Maybe it can be optional.

bluss avatar Apr 05 '21 08:04 bluss

After exploring this, I'm ready to try adding something like ShapeError(Box<ErrorDetails>) to pack in more information. Thoughts? What I don't like is the code bloat that results from cleanup pads (code to drop the extra box in various places). It could even be made optional, to have such error details.

bluss avatar Apr 17 '21 19:04 bluss