Skip to content

Call Tensor::alias() when returning an input Tensor #1433

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

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -12,6 +12,7 @@ __API Changes__:

#1374 Add accumulate to index_put_<br/>
`torch.optim.lr_scheduler.PolynomialLR` `power` type has been corrected, is now double.<br/>
Returning an input tensor has been corrected, is now `alias()`.<br/>

# NuGet Version 0.105.0

Expand Down
2 changes: 1 addition & 1 deletion src/TorchSharp/LinearAlgebra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public static Tensor multi_dot(IList<Tensor> tensors)
throw new ArgumentException(nameof(tensors));
}
if (tensors.Count == 1) {
return tensors[0];
return tensors[0].alias();
}

using (var parray = new PinnedArray<IntPtr>()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Tensor cat(IList<Tensor> tensors, long dim = 0)
switch (tensors.Count)
{
case <=0: throw new ArgumentException(nameof(tensors));
case 1: return tensors[0];
case 1: return tensors[0].alias();
}

using var parray = new PinnedArray<IntPtr>();
Expand Down
2 changes: 1 addition & 1 deletion src/TorchSharp/Tensor/torch.OtherOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static IList<Tensor> broadcast_tensors(params Tensor[] tensors)
throw new ArgumentException(nameof(tensors));
}
if (tensors.Length == 1) {
return tensors;
return new Tensor[] { tensors[0].alias() };
}

IntPtr[] ptrArray;
Expand Down