From 23ca0cc3d596cf2d83ddf208e4d6d60e06b7fdf7 Mon Sep 17 00:00:00 2001 From: Niklas Gustafsson Date: Fri, 17 Feb 2023 20:12:13 -0800 Subject: [PATCH 1/3] Fixed formatting issue. --- src/TorchSharp/Tensor/Tensor.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TorchSharp/Tensor/Tensor.cs b/src/TorchSharp/Tensor/Tensor.cs index 512dc4c11..8cfb10e98 100644 --- a/src/TorchSharp/Tensor/Tensor.cs +++ b/src/TorchSharp/Tensor/Tensor.cs @@ -5784,8 +5784,7 @@ public Tensor rot90(long k = 1, (long, long)? dims = null) dims = (0, 1); } - var res = - LibTorchSharp.THSTensor_rot90(Handle, k, dims.Value.Item1, dims.Value.Item2); + var res = LibTorchSharp.THSTensor_rot90(Handle, k, dims.Value.Item1, dims.Value.Item2); if (res == IntPtr.Zero) { CheckForErrors(); } return new Tensor(res); } From 8e879050c3ac783f408a1bb267d917221768763d Mon Sep 17 00:00:00 2001 From: Niklas Gustafsson Date: Tue, 21 Feb 2023 09:15:59 -0800 Subject: [PATCH 2/3] Minor changes to ToString() --- .../Tensor/TensorExtensionMethods.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/TorchSharp/Tensor/TensorExtensionMethods.cs b/src/TorchSharp/Tensor/TensorExtensionMethods.cs index 534ac25cd..1fe23d67b 100644 --- a/src/TorchSharp/Tensor/TensorExtensionMethods.cs +++ b/src/TorchSharp/Tensor/TensorExtensionMethods.cs @@ -44,18 +44,21 @@ public static TensorStringStyle TensorStringStyle { /// Enable scientific notation. public static void set_printoptions( int precision, - int linewidth = 100, - string newLine = "\n", + int? linewidth = 100, + string? newLine = "\n", bool sci_mode = false) { torch.floatFormat = sci_mode ? $"E{precision}" : $"F{precision}"; - torch.newLine = newLine; - torch.lineWidth = linewidth; + if (newLine is not null) + torch.newLine = newLine; + if (linewidth.HasValue) + torch.lineWidth = linewidth.Value; } /// /// Set options for printing. /// + /// The default string formatting style used by ToString(), print(), and str() /// /// The format string to use for floating point values. /// See: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings @@ -63,13 +66,17 @@ public static void set_printoptions( /// The number of characters per line for the purpose of inserting line breaks (default = 100). /// The string to use to represent new-lines. Starts out as 'Environment.NewLine' public static void set_printoptions( - string floatFormat = "g5", - int linewidth = 100, - string newLine = "\n") + TensorStringStyle style = TensorStringStyle.Julia, + string? floatFormat = null, + int? linewidth = null, + string? newLine = null) { - torch.floatFormat = floatFormat; - torch.newLine = newLine; - torch.lineWidth = linewidth; + if (floatFormat is not null) + torch.floatFormat = floatFormat; + if (newLine is not null) + torch.newLine = newLine; + if (linewidth.HasValue) + torch.lineWidth = linewidth.Value; } public const TensorStringStyle julia = TensorStringStyle.Julia; From 76e566fb4a81ff30d400130b9ec61883edc550aa Mon Sep 17 00:00:00 2001 From: Niklas Gustafsson Date: Tue, 21 Feb 2023 10:57:30 -0800 Subject: [PATCH 3/3] Fixed the defaults of set_printoptions() --- src/TorchSharp/Tensor/TensorExtensionMethods.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TorchSharp/Tensor/TensorExtensionMethods.cs b/src/TorchSharp/Tensor/TensorExtensionMethods.cs index 1fe23d67b..e54f89372 100644 --- a/src/TorchSharp/Tensor/TensorExtensionMethods.cs +++ b/src/TorchSharp/Tensor/TensorExtensionMethods.cs @@ -44,8 +44,8 @@ public static TensorStringStyle TensorStringStyle { /// Enable scientific notation. public static void set_printoptions( int precision, - int? linewidth = 100, - string? newLine = "\n", + int? linewidth = null, + string? newLine = null, bool sci_mode = false) { torch.floatFormat = sci_mode ? $"E{precision}" : $"F{precision}"; @@ -66,11 +66,13 @@ public static void set_printoptions( /// The number of characters per line for the purpose of inserting line breaks (default = 100). /// The string to use to represent new-lines. Starts out as 'Environment.NewLine' public static void set_printoptions( - TensorStringStyle style = TensorStringStyle.Julia, + TensorStringStyle? style = null, string? floatFormat = null, int? linewidth = null, string? newLine = null) { + if (style.HasValue) + torch._style = style.Value; if (floatFormat is not null) torch.floatFormat = floatFormat; if (newLine is not null)