Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update newline character #1419

Merged
merged 17 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ __Bug Fixes__:
#1387 Attaching tensor to a DisposeScope no longer makes Statistics.DetachedFromScopeCount go negative.<br/>
#1390 DisposeScopeManager.Statistics now includes DisposedOutsideScopeCount and AttachedToScopeCount. ThreadTotalLiveCount is now exact instead of approximate. ToString gives a useful debug string, and documentation is added for how to troubleshoot memory leaks. Also DisposeScopeManager.Statistics.TensorStatistics and DisposeScopeManager.Statistics.PackedSequenceStatistics provide separate metrics for these objects.<br/>
#1392 ToTensor() extension method memory leaks fixed.<br/>
#1414 tensor.print() - Missing default "newLine" Parameter<br/>

# NuGet Version 0.103.0

Expand Down
2 changes: 1 addition & 1 deletion src/TorchSharp/Tensor/TensorExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static string cstr(this Tensor tensor, string? fltFormat = "g5", int? wid
/// The style to use -- either 'default,' 'metadata,' 'julia,' or 'numpy'
/// </param>
/// <returns></returns>
public static Tensor print(this Tensor t, string? fltFormat = "g5", int? width = 100, string? newLine = "", CultureInfo? cultureInfo = null, TensorStringStyle style = TensorStringStyle.Default)
public static Tensor print(this Tensor t, string? fltFormat = "g5", int? width = 100, string? newLine = "\n", CultureInfo? cultureInfo = null, TensorStringStyle style = TensorStringStyle.Default)
{
Console.WriteLine(t.ToString(style, fltFormat, width, cultureInfo, newLine));
return t;
Expand Down
21 changes: 21 additions & 0 deletions test/TorchSharpTest/TestTorchTensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ public void TestToString1()
Assert.Equal("[2x2], type = Float32, device = cpu", str);
}

[Fact]
[TestOf(nameof(TensorExtensionMethods.print))]
public void TestTensorDefaultPrint()
{
Tensor t = torch.zeros(2, 2);
string expectedOutput = t.ToString(TensorStringStyle.Default, "g5", 100, null, "\n") + Environment.NewLine;
var originalOut = Console.Out;
using (var sw = new StringWriter())
{
try {
alinpahontu2912 marked this conversation as resolved.
Show resolved Hide resolved
Console.SetOut(sw);
t.print();
var result = sw.ToString();
Assert.Equal(expectedOutput, result);
}
finally {
Console.SetOut(originalOut);
}
}
}

[Fact]
[TestOf(nameof(Tensor.ToString))]
public void Test1DToCSharpString()
Expand Down