22using System ;
33using static TorchSharp . PInvoke . NativeMethods ;
44
5+ #nullable enable
56namespace TorchSharp
67{
78 public static partial class torch
@@ -19,13 +20,18 @@ public static partial class functional
1920 /// <param name="eps">small value to avoid division by zero</param>
2021 public static Tensor normalize ( Tensor input , double p = 2.0 , long dim = 1L , double eps = 1e-12 )
2122 {
22- return null ;
23+ var res = THSNN_normalize (
24+ input . Handle ,
25+ p , dim , eps ) ;
26+ if ( res == IntPtr . Zero )
27+ torch . CheckForErrors ( ) ;
28+ return new Tensor ( res ) ;
2329 }
2430
2531 /// <summary>
2632 /// Applies Batch Normalization for each channel across a batch of data.
2733 /// </summary>
28- public static Tensor batch_norm ( Tensor input , Tensor running_mean , Tensor running_var , Tensor weight = null , Tensor bias = null , bool training = false , double momentum = 0.1 , double eps = 1e-5 )
34+ public static Tensor batch_norm ( Tensor input , Tensor running_mean , Tensor running_var , Tensor ? weight = null , Tensor ? bias = null , bool training = false , double momentum = 0.1 , double eps = 1e-5 )
2935 {
3036 var res = THSNN_batch_norm (
3137 input . Handle ,
@@ -43,7 +49,7 @@ public static Tensor batch_norm(Tensor input, Tensor running_mean, Tensor runnin
4349 /// <summary>
4450 /// Applies Group Normalization for last certain number of dimensions.
4551 /// </summary>
46- public static Tensor group_norm ( Tensor input , long num_groups , Tensor weight = null , Tensor bias = null , double eps = 1e-5 )
52+ public static Tensor group_norm ( Tensor input , long num_groups , Tensor ? weight = null , Tensor ? bias = null , double eps = 1e-5 )
4753 {
4854 var res = THSNN_group_norm (
4955 input . Handle ,
@@ -59,7 +65,7 @@ public static Tensor group_norm(Tensor input, long num_groups, Tensor weight = n
5965 /// <summary>
6066 /// Applies Instance Normalization for each channel in each data sample in a batch.
6167 /// </summary>
62- public static Tensor instance_norm ( Tensor input , Tensor running_mean = null , Tensor running_var = null , Tensor weight = null , Tensor bias = null , bool use_input_stats = true , double momentum = 0.1 , double eps = 1e-5 )
68+ public static Tensor instance_norm ( Tensor input , Tensor ? running_mean = null , Tensor ? running_var = null , Tensor ? weight = null , Tensor ? bias = null , bool use_input_stats = true , double momentum = 0.1 , double eps = 1e-5 )
6369 {
6470 var res = THSNN_instance_norm (
6571 input . Handle ,
@@ -77,7 +83,7 @@ public static Tensor instance_norm(Tensor input, Tensor running_mean = null, Ten
7783 /// <summary>
7884 /// Applies Layer Normalization for last certain number of dimensions.
7985 /// </summary>
80- public static Tensor layer_norm ( Tensor input , long [ ] normalized_shape , Tensor weight = null , Tensor bias = null , double eps = 1e-5 )
86+ public static Tensor layer_norm ( Tensor input , long [ ] normalized_shape , Tensor ? weight = null , Tensor ? bias = null , double eps = 1e-5 )
8187 {
8288 IntPtr res ;
8389 unsafe {
0 commit comments