Skip to content

Commit 24d4c4a

Browse files
Addressed PR comments.
1 parent 6a0e797 commit 24d4c4a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/TorchSharp/Tensor/Tensor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5185,13 +5185,13 @@ public Tensor roll((long, long, long) shifts, (long, long, long) dims)
51855185
/// Elements that are shifted beyond the last position are re-introduced at the first position.
51865186
/// If a dimension is not specified, the tensor will be flattened before rolling and then restored to the original shape.
51875187
/// </summary>
5188-
public Tensor roll(IEnumerable<long> shifts, IEnumerable<long>? dims = null)
5188+
public Tensor roll(ReadOnlySpan<long> shifts, IEnumerable<long>? dims = null)
51895189
{
5190-
var shLen = shifts.Count();
5190+
var shLen = shifts.Length;
51915191
var dmLen = dims is null ? 0 : dims.Count();
51925192

51935193
unsafe {
5194-
fixed (long* sh = shifts.ToArray(), dm = (dims == null) ? null : dims.ToArray()) {
5194+
fixed (long* sh = shifts, dm = (dims == null) ? null : dims.ToArray()) {
51955195
var res =
51965196
THSTensor_roll(Handle, (IntPtr)sh, shLen, (IntPtr)dm, dmLen);
51975197
if (res == IntPtr.Zero) { torch.CheckForErrors(); }

src/TorchSharp/Tensor/Tensor.torch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static Tensor cat(IList<Tensor> tensors, long dimension)
9595
/// Elements that are shifted beyond the last position are re-introduced at the first position.
9696
/// If a dimension is not specified, the tensor will be flattened before rolling and then restored to the original shape.
9797
/// </summary>
98-
public static Tensor roll(Tensor input, IEnumerable<long> shifts, IEnumerable<long> dims) => input.roll(shifts, dims);
98+
public static Tensor roll(Tensor input, ReadOnlySpan<long> shifts, IEnumerable<long> dims) => input.roll(shifts, dims);
9999

100100
/// <summary>
101101
/// Returns a tensor with all the dimensions of input of size 1 removed. When dim is given, a squeeze operation is done only in the given dimension.

0 commit comments

Comments
 (0)