Closed parrt closed 2 years ago
The linked PR introduces the dtype as an optional feature to explain and clarify via the dtypes
boolean flag (default: False
).
The code structure for dtypes is similar to shape: a dedicated function to obtain the dtype (which should work for each supported backend). In numpy structured arrays are a special case, currently displayed as a void type. This is probably not a widely used feature in this context, so should be fine.
For displaying the information we can consider multiple approaches:
The second option can be elegantly achieved by creating a custom legend:
This was created with patches (and a mapping from type to color). Code example:
import matplotlib.patches as mpatches
g = mpatches.Patch(color='darkgreen', label='The green data')
b = mpatches.Patch(color='lightblue', label='The blue data')
y = mpatches.Patch(color='orange', label='The orange data')
leg = plt.figlegend([b, g, y], ['float64', 'int32', 'boolean'], loc='center right')
ax.add_artist(leg)
fig_width += 250
Colors are currently indicating matrix/vector. This is not really needed as the same information can be observed from the shape, making the color legend for types an interesting option.
The third option might be tricky to get readable types for all shapes:
@parrt Have you had any time to think about this issue? If so, then we can wrap up the open work (or close the PR if we decide not to include the feature)
From @sbrugman:
Our concrete issue was with Pytorch (unexpectedly) converting tensors with only integers to float, which later in the program resulted in an error because it could not be used as an index. Another issue was changing size from 32 to 64 bit floats.
It's indeed the element type of the matrix.
There are multiple somewhat related issues: https://discuss.pytorch.org/t/problems-with-target-arrays-of-int-int32-types-in-loss-functions/140/2 https://discuss.pytorch.org/t/why-pytorch-is-giving-me-hard-time-with-float-long-double-tensor/14678/6
The common denominator between dimensionality debugging is that both type and dimensionality are practically hidden from the user: