We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ceb9e62 commit ce18679Copy full SHA for ce18679
src/TorchSharp/Tensor/Tensor.cs
@@ -7405,7 +7405,7 @@ public static Tensor WrappedTensorDisposeScope(Func<Tensor> expr)
7405
internal static Tensor InstantiateTensorWithLeakSafeTypeChange(IntPtr handle, ScalarType? dtype)
7406
{
7407
var tensor = new Tensor(handle);
7408
- if (dtype.HasValue) {
+ if (dtype.HasValue && tensor.dtype != dtype.Value) {
7409
var typed = tensor.to_type(dtype.Value);
7410
tensor.Dispose();
7411
return typed;
0 commit comments