Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Native/LibTorchSharp/THSVision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Tensor THSVision_ApplyGridTransform(Tensor i, Tensor g, const int8_t m, const fl

if (m == 0) {
mask = mask < 0.5;
img[mask] = fill_img[mask];
img = torch::where(mask, fill_img, img);
}
else {
img = img * mask + (-mask + 1.0) * fill_img;
Expand Down
54 changes: 54 additions & 0 deletions test/TorchSharpTest/TestTorchVision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,60 @@ public void TestRotateImage45DegreesClockwise()
}
}

[Fact]
public void TestAffineTransform3D()
{
// 3D input: [C, H, W]
var img = torch.rand(new long[] { 1, 48, 48 });
var result = functional.affine(
img,
angle: 0f,
translate: new[] { 0, 0 },
scale: 1f,
shear: new[] { 1f, 1f },
fill: 0);
Assert.Equal(img.shape, result.shape);
}

[Fact]
public void TestAffineTransform4D()
{
// 4D input: [N, C, H, W] — reproduces issue #1502
var img = torch.rand(new long[] { 1, 1, 48, 48 });
var result = functional.affine(
img,
angle: 0f,
translate: new[] { 0, 0 },
scale: 1f,
shear: new[] { 1f, 1f },
fill: 0);
Assert.Equal(img.shape, result.shape);
}

[Fact]
public void TestAffineTransform4DBatch()
{
// 4D input with batch > 1
var img = torch.rand(new long[] { 4, 3, 32, 32 });
var result = functional.affine(
img,
angle: 15f,
translate: new[] { 5, 5 },
scale: 0.9f,
shear: new[] { 10f, 5f },
fill: 0);
Assert.Equal(img.shape, result.shape);
}

[Fact]
public void TestRotateWithFill()
{
// Rotate with fill also uses ApplyGridTransform — verify it works
var img = torch.rand(new long[] { 1, 1, 48, 48 });
var result = functional.rotate(img, 45f, InterpolationMode.Nearest, fill: new float[] { 0f });
Assert.Equal(img.shape, result.shape);
}

[Fact]
public void Solarize_InvertedPixel_True()
{
Expand Down