robertknight / rten

ONNX neural network inference engine
124 stars 9 forks source link

Improve debug formatting of tensors #377

Closed robertknight closed 1 month ago

robertknight commented 1 month ago

Improve debug formatting of tensors by adding a custom Debug impl instead of using the derived one. The derived impl has been completely useless since views were changed to use custom storage types instead of slices. In the process an issue was resolved where the Clone impl for tensor iterators had an unnecessary T: Clone bound (where T is the element type).

For the expression NdTensor::full([2, 5, 5], 1.).view():

Before:

TensorBase { data: ViewData { ptr: 0x7fc9a0004080, len: 50, _marker: PhantomData<&f64> }, layout: NdLayout { shape: [2, 5, 5], strides: [25, 5, 1] } }

After:

[[[1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0]],

 [[1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0],
  [1.0, 1.0, 1.0, 1.0, 1.0]]], shape=[2, 5, 5], strides=[25, 5, 1]