Print tensor to string with size constraints

If I print a huge tensor in libtorch to a string it will simply print it all. Is there a way to get the output in a nice way like if I print a tensor in python, where it limits what it puts out for large tensors?

Currently I do this to print to a string:

        std::stringstream buffer;
        buffer << *t << std::endl;

@Anders_G
Currently, there is no way to act like python print. We do plan to improve this later.
The only thing that you can control is how many chars in one line. see here:
https://github.com/pytorch/pytorch/blob/816d37b1d88bae649db32417443d9247cc3dbb76/aten/src/ATen/core/Formatting.h#L19

1 Like