Skip to content

Commit 288f063

Browse files
Merge pull request #931 from NiklasGustafsson/missing
Fixed defaults for set_printoptions.
2 parents 17a35ca + 59c6ec7 commit 288f063

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/TorchSharp/Tensor/Tensor.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5784,8 +5784,7 @@ public Tensor rot90(long k = 1, (long, long)? dims = null)
57845784
dims = (0, 1);
57855785
}
57865786

5787-
var res =
5788-
LibTorchSharp.THSTensor_rot90(Handle, k, dims.Value.Item1, dims.Value.Item2);
5787+
var res = LibTorchSharp.THSTensor_rot90(Handle, k, dims.Value.Item1, dims.Value.Item2);
57895788
if (res == IntPtr.Zero) { CheckForErrors(); }
57905789
return new Tensor(res);
57915790
}

src/TorchSharp/Tensor/TensorExtensionMethods.cs

+19-10
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,41 @@ public static TensorStringStyle TensorStringStyle {
4444
/// <param name="sci_mode">Enable scientific notation.</param>
4545
public static void set_printoptions(
4646
int precision,
47-
int linewidth = 100,
48-
string newLine = "\n",
47+
int? linewidth = null,
48+
string? newLine = null,
4949
bool sci_mode = false)
5050
{
5151
torch.floatFormat = sci_mode ? $"E{precision}" : $"F{precision}";
52-
torch.newLine = newLine;
53-
torch.lineWidth = linewidth;
52+
if (newLine is not null)
53+
torch.newLine = newLine;
54+
if (linewidth.HasValue)
55+
torch.lineWidth = linewidth.Value;
5456
}
5557

5658
/// <summary>
5759
/// Set options for printing.
5860
/// </summary>
61+
/// <param name="style">The default string formatting style used by ToString(), print(), and str()</param>
5962
/// <param name="floatFormat">
6063
/// The format string to use for floating point values.
6164
/// See: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
6265
/// </param>
6366
/// <param name="linewidth">The number of characters per line for the purpose of inserting line breaks (default = 100).</param>
6467
/// <param name="newLine">The string to use to represent new-lines. Starts out as 'Environment.NewLine'</param>
6568
public static void set_printoptions(
66-
string floatFormat = "g5",
67-
int linewidth = 100,
68-
string newLine = "\n")
69+
TensorStringStyle? style = null,
70+
string? floatFormat = null,
71+
int? linewidth = null,
72+
string? newLine = null)
6973
{
70-
torch.floatFormat = floatFormat;
71-
torch.newLine = newLine;
72-
torch.lineWidth = linewidth;
74+
if (style.HasValue)
75+
torch._style = style.Value;
76+
if (floatFormat is not null)
77+
torch.floatFormat = floatFormat;
78+
if (newLine is not null)
79+
torch.newLine = newLine;
80+
if (linewidth.HasValue)
81+
torch.lineWidth = linewidth.Value;
7382
}
7483

7584
public const TensorStringStyle julia = TensorStringStyle.Julia;

0 commit comments

Comments
 (0)