Skip to content

Commit

Permalink
Added #nullable enable to a number of files.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasGustafsson committed Oct 30, 2024
1 parent 38f2dfc commit 2b01a71
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 40 deletions.
5 changes: 3 additions & 2 deletions src/TorchSharp/NN/ParameterList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using static TorchSharp.torch.nn;

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

public override Parameter get_parameter(string target)
public override Parameter? get_parameter(string target)
{
if (int.TryParse(target, out int idx) && idx > -1 && idx < _list.Count) {
return _list[idx];
}
return null;
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/TorchSharp/NN/Sequential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using static TorchSharp.torch;

#nullable enable
namespace TorchSharp
{
using System.Runtime.CompilerServices;
Expand All @@ -22,7 +23,7 @@ namespace Modules
/// This allows `Sequential.forward` to be implemented directly in this class, and to do so efficiently.
/// For scenarios where customization via derivation is useful, use one of the type-parameterized versions of
/// Sequential and implement the `forward` method in the derived class, which do not assume that the submodules
/// have a uniform Module base class.
/// have a uniform Module base class.
/// </remarks>
public class Sequential : torch.nn.Module<Tensor, Tensor>
{
Expand Down
7 changes: 4 additions & 3 deletions src/TorchSharp/NN/Utils/PackedSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using static TorchSharp.PInvoke.NativeMethods;

#nullable enable
namespace TorchSharp
{
public static partial class torch
Expand All @@ -20,7 +21,7 @@ public static partial class rnn
/// </summary>
public sealed class PackedSequence : IDisposable
{
internal DisposeScope OwningDisposeScope {
internal DisposeScope? OwningDisposeScope {
get => mOwningDisposeScope;
set {
mOwningDisposeScope = value;
Expand Down Expand Up @@ -81,7 +82,7 @@ protected override bool ReleaseHandle()
/// </summary>
internal bool IsInvalid => handle.IsInvalid;
private HType handle;
private DisposeScope mOwningDisposeScope;
private DisposeScope? mOwningDisposeScope;

internal PackedSequence(HType handle)
{
Expand Down Expand Up @@ -137,7 +138,7 @@ public PackedSequence MoveToOtherDisposeScope(PackedSequence other)
return MoveToOtherDisposeScope(other.OwningDisposeScope);
}

public PackedSequence MoveToOtherDisposeScope(DisposeScope other)
public PackedSequence MoveToOtherDisposeScope(DisposeScope? other)
{
if (OwningDisposeScope == null && other != null) {
other.Attach(this);
Expand Down
1 change: 1 addition & 0 deletions src/TorchSharp/Scalar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using static TorchSharp.PInvoke.NativeMethods;

#nullable enable
namespace TorchSharp
{
/// <summary>
Expand Down
53 changes: 27 additions & 26 deletions src/TorchSharp/Special.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using static TorchSharp.PInvoke.NativeMethods;

#nullable enable
namespace TorchSharp
{
public static partial class torch
Expand All @@ -14,7 +15,7 @@ public static class special
/// <param name="input">Input tensor</param>
/// <param name="out">Optional output tensor, will be modified if present.</param>
/// <returns></returns>
public static Tensor airy_ai(Tensor input, Tensor @out = null)
public static Tensor airy_ai(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_airy_ai(input.Handle) :
Expand All @@ -29,7 +30,7 @@ public static Tensor airy_ai(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor bessel_j0(Tensor input, Tensor @out = null)
public static Tensor bessel_j0(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_bessel_j0(input.Handle) :
Expand All @@ -44,7 +45,7 @@ public static Tensor bessel_j0(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor bessel_j1(Tensor input, Tensor @out = null)
public static Tensor bessel_j1(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_bessel_j1(input.Handle) :
Expand All @@ -59,7 +60,7 @@ public static Tensor bessel_j1(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor bessel_y0(Tensor input, Tensor @out = null)
public static Tensor bessel_y0(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_bessel_y0(input.Handle) :
Expand All @@ -74,7 +75,7 @@ public static Tensor bessel_y0(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor bessel_y1(Tensor input, Tensor @out = null)
public static Tensor bessel_y1(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_bessel_y1(input.Handle) :
Expand All @@ -89,7 +90,7 @@ public static Tensor bessel_y1(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor modified_bessel_i0(Tensor input, Tensor @out = null)
public static Tensor modified_bessel_i0(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_modified_bessel_i0(input.Handle) :
Expand All @@ -104,7 +105,7 @@ public static Tensor modified_bessel_i0(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor modified_bessel_i1(Tensor input, Tensor @out = null)
public static Tensor modified_bessel_i1(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_modified_bessel_i1(input.Handle) :
Expand All @@ -119,7 +120,7 @@ public static Tensor modified_bessel_i1(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor modified_bessel_k0(Tensor input, Tensor @out = null)
public static Tensor modified_bessel_k0(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_modified_bessel_k0(input.Handle) :
Expand All @@ -134,7 +135,7 @@ public static Tensor modified_bessel_k0(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor modified_bessel_k1(Tensor input, Tensor @out = null)
public static Tensor modified_bessel_k1(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_modified_bessel_k1(input.Handle) :
Expand All @@ -149,7 +150,7 @@ public static Tensor modified_bessel_k1(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor scaled_modified_bessel_k0(Tensor input, Tensor @out = null)
public static Tensor scaled_modified_bessel_k0(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_scaled_modified_bessel_k0(input.Handle) :
Expand All @@ -164,7 +165,7 @@ public static Tensor scaled_modified_bessel_k0(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor scaled_modified_bessel_k1(Tensor input, Tensor @out = null)
public static Tensor scaled_modified_bessel_k1(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_scaled_modified_bessel_k1(input.Handle) :
Expand All @@ -179,7 +180,7 @@ public static Tensor scaled_modified_bessel_k1(Tensor input, Tensor @out = null)
/// </summary>
/// <param name="input">The input tensor</param>
/// <param name="out">An optional output tensor, which will be modified if present.</param>
public static Tensor spherical_bessel_j0(Tensor input, Tensor @out = null)
public static Tensor spherical_bessel_j0(Tensor input, Tensor? @out = null)
{
var res = @out is null ?
THSSpecial_spherical_bessel_j0(input.Handle) :
Expand All @@ -197,7 +198,7 @@ public static Tensor spherical_bessel_j0(Tensor input, Tensor @out = null)
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @out = null)
public static Tensor chebyshev_polynomial_t(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_chebyshev_polynomial_t(x.Handle, n.Handle) :
Expand All @@ -216,7 +217,7 @@ public static Tensor chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @out = nu
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @out = null)
public static Tensor chebyshev_polynomial_u(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_chebyshev_polynomial_u(x.Handle, n.Handle) :
Expand All @@ -234,7 +235,7 @@ public static Tensor chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @out = nu
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @out = null)
public static Tensor chebyshev_polynomial_v(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_chebyshev_polynomial_v(x.Handle, n.Handle) :
Expand All @@ -252,7 +253,7 @@ public static Tensor chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @out = nu
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @out = null)
public static Tensor chebyshev_polynomial_w(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_chebyshev_polynomial_w(x.Handle, n.Handle) :
Expand All @@ -270,7 +271,7 @@ public static Tensor chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @out = nu
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor shifted_chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @out = null)
public static Tensor shifted_chebyshev_polynomial_t(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_shifted_chebyshev_polynomial_t(x.Handle, n.Handle) :
Expand All @@ -289,7 +290,7 @@ public static Tensor shifted_chebyshev_polynomial_t(Tensor x, Tensor n, Tensor @
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor shifted_chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @out = null)
public static Tensor shifted_chebyshev_polynomial_u(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_shifted_chebyshev_polynomial_u(x.Handle, n.Handle) :
Expand All @@ -307,7 +308,7 @@ public static Tensor shifted_chebyshev_polynomial_u(Tensor x, Tensor n, Tensor @
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor shifted_chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @out = null)
public static Tensor shifted_chebyshev_polynomial_v(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_shifted_chebyshev_polynomial_v(x.Handle, n.Handle) :
Expand All @@ -325,7 +326,7 @@ public static Tensor shifted_chebyshev_polynomial_v(Tensor x, Tensor n, Tensor @
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor shifted_chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @out = null)
public static Tensor shifted_chebyshev_polynomial_w(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_shifted_chebyshev_polynomial_w(x.Handle, n.Handle) :
Expand All @@ -343,7 +344,7 @@ public static Tensor shifted_chebyshev_polynomial_w(Tensor x, Tensor n, Tensor @
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor hermite_polynomial_h(Tensor x, Tensor n, Tensor @out = null)
public static Tensor hermite_polynomial_h(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_hermite_polynomial_h(x.Handle, n.Handle) :
Expand All @@ -361,7 +362,7 @@ public static Tensor hermite_polynomial_h(Tensor x, Tensor n, Tensor @out = null
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor hermite_polynomial_he(Tensor x, Tensor n, Tensor @out = null)
public static Tensor hermite_polynomial_he(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_hermite_polynomial_he(x.Handle, n.Handle) :
Expand All @@ -373,14 +374,14 @@ public static Tensor hermite_polynomial_he(Tensor x, Tensor n, Tensor @out = nul

/// <summary>
/// Laguerre polynomials
///
///
/// See: https://en.wikipedia.org/wiki/Laguerre_polynomials
/// </summary>
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
/// <returns></returns>
public static Tensor laguerre_polynomial_l(Tensor x, Tensor n, Tensor @out = null)
public static Tensor laguerre_polynomial_l(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_laguerre_polynomial_l(x.Handle, n.Handle) :
Expand All @@ -392,13 +393,13 @@ public static Tensor laguerre_polynomial_l(Tensor x, Tensor n, Tensor @out = nul

/// <summary>
/// Legendre polynomials
///
///
/// https://en.wikipedia.org/wiki/Legendre_polynomials
/// </summary>
/// <param name="x">The input tensor.</param>
/// <param name="n">n</param>
/// <param name="out">An optional output tensor.</param>
public static Tensor legendre_polynomial_p(Tensor x, Tensor n, Tensor @out = null)
public static Tensor legendre_polynomial_p(Tensor x, Tensor n, Tensor? @out =null)
{
var res = @out is null ?
THSSpecial_legendre_polynomial_p(x.Handle, n.Handle) :
Expand Down
Loading

0 comments on commit 2b01a71

Please sign in to comment.