Skip to content

Commit 01da08d

Browse files
Fixed #1402
1 parent e8c1074 commit 01da08d

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

RELEASENOTES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
Releases, starting with 9/2/2021, are listed with the most recent release at the top.
44

5+
# NuGet Version 0.104.0
6+
7+
__Breaking Changes__:
8+
9+
The argument defaults for `torch.diagonal()` and `Tensor.diagonal()` arguments have been changed.
10+
11+
__Bug Fixes__:
12+
13+
#1400 There may be an error in torchvision.transforms.GaussianBlur
14+
#1402 diagonal() has incorrect default
15+
516
# NuGet Version 0.103.1
617

718
__Breaking Changes__:

src/TorchSharp/LinearAlgebra.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public static (Tensor, Tensor) slogdet(Tensor input)
136136
/// </summary>
137137
/// <param name="input">The input tensor</param>
138138
/// <param name="offset">Which diagonal to consider. Default: 0 (main diagonal).</param>
139-
/// <param name="dim1">First dimension with respect to which to take diagonal. Default: -1.</param>
140-
/// <param name="dim2">Second dimension with respect to which to take diagonal. Default: -2.</param>
139+
/// <param name="dim1">First dimension with respect to which to take diagonal. Default: -2.</param>
140+
/// <param name="dim2">Second dimension with respect to which to take diagonal. Default: -1.</param>
141141
/// <remarks>
142142
/// Applying torch.diag_embed() to the output of this function with the same arguments yields a diagonal matrix with the diagonal entries of the input.
143143
/// However, torch.diag_embed() has different default dimensions, so those need to be explicitly specified.

src/TorchSharp/Tensor/Tensor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3329,8 +3329,9 @@ public Tensor diagflat(long offset = 0)
33293329
/// Applying torch.diag_embed() to the output of this function with the same arguments yields a diagonal matrix with the diagonal entries of the input.
33303330
/// However, torch.diag_embed() has different default dimensions, so those need to be explicitly specified.
33313331
/// </remarks>
3332-
public Tensor diagonal(long offset = 0, long dim1 = 0, long dim2 = 0)
3332+
public Tensor diagonal(long offset = 0L, long dim1 = 0L, long dim2 = 1L)
33333333
{
3334+
if (dim1 == dim2) throw new ArgumentException($"Diagonal dimensions cannot be identical {dim1}, {dim2}");
33343335
var res = NativeMethods.THSTensor_diagonal(Handle, offset, dim1, dim2);
33353336
if (res == IntPtr.Zero) { CheckForErrors(); }
33363337
return new Tensor(res);

src/TorchSharp/Tensor/torch.OtherOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public static Tensor diag_embed(Tensor input, long offset = 0L, long dim1 = -2L,
313313
/// Applying torch.diag_embed() to the output of this function with the same arguments yields a diagonal matrix with the diagonal entries of the input.
314314
/// However, torch.diag_embed() has different default dimensions, so those need to be explicitly specified.
315315
/// </remarks>
316-
public static Tensor diagonal(Tensor input, long offset = 0, long dim1 = 0, long dim2 = 0) => input.diagonal(offset, dim1, dim2);
316+
public static Tensor diagonal(Tensor input, long offset = 0L, long dim1 = 0L, long dim2 = 1L) => input.diagonal(offset, dim1, dim2);
317317

318318
// https://pytorch.org/docs/stable/generated/torch.diff
319319
/// <summary>

test/TorchSharpTest/TestTorchTensorBugs.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,5 +1692,15 @@ public void Validate1400()
16921692
var img = torch.rand(1,3,256,256);
16931693
var t = trans.call(img);
16941694
}
1695+
1696+
[Fact]
1697+
public void Validate1402()
1698+
{
1699+
var t = torch.arange(100).reshape(10,10);
1700+
1701+
var d = t.diagonal();
1702+
1703+
Assert.Equal(new long[]{0, 11, 22, 33, 44, 55, 66, 77, 88, 99}, d.data<long>().ToArray());
1704+
}
16951705
}
16961706
}

0 commit comments

Comments
 (0)