Skip to content

Commit 2b01a71

Browse files
Added #nullable enable to a number of files.
1 parent 38f2dfc commit 2b01a71

File tree

9 files changed

+49
-40
lines changed

9 files changed

+49
-40
lines changed

src/TorchSharp/NN/ParameterList.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using static TorchSharp.torch.nn;
55

6+
#nullable enable
67
namespace TorchSharp
78
{
89
using System.Linq;
@@ -43,15 +44,15 @@ public override bool has_parameter(string target)
4344
return int.TryParse(target, out int idx) && idx > -1 && idx < _list.Count && _list[idx] is not null;
4445
}
4546

46-
public override Parameter get_parameter(string target)
47+
public override Parameter? get_parameter(string target)
4748
{
4849
if (int.TryParse(target, out int idx) && idx > -1 && idx < _list.Count) {
4950
return _list[idx];
5051
}
5152
return null;
5253
}
5354

54-
protected override void _toEpilog(torch.ScalarType? dtype, torch.Device device, bool non_blocking)
55+
protected override void _toEpilog(torch.ScalarType? dtype, torch.Device? device, bool non_blocking)
5556
{
5657
for (int i = 0; i < _list.Count; i++) {
5758

src/TorchSharp/NN/Sequential.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using static TorchSharp.torch;
88

9+
#nullable enable
910
namespace TorchSharp
1011
{
1112
using System.Runtime.CompilerServices;
@@ -22,7 +23,7 @@ namespace Modules
2223
/// This allows `Sequential.forward` to be implemented directly in this class, and to do so efficiently.
2324
/// For scenarios where customization via derivation is useful, use one of the type-parameterized versions of
2425
/// Sequential and implement the `forward` method in the derived class, which do not assume that the submodules
25-
/// have a uniform Module base class.
26+
/// have a uniform Module base class.
2627
/// </remarks>
2728
public class Sequential : torch.nn.Module<Tensor, Tensor>
2829
{

src/TorchSharp/NN/Utils/PackedSequence.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Runtime.InteropServices;
66
using static TorchSharp.PInvoke.NativeMethods;
77

8+
#nullable enable
89
namespace TorchSharp
910
{
1011
public static partial class torch
@@ -20,7 +21,7 @@ public static partial class rnn
2021
/// </summary>
2122
public sealed class PackedSequence : IDisposable
2223
{
23-
internal DisposeScope OwningDisposeScope {
24+
internal DisposeScope? OwningDisposeScope {
2425
get => mOwningDisposeScope;
2526
set {
2627
mOwningDisposeScope = value;
@@ -81,7 +82,7 @@ protected override bool ReleaseHandle()
8182
/// </summary>
8283
internal bool IsInvalid => handle.IsInvalid;
8384
private HType handle;
84-
private DisposeScope mOwningDisposeScope;
85+
private DisposeScope? mOwningDisposeScope;
8586

8687
internal PackedSequence(HType handle)
8788
{
@@ -137,7 +138,7 @@ public PackedSequence MoveToOtherDisposeScope(PackedSequence other)
137138
return MoveToOtherDisposeScope(other.OwningDisposeScope);
138139
}
139140

140-
public PackedSequence MoveToOtherDisposeScope(DisposeScope other)
141+
public PackedSequence MoveToOtherDisposeScope(DisposeScope? other)
141142
{
142143
if (OwningDisposeScope == null && other != null) {
143144
other.Attach(this);

src/TorchSharp/Scalar.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using static TorchSharp.PInvoke.NativeMethods;
44

5+
#nullable enable
56
namespace TorchSharp
67
{
78
/// <summary>

src/TorchSharp/Special.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using static TorchSharp.PInvoke.NativeMethods;
44

5+
#nullable enable
56
namespace TorchSharp
67
{
78
public static partial class torch
@@ -14,7 +15,7 @@ public static class special
1415
/// <param name="input">Input tensor</param>
1516
/// <param name="out">Optional output tensor, will be modified if present.</param>
1617
/// <returns></returns>
17-
public static Tensor airy_ai(Tensor input, Tensor @out = null)
18+
public static Tensor airy_ai(Tensor input, Tensor? @out = null)
1819
{
1920
var res = @out is null ?
2021
THSSpecial_airy_ai(input.Handle) :
@@ -29,7 +30,7 @@ public static Tensor airy_ai(Tensor input, Tensor @out = null)
2930
/// </summary>
3031
/// <param name="input">The input tensor</param>
3132
/// <param name="out">An optional output tensor, which will be modified if present.</param>
32-
public static Tensor bessel_j0(Tensor input, Tensor @out = null)
33+
public static Tensor bessel_j0(Tensor input, Tensor? @out = null)
3334
{
3435
var res = @out is null ?
3536
THSSpecial_bessel_j0(input.Handle) :
@@ -44,7 +45,7 @@ public static Tensor bessel_j0(Tensor input, Tensor @out = null)
4445
/// </summary>
4546
/// <param name="input">The input tensor</param>
4647
/// <param name="out">An optional output tensor, which will be modified if present.</param>
47-
public static Tensor bessel_j1(Tensor input, Tensor @out = null)
48+
public static Tensor bessel_j1(Tensor input, Tensor? @out = null)
4849
{
4950
var res = @out is null ?
5051
THSSpecial_bessel_j1(input.Handle) :
@@ -59,7 +60,7 @@ public static Tensor bessel_j1(Tensor input, Tensor @out = null)
5960
/// </summary>
6061
/// <param name="input">The input tensor</param>
6162
/// <param name="out">An optional output tensor, which will be modified if present.</param>
62-
public static Tensor bessel_y0(Tensor input, Tensor @out = null)
63+
public static Tensor bessel_y0(Tensor input, Tensor? @out = null)
6364
{
6465
var res = @out is null ?
6566
THSSpecial_bessel_y0(input.Handle) :
@@ -74,7 +75,7 @@ public static Tensor bessel_y0(Tensor input, Tensor @out = null)
7475
/// </summary>
7576
/// <param name="input">The input tensor</param>
7677
/// <param name="out">An optional output tensor, which will be modified if present.</param>
77-
public static Tensor bessel_y1(Tensor input, Tensor @out = null)
78+
public static Tensor bessel_y1(Tensor input, Tensor? @out = null)
7879
{
7980
var res = @out is null ?
8081
THSSpecial_bessel_y1(input.Handle) :
@@ -89,7 +90,7 @@ public static Tensor bessel_y1(Tensor input, Tensor @out = null)
8990
/// </summary>
9091
/// <param name="input">The input tensor</param>
9192
/// <param name="out">An optional output tensor, which will be modified if present.</param>
92-
public static Tensor modified_bessel_i0(Tensor input, Tensor @out = null)
93+
public static Tensor modified_bessel_i0(Tensor input, Tensor? @out = null)
9394
{
9495
var res = @out is null ?
9596
THSSpecial_modified_bessel_i0(input.Handle) :
@@ -104,7 +105,7 @@ public static Tensor modified_bessel_i0(Tensor input, Tensor @out = null)
104105
/// </summary>
105106
/// <param name="input">The input tensor</param>
106107
/// <param name="out">An optional output tensor, which will be modified if present.</param>
107-
public static Tensor modified_bessel_i1(Tensor input, Tensor @out = null)
108+
public static Tensor modified_bessel_i1(Tensor input, Tensor? @out = null)
108109
{
109110
var res = @out is null ?
110111
THSSpecial_modified_bessel_i1(input.Handle) :
@@ -119,7 +120,7 @@ public static Tensor modified_bessel_i1(Tensor input, Tensor @out = null)
119120
/// </summary>
120121
/// <param name="input">The input tensor</param>
121122
/// <param name="out">An optional output tensor, which will be modified if present.</param>
122-
public static Tensor modified_bessel_k0(Tensor input, Tensor @out = null)
123+
public static Tensor modified_bessel_k0(Tensor input, Tensor? @out = null)
123124
{
124125
var res = @out is null ?
125126
THSSpecial_modified_bessel_k0(input.Handle) :
@@ -134,7 +135,7 @@ public static Tensor modified_bessel_k0(Tensor input, Tensor @out = null)
134135
/// </summary>
135136
/// <param name="input">The input tensor</param>
136137
/// <param name="out">An optional output tensor, which will be modified if present.</param>
137-
public static Tensor modified_bessel_k1(Tensor input, Tensor @out = null)
138+
public static Tensor modified_bessel_k1(Tensor input, Tensor? @out = null)
138139
{
139140
var res = @out is null ?
140141
THSSpecial_modified_bessel_k1(input.Handle) :
@@ -149,7 +150,7 @@ public static Tensor modified_bessel_k1(Tensor input, Tensor @out = null)
149150
/// </summary>
150151
/// <param name="input">The input tensor</param>
151152
/// <param name="out">An optional output tensor, which will be modified if present.</param>
152-
public static Tensor scaled_modified_bessel_k0(Tensor input, Tensor @out = null)
153+
public static Tensor scaled_modified_bessel_k0(Tensor input, Tensor? @out = null)
153154
{
154155
var res = @out is null ?
155156
THSSpecial_scaled_modified_bessel_k0(input.Handle) :
@@ -164,7 +165,7 @@ public static Tensor scaled_modified_bessel_k0(Tensor input, Tensor @out = null)
164165
/// </summary>
165166
/// <param name="input">The input tensor</param>
166167
/// <param name="out">An optional output tensor, which will be modified if present.</param>
167-
public static Tensor scaled_modified_bessel_k1(Tensor input, Tensor @out = null)
168+
public static Tensor scaled_modified_bessel_k1(Tensor input, Tensor? @out = null)
168169
{
169170
var res = @out is null ?
170171
THSSpecial_scaled_modified_bessel_k1(input.Handle) :
@@ -179,7 +180,7 @@ public static Tensor scaled_modified_bessel_k1(Tensor input, Tensor @out = null)
179180
/// </summary>
180181
/// <param name="input">The input tensor</param>
181182
/// <param name="out">An optional output tensor, which will be modified if present.</param>
182-
public static Tensor spherical_bessel_j0(Tensor input, Tensor @out = null)
183+
public static Tensor spherical_bessel_j0(Tensor input, Tensor? @out = null)
183184
{
184185
var res = @out is null ?
185186
THSSpecial_spherical_bessel_j0(input.Handle) :
@@ -197,7 +198,7 @@ public static Tensor spherical_bessel_j0(Tensor input, Tensor @out = null)
197198
/// <param name="x">The input tensor.</param>
198199
/// <param name="n">n</param>
199200
/// <param name="out">An optional output tensor.</param>
200-
public static Tensor chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @out = null)
201+
public static Tensor chebyshev_polynomial_t(Tensor x, Tensor n, Tensor? @out =null)
201202
{
202203
var res = @out is null ?
203204
THSSpecial_chebyshev_polynomial_t(x.Handle, n.Handle) :
@@ -216,7 +217,7 @@ public static Tensor chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @out = nu
216217
/// <param name="x">The input tensor.</param>
217218
/// <param name="n">n</param>
218219
/// <param name="out">An optional output tensor.</param>
219-
public static Tensor chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @out = null)
220+
public static Tensor chebyshev_polynomial_u(Tensor x, Tensor n, Tensor? @out =null)
220221
{
221222
var res = @out is null ?
222223
THSSpecial_chebyshev_polynomial_u(x.Handle, n.Handle) :
@@ -234,7 +235,7 @@ public static Tensor chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @out = nu
234235
/// <param name="x">The input tensor.</param>
235236
/// <param name="n">n</param>
236237
/// <param name="out">An optional output tensor.</param>
237-
public static Tensor chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @out = null)
238+
public static Tensor chebyshev_polynomial_v(Tensor x, Tensor n, Tensor? @out =null)
238239
{
239240
var res = @out is null ?
240241
THSSpecial_chebyshev_polynomial_v(x.Handle, n.Handle) :
@@ -252,7 +253,7 @@ public static Tensor chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @out = nu
252253
/// <param name="x">The input tensor.</param>
253254
/// <param name="n">n</param>
254255
/// <param name="out">An optional output tensor.</param>
255-
public static Tensor chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @out = null)
256+
public static Tensor chebyshev_polynomial_w(Tensor x, Tensor n, Tensor? @out =null)
256257
{
257258
var res = @out is null ?
258259
THSSpecial_chebyshev_polynomial_w(x.Handle, n.Handle) :
@@ -270,7 +271,7 @@ public static Tensor chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @out = nu
270271
/// <param name="x">The input tensor.</param>
271272
/// <param name="n">n</param>
272273
/// <param name="out">An optional output tensor.</param>
273-
public static Tensor shifted_chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @out = null)
274+
public static Tensor shifted_chebyshev_polynomial_t(Tensor x, Tensor n, Tensor? @out =null)
274275
{
275276
var res = @out is null ?
276277
THSSpecial_shifted_chebyshev_polynomial_t(x.Handle, n.Handle) :
@@ -289,7 +290,7 @@ public static Tensor shifted_chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @
289290
/// <param name="x">The input tensor.</param>
290291
/// <param name="n">n</param>
291292
/// <param name="out">An optional output tensor.</param>
292-
public static Tensor shifted_chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @out = null)
293+
public static Tensor shifted_chebyshev_polynomial_u(Tensor x, Tensor n, Tensor? @out =null)
293294
{
294295
var res = @out is null ?
295296
THSSpecial_shifted_chebyshev_polynomial_u(x.Handle, n.Handle) :
@@ -307,7 +308,7 @@ public static Tensor shifted_chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @
307308
/// <param name="x">The input tensor.</param>
308309
/// <param name="n">n</param>
309310
/// <param name="out">An optional output tensor.</param>
310-
public static Tensor shifted_chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @out = null)
311+
public static Tensor shifted_chebyshev_polynomial_v(Tensor x, Tensor n, Tensor? @out =null)
311312
{
312313
var res = @out is null ?
313314
THSSpecial_shifted_chebyshev_polynomial_v(x.Handle, n.Handle) :
@@ -325,7 +326,7 @@ public static Tensor shifted_chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @
325326
/// <param name="x">The input tensor.</param>
326327
/// <param name="n">n</param>
327328
/// <param name="out">An optional output tensor.</param>
328-
public static Tensor shifted_chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @out = null)
329+
public static Tensor shifted_chebyshev_polynomial_w(Tensor x, Tensor n, Tensor? @out =null)
329330
{
330331
var res = @out is null ?
331332
THSSpecial_shifted_chebyshev_polynomial_w(x.Handle, n.Handle) :
@@ -343,7 +344,7 @@ public static Tensor shifted_chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @
343344
/// <param name="x">The input tensor.</param>
344345
/// <param name="n">n</param>
345346
/// <param name="out">An optional output tensor.</param>
346-
public static Tensor hermite_polynomial_h(Tensor x, Tensor n, Tensor @out = null)
347+
public static Tensor hermite_polynomial_h(Tensor x, Tensor n, Tensor? @out =null)
347348
{
348349
var res = @out is null ?
349350
THSSpecial_hermite_polynomial_h(x.Handle, n.Handle) :
@@ -361,7 +362,7 @@ public static Tensor hermite_polynomial_h(Tensor x, Tensor n, Tensor @out = null
361362
/// <param name="x">The input tensor.</param>
362363
/// <param name="n">n</param>
363364
/// <param name="out">An optional output tensor.</param>
364-
public static Tensor hermite_polynomial_he(Tensor x, Tensor n, Tensor @out = null)
365+
public static Tensor hermite_polynomial_he(Tensor x, Tensor n, Tensor? @out =null)
365366
{
366367
var res = @out is null ?
367368
THSSpecial_hermite_polynomial_he(x.Handle, n.Handle) :
@@ -373,14 +374,14 @@ public static Tensor hermite_polynomial_he(Tensor x, Tensor n, Tensor @out = nul
373374

374375
/// <summary>
375376
/// Laguerre polynomials
376-
///
377+
///
377378
/// See: https://en.wikipedia.org/wiki/Laguerre_polynomials
378379
/// </summary>
379380
/// <param name="x">The input tensor.</param>
380381
/// <param name="n">n</param>
381382
/// <param name="out">An optional output tensor.</param>
382383
/// <returns></returns>
383-
public static Tensor laguerre_polynomial_l(Tensor x, Tensor n, Tensor @out = null)
384+
public static Tensor laguerre_polynomial_l(Tensor x, Tensor n, Tensor? @out =null)
384385
{
385386
var res = @out is null ?
386387
THSSpecial_laguerre_polynomial_l(x.Handle, n.Handle) :
@@ -392,13 +393,13 @@ public static Tensor laguerre_polynomial_l(Tensor x, Tensor n, Tensor @out = nul
392393

393394
/// <summary>
394395
/// Legendre polynomials
395-
///
396+
///
396397
/// https://en.wikipedia.org/wiki/Legendre_polynomials
397398
/// </summary>
398399
/// <param name="x">The input tensor.</param>
399400
/// <param name="n">n</param>
400401
/// <param name="out">An optional output tensor.</param>
401-
public static Tensor legendre_polynomial_p(Tensor x, Tensor n, Tensor @out = null)
402+
public static Tensor legendre_polynomial_p(Tensor x, Tensor n, Tensor? @out =null)
402403
{
403404
var res = @out is null ?
404405
THSSpecial_legendre_polynomial_p(x.Handle, n.Handle) :

0 commit comments

Comments
 (0)