Skip to content

Commit 9de2d71

Browse files
authored
Merge pull request #8 from interesaaat/LibTorchSharpFirstTest
Fixed bugs with the JIT types
2 parents e8702cb + 1b946ba commit 9de2d71

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

TorchSharp/JIT/Module.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ private Type GetType(Type type)
143143
switch (type.Kind)
144144
{
145145
case Type.TypeKind.DynamicType:
146-
return type.AsDynamicType();
146+
var dynamic = type.AsDynamicType();
147+
type.Dispose();
148+
return dynamic;
147149
case Type.TypeKind.TensorType:
148-
return type.AsDynamicType();
150+
var tensor = type.AsTensorType();
151+
type.Dispose();
152+
return tensor;
149153
default:
150154
return type;
151155
}

TorchSharp/JIT/Type/DynamicType .cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ internal DynamicType(IntPtr handle) : base(handle)
88
{
99
this.handle = new HType(handle, true);
1010
}
11-
12-
internal DynamicType(Type type) : base()
13-
{
14-
handle = type.handle;
15-
type.handle = new HType(IntPtr.Zero, true);
16-
type.Dispose();
17-
}
1811
}
1912
}

TorchSharp/JIT/Type/Type.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,24 @@ protected void Dispose(bool disposing)
7878
}
7979

8080
[DllImport("libTorchSharp")]
81-
extern static short THSJIT_typeKind(HType handle);
81+
extern static sbyte THSJIT_typeKind(HType handle);
8282

8383
internal TypeKind Kind
8484
{
8585
get { return (TypeKind)THSJIT_typeKind(handle); }
8686
}
8787

88+
[DllImport("libTorchSharp")]
89+
extern static IntPtr THSJIT_typeCast(HType module);
90+
8891
internal TensorType AsTensorType()
8992
{
90-
return new TensorType(this);
93+
return new TensorType(THSJIT_typeCast(handle));
9194
}
9295

9396
internal DynamicType AsDynamicType()
9497
{
95-
return new DynamicType(this);
98+
return new DynamicType(THSJIT_typeCast(handle));
9699
}
97100

98101
internal enum TypeKind : sbyte

0 commit comments

Comments
 (0)