Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug formatting of tensors #377

Merged
merged 2 commits into from
Oct 11, 2024
Merged

Improve debug formatting of tensors #377

merged 2 commits into from
Oct 11, 2024

Conversation

robertknight
Copy link
Owner

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]

Replace derived `Clone` impls for tensor iterators with manual implementations
to remove the unnecessary `T: Clone` bound that the derived impl adds.

See also rust-lang/rust#26925.
Add a `Debug` impl for TensorBase that outputs the data in logical order, elided
if sufficiently long, followed by shape and stride info.

The main `tensor.rs` module is growing very long (~3.8K lines, of which 40% are
tests), so start the process of moving some impls and their tests into separate
modules.
@robertknight robertknight merged commit 0a95bfc into main Oct 11, 2024
2 checks passed
@robertknight robertknight deleted the tensor-debug branch October 11, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant