Skip to content

Commit b31789d

Browse files
update newline character (#1419)
* update newline character
1 parent 458b77e commit b31789d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ __Bug Fixes__:
4040
#1387 Attaching tensor to a DisposeScope no longer makes Statistics.DetachedFromScopeCount go negative.<br/>
4141
#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/>
4242
#1392 ToTensor() extension method memory leaks fixed.<br/>
43+
#1414 tensor.print() - Missing default "newLine" Parameter<br/>
4344

4445
# NuGet Version 0.103.0
4546

src/TorchSharp/Tensor/TensorExtensionMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public static string cstr(this Tensor tensor, string? fltFormat = "g5", int? wid
259259
/// The style to use -- either 'default,' 'metadata,' 'julia,' or 'numpy'
260260
/// </param>
261261
/// <returns></returns>
262-
public static Tensor print(this Tensor t, string? fltFormat = "g5", int? width = 100, string? newLine = "", CultureInfo? cultureInfo = null, TensorStringStyle style = TensorStringStyle.Default)
262+
public static Tensor print(this Tensor t, string? fltFormat = "g5", int? width = 100, string? newLine = "\n", CultureInfo? cultureInfo = null, TensorStringStyle style = TensorStringStyle.Default)
263263
{
264264
Console.WriteLine(t.ToString(style, fltFormat, width, cultureInfo, newLine));
265265
return t;

test/TorchSharpTest/TestTorchTensor.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,29 @@ public void TestToString1()
282282
Assert.Equal("[2x2], type = Float32, device = cpu", str);
283283
}
284284

285+
[Fact]
286+
[TestOf(nameof(TensorExtensionMethods.print))]
287+
public void TestTensorDefaultPrint()
288+
{
289+
Tensor t = torch.zeros(2, 2);
290+
string expectedOutput = t.ToString(TensorStringStyle.Default, "g5", 100, null, "\n") + Environment.NewLine;
291+
var originalOut = Console.Out;
292+
using (var sw = new StringWriter())
293+
{
294+
try
295+
{
296+
Console.SetOut(sw);
297+
t.print();
298+
var result = sw.ToString();
299+
Assert.Equal(expectedOutput, result);
300+
}
301+
finally
302+
{
303+
Console.SetOut(originalOut);
304+
}
305+
}
306+
}
307+
285308
[Fact]
286309
[TestOf(nameof(Tensor.ToString))]
287310
public void Test1DToCSharpString()

0 commit comments

Comments
 (0)