@@ -15,7 +15,6 @@ internal Linear (IntPtr handle, IntPtr boxedHandle) : base (handle, boxedHandle)
1515 public new static Linear Load ( String modelPath )
1616 {
1717 var res = Module . Load ( modelPath ) ;
18- Torch . CheckForErrors ( ) ;
1918 return new Linear ( res . handle . DangerousGetHandle ( ) , IntPtr . Zero ) ;
2019 }
2120
@@ -25,7 +24,7 @@ internal Linear (IntPtr handle, IntPtr boxedHandle) : base (handle, boxedHandle)
2524 public TorchTensor Forward ( TorchTensor tensor )
2625 {
2726 var res = THSNN_Linear_forward ( handle , tensor . Handle ) ;
28- Torch . CheckForErrors ( ) ;
27+ if ( res == IntPtr . Zero ) { Torch . CheckForErrors ( ) ; }
2928 return new TorchTensor ( res ) ;
3029 }
3130 [ DllImport ( "LibTorchSharp" ) ]
@@ -36,7 +35,7 @@ public TorchTensor Forward (TorchTensor tensor)
3635 public TorchTensor ? Bias {
3736 get {
3837 var res = THSNN_Linear_bias ( handle ) ;
39- Torch . CheckForErrors ( ) ;
38+ if ( res == IntPtr . Zero ) { Torch . CheckForErrors ( ) ; }
4039 return ( ( res == IntPtr . Zero ) ? null : new TorchTensor ( res ) ) ;
4140 }
4241 set {
@@ -52,7 +51,7 @@ public TorchTensor? Bias {
5251 public TorchTensor Weight {
5352 get {
5453 var res = THSNN_Linear_weight ( handle ) ;
55- Torch . CheckForErrors ( ) ;
54+ if ( res == IntPtr . Zero ) { Torch . CheckForErrors ( ) ; }
5655 return new TorchTensor ( res ) ;
5756 }
5857 set {
@@ -69,7 +68,7 @@ public static partial class Modules
6968 static public Linear Linear ( long inputSize , long outputSize , bool hasBias = true )
7069 {
7170 var res = THSNN_Linear_ctor ( inputSize , outputSize , hasBias , out var boxedHandle ) ;
72- Torch . CheckForErrors ( ) ;
71+ if ( res == IntPtr . Zero ) { Torch . CheckForErrors ( ) ; }
7372 return new Linear ( res , boxedHandle ) ;
7473 }
7574 }
0 commit comments