@@ -20,8 +20,6 @@ public class ByteTensor : ITorchTensor<byte>
20
20
21
21
internal sealed class HType : SafeHandle
22
22
{
23
- internal bool shouldClean = true ;
24
-
25
23
public HType ( IntPtr preexistingHandle , bool ownsHandle ) : base ( IntPtr . Zero , ownsHandle )
26
24
{
27
25
SetHandle ( preexistingHandle ) ;
@@ -36,12 +34,7 @@ internal HType() : base(IntPtr.Zero, true)
36
34
37
35
protected override bool ReleaseHandle ( )
38
36
{
39
- // var atenTensor = new AtenSharp.ByteTensor(THS_getTHTensorUnsafe(this));
40
- // atenTensor.Dispose();
41
- if ( shouldClean )
42
- {
43
- THS_Delete ( this ) ;
44
- }
37
+ THS_Delete ( this ) ;
45
38
return true ;
46
39
}
47
40
@@ -56,10 +49,9 @@ protected override void Dispose(bool disposing)
56
49
57
50
internal HType handle ;
58
51
59
- internal ByteTensor ( HType handle , bool shouldClean = true )
52
+ internal ByteTensor ( HType handle )
60
53
{
61
54
this . handle = handle ;
62
- this . handle . shouldClean = shouldClean ;
63
55
}
64
56
65
57
/// <summary>
@@ -328,8 +320,6 @@ public class ShortTensor : ITorchTensor<short>
328
320
329
321
internal sealed class HType : SafeHandle
330
322
{
331
- internal bool shouldClean = true ;
332
-
333
323
public HType ( IntPtr preexistingHandle , bool ownsHandle ) : base ( IntPtr . Zero , ownsHandle )
334
324
{
335
325
SetHandle ( preexistingHandle ) ;
@@ -344,12 +334,7 @@ internal HType() : base(IntPtr.Zero, true)
344
334
345
335
protected override bool ReleaseHandle ( )
346
336
{
347
- // var atenTensor = new AtenSharp.ShortTensor(THS_getTHTensorUnsafe(this));
348
- // atenTensor.Dispose();
349
- if ( shouldClean )
350
- {
351
- THS_Delete ( this ) ;
352
- }
337
+ THS_Delete ( this ) ;
353
338
return true ;
354
339
}
355
340
@@ -364,10 +349,9 @@ protected override void Dispose(bool disposing)
364
349
365
350
internal HType handle ;
366
351
367
- internal ShortTensor ( HType handle , bool shouldClean = true )
352
+ internal ShortTensor ( HType handle )
368
353
{
369
354
this . handle = handle ;
370
- this . handle . shouldClean = shouldClean ;
371
355
}
372
356
373
357
/// <summary>
@@ -636,8 +620,6 @@ public class IntTensor : ITorchTensor<int>
636
620
637
621
internal sealed class HType : SafeHandle
638
622
{
639
- internal bool shouldClean = true ;
640
-
641
623
public HType ( IntPtr preexistingHandle , bool ownsHandle ) : base ( IntPtr . Zero , ownsHandle )
642
624
{
643
625
SetHandle ( preexistingHandle ) ;
@@ -652,12 +634,7 @@ internal HType() : base(IntPtr.Zero, true)
652
634
653
635
protected override bool ReleaseHandle ( )
654
636
{
655
- // var atenTensor = new AtenSharp.IntTensor(THS_getTHTensorUnsafe(this));
656
- // atenTensor.Dispose();
657
- if ( shouldClean )
658
- {
659
- THS_Delete ( this ) ;
660
- }
637
+ THS_Delete ( this ) ;
661
638
return true ;
662
639
}
663
640
@@ -672,10 +649,9 @@ protected override void Dispose(bool disposing)
672
649
673
650
internal HType handle ;
674
651
675
- internal IntTensor ( HType handle , bool shouldClean = true )
652
+ internal IntTensor ( HType handle )
676
653
{
677
654
this . handle = handle ;
678
- this . handle . shouldClean = shouldClean ;
679
655
}
680
656
681
657
/// <summary>
@@ -944,8 +920,6 @@ public class LongTensor : ITorchTensor<long>
944
920
945
921
internal sealed class HType : SafeHandle
946
922
{
947
- internal bool shouldClean = true ;
948
-
949
923
public HType ( IntPtr preexistingHandle , bool ownsHandle ) : base ( IntPtr . Zero , ownsHandle )
950
924
{
951
925
SetHandle ( preexistingHandle ) ;
@@ -960,12 +934,7 @@ internal HType() : base(IntPtr.Zero, true)
960
934
961
935
protected override bool ReleaseHandle ( )
962
936
{
963
- // var atenTensor = new AtenSharp.LongTensor(THS_getTHTensorUnsafe(this));
964
- // atenTensor.Dispose();
965
- if ( shouldClean )
966
- {
967
- THS_Delete ( this ) ;
968
- }
937
+ THS_Delete ( this ) ;
969
938
return true ;
970
939
}
971
940
@@ -980,10 +949,9 @@ protected override void Dispose(bool disposing)
980
949
981
950
internal HType handle ;
982
951
983
- internal LongTensor ( HType handle , bool shouldClean = true )
952
+ internal LongTensor ( HType handle )
984
953
{
985
954
this . handle = handle ;
986
- this . handle . shouldClean = shouldClean ;
987
955
}
988
956
989
957
/// <summary>
@@ -1252,8 +1220,6 @@ public class DoubleTensor : ITorchTensor<double>
1252
1220
1253
1221
internal sealed class HType : SafeHandle
1254
1222
{
1255
- internal bool shouldClean = true ;
1256
-
1257
1223
public HType ( IntPtr preexistingHandle , bool ownsHandle ) : base ( IntPtr . Zero , ownsHandle )
1258
1224
{
1259
1225
SetHandle ( preexistingHandle ) ;
@@ -1268,12 +1234,7 @@ internal HType() : base(IntPtr.Zero, true)
1268
1234
1269
1235
protected override bool ReleaseHandle ( )
1270
1236
{
1271
- // var atenTensor = new AtenSharp.DoubleTensor(THS_getTHTensorUnsafe(this));
1272
- // atenTensor.Dispose();
1273
- if ( shouldClean )
1274
- {
1275
- THS_Delete ( this ) ;
1276
- }
1237
+ THS_Delete ( this ) ;
1277
1238
return true ;
1278
1239
}
1279
1240
@@ -1288,10 +1249,9 @@ protected override void Dispose(bool disposing)
1288
1249
1289
1250
internal HType handle ;
1290
1251
1291
- internal DoubleTensor ( HType handle , bool shouldClean = true )
1252
+ internal DoubleTensor ( HType handle )
1292
1253
{
1293
1254
this . handle = handle ;
1294
- this . handle . shouldClean = shouldClean ;
1295
1255
}
1296
1256
1297
1257
/// <summary>
@@ -1560,8 +1520,6 @@ public class FloatTensor : ITorchTensor<float>
1560
1520
1561
1521
internal sealed class HType : SafeHandle
1562
1522
{
1563
- internal bool shouldClean = true ;
1564
-
1565
1523
public HType ( IntPtr preexistingHandle , bool ownsHandle ) : base ( IntPtr . Zero , ownsHandle )
1566
1524
{
1567
1525
SetHandle ( preexistingHandle ) ;
@@ -1576,12 +1534,7 @@ internal HType() : base(IntPtr.Zero, true)
1576
1534
1577
1535
protected override bool ReleaseHandle ( )
1578
1536
{
1579
- // var atenTensor = new AtenSharp.FloatTensor(THS_getTHTensorUnsafe(this));
1580
- // atenTensor.Dispose();
1581
- if ( shouldClean )
1582
- {
1583
- THS_Delete ( this ) ;
1584
- }
1537
+ THS_Delete ( this ) ;
1585
1538
return true ;
1586
1539
}
1587
1540
@@ -1596,10 +1549,9 @@ protected override void Dispose(bool disposing)
1596
1549
1597
1550
internal HType handle ;
1598
1551
1599
- internal FloatTensor ( HType handle , bool shouldClean = true )
1552
+ internal FloatTensor ( HType handle )
1600
1553
{
1601
1554
this . handle = handle ;
1602
- this . handle . shouldClean = shouldClean ;
1603
1555
}
1604
1556
1605
1557
/// <summary>
@@ -1866,33 +1818,33 @@ internal enum ATenScalarMapping : short
1866
1818
1867
1819
public static class TensorExtensionMethods
1868
1820
{
1869
- internal static ITorchTensor < T > ToTorchTensor < T > ( this IntPtr rawTensor , bool shouldClean = true )
1821
+ internal static ITorchTensor < T > ToTorchTensor < T > ( this IntPtr rawTensor )
1870
1822
{
1871
1823
switch ( true )
1872
1824
{
1873
1825
case bool _ when typeof ( T ) == typeof ( byte ) :
1874
1826
{
1875
- return ( ITorchTensor < T > ) new ByteTensor ( new ByteTensor . HType ( rawTensor , true ) , shouldClean ) ;
1827
+ return ( ITorchTensor < T > ) new ByteTensor ( new ByteTensor . HType ( rawTensor , true ) ) ;
1876
1828
}
1877
1829
case bool _ when typeof ( T ) == typeof ( short ) :
1878
1830
{
1879
- return ( ITorchTensor < T > ) new ShortTensor ( new ShortTensor . HType ( rawTensor , true ) , shouldClean ) ;
1831
+ return ( ITorchTensor < T > ) new ShortTensor ( new ShortTensor . HType ( rawTensor , true ) ) ;
1880
1832
}
1881
1833
case bool _ when typeof ( T ) == typeof ( int ) :
1882
1834
{
1883
- return ( ITorchTensor < T > ) new IntTensor ( new IntTensor . HType ( rawTensor , true ) , shouldClean ) ;
1835
+ return ( ITorchTensor < T > ) new IntTensor ( new IntTensor . HType ( rawTensor , true ) ) ;
1884
1836
}
1885
1837
case bool _ when typeof ( T ) == typeof ( long ) :
1886
1838
{
1887
- return ( ITorchTensor < T > ) new LongTensor ( new LongTensor . HType ( rawTensor , true ) , shouldClean ) ;
1839
+ return ( ITorchTensor < T > ) new LongTensor ( new LongTensor . HType ( rawTensor , true ) ) ;
1888
1840
}
1889
1841
case bool _ when typeof ( T ) == typeof ( double ) :
1890
1842
{
1891
- return ( ITorchTensor < T > ) new DoubleTensor ( new DoubleTensor . HType ( rawTensor , true ) , shouldClean ) ;
1843
+ return ( ITorchTensor < T > ) new DoubleTensor ( new DoubleTensor . HType ( rawTensor , true ) ) ;
1892
1844
}
1893
1845
case bool _ when typeof ( T ) == typeof ( float ) :
1894
1846
{
1895
- return ( ITorchTensor < T > ) new FloatTensor ( new FloatTensor . HType ( rawTensor , true ) , shouldClean ) ;
1847
+ return ( ITorchTensor < T > ) new FloatTensor ( new FloatTensor . HType ( rawTensor , true ) ) ;
1896
1848
}
1897
1849
default : throw new NotImplementedException ( $ "Creating tensor of type { typeof ( T ) } is not supported.") ;
1898
1850
}
0 commit comments