Skip to content

Commit ce18679

Browse files
committed
If tensor dtype is already correct bypass type conversion
1 parent ceb9e62 commit ce18679

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/TorchSharp/Tensor/Tensor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7405,7 +7405,7 @@ public static Tensor WrappedTensorDisposeScope(Func<Tensor> expr)
74057405
internal static Tensor InstantiateTensorWithLeakSafeTypeChange(IntPtr handle, ScalarType? dtype)
74067406
{
74077407
var tensor = new Tensor(handle);
7408-
if (dtype.HasValue) {
7408+
if (dtype.HasValue && tensor.dtype != dtype.Value) {
74097409
var typed = tensor.to_type(dtype.Value);
74107410
tensor.Dispose();
74117411
return typed;

0 commit comments

Comments
 (0)