2
2
using System ;
3
3
using static TorchSharp . PInvoke . NativeMethods ;
4
4
5
+ #nullable enable
5
6
namespace TorchSharp
6
7
{
7
8
public static partial class torch
@@ -10,10 +11,27 @@ public static partial class nn
10
11
{
11
12
public static partial class functional
12
13
{
14
+ /// <summary>
15
+ /// Perform normalization of inputs over specified dimension.
16
+ /// </summary>
17
+ /// <param name="input">Input tensor of any shape.</param>
18
+ /// <param name="p">the exponent value in the norm formulation</param>
19
+ /// <param name="dim">the dimension to reduce</param>
20
+ /// <param name="eps">small value to avoid division by zero</param>
21
+ public static Tensor normalize ( Tensor input , double p = 2.0 , long dim = 1L , double eps = 1e-12 )
22
+ {
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 ) ;
29
+ }
30
+
13
31
/// <summary>
14
32
/// Applies Batch Normalization for each channel across a batch of data.
15
33
/// </summary>
16
- 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 )
17
35
{
18
36
var res = THSNN_batch_norm (
19
37
input . Handle ,
@@ -31,7 +49,7 @@ public static Tensor batch_norm(Tensor input, Tensor running_mean, Tensor runnin
31
49
/// <summary>
32
50
/// Applies Group Normalization for last certain number of dimensions.
33
51
/// </summary>
34
- 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 )
35
53
{
36
54
var res = THSNN_group_norm (
37
55
input . Handle ,
@@ -47,7 +65,7 @@ public static Tensor group_norm(Tensor input, long num_groups, Tensor weight = n
47
65
/// <summary>
48
66
/// Applies Instance Normalization for each channel in each data sample in a batch.
49
67
/// </summary>
50
- 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 )
51
69
{
52
70
var res = THSNN_instance_norm (
53
71
input . Handle ,
@@ -65,7 +83,7 @@ public static Tensor instance_norm(Tensor input, Tensor running_mean = null, Ten
65
83
/// <summary>
66
84
/// Applies Layer Normalization for last certain number of dimensions.
67
85
/// </summary>
68
- 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 )
69
87
{
70
88
IntPtr res ;
71
89
unsafe {
0 commit comments