Hi,
Great project!
I think it would be relatively easy to make it even more awesome. :)
Many people deal with data science nowadays, and there
tensor properties, like shape, are more frequent source of error
than e.g. values in the array.
Currently arrays / tensors are displayed like this:
x: ndarray = array([ 1, 2... ])
y: Tensor = tensor([ 1, 2... ])
I would recommend at least two extra piece of information: shape and dtype, something like this:
x: ndarray[float64] (200,300) = array([ 1, 2... ])
Or maybe:
x: Tensor, cpu/f32, 2d, (200,300) = array([ 1, 2... ])
Maybe it would be even nicer to make the hook configurable, like:
import frosch
frosch.hook(array_shapes=True, array_types=True, array_device=False, requires_grad=True, array_values=False)
Of course, you can always add almost infinite useful tricks to numpy/pytorch, e.g.
isnan/isinf, so here is a final variant to consider:
x: Tensor, type=cpu/f32, grad=F, shape=(200,300), inf:0 NaN:0, min: -3, max:1e8, mean: 0.0001
Of course, these might take time to print, but if it is configurable, then it doesn't really matter.
Another way, which would be also cool, is having a configurable extra printer.
E.g.
import frosch
import my_tricks
frosch.hook( (np.ndarray, my_tricks.numpy_printer) )
In this case anybody could customize their own printer, and add an extra representation.
I imagine the print like this:
x: ndarray "Whatever string the function returned"
And the function interface would be:
extra_info = ....
return extra_info + default_printers_text
This might mess up colors, i see it.
There could be other ways to define values, like returning a dictionary of texts,
like "pre_type", "post_type", "pre_value", "post_value" , and format them something like this:
f'{pre_type}{type}{post_type} = {pre_value}{value}{post_value}
In this way you don't have much issues with the coloring, it is still controlled by you,
but people could customize the printer.
Which one to choose?
Well, i like my own printers, e.g. testing for NaNs, but for most people a reasonable built-in would be the easiest,
maybe with some verbosity parameter in the hook installer.
But once again: it is a great project already, and much more readable than any default.
I really appreciate your efforts, and even if you don't incorporate anything from the above,
it is already a lot of help for lot of people. But maybe the above could make it even better. :)