question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there interest to make TorchSharp for user friendly with e.g. .NET Interactive?

See original GitHub issue
New TorchSharp Test Project
Torch.SetSeed(1234);
var tensor = Float32Tensor.rand(new long[] { 4, 4 });
Console.Write(tensor)

Currently, there is no friendly print function when using TorchSharp in e.g. .NET Interactive , or I could have miss it?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
NiklasGustafssoncommented, Jun 23, 2021

I’m proposing a second ToString() overload defined on TorchTensor:

public string ToString(bool withData, string fltFormat = "g5", int width = 100)

The boolean is there to distinguish from the overriden ToString(), and is not necessary if the method is called something else.

One could also define it as:

public new string ToString(bool withData = false, string fltFormat = "g5", int width = 100)

to hide the overridden method.

Anyway, it would produce output like this:

[2x2x4], type = Float32, device = cpu

[0,:,:] =
 0.0000000   3.1410000 6.2834000    3.1415200
 0.0000063 -13.1415300 0.0100000 4713.1400000

[1,:,:] =
 0.0100000 0.0000000 0.0000000 0.0000000
 0.0000000 0.0000000 0.0000000 0.0000000

In this case, by passing in “0.0000000” as the format string.

The width parameter is there to prevent the method from making up extremely long lines. Instead, when the width is reached, each row ends with ‘…’

2reactions
NiklasGustafssoncommented, Jun 22, 2021

Working on a better ToString() would be interesting. I’m personally partial to how Julia prints tensors with more than two dimensions:

julia> x = rand(5,5, 5,5)
5×5×5×5 Array{Float64, 4}:
[:, :, 1, 1] =
 0.223483   0.753928   0.452195  0.715721  0.126067
 0.0451747  0.0833317  0.748877  0.4885    0.00116933
 0.34196    0.742832   0.838799  0.581502  0.317049
 0.175496   0.710619   0.129817  0.860807  0.0574395
 0.282793   0.828668   0.998318  0.874329  0.814805

[:, :, 2, 1] =
 0.728446  0.198255  0.809055  0.170687  0.207785
 0.022082  0.954964  0.461224  0.919482  0.990253
 0.101978  0.551891  0.57791   0.265696  0.759774
 0.854822  0.685592  0.837295  0.306617  0.368236
 0.527747  0.337722  0.347441  0.487223  0.813792

[:, :, 3, 1] =
 0.0282523  0.864711  0.656607  0.990119  0.365758
 0.485043   0.046835  0.788797  0.956218  0.888144
 0.0170756  0.602304  0.131042  0.530784  0.189504
 0.358518   0.610178  0.262251  0.70639   0.374479
 0.377738   0.609482  0.992617  0.754387  0.0318602

I like that the indices are printed (Julia is a column-major language, so the indices would be in the first dimensions rather than the last in .NET.)

@dsyme – you probably have thoughts on this topic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there interest to make TorchSharp for user friendly with ...
Currently, there is no friendly print function when using TorchSharp in e.g. .NET Interactive , or I could have miss it?
Read more >
TorchSharp & Tensor Programming - YouTube
In this week's community standup Don Syme talks about TorchSharp, a set of . NET bindings for the PyTorch engine, and tensor programming....
Read more >
How to train a neural network model from scratch using C#. ...
Extend integration of TorchSharp within ML.NET especially for deep learning use cases. If your interest is deep learning in .NET, Torchsharp is ...
Read more >
Does anyone actually use ML.NET? : r/dotnet
I work in engineering and we make a LOB application for pressure vessels calculation. I'm interested, if you like to share, in what...
Read more >
Text Classification in C# with ML.NET 2.0
Let's take a look at how ML.NET 2.0's new Text Transformer features can be used to perform multi-class classification and map utterances to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found