Closed whuanle closed 2 weeks ago
It seems to be the problem of print
instead of slice
:
Maybe related to #1250
I have found why the problem was not discovered at that time. The unit test Validate_1250
uses torch.zeros(0)
to create the tensor. However this is a 1d tensor rather than a scalar (although there is no element inside it).
The unit test should be look like this instead:
[Fact]
public void Validate_1250()
{
var scalar = torch.zeros(Array.Empty<long>());
Assert.Equal("0", scalar.npstr());
Assert.Equal("[], type = Float32, device = cpu, value = 0", scalar.cstr());
}
By the way, the expected value for cstr
is set to the current result. But it's a bit strange, if we compare those three below:
using TorchSharp;
var zero = torch.tensor(0f);
var one = torch.tensor(new float[] { 0, 0 });
var two = torch.tensor(new float[,] { { 0, 0 }, { 0, 0 } });
Console.WriteLine(zero.cstr());
// [], type = Float32, device = cpu, value = 0
Console.WriteLine(one.cstr());
// [2], type = Float32, device = cpu, value = float [] {0f, 0f}
Console.WriteLine(two.cstr());
/*
[2x2], type = Float32, device = cpu, value =
float [,] {
{0f, 0f},
{0f, 0f}
}
*/
Maybe I would expect it to be [], type = Float32, device = cpu, value = float 0f
.
If we want to follow you should be able to copy the output and paste it into your code
, maybe it should be float (0f)
to meet the pattern of new xxxxxx
.
TorchSharp can't slice like Pytorch.
Python:
result:
C#:
result:
But if you get a layer, it's normal.