docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Functional

    Represents the static functional methods for model building and compilation.

    Inheritance
    object
    Functional
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.InferenceEngine
    Assembly: Unity.InferenceEngine.dll
    Syntax
    [MovedFrom("Unity.Sentis")]
    public static class Functional
    Remarks

    The Functional class provides an API for creating and modifying neural network models by adding operators. This API enables you to build models from scratch with C# scripts. You can also edit existing models by adding operators before the model inputs or after its outputs.

    To use the Functional API, you work with FunctionalGraph objects to define model structure and FunctionalTensor objects to represent intermediate tensor values. A typical workflow is:

    1. Create a FunctionalGraph instance.
    2. Add inputs to the graph using AddInputs(Model).
    3. Construct the graph using Functional operators.
    4. Compile() the model to produce a runnable Model.

    The Functional class provides several categories of operators, which include:

    • Tensor creation and manipulation: ARange, Full, Reshape, Transpose, Squeeze, Gather, etc.
    • Mathematical operations: Add, MatMul, LogicalXor, etc.
    • Neural network layers: Conv2D, AvgPool3D, HardSigmoid, etc.
    • Reduction operations: CumSum, ReduceMean, ArgMax, etc.
    • Comparison operations: GreaterEqual, Less, etc.
    • More advanced operations: NMS for computer vision, STFT, and other spectral operations

    When editing existing models, use the Forward(Model, params FunctionalTensor[]) or ForwardWithCopy(Model, params FunctionalTensor[]) methods to incorporate the operations from a loaded model into your functional graph. The Forward(Model, params FunctionalTensor[]) method destructively modifies the source model for better performance, while ForwardWithCopy(Model, params FunctionalTensor[]) creates a copy to preserve the original.

    Performance considerations

    • The Compile() method is a slow operation that requires significant memory. It is recommended to run compilation offline and serialize the resulting model for runtime use.
    • Sentis applies automatic optimizations during compilation, so the actual operations executed during inference may differ from your API calls.
    • Operations return FunctionalTensor objects that represent computational graphs, not concrete data values. Inference computation occurs when you schedule the execution of the model on a Worker.

    The Functional API supports operator overloading on FunctionalTensor objects, allowing natural mathematical syntax.

    • Mathematical binary operators: x + y for Add, x - y for Sub, x * y for Mul, x / y for Div, x % y for Remainder
    • Mathematical unary operators: +x for Clone, -x for Neg
    • Logical operators: x & y for BitwiseAnd, x | y for BitwiseOr, x ^ y for BitwiseXor, ~x for BitwiseNot
    • Comparison operators: x > y for Greater, x >= y for GreaterEqual, x < y for Less, x <= y for LessEqual

    For a complete list of supported operations, refer to Supported functional methods.

    Examples

    The following example demonstrates how to use the Functional API to create a model from scratch.

    var graph = new FunctionalGraph();
    var x = graph.AddInput(DataType.Float, new TensorShape(2, 3));
    var y = graph.AddInput(DataType.Float, new TensorShape(2, 3));
    var z = graph.AddInput(DataType.Float, new TensorShape(2, 3));
    var add = x + y;
    var sqrt = Functional.Sqrt(z);
    var atan2 = Functional.Atan2(add, sqrt);
    graph.AddOutput(atan2);
    var model = graph.Compile();

    Methods

    ARange(int)

    Returns a 1D tensor of size ⌈end / step⌉ with values from the interval [0, end) with a step 1 beginning at 0.

    Declaration
    public static FunctionalTensor ARange(int end)
    Parameters
    Type Name Description
    int end

    The upper end of the interval.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with all integer values from 0 (included) to end (not included). The input value is an integer representing the end of the range. If end is less than or equal to 0, returns an empty tensor.

    Examples
    // Get a tensor with values [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    var tensor = Functional.ARange(10);

    ARange(int, int, int)

    Returns a 1D tensor of size ⌈(end − start) / step⌉ with values from the interval [start, end), with a step beginning from start.

    Declaration
    public static FunctionalTensor ARange(int start, int end, int step = 1)
    Parameters
    Type Name Description
    int start

    The value of the first element.

    int end

    The upper end of the interval.

    int step

    (Optional) The delta between each element. Default value is 1.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with all integer values from start (included) to end (not included), separated by the (optional) step value. The three inputs are integers: the start and end of the range, and the step between values. If end is less than or equal to start, the returned tensor is empty. The step parameter is optional and defaults to 1.

    Examples
    // Get a tensor with values [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    var tensor = Functional.ARange(0, 10);
    // Get a tensor with values [2, 5, 8, 11, 14]
    var tensor2 = Functional.ARange(2, 15, 3);

    ARange(float)

    Returns a 1D tensor of size ⌈end / step⌉ with values from the interval [0, end) with a step 1 beginning at 0.

    Declaration
    public static FunctionalTensor ARange(float end)
    Parameters
    Type Name Description
    float end

    The upper end of the interval.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with all float values from 0 (included) to end (not included). The input is a float value representing the end of the range. If end is less than or equal to 0, returns an empty tensor.

    Examples
    // Get a tensor with float values [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
    var tensor = Functional.ARange(10f);

    ARange(float, float, float)

    Returns a 1D tensor of size ⌈(end − start) / step⌉ with values from the interval [start, end), with a step beginning from start.

    Declaration
    public static FunctionalTensor ARange(float start, float end, float step = 1)
    Parameters
    Type Name Description
    float start

    The value of the first element.

    float end

    The upper end of the interval.

    float step

    (Optional) The delta between each element. Default value is 1.0.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with all float values from start (included) to end (not included), separated by the (optional) step value. The three inputs are floats: the start and end of the range, and the step between values. If end is less than or equal to start, the returned tensor is empty. The step parameter is optional and defaults to 1.0.

    Examples
    // Get a tensor with values [0.1, 1.2, 2.3, 3.4, 4.5, 5.6]
    var tensor = Functional.ARange(0.1f, 6f, 1.1f);
    // Get a tensor with values [2.2, 3.2, 4.2, 5.2, 6.2]
    var tensor = Functional.ARange(2.2f, 7f);

    Abs(FunctionalTensor)

    Returns |input| element-wise.

    Declaration
    public static FunctionalTensor Abs(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the absolute value of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { -2.5f, -1.0f, 0.0f, 1.5f, 3.0f });
    var result = Functional.Abs(input);
    // Result: [2.5, 1.0, 0.0, 1.5, 3.0]

    Acos(FunctionalTensor)

    Returns acos(input) element-wise.

    Declaration
    public static FunctionalTensor Acos(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the inverse cosine (arccosine) of each element in the input tensor. Mathematically defined for input values in [-1, 1]. Values outside this range will produce undefined results. The output is in radians in the range [0, π].

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Acos(input);
    // Result: [3.14159, 1.5708, 0.0] (approximately π, π/2, 0)

    Acosh(FunctionalTensor)

    Returns acosh(input) element-wise.

    Declaration
    public static FunctionalTensor Acosh(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the inverse hyperbolic cosine of each element in the input tensor. Mathematically defined for input values in [1, ∞). Values outside this range will produce undefined results.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.Acosh(input);
    // Result: [0.0, 1.317, 1.763] (approximately)

    Add(FunctionalTensor, FunctionalTensor)

    Returns input + other element-wise.

    Declaration
    public static FunctionalTensor Add(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise addition of two tensors. Promotes input and other to a compatible data type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var b = Functional.Constant(new[] { 4.0f, 5.0f, 6.0f });
    var result = Functional.Add(a, b);
    // Result: [5.0, 7.0, 9.0]

    AddBMM(FunctionalTensor, FunctionalTensor, FunctionalTensor)

    Performs a batch matrix-matrix product of matrices : y = x @ a + b. Uses the following tensors:

    • Bias tensor B with shape (N).
    • Weight tensor A with shape (K, N).
    • Input tensor X with shape (..., M, K).
    • Output tensor O with shape (..., M, N).
    Declaration
    public static FunctionalTensor AddBMM(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor X with shape (..., M, K).

    FunctionalTensor weight

    The weight tensor A with shape (K, N).

    FunctionalTensor bias

    The bias tensor B with shape (N).

    Returns
    Type Description
    FunctionalTensor

    The output tensor with shape (..., M, N).

    Remarks

    This operation performs matrix multiplication followed by bias addition: output = input @ weight + bias. The bias is broadcast-added to each row of the matrix multiplication result. Promotes all inputs to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var weight = Functional.Constant(new TensorShape(2, 2), new[] { 0.5f, 0.5f, 0.5f, 0.5f });
    var bias = Functional.Constant(new[] { 1.0f, -1.0f });
    var result = Functional.AddBMM(input, weight, bias);
    // Result: [[2.5, -0.5], [4.5, 2.5]]
    // Matrix multiply: [[1.5, 1.5], [3.5, 3.5]], then add bias to each row

    ArgMax(FunctionalTensor, int, bool)

    Returns the indices of the maximum value of the elements of the input along a dimension.

    Declaration
    public static FunctionalTensor ArgMax(FunctionalTensor input, int dim = 0, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation finds the index of the maximum value along the specified dimension. If keepdim is false (default), the output tensor has one fewer dimension than the input.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 3.5f, -2.0f, 3.0f });
    // Get indices of max values along dimension 1
    var tensor = Functional.ArgMax(input, dim: 1);
    // Result: [2, 0]
    // When keepdim is true, the resulting tensor has the same rank as the input
    var tensor2 = Functional.ArgMax(input, dim: 1, keepdim: true);
    // Result: [[2], [0]]

    ArgMin(FunctionalTensor, int, bool)

    Returns the indices of the minimum value of the elements of the input along a dimension.

    Declaration
    public static FunctionalTensor ArgMin(FunctionalTensor input, int dim = 0, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation finds the index of the minimum value along the specified dimension. If keepdim is false (default), the output tensor has one fewer dimension than the input.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 3.5f, -2.0f, 3.0f });
    // Get indices of min values along dimension 1
    var tensor = Functional.ArgMin(input, dim: 1);
    // Result: [0, 1]
    // When keepdim is true, the resulting tensor has the same rank as the input
    var tensor2 = Functional.ArgMin(input, dim: 1, keepdim: true);
    // Result: [[0], [1]]

    AsStrided(FunctionalTensor, int[], int[], int)

    Returns a tensor with shape size, filled with values taken from the input tensor using stride and offset.

    Declaration
    public static FunctionalTensor AsStrided(FunctionalTensor input, int[] size, int[] stride, int offset = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] size

    The shape of the output tensor.

    int[] stride

    The stride of the output tensor.

    int offset

    (Optional) The data offset of the output tensor. Default value is 0.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor of the given size, with values taken from the input tensor, using the stride, and starting at offset. The size is the shape of the created tensor. The stride determines the step in the input tensor for each dimension. The offset (optional) specifies the starting position in the input tensor.

    Examples
    var input = Functional.ARange(12); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
    // Create a tensor of shape [3, 2] from values in input tensor
    var strided = Functional.AsStrided(input, new int[] {3, 2}, new int[] {4, 1}, 0);
    // Result is a tensor of shape [3, 2], with values: [[0, 1], [4, 5], [8, 9]]

    Asin(FunctionalTensor)

    Returns asin(input) element-wise.

    Declaration
    public static FunctionalTensor Asin(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the inverse sine (arcsine) of each element in the input tensor. Mathematically defined for input values in [-1, 1]. Values outside this range will produce undefined results. The output is in radians in the range [-π/2, π/2].

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Asin(input);
    // Result: [-1.5708, 0.0, 1.5708] (approximately -π/2, 0, π/2)

    Asinh(FunctionalTensor)

    Returns asinh(input) element-wise.

    Declaration
    public static FunctionalTensor Asinh(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the inverse hyperbolic sine of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Asinh(input);
    // Result: [-0.881, 0.0, 0.881] (approximately)

    AtLeast1D(params FunctionalTensor[])

    Expands each input tensor with rank less than 1 to rank 1. Returns an array of expanded tensors.

    Declaration
    public static FunctionalTensor[] AtLeast1D(params FunctionalTensor[] tensors)
    Parameters
    Type Name Description
    FunctionalTensor[] tensors

    The input tensor array.

    Returns
    Type Description
    FunctionalTensor[]

    The output tensor array.

    Remarks

    This operation ensures that all input tensors have at least one dimension. Expands scalar tensors (rank 0) to shape [1]. Tensors with rank 1 or higher remain unchanged.

    Examples
    var scalar = Functional.Constant(5.0f); // Shape: []
    var vector = Functional.Constant(new[] { 1.0f, 2.0f }); // Shape: [2]
    var results = Functional.AtLeast1D(scalar, vector);
    // results[0] shape: [1], values: [5.0]
    // results[1] shape: [2], values: [1.0, 2.0] (unchanged)

    AtLeast2D(params FunctionalTensor[])

    Expands each input tensor with rank less than 2 to rank 2. Returns an array of expanded tensors.

    Declaration
    public static FunctionalTensor[] AtLeast2D(params FunctionalTensor[] tensors)
    Parameters
    Type Name Description
    FunctionalTensor[] tensors

    The input tensor array.

    Returns
    Type Description
    FunctionalTensor[]

    The output tensor array.

    Remarks

    This operation ensures that all input tensors have at least 2 dimensions. Expands tensors with rank less than 2 by prepending dimensions of size 1. Tensors with rank 2 or higher remain unchanged. Scalars become [1, 1], vectors become [1, n], and matrices remain unchanged.

    Examples
    var scalar = Functional.Constant(5.0f); // Shape: []
    var vector = Functional.Constant(new[] { 1.0f, 2.0f }); // Shape: [2]
    var matrix = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [2, 2]
    var results = Functional.AtLeast2D(scalar, vector, matrix);
    // results[0] shape: [1, 1], values: [[5.0]]
    // results[1] shape: [1, 2], values: [[1.0, 2.0]]
    // results[2] shape: [2, 2], values: [[1.0, 2.0], [3.0, 4.0]] (unchanged)

    AtLeast3D(params FunctionalTensor[])

    Expands each input tensor with rank less than 3 to rank 3. Returns an array of expanded tensors.

    Declaration
    public static FunctionalTensor[] AtLeast3D(params FunctionalTensor[] tensors)
    Parameters
    Type Name Description
    FunctionalTensor[] tensors

    The input tensor array.

    Returns
    Type Description
    FunctionalTensor[]

    The output tensor array.

    Remarks

    This operation ensures that all input tensors have at least 3 dimensions. Expands tensors with rank less than 3 by prepending dimensions of size 1, while tensors with rank 3 or higher remain unchanged. Scalars become [1, 1, 1], vectors become [1, 1, n], matrices become [1, m, n], and 3D tensors remain unchanged.

    Examples
    var scalar = Functional.Constant(5.0f); // Shape: []
    var vector = Functional.Constant(new[] { 1.0f, 2.0f }); // Shape: [2]
    var matrix = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [2, 2]
    var results = Functional.AtLeast3D(scalar, vector, matrix);
    // results[0] shape: [1, 1, 1], values: [[[5.0]]]
    // results[1] shape: [1, 1, 2], values: [[[1.0, 2.0]]]
    // results[2] shape: [1, 2, 2], values: [[[1.0, 2.0], [3.0, 4.0]]]

    Atan(FunctionalTensor)

    Returns atan(input) element-wise.

    Declaration
    public static FunctionalTensor Atan(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the inverse tangent (arctangent) of each element in the input tensor. The output is in radians in the range [-π/2, π/2].

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Atan(input);
    // Result: [-0.785, 0.0, 0.785] (approximately -π/4, 0, π/4)

    Atan2(FunctionalTensor, FunctionalTensor)

    Returns Atan2(input, other) element-wise.

    Declaration
    public static FunctionalTensor Atan2(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the arctangent of input/other, taking into account the signs of both arguments to determine the quadrant. The output is in radians in the range [-π, π].

    Examples
    var y = Functional.Constant(new[] { 1.0f, -1.0f, 0.0f });
    var x = Functional.Constant(new[] { 1.0f, 1.0f, -1.0f });
    var result = Functional.Atan2(y, x);
    // Result: [0.785, -0.785, 3.14159] (approximately π/4, -π/4, π)

    Atanh(FunctionalTensor)

    Returns atanh(input) element-wise.

    Declaration
    public static FunctionalTensor Atanh(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the inverse hyperbolic tangent of each element in the input tensor. Mathematically defined for input values in (-1, 1). Values outside this range will produce undefined results.

    Examples
    var input = Functional.Constant(new[] { -0.5f, 0.0f, 0.5f });
    var result = Functional.Atanh(input);
    // Result: [-0.549, 0.0, 0.549] (approximately)

    AvgPool1D(FunctionalTensor, int, int?, int)

    Returns the result of a 1D average pooling of the input.

    Declaration
    public static FunctionalTensor AvgPool1D(FunctionalTensor input, int kernelSize, int? stride = null, int padding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int kernelSize

    The size of the kernel.

    int? stride

    The optional stride of the pooling. The default value is the kernel size.

    int padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 1D average pooling to the input tensor by computing the average of elements within a sliding window. The input tensor must have rank 3 with shape [batch, channels, width]. The kernel slides over the spatial dimension with the specified stride, and applies padding symmetrically at both ends. The default stride is the kernel size (non-overlapping windows).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 6), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); // Shape: [1, 1, 6]
    var result = Functional.AvgPool1D(input, kernelSize: 2, stride: 2);
    // Result shape: [1, 1, 3]
    // Values: [[[1.5, 3.5, 5.5]]] (averages of [1,2], [3,4], [5,6])

    AvgPool2D(FunctionalTensor, int, int?, int)

    Returns the result of a 2D average pooling of the input.

    Declaration
    public static FunctionalTensor AvgPool2D(FunctionalTensor input, int kernelSize, int? stride = null, int padding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int kernelSize

    The size of the kernel.

    int? stride

    The optional stride of the pooling. The default value is the kernel size.

    int padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 2D average pooling to the input tensor by computing the average of elements within a sliding 2D window. The input tensor must have rank 4 with shape [batch, channels, height, width]. The kernel slides over the spatial dimensions with the specified stride, and applies padding symmetrically on all sides. The default stride is the kernel size (non-overlapping windows).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 4, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f }); // Shape: [1, 1, 4, 4]
    var result = Functional.AvgPool2D(input, kernelSize: 2, stride: 2);
    // Result shape: [1, 1, 2, 2]
    // Values: [[[[3.5, 5.5], [11.5, 13.5]]]] (average of each 2x2 block)

    AvgPool2D(FunctionalTensor, (int, int), (int, int)?, (int, int)?)

    Returns the result of a 2D average pooling of the input.

    Declaration
    public static FunctionalTensor AvgPool2D(FunctionalTensor input, (int, int) kernelSize, (int, int)? stride = null, (int, int)? padding = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    (int, int) kernelSize

    The size of the kernel.

    (int, int)? stride

    The optional stride of the pooling. The default value is the kernel size.

    (int, int)? padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 2D average pooling to the input tensor by computing the average of elements within a sliding 2D window. The input tensor must have rank 4 with shape [batch, channels, height, width]. This overload allows specifying different kernelSize, stride, and padding for height and width dimensions using tuples. The default stride is the kernel size for each dimension (non-overlapping windows).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 3, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }); // Shape: [1, 1, 3, 4]
    var result = Functional.AvgPool2D(input, kernelSize: (2, 2), stride: (1, 2));
    // Result shape: [1, 1, 2, 2]
    // Values: [[[[3.5, 5.5], [7.5, 9.5]]]]

    AvgPool3D(FunctionalTensor, int, int?, int)

    Returns the result of a 3D average pooling of the input.

    Declaration
    public static FunctionalTensor AvgPool3D(FunctionalTensor input, int kernelSize, int? stride = null, int padding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int kernelSize

    The size of the kernel.

    int? stride

    The optional stride of the pooling. The default value is the kernel size.

    int padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 3D average pooling to the input tensor by computing the average of elements within a sliding 3D window. The input tensor must have rank 5 with shape [batch, channels, depth, height, width]. The kernel slides over the spatial dimensions with the specified stride, and applies padding uniformly on all sides. The default stride is the kernel size (non-overlapping windows).

    Examples
    // Create a 3D tensor with shape [1, 1, 2, 2, 2] (batch=1, channels=1, 2x2x2 volume)
    var input = Functional.Constant(new TensorShape(1, 1, 2, 2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f });
    var result = Functional.AvgPool3D(input, kernelSize: 2, stride: 2);
    // Result shape: [1, 1, 1, 1, 1]
    // Values: [[[[[4.5]]]]] (average of all 8 elements)

    AvgPool3D(FunctionalTensor, (int, int, int), (int, int, int)?, (int, int, int)?)

    Returns the result of a 3D average pooling of the input.

    Declaration
    public static FunctionalTensor AvgPool3D(FunctionalTensor input, (int, int, int) kernelSize, (int, int, int)? stride = null, (int, int, int)? padding = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    (int, int, int) kernelSize

    The size of the kernel.

    (int, int, int)? stride

    The optional stride of the pooling. The default value is the kernel size.

    (int, int, int)? padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 3D average pooling to the input tensor by computing the average of elements within a sliding 3D window. The input tensor must have rank 5 with shape [batch, channels, depth, height, width]. This overload allows specifying different kernelSize, stride, and padding for each spatial dimension using tuples. The default stride is the kernel size for each dimension (non-overlapping windows).

    Examples
    // Create a 3D tensor with shape [1, 1, 2, 2, 4]
    var input = Functional.Constant(new TensorShape(1, 1, 2, 2, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f });
    var result = Functional.AvgPool3D(input, kernelSize: (2, 2, 2), stride: (2, 2, 2));
    // Result shape: [1, 1, 1, 1, 2]
    // Values: [[[[[7.5, 9.5]]]]]

    BatchNorm(FunctionalTensor, FunctionalTensor, FunctionalTensor, FunctionalTensor, FunctionalTensor, float)

    Returns the result of computing the mean variance on the second dimension of the input tensor and normalizes it according to the weight and bias.

    Declaration
    public static FunctionalTensor BatchNorm(FunctionalTensor input, FunctionalTensor runningMean, FunctionalTensor runningVar, FunctionalTensor weight, FunctionalTensor bias, float eps = 1E-05)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor runningMean

    The mean values tensor.

    FunctionalTensor runningVar

    The variance values tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The bias tensor.

    float eps

    The epsilon value used to avoid division by zero. Default is 1.0e-5.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies Batch Normalization to the input tensor. It normalizes the input using pre-computed runningMean and runningVar statistics, then scales and shifts by learned weight and bias parameters. The formula is: (input - runningMean) / sqrt(runningVar + eps) * weight + bias. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var runningMean = Functional.Constant(new[] { 2.5f });
    var runningVar = Functional.Constant(new[] { 1.25f });
    var weight = Functional.Constant(new[] { 1.0f });
    var bias = Functional.Constant(new[] { 0.0f });
    // Normalizes input using the running statistics
    var result = Functional.BatchNorm(input, runningMean, runningVar, weight, bias);

    Bernoulli(FunctionalTensor, DataType, int?)

    Returns an output generated with values 0 and 1 from a Bernoulli distribution.

    Declaration
    public static FunctionalTensor Bernoulli(FunctionalTensor input, DataType dataType = DataType.Int, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The probabilities used for generating the output values.

    DataType dataType

    The data type of the output.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random binary values (0 or 1) based on Bernoulli trials. Each element in the input tensor represents the probability of generating a 1 at that position. The output has the same shape as the input. You can provide an optional seed for reproducible results.

    Examples
    var probs = Functional.Constant(new[] { 0.0f, 0.5f, 1.0f });
    var result = Functional.Bernoulli(probs, DataType.Int, seed: 42);
    // Result: Binary values (0 or 1) based on probabilities
    // [0, 0/1 (random), 1]

    BitwiseAnd(FunctionalTensor, FunctionalTensor)

    Returns the bitwise AND input & other element-wise.

    Declaration
    public static FunctionalTensor BitwiseAnd(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise bitwise AND on integer tensors. The tensors must be of integer type and broadcastable to a common shape.

    Examples
    var a = Functional.Constant(new[] { 12, 15, 7 }); // Binary: 1100, 1111, 0111
    var b = Functional.Constant(new[] { 10, 9, 5 });  // Binary: 1010, 1001, 0101
    var result = Functional.BitwiseAnd(a, b);
    // Result: [8, 9, 5] (Binary: 1000, 1001, 0101)

    BitwiseNot(FunctionalTensor)

    Returns the bitwise NOT ~input element-wise.

    Declaration
    public static FunctionalTensor BitwiseNot(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise bitwise NOT (complement) on integer tensors. The tensor must be of integer type.

    Examples
    var input = Functional.Constant(new[] { 0, 1, 5, -1 });
    var result = Functional.BitwiseNot(input);
    // Result: [-1, -2, -6, 0] (bitwise complement)

    BitwiseOr(FunctionalTensor, FunctionalTensor)

    Returns the bitwise OR input | other element-wise.

    Declaration
    public static FunctionalTensor BitwiseOr(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise bitwise OR on integer tensors. The tensors must be of integer type and broadcastable to a common shape.

    Examples
    var a = Functional.Constant(new[] { 12, 15, 7 }); // Binary: 1100, 1111, 0111
    var b = Functional.Constant(new[] { 10, 9, 5 });  // Binary: 1010, 1001, 0101
    var result = Functional.BitwiseOr(a, b);
    // Result: [14, 15, 7] (Binary: 1110, 1111, 0111)

    BitwiseXor(FunctionalTensor, FunctionalTensor)

    Returns the bitwise XOR input ^ other element-wise.

    Declaration
    public static FunctionalTensor BitwiseXor(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise bitwise XOR (exclusive OR) on integer tensors. The tensors must be of integer type and broadcastable to a common shape.

    Examples
    var a = Functional.Constant(new[] { 12, 15, 7 }); // Binary: 1100, 1111, 0111
    var b = Functional.Constant(new[] { 10, 9, 5 });  // Binary: 1010, 1001, 0101
    var result = Functional.BitwiseXor(a, b);
    // Result: [6, 6, 2] (Binary: 0110, 0110, 0010)

    BlackmanWindow(int, bool)

    Returns a Blackman window of shape [windowLength].

    Declaration
    public static FunctionalTensor BlackmanWindow(int windowLength, bool periodic)
    Parameters
    Type Name Description
    int windowLength

    The size of the window.

    bool periodic

    If true, returns a window to use as a periodic function. If false, return a symmetric window.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates a Blackman window used for spectral analysis and filtering.

    Examples
    var window = Functional.BlackmanWindow(windowLength: 8, periodic: true);
    // Result: Blackman window with shape [8]: [0.0, 0.066, 0.34, 0.774, 1.0, 0.774, 0.34, 0.066]

    BroadcastTo(FunctionalTensor, int[])

    Returns the input tensor broadcasted to a shape.

    Declaration
    public static FunctionalTensor BroadcastTo(this FunctionalTensor input, int[] shape)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] shape

    The shape to broadcast to.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation expands the input tensor to match the specified shape by duplicating elements along dimensions of size 1. Broadcasting follows these rules: dimensions are aligned from right to left, and dimensions of size 1 can be expanded to any size. The input tensor's shape must be compatible with the target shape for broadcasting.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f }); // Shape: [3]
    var result = Functional.BroadcastTo(input, new[] { 2, 3 });
    // Result shape: [2, 3]
    // [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]

    Ceil(FunctionalTensor)

    Returns ⌈input⌉ element-wise.

    Declaration
    public static FunctionalTensor Ceil(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the ceiling (smallest integer greater than or equal to) of each element in the input tensor. If input is already an integer tensor, it is returned unchanged.

    Examples
    var input = Functional.Constant(new[] { -1.7f, -0.3f, 0.5f, 1.2f });
    var result = Functional.Ceil(input);
    // Result: [-1.0, 0.0, 1.0, 2.0]

    Celu(FunctionalTensor, float)

    Returns celu(input) element-wise.

    Declaration
    public static FunctionalTensor Celu(FunctionalTensor input, float alpha = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    float alpha

    The alpha value for the celu. Default is 1.0.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Continuously Differentiable Exponential Linear Unit (CELU) activation function element-wise. CELU is defined as max(0, x) + min(0, alpha * (e^(x/alpha) - 1)). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Celu(input, alpha: 1.0f);
    // Result: [-0.864, -0.632, 0.0, 1.0, 2.0]

    Clamp(FunctionalTensor, int, int)

    Returns input clamped to the range [min, max] element-wise.

    Declaration
    public static FunctionalTensor Clamp(FunctionalTensor input, int min, int max)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int min

    The min value.

    int max

    The max value.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation clamps each element in the input tensor to the specified range. Values below min are set to min, and values above max are set to max.

    Examples
    var input = Functional.Constant(new[] { -5, 0, 5, 10 });
    var result = Functional.Clamp(input, 0, 8);
    // Result: [0, 0, 5, 8]

    Clamp(FunctionalTensor, float, float)

    Returns input clamped to the range [min, max] element-wise.

    Declaration
    public static FunctionalTensor Clamp(FunctionalTensor input, float min, float max)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    float min

    The min value.

    float max

    The max value.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation clamps each element in the input tensor to the specified range. Values below min are set to min, and values above max are set to max.

    Examples
    var input = Functional.Constant(new[] { -5.0f, 0.0f, 5.0f, 10.0f });
    var result = Functional.Clamp(input, 0.0f, 8.0f);
    // Result: [0.0, 0.0, 5.0, 8.0]

    Clone(FunctionalTensor)

    Returns a copy of the input.

    Declaration
    public static FunctionalTensor Clone(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation creates a copy of the input tensor. The resulting tensor has the same shape and values as the input, but is a distinct tensor in the computational graph.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.Clone(input);
    // Result: [1.0, 2.0, 3.0]

    Concat(FunctionalTensor[], int)

    Returns the input tensors concatenated along a dimension.

    Declaration
    public static FunctionalTensor Concat(FunctionalTensor[] tensors, int dim = 0)
    Parameters
    Type Name Description
    FunctionalTensor[] tensors

    The input tensors.

    int dim

    The dimension along which to concatenate.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator concatenates a sequence of tensors along an existing dimension. All tensors must have the same shape except in the concatenation dimension. The output tensor has the same rank as the input tensors, with the concatenation dimension size equal to the sum of the input sizes.

    Examples
    var a = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var b = Functional.Constant(new TensorShape(2, 2), new[] { 7, 8, 9, 10 });
    var result = Functional.Concat(new[] { a, b }, dim: 1);
    // Result shape: [2, 5] (concatenated along dimension 1)

    Constant(int)

    Returns a scalar integer tensor.

    Declaration
    public static FunctionalTensor Constant(int value)
    Parameters
    Type Name Description
    int value

    The value of the element.

    Returns
    Type Description
    FunctionalTensor

    The tensor.

    Remarks

    This operation creates a scalar integer tensor (rank 0 - containing a single value).

    Examples
    // Create a scalar integer tensor with value 42
    var scalar = Functional.Constant(42);

    Constant(int[])

    Returns a 1D integer tensor.

    Declaration
    public static FunctionalTensor Constant(int[] values)
    Parameters
    Type Name Description
    int[] values

    The values of the elements.

    Returns
    Type Description
    FunctionalTensor

    The tensor.

    Remarks

    This operation creates a 1D integer tensor from an array of values. The array length determines the tensor shape.

    Examples
    // Create a 1D tensor of shape [5]
    var vector = Functional.Constant(new[] { 1, 2, 3, 4, 5 });

    Constant(float)

    Returns a scalar float tensor.

    Declaration
    public static FunctionalTensor Constant(float value)
    Parameters
    Type Name Description
    float value

    The value of the element.

    Returns
    Type Description
    FunctionalTensor

    The tensor.

    Remarks

    This operation creates a scalar float tensor (rank 0 - containing a single value).

    Examples
    // Create a scalar float tensor with value 3.14
    var scalar = Functional.Constant(3.14f);

    Constant(float[])

    Returns a 1D float tensor.

    Declaration
    public static FunctionalTensor Constant(float[] values)
    Parameters
    Type Name Description
    float[] values

    The values of the elements.

    Returns
    Type Description
    FunctionalTensor

    The tensor.

    Remarks

    This operation creates a 1D float tensor from an array of values. The array length determines the tensor shape.

    Examples
    // Create a 1D tensor with shape [5]
    var vector = Functional.Constant(new[] { 1.0f, 2.5f, 3.7f, 4.2f, 5.1f });

    Constant(Tensor)

    Returns a functional tensor with shape and data taken from a tensor.

    Declaration
    public static FunctionalTensor Constant(Tensor tensor)
    Parameters
    Type Name Description
    Tensor tensor

    The tensor to use as the source.

    Returns
    Type Description
    FunctionalTensor

    The functional tensor.

    Remarks

    This operation creates a FunctionalTensor from an existing Tensor object. You can use the created functional tensor in FunctionalGraph construction.

    Examples
    var tensor1 = new Tensor<float>(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    // Create a functional tensor from the existing tensor
    var tensor2 = Functional.Constant(tensor1);

    Constant(TensorShape, int[])

    Returns an integer tensor.

    Declaration
    public static FunctionalTensor Constant(TensorShape shape, int[] values)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    int[] values

    The values of the element.

    Returns
    Type Description
    FunctionalTensor

    The tensor.

    Remarks

    This operation creates an integer tensor with the specified shape and values. Ensure the values array contains enough elements to fill the tensor.

    Examples
    // Create an int tensor of shape [2, 3]
    var tensor = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });

    Constant(TensorShape, float[])

    Returns a float tensor.

    Declaration
    public static FunctionalTensor Constant(TensorShape shape, float[] values)
    Parameters
    Type Name Description
    TensorShape shape

    The shape of the tensor.

    float[] values

    The values of the element.

    Returns
    Type Description
    FunctionalTensor

    The tensor.

    Remarks

    This operation creates a float tensor with the specified shape and values. Ensure the values array contains enough elements to fill the tensor.

    Examples
    // Create a float tensor of shape [2, 3]
    var tensor = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });

    Conv1D(FunctionalTensor, FunctionalTensor, FunctionalTensor, int, int, int, int)

    Returns the result of a 1D convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor Conv1D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, int stride = 1, int padding = 0, int dilation = 1, int groups = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    int stride

    The stride value for each spatial dimension of the filter.

    int padding

    The lower and upper padding values for each spatial dimension of the filter.

    int dilation

    The dilation value of each spatial dimension of the filter.

    int groups

    The number of groups to divide input channels and output channels into.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 1D convolution over the input tensor. The input must have rank 3 with shape [batch, channels, width]. The weight must have rank 3 with shape [out_channels, in_channels/groups, kernel_width]. The bias (if provided) must have rank 1 with shape [out_channels]. Promotes all tensors to float type if necessary. The groups parameter allows for grouped convolutions to divide input and output channels into independent groups. dilation controls spacing between kernel elements. The standard convolution is dilation=1.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 10), new float[30]); // Shape: [1, 3, 10]
    var weight = Functional.Constant(new TensorShape(16, 3, 3), new float[144]); // 16 filters, 3 input channels, kernel size 3
    var bias = Functional.Constant(new float[16]); // 16 output channels
    var result = Functional.Conv1D(input, weight, bias, stride: 1, padding: 1);
    // Result shape: [1, 16, 10] (with padding=1, output width preserved)

    Conv2D(FunctionalTensor, FunctionalTensor, FunctionalTensor, int, int, int, int)

    Returns the result of a 2D convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor Conv2D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, int stride = 1, int padding = 0, int dilation = 1, int groups = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    int stride

    The stride value for each spatial dimension of the filter.

    int padding

    The lower and upper padding values for each spatial dimension of the filter.

    int dilation

    The dilation value of each spatial dimension of the filter.

    int groups

    The number of groups to divide input channels and output channels into.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 2D convolution over the input tensor. The input must have rank 4 with shape [batch, channels, height, width]. The weight must have rank 4 with shape [out_channels, in_channels/groups, kernel_height, kernel_width]. The bias (if provided) must have rank 1 with shape [out_channels]. Promotes all tensors to float type if necessary. This is the standard convolution used in Convolutional Neural Networks (CNN) for image processing. stride, padding, dilation, and groups apply uniformly to both spatial dimensions.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 32, 32), new float[3072]); // Shape: [1, 3, 32, 32]
    var weight = Functional.Constant(new TensorShape(64, 3, 3, 3), new float[1728]); // 64 filters, 3x3 kernel
    var bias = Functional.Constant(new float[64]);
    var result = Functional.Conv2D(input, weight, bias, stride: 1, padding: 1);
    // Result shape: [1, 64, 32, 32] (with padding=1, spatial dims preserved)

    Conv2D(FunctionalTensor, FunctionalTensor, FunctionalTensor, (int, int), (int, int), (int, int), int)

    Returns the result of a 2D convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor Conv2D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, (int, int) stride, (int, int) padding, (int, int) dilation, int groups = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    (int, int) stride

    The stride value for each spatial dimension of the filter.

    (int, int) padding

    The lower and upper padding values for each spatial dimension of the filter.

    (int, int) dilation

    The dilation value of each spatial dimension of the filter.

    int groups

    The number of groups to divide input channels and output channels into.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 2D convolution over the input tensor with per-dimension control. The input must have rank 4 with shape [batch, channels, height, width]. The weight must have rank 4 with shape [out_channels, in_channels/groups, kernel_height, kernel_width]. This overload allows specifying different stride, padding, and dilation values for height and width dimensions using tuples. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 32, 64), new float[6144]); // Shape: [1, 3, 32, 64]
    var weight = Functional.Constant(new TensorShape(64, 3, 3, 3), new float[1728]);
    var bias = Functional.Constant(new float[64]);
    var result = Functional.Conv2D(input, weight, bias, stride: (1, 2), padding: (1, 1), dilation: (1, 1));
    // Result shape: [1, 64, 32, 32] (stride 2 in width dimension)

    Conv3D(FunctionalTensor, FunctionalTensor, FunctionalTensor, int, int, int, int)

    Returns the result of a 3D convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor Conv3D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, int stride = 1, int padding = 0, int dilation = 1, int groups = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    int stride

    The stride value for each spatial dimension of the filter.

    int padding

    The lower and upper padding values for each spatial dimension of the filter.

    int dilation

    The dilation value of each spatial dimension of the filter.

    int groups

    The number of groups to divide input channels and output channels into.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 3D convolution over the input tensor. The input must have rank 5 with shape [batch, channels, depth, height, width]. The weight must have rank 5 with shape [out_channels, in_channels/groups, kernel_depth, kernel_height, kernel_width]. The bias (if provided) must have rank 1 with shape [out_channels]. Promotes all tensors to float type if necessary. 3D convolutions are used for video processing and volumetric data. stride, padding, dilation, and groups apply uniformly to all spatial dimensions.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 16, 32, 32), new float[49152]); // Shape: [1, 3, 16, 32, 32]
    var weight = Functional.Constant(new TensorShape(64, 3, 3, 3, 3), new float[5184]); // 64 filters, 3x3x3 kernel
    var bias = Functional.Constant(new float[64]);
    var result = Functional.Conv3D(input, weight, bias, stride: 1, padding: 1);
    // Result shape: [1, 64, 16, 32, 32] (with padding=1, spatial dims preserved)

    Conv3D(FunctionalTensor, FunctionalTensor, FunctionalTensor, (int, int, int), (int, int, int), (int, int, int), int)

    Returns the result of a 3D convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor Conv3D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, (int, int, int) stride, (int, int, int) padding, (int, int, int) dilation, int groups = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    (int, int, int) stride

    The stride value for each spatial dimension of the filter.

    (int, int, int) padding

    The lower and upper padding values for each spatial dimension of the filter.

    (int, int, int) dilation

    The dilation value of each spatial dimension of the filter.

    int groups

    The number of groups to divide input channels and output channels into.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 3D convolution over the input tensor with per-dimension control. The input must have rank 5 with shape [batch, channels, depth, height, width]. The weight must have rank 5 with shape [out_channels, in_channels/groups, kernel_depth, kernel_height, kernel_width]. This overload allows specifying different stride, padding, and dilation values for each spatial dimension using tuples. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 16, 32, 32), new float[49152]); // Shape: [1, 3, 16, 32, 32]
    var weight = Functional.Constant(new TensorShape(64, 3, 3, 3, 3), new float[5184]);
    var bias = Functional.Constant(new float[64]);
    var result = Functional.Conv3D(input, weight, bias, stride: (2, 1, 1), padding: (1, 1, 1), dilation: (1, 1, 1));
    // Result shape: [1, 64, 8, 32, 32] (stride 2 in depth dimension)

    ConvTranspose1D(FunctionalTensor, FunctionalTensor, FunctionalTensor, int, int, int)

    Returns the result of a 1D transposed convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor ConvTranspose1D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, int stride = 1, int padding = 0, int outputPadding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    int stride

    The stride value for each spatial dimension of the filter.

    int padding

    The lower and upper padding values for each spatial dimension of the filter.

    int outputPadding

    The output padding value for each spatial dimension in the filter.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 1D transposed convolution over the input tensor. The input must have rank 3 with shape [batch, channels, width]. The weight must have rank 3 with shape [in_channels, out_channels, kernel_width]. The bias (if provided) must have rank 1 with shape [out_channels]. Promotes all tensors to float type if necessary. outputPadding adds additional size to the output dimension.

    Examples
    var input = Functional.Constant(new TensorShape(1, 16, 10), new float[160]); // Shape: [1, 16, 10]
    var weight = Functional.Constant(new TensorShape(16, 3, 3), new float[144]); // 16 input channels, 3 output channels, kernel size 3
    var bias = Functional.Constant(new float[3]);
    var result = Functional.ConvTranspose1D(input, weight, bias, stride: 2, padding: 1);
    // Result shape: [1, 3, 19] (upsampled by stride 2)

    ConvTranspose2D(FunctionalTensor, FunctionalTensor, FunctionalTensor, int, int, int)

    Returns the result of a 2D transposed convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor ConvTranspose2D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, int stride = 1, int padding = 0, int outputPadding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    int stride

    The stride value for each spatial dimension of the filter.

    int padding

    The lower and upper padding values for each spatial dimension of the filter.

    int outputPadding

    The output padding value for each spatial dimension in the filter.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 2D transposed convolution over the input tensor. The input must have rank 4 with shape [batch, channels, height, width]. The weight must have rank 4 with shape [in_channels, out_channels, kernel_height, kernel_width]. The bias (if provided) must have rank 1 with shape [out_channels]. Promotes all tensors to float type if necessary. stride, padding, and outputPadding apply uniformly to both spatial dimensions.

    Examples
    var input = Functional.Constant(new TensorShape(1, 64, 16, 16), new float[16384]); // Shape: [1, 64, 16, 16]
    var weight = Functional.Constant(new TensorShape(64, 32, 4, 4), new float[32768]); // 64 in channels, 32 out channels
    var bias = Functional.Constant(new float[32]);
    var result = Functional.ConvTranspose2D(input, weight, bias, stride: 2, padding: 1);
    // Result shape: [1, 32, 32, 32] (upsampled by stride 2)

    ConvTranspose2D(FunctionalTensor, FunctionalTensor, FunctionalTensor, (int, int), (int, int), (int, int))

    Returns the result of a 2D transposed convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor ConvTranspose2D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, (int, int) stride, (int, int) padding, (int, int) outputPadding)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    (int, int) stride

    The stride value for each spatial dimension of the filter.

    (int, int) padding

    The lower and upper padding values for each spatial dimension of the filter.

    (int, int) outputPadding

    The output padding value for each spatial dimension in the filter.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 2D transposed convolution over the input tensor with per-dimension control. The input must have rank 4 with shape [batch, channels, height, width]. The weight must have rank 4 with shape [in_channels, out_channels, kernel_height, kernel_width]. This overload allows specifying different stride, padding, and outputPadding values for height and width dimensions using tuples. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 64, 16, 32), new float[32768]); // Shape: [1, 64, 16, 32]
    var weight = Functional.Constant(new TensorShape(64, 32, 4, 4), new float[32768]);
    var bias = Functional.Constant(new float[32]);
    var result = Functional.ConvTranspose2D(input, weight, bias, stride: (2, 2), padding: (1, 1), outputPadding: (0, 0));
    // Result shape: [1, 32, 32, 32] (stride 2 in height, 1 in width)

    ConvTranspose3D(FunctionalTensor, FunctionalTensor, FunctionalTensor, int, int, int)

    Returns the result of a 3D transposed convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor ConvTranspose3D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, int stride = 1, int padding = 0, int outputPadding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    int stride

    The stride value for each spatial dimension of the filter.

    int padding

    The lower and upper padding values for each spatial dimension of the filter.

    int outputPadding

    The output padding value for each spatial dimension in the filter.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 3D transposed convolution over the input tensor. The input must have rank 5 with shape [batch, channels, depth, height, width]. The weight must have rank 5 with shape [in_channels, out_channels, kernel_depth, kernel_height, kernel_width]. The bias (if provided) must have rank 1 with shape [out_channels]. Promotes all tensors to float type if necessary. 3D transposed convolutions are used for volumetric data upsampling and video generation. stride, padding, and outputPadding apply uniformly to all spatial dimensions.

    Examples
    var input = Functional.Constant(new TensorShape(1, 64, 8, 16, 16), new float[131072]); // Shape: [1, 64, 8, 16, 16]
    var weight = Functional.Constant(new TensorShape(64, 32, 4, 4, 4), new float[131072]); // 64 in channels, 32 out channels
    var bias = Functional.Constant(new float[32]);
    var result = Functional.ConvTranspose3D(input, weight, bias, stride: 2, padding: 1);
    // Result shape: [1, 32, 16, 32, 32] (upsampled by stride 2)

    ConvTranspose3D(FunctionalTensor, FunctionalTensor, FunctionalTensor, (int, int, int), (int, int, int), (int, int, int))

    Returns the result of a 3D transposed convolution of the input with the weight and bias tensors.

    Declaration
    public static FunctionalTensor ConvTranspose3D(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, (int, int, int) stride, (int, int, int) padding, (int, int, int) outputPadding)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The optional bias tensor.

    (int, int, int) stride

    The stride value for each spatial dimension of the filter.

    (int, int, int) padding

    The lower and upper padding values for each spatial dimension of the filter.

    (int, int, int) outputPadding

    The output padding value for each spatial dimension in the filter.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies a 3D transposed convolution over the input tensor with per-dimension control. The input must have rank 5 with shape [batch, channels, depth, height, width]. The weight must have rank 5 with shape [in_channels, out_channels, kernel_depth, kernel_height, kernel_width]. This overload allows specifying different stride, padding, and outputPadding values for each spatial dimension using tuples. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 64, 8, 16, 16), new float[131072]); // Shape: [1, 64, 8, 16, 16]
    var weight = Functional.Constant(new TensorShape(64, 32, 4, 4, 4), new float[131072]);
    var bias = Functional.Constant(new float[32]);
    var result = Functional.ConvTranspose3D(input, weight, bias, stride: (2, 2, 1), padding: (1, 1, 1), outputPadding: (0, 0, 0));
    // Result shape: [1, 32, 16, 32, 16] (stride 2 in depth and height, 1 in width)

    Cos(FunctionalTensor)

    Returns cos(input) element-wise.

    Declaration
    public static FunctionalTensor Cos(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the cosine of each element in the input tensor. Input is expected in radians.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 1.5708f, 3.14159f });
    var result = Functional.Cos(input);
    // Result: [1.0, 0.0, -1.0] (approximately cos(0), cos(π/2), cos(π))

    Cosh(FunctionalTensor)

    Returns cosh(input) element-wise.

    Declaration
    public static FunctionalTensor Cosh(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the hyperbolic cosine of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Cosh(input);
    // Result: [1.543, 1.0, 1.543] (approximately)

    CumSum(FunctionalTensor, int)

    Returns the cumulative sum of the elements of the input in a dimension.

    Declaration
    public static FunctionalTensor CumSum(FunctionalTensor input, int dim)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension in which to sum.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the cumulative sum of elements along the specified dimension. Each element in the output is the sum of all elements up to and including that position along the dimension. The output tensor has the same shape as the input tensor.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var result = Functional.CumSum(input, 0);
    // Result: [1.0, 3.0, 6.0, 10.0]
    // (1, 1+2, 1+2+3, 1+2+3+4)

    Deg2Rad(FunctionalTensor)

    Returns the input values converted from angles in degrees to radians element-wise.

    Declaration
    public static FunctionalTensor Deg2Rad(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation converts angles from degrees to radians by multiplying each element by π/180.

    Examples
    var degrees = Functional.Constant(new[] { 0.0f, 90.0f, 180.0f, 360.0f });
    var radians = Functional.Deg2Rad(degrees);
    // Result: [0.0, 1.571, 3.142, 6.283] (approximately 0, π/2, π, 2π)

    Diagonal(FunctionalTensor, int, int, int)

    Returns the remaining dimensions of the input, with the diagonal defined by dim1 and dim2 appended as the last dimension.

    Declaration
    public static FunctionalTensor Diagonal(FunctionalTensor input, int offset = 0, int dim1 = 0, int dim2 = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int offset

    Defines the diagonal to consider as an offset from the main diagonal.

    int dim1

    The first dimension that defines the diagonal.

    int dim2

    The second dimension that defines the diagonal.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation extracts diagonal elements from the input tensor along two specified dimensions. The offset parameter controls which diagonal to extract: 0 for the main diagonal, a positive value for above the main diagonal, and negative for below the main diagonal. Appends the extracted diagonal elements as the last dimension of the output tensor.

    Examples
    var input = Functional.Constant(new TensorShape(3, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f });
    var result = Functional.Diagonal(input);
    // Result: [1.0, 5.0, 9.0] (main diagonal elements)
    
    var result2 = Functional.Diagonal(input, offset: 1);
    // Result: [2.0, 6.0] (diagonal above the main diagonal)

    Div(FunctionalTensor, FunctionalTensor)

    Returns input / other element-wise.

    Declaration
    public static FunctionalTensor Div(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise division of two tensors. Promotes input and other to float type if necessary. The tensors are broadcast to a common shape. The result isn't rounded.

    Examples
    var a = Functional.Constant(new[] { 10.0f, 15.0f, 20.0f });
    var b = Functional.Constant(new[] { 2.0f, 3.0f, 4.0f });
    var result = Functional.Div(a, b);
    // Result: [5.0, 5.0, 5.0]

    Div(FunctionalTensor, FunctionalTensor, string)

    Returns input / other element-wise with rounding mode.

    Declaration
    public static FunctionalTensor Div(FunctionalTensor input, FunctionalTensor other, string roundingMode)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    string roundingMode

    The type of rounding applied to the result:

    • null: Default behavior. Performs no rounding.
    • trunc: Rounds the results of the division towards zero.
    • floor: Rounds the results of the division down.
    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise division with optional rounding. Promotes input and other to float type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 7, 8, 9 });
    var b = Functional.Constant(new[] { 2, 2, 2 });
    var resultDefault = Functional.Div(a, b, null);
    // Result: [3.5, 4.0, 4.5]
    var resultTrunc = Functional.Div(a, b, "trunc");
    // Result: [3, 4, 4]
    var resultFloor = Functional.Div(a, b, "floor");
    // Result: [3, 4, 4]

    Einsum(string, params FunctionalTensor[])

    Returns the sums the product of the elements of the operands tensors along dimensions specified using a notation based on the Einstein summation convention.

    Declaration
    public static FunctionalTensor Einsum(string equation, params FunctionalTensor[] operands)
    Parameters
    Type Name Description
    string equation

    The equation of the Einstein summation as a comma-separated list of subscript labels.

    FunctionalTensor[] operands

    The input tensors.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs Einstein summation. The equation string specifies which dimensions to multiply and sum over using subscript labels. In the equation, repeated indices define dimensions to sum over, and indices that appear only once are kept in the output.

    Examples
    // Matrix multiplication: C[i,j] = sum_k A[i,k] * B[k,j]
    var a = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var b = Functional.Constant(new TensorShape(2, 2), new[] { 5.0f, 6.0f, 7.0f, 8.0f });
    var result = Functional.Einsum("ij,jk->ik", a, b);
    // Result: [[19.0, 22.0], [43.0, 50.0]]
    
    // Batch dot product: sum_i A[i] * B[i]
    var x = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var y = Functional.Constant(new[] { 4.0f, 5.0f, 6.0f });
    var dot = Functional.Einsum("i,i->", x, y);
    // Result: 32.0 (1*4 + 2*5 + 3*6)

    Elu(FunctionalTensor, float)

    Returns elu(input) element-wise.

    Declaration
    public static FunctionalTensor Elu(FunctionalTensor input, float alpha = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    float alpha

    The alpha value for the elu. Default is 1.0.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Exponential Linear Unit (ELU) activation function element-wise. ELU is defined as x if x > 0, else alpha * (e^x - 1). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Elu(input, alpha: 1.0f);
    // Result: [-0.864, -0.632, 0.0, 1.0, 2.0]

    Equals(FunctionalTensor, int)

    Returns input == value element-wise.

    Declaration
    public static FunctionalTensor Equals(FunctionalTensor input, int value)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input.

    int value

    The integer value.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator compares each element of the input tensor with a scalar integer value for equality. Returns an integer tensor where each element is 1 if equal to the value, and 0 otherwise. Promotes value to match input's data type if necessary.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 2, 1 });
    var result = Functional.Equals(input, 2);
    // Result: [0, 1, 0, 1, 0] (only elements equal to 2 return 1)

    Equals(FunctionalTensor, float)

    Returns input == value element-wise.

    Declaration
    public static FunctionalTensor Equals(FunctionalTensor input, float value)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input.

    float value

    The float value.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator compares each element of the input tensor with a scalar float value for equality. Returns an integer tensor where each element is 1 if equal to the value, and 0 otherwise.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.5f, 3.0f, 2.5f });
    var result = Functional.Equals(input, 2.5f);
    // Result: [0, 1, 0, 1] (only elements equal to 2.5 return 1)

    Equals(FunctionalTensor, FunctionalTensor)

    Returns input == other element-wise.

    Declaration
    public static FunctionalTensor Equals(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input.

    FunctionalTensor other

    The second input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator compares two tensors element-wise for equality. Returns an integer tensor where each element is 1 if the corresponding elements are equal, and 0 otherwise. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var b = Functional.Constant(new[] { 1.0f, 0.0f, 3.0f });
    var result = Functional.Equals(a, b);
    // Result: [1, 0, 1] (true, false, true)

    Erf(FunctionalTensor)

    Returns the error function of input element-wise.

    Declaration
    public static FunctionalTensor Erf(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the Gauss error function. The output is in the range (-1, 1).

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Erf(input);
    // Result: [-0.995, -0.843, 0.0, 0.843, 0.995] (approximately)

    Exp(FunctionalTensor)

    Returns e^input element-wise.

    Declaration
    public static FunctionalTensor Exp(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the exponential (e raised to the power of each element) of the input tensor.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 1.0f, 2.0f });
    var result = Functional.Exp(input);
    // Result: [1.0, 2.718, 7.389] (approximately e^0, e^1, e^2)

    Expm1(FunctionalTensor)

    Returns e^input - 1 element-wise.

    Declaration
    public static FunctionalTensor Expm1(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes e^x - 1 for each element. This function provides better numerical precision than computing exp(x) - 1 for small values of x.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 0.5f, 1.0f });
    var result = Functional.Expm1(input);
    // Result: [0.0, 0.649, 1.718] (approximately e^0-1, e^0.5-1, e^1-1)

    FMod(FunctionalTensor, FunctionalTensor)

    Returns input % other element-wise. The sign of the output is the same as that of the dividend.

    Declaration
    public static FunctionalTensor FMod(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the modulo where the sign of the result matches the sign of the dividend (input). Promotes input and other to a compatible data type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 7.0f, -7.0f, 7.0f, -7.0f });
    var b = Functional.Constant(new[] { 3.0f, 3.0f, -3.0f, -3.0f });
    var result = Functional.FMod(a, b);
    // Result: [1.0, -1.0, 1.0, -1.0] (sign follows dividend)

    Flip(FunctionalTensor, int[])

    Returns the input tensor with its elements reversed on some dimensions.

    Declaration
    public static FunctionalTensor Flip(this FunctionalTensor input, int[] dims)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dims

    The dimensions on which to reverse the elements, values may not repeat.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation reverses the order of elements along the specified dimensions. An array specifies the dimension indices. The array must not contain repeated dimensions. The input's shape remains the same.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.Flip(input, new[] { 0 });
    // Result: [[4.0, 5.0, 6.0], [1.0, 2.0, 3.0]] (reversed along rows)
    
    var result2 = Functional.Flip(input, new[] { 1 });
    // Result: [[3.0, 2.0, 1.0], [6.0, 5.0, 4.0]] (reversed along columns)
    
    var result3 = Functional.Flip(input, new[] { 0, 1 });
    // Result: [[6.0, 5.0, 4.0], [3.0, 2.0, 1.0]] (reversed along rows and columns)

    FlipLR(FunctionalTensor)

    Returns the input tensor with its elements reversed on the second dimension.

    Declaration
    public static FunctionalTensor FlipLR(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation flips the tensor left-to-right by reversing the order of elements along dimension 1 (columns). Equivalent to calling Flip(FunctionalTensor, int[]) with dims=[1].

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.FlipLR(input);
    // Result: [[3.0, 2.0, 1.0], [6.0, 5.0, 4.0]]

    FlipUD(FunctionalTensor)

    Returns the input tensor with its elements reversed on the first dimension.

    Declaration
    public static FunctionalTensor FlipUD(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation flips the tensor up-to-down by reversing the order of elements along dimension 0 (rows). Equivalent to calling Flip(FunctionalTensor, int[]) with dims=[0].

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.FlipUD(input);
    // Result: [[4.0, 5.0, 6.0], [1.0, 2.0, 3.0]]

    Float(FunctionalTensor)

    Returns the input cast to floats element-wise.

    Declaration
    public static FunctionalTensor Float(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation casts all elements of the input tensor to floating-point type. Converts integer values to their float equivalents. If the input is already float type, it is returned unchanged. Equivalent to calling Type(input, DataType.Float).

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3 });
    var result = Functional.Float(input);
    // Result: [1.0, 2.0, 3.0] (converted to float)

    FloatPower(FunctionalTensor, FunctionalTensor)

    Returns input^exponent element-wise.

    Declaration
    public static FunctionalTensor FloatPower(FunctionalTensor input, FunctionalTensor exponent)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor exponent

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation raises the first input to the power of the second input. Promotes input and exponent to float type if necessary. The tensors are broadcast to a common shape.

    Examples
    var base = Functional.Constant(new[] { 2, 3, 4 });
    var exponent = Functional.Constant(new[] { 3, 2, 1 });
    var result = Functional.FloatPower(base, exponent);
    // Result: [8.0, 9.0, 4.0]

    Floor(FunctionalTensor)

    Returns ⌊input⌋ element-wise.

    Declaration
    public static FunctionalTensor Floor(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the floor (largest integer less than or equal to) of each element in the input tensor. If input is already an integer tensor, it is returned unchanged.

    Examples
    var input = Functional.Constant(new[] { -1.7f, -0.3f, 0.5f, 1.2f });
    var result = Functional.Floor(input);
    // Result: [-2.0, -1.0, 0.0, 1.0]

    FloorDivide(FunctionalTensor, FunctionalTensor)

    Returns ⌊input/other⌋ element-wise.

    Declaration
    public static FunctionalTensor FloorDivide(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise division and floors the result. Promotes input and other to a compatible data type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 7.0f, 8.0f, 9.0f });
    var b = Functional.Constant(new[] { 2.0f, 2.0f, 2.0f });
    var result = Functional.FloorDivide(a, b);
    // Result: [3.0, 4.0, 4.0]

    Forward(Model, params FunctionalTensor[])

    Creates and returns an array of FunctionalTensor as the output of the forward pass of an existing model.

    Sentis will make destructive edits of the source model.

    Declaration
    public static FunctionalTensor[] Forward(Model model, params FunctionalTensor[] inputs)
    Parameters
    Type Name Description
    Model model

    The model to use as the source.

    FunctionalTensor[] inputs

    The functional tensors to use as the inputs to the model.

    Returns
    Type Description
    FunctionalTensor[]

    The functional tensor array.

    Remarks

    This operation integrates an existing model into a functional graph. Passes the provided tensors as inputs to the model, and the model's outputs are tensors that can be used in further computations.

    This method allows you to chain or compose models, enabling workflows such as:

    • Adding preprocessing operations before a model's inputs
    • Adding postprocessing operations after a model's outputs
    • Combining multiple models into a larger computational graph

    Important: This method makes destructive modifications to the source model for performance optimization. To keep the original model unchanged, use ForwardWithCopy(Model, params FunctionalTensor[]) instead.

    The number of input functional tensors must match the number of inputs expected by the model. The returned array will contain one functional tensor for each output of the model.

    Examples
    // Load an existing model
    var model = ModelLoader.Load(modelAsset);
    
    // Create a functional graph with preprocessing
    var graph = new FunctionalGraph();
    var input = graph.AddInput(DataType.Float, new TensorShape(1, 3, 224, 224));
    
    // Apply preprocessing: normalize the input
    var mean = Functional.Constant(new TensorShape(1, 3, 1, 1), new[] { 0.485f, 0.456f, 0.406f });
    var std = Functional.Constant(new TensorShape(1, 3, 1, 1), new[] { 0.229f, 0.224f, 0.225f });
    var normalized = (input - mean) / std;
    
    // Pass the preprocessed input through the existing model
    var outputs = Functional.Forward(model, normalized);
    
    // Use the model outputs (apply softmax for classification)
    var probabilities = Functional.Softmax(outputs[0], dim: -1);
    
    graph.AddOutput(probabilities);
    var combinedModel = graph.Compile();

    ForwardWithCopy(Model, params FunctionalTensor[])

    Creates and returns an array of FunctionalTensor as the output of the forward pass of an existing model.

    Sentis will copy the source model and not make edits to it.

    Declaration
    public static FunctionalTensor[] ForwardWithCopy(Model model, params FunctionalTensor[] inputs)
    Parameters
    Type Name Description
    Model model

    The model to use as the source.

    FunctionalTensor[] inputs

    The functional tensors to use as the inputs to the model.

    Returns
    Type Description
    FunctionalTensor[]

    The functional tensor array.

    Remarks

    This operation integrates an existing model into a functional graph. Passes the provided tensors as inputs to the model, and the model's outputs are tensors that can be used in further computations.

    This method allows you to chain or compose models, enabling workflows such as:

    • Adding preprocessing operations before a model's inputs
    • Adding postprocessing operations after a model's outputs
    • Combining multiple models into a larger computational graph

    This method creates a copy of the source model before processing, ensuring that the original model remains unmodified. This is useful when you need to reuse the same model multiple times or preserve it for other purposes. Note: Copying incurs additional memory overhead and processing time compared to the destructive Forward(Model, params FunctionalTensor[]) method.

    The number of input functional tensors must match the number of inputs expected by the model. The returned array will contain one functional tensor for each output of the model.

    Examples
    // Load an existing model that you want to preserve
    var baseModel = ModelLoader.Load(modelAsset);
    
    // Create two different functional graphs using the same base model
    var graph1 = new FunctionalGraph();
    var input1 = graph1.AddInput(DataType.Float, new TensorShape(1, 3, 224, 224));
    var outputs1 = Functional.ForwardWithCopy(baseModel, input1);
    var result1 = Functional.Relu(outputs1[0]); // Apply Relu postprocessing
    graph1.AddOutput(result1);
    var model1 = graph1.Compile();
    
    var graph2 = new FunctionalGraph();
    var input2 = graph2.AddInput(DataType.Float, new TensorShape(1, 3, 224, 224));
    var outputs2 = Functional.ForwardWithCopy(baseModel, input2);
    var result2 = Functional.Sigmoid(outputs2[0]); // Apply Sigmoid postprocessing
    graph2.AddOutput(result2);
    var model2 = graph2.Compile();
    
    // baseModel remains unchanged and can still be used independently

    Frac(FunctionalTensor)

    Returns the fractional part of the input element-wise.

    Declaration
    public static FunctionalTensor Frac(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the fractional part by subtracting the truncated integer part from input. For integer tensors, returns a tensor of zeros.

    Examples
    var input = Functional.Constant(new[] { -1.7f, -0.3f, 0.5f, 1.2f, 2.9f });
    var result = Functional.Frac(input);
    // Result: [-0.7, -0.3, 0.5, 0.2, 0.9]

    Full(int[], int)

    Returns a tensor filled with constant fillValue with given shape size.

    Declaration
    public static FunctionalTensor Full(int[] size, int fillValue)
    Parameters
    Type Name Description
    int[] size

    The shape of the tensor.

    int fillValue

    The fill value of the tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the specified shape (size), with all elements initialized to the provided integer value fillValue.

    Examples
    // Create a tensor of shape [3, 4] filled with the value 42
    var tensor = Functional.Full(new int[] {3, 4}, 42);
    // Create a tensor of shape [2, 3, 4] filled with the value -5
    var tensor2 = Functional.Full(new int[] {2, 3, 4}, -5);

    Full(int[], float)

    Returns a tensor filled with a constant fillValue with given shape size.

    Declaration
    public static FunctionalTensor Full(int[] size, float fillValue)
    Parameters
    Type Name Description
    int[] size

    The shape of the tensor.

    float fillValue

    The fill value of the tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the specified shape (size), with all elements initialized to the provided float value fillValue.

    Examples
    // Create a tensor of shape [3, 4] filled with the value 3.14
    var tensor = Functional.Full(new int[] {3, 4}, 3.14f);
    // Create a tensor of shape [2, 3, 4] filled with the value -0.5
    var tensor2 = Functional.Full(new int[] {2, 3, 4}, -0.5f);

    FullLike(FunctionalTensor, int)

    Returns a tensor filled with a constant value with the same shape as the input tensor.

    Declaration
    public static FunctionalTensor FullLike(FunctionalTensor input, int fillValue)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int fillValue

    The fill value of the tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the same shape as the input tensor, with all elements initialized to the provided integer value fillValue.

    Examples
    var input = Functional.Constant(new TensorShape(3, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
    // Create a tensor of the same shape as input filled with 42
    var tensor = Functional.FullLike(input, 42);

    FullLike(FunctionalTensor, float)

    Returns a tensor filled with a constant value fillValue with the same shape as the input tensor.

    Declaration
    public static FunctionalTensor FullLike(FunctionalTensor input, float fillValue)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    float fillValue

    The fill value of the tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the same shape as the input tensor, with all elements initialized to the provided float value fillValue.

    Examples
    var input = Functional.Constant(new TensorShape(3, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
    // Create a tensor of the same shape as input filled with 3.14
    var tensor = Functional.FullLike(input, 3.14f);

    Gather(FunctionalTensor, int, FunctionalTensor)

    Returns the input tensor gathered along a dimension with index values.

    Declaration
    public static FunctionalTensor Gather(this FunctionalTensor input, int dim, FunctionalTensor index)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to gather.

    FunctionalTensor index

    The indices tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator gathers values from the input tensor along a specified dimension using an index tensor. For each element in the index tensor, the corresponding value is gathered from the input at that index position. The output has the same shape as the index tensor. The index tensor must be integer type and have values within valid range for the specified dimension.

    Examples
    var input = Functional.Constant(new[] { 10, 20, 30, 40 });
    var index = Functional.Constant(new[] { 0, 2, 1, 3 });
    var result = Functional.Gather(input, dim: 0, index);
    // Result: [10, 30, 20, 40] (values gathered at specified indices)

    Gelu(FunctionalTensor)

    Returns gelu(input) element-wise.

    Declaration
    public static FunctionalTensor Gelu(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Gaussian Error Linear Unit (GELU) activation function element-wise. GELU is defined as x * Φ(x), where Φ(x) is the cumulative distribution function of the standard normal distribution. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Gelu(input);
    // Result: [-0.0454, -0.1587, 0.0, 0.8413, 1.9546]

    Greater(FunctionalTensor, FunctionalTensor)

    Returns input > other element-wise.

    Declaration
    public static FunctionalTensor Greater(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input.

    FunctionalTensor other

    The second input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator performs element-wise greater-than comparison between two tensors. Returns an integer tensor where each element is 1 if input[i] > other[i], and 0 otherwise. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 3.0f, 1.0f, 5.0f });
    var b = Functional.Constant(new[] { 2.0f, 1.0f, 6.0f });
    var result = Functional.Greater(a, b);
    // Result: [1, 0, 0] (3>2: true, 1>1: false, 5>6: false)

    GreaterEqual(FunctionalTensor, FunctionalTensor)

    Returns input ≥ other element-wise.

    Declaration
    public static FunctionalTensor GreaterEqual(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input.

    FunctionalTensor other

    The second input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator performs element-wise greater-than or equal to comparison between two tensors. Returns an integer tensor where each element is 1 if input[i] ≥ other[i], and 0 otherwise. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 3.0f, 1.0f, 5.0f });
    var b = Functional.Constant(new[] { 2.0f, 1.0f, 6.0f });
    var result = Functional.GreaterEqual(a, b);
    // Result: [1, 1, 0] (3≥2: true, 1≥1: true, 5≥6: false)

    GridSample(FunctionalTensor, FunctionalTensor, string, string, bool)

    Returns the input tensor sampled at coordinates given by the grid tensor.

    Declaration
    public static FunctionalTensor GridSample(FunctionalTensor input, FunctionalTensor grid, string mode = "bilinear", string paddingMode = "zeros", bool alignCorners = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor grid

    The grid tensor containing the spatial coordinates per output pixel.

    string mode

    The mode used for interpolating. The options are: nearest or bilinear. bicubic maps to bilinear.

    string paddingMode

    The mode to use for sampling out-of-bounds coordinates. The options are: zeros, border, or reflection.

    bool alignCorners

    Whether to map the extreme values in the coordinates -1 and 1 to the center of the corner pixels rather than the outer edges.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation samples the input tensor at locations specified by a grid of coordinates. The grid tensor contains normalized coordinates in the range [-1, 1] where (-1, -1) is the top-left corner and (1, 1) is the bottom-right corner. Promotes input and grid to float type if necessary. Available modes are nearest or bilinear. Padding modes: zeros (out-of-bounds samples are 0), border (clamp to edge), reflection (reflect at boundary). When alignCorners is true, extreme grid values [-1, 1] map to pixel centers. When false, they map to pixel edges.

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 4, 4), new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f }); // Shape: [1, 1, 4, 4]
    var grid = Functional.Constant(new TensorShape(1, 2, 2, 2), new float[] { -0.8f, -0.2f, 0.2f, 0.8f, -1.0f, 1.0f, 0.0f, 0.0f }); // Sampling coordinates
    var result = Functional.GridSample(input, grid, mode: "bilinear", paddingMode: "zeros");
    // Result shape: [1, 1, 2, 2] (sampled at grid locations) with values [[[[4.86, 13.41], [3.25, 8.5]]]]

    HammingWindow(int, bool)

    Returns a Hamming window of shape [windowLength] with α = 0.54347826087 and β = 0.45652173913.

    Declaration
    public static FunctionalTensor HammingWindow(int windowLength, bool periodic)
    Parameters
    Type Name Description
    int windowLength

    The size of the window.

    bool periodic

    If true, returns a window to use as a periodic function. If false, return a symmetric window.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates a Hamming window used for spectral analysis and filtering. Computes the window as α - β * cos(2π * n / (N-1)) for symmetric, or α - β * cos(2π * n / N) for periodic.

    Examples
    var window = Functional.HammingWindow(windowLength: 16, periodic: true);
    // Result: Hamming window with shape [16]: [0.087, 0.122, 0.221, 0.369, 0.543, 0.718, 0.866, 0.965, 1, 0.965, 0.866, 0.718, 0.543, 0.369, 0.221, 0.122]

    HannWindow(int, bool)

    Returns a Hann window of shape [windowLength].

    Declaration
    public static FunctionalTensor HannWindow(int windowLength, bool periodic)
    Parameters
    Type Name Description
    int windowLength

    The size of the window.

    bool periodic

    If true, returns a window to use as a periodic function. If false, return a symmetric window.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates a Hann window used for spectral analysis and filtering. Computes the window as 0.5 * (1 - cos(2π * n / (N-1))) for symmetric, or 0.5 * (1 - cos(2π * n / N)) for periodic.

    Examples
    var window = Functional.HannWindow(windowLength: 16, periodic: false);
    // Result: Hann window with shape [16]: [0, 0.043, 0.165, 0.345, 0.552, 0.75, 0.905, 0.989, 0.989, 0.905, 0.75, 0.552, 0.345, 0.165, 0.043, 0]

    HardSigmoid(FunctionalTensor)

    Returns hard_sigmoid(input) element-wise.

    Declaration
    public static FunctionalTensor HardSigmoid(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Hard Sigmoid activation function element-wise. Hard Sigmoid is defined as max(0, min(1, x/6 + 0.5)), providing a piecewise linear approximation to Sigmoid(FunctionalTensor). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -3.0f, -1.0f, 0.0f, 1.0f, 3.0f });
    var result = Functional.HardSigmoid(input);
    // Result: [0.0, 0.333, 0.5, 0.666, 1.0]

    HardSwish(FunctionalTensor)

    Returns hardswish(input) element-wise.

    Declaration
    public static FunctionalTensor HardSwish(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Hard Swish activation function element-wise. Hard Swish is defined as x * relu6(x + 3) / 6. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -3.0f, -1.0f, 0.0f, 1.0f, 3.0f });
    var result = Functional.HardSwish(input);
    // Result: [0.0, -0.333, 0.0, 0.666, 3.0]

    IndexSelect(FunctionalTensor, int, FunctionalTensor)

    Returns the input tensor indexed along a dimension with entries in a 1D index tensor.

    Declaration
    public static FunctionalTensor IndexSelect(this FunctionalTensor input, int dim, FunctionalTensor index)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to select.

    FunctionalTensor index

    The indices tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator selects elements from the input tensor along a specified dimension using a 1D index tensor. Unlike Gather(FunctionalTensor, int, FunctionalTensor), IndexSelect always uses a 1D index tensor and the output preserves the input shape except along the selection dimension. The index tensor must be integer type and contain valid indices for the specified dimension.

    Examples
    var input = Functional.Constant(new TensorShape(3, 4), new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
    var index = Functional.Constant(new[] { 0, 2 }); // Select rows 0 and 2
    var result = Functional.IndexSelect(input, dim: 0, index);
    // Result shape: [2, 4] (selected rows)

    InstanceNorm(FunctionalTensor, FunctionalTensor, FunctionalTensor, float)

    Returns the result of computing the mean variance on the spatial dimensions of the input tensor and normalizes it according to the weight and bias.

    Declaration
    public static FunctionalTensor InstanceNorm(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, float eps = 1E-05)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The bias tensor.

    float eps

    The epsilon value used to avoid division by zero. Default is 1.0e-5.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies Instance Normalization to the input tensor. Instance normalization computes mean and variance statistics separately for each instance and channel, normalizing over spatial dimensions. The normalization is then scaled and shifted by learned weight and bias parameters. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [1, 1, 2, 2]
    var weight = Functional.Constant(new[] { 1.0f });
    var bias = Functional.Constant(new[] { 0.0f });
    // Normalizes each instance independently across spatial dimensions
    var result = Functional.InstanceNorm(input, weight, bias);

    Int(FunctionalTensor)

    Returns the input cast to integers element-wise.

    Declaration
    public static FunctionalTensor Int(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation casts all elements of the input tensor to integer type. Truncates floating-point values toward zero. If the input is already integer type, it's returned unchanged. Equivalent to calling Type(input, DataType.Int).

    Examples
    var input = Functional.Constant(new[] { 1.5f, -2.7f, 3.2f });
    var result = Functional.Int(input);
    // Result: [1, -2, 3] (truncated toward zero)

    Interpolate(FunctionalTensor, int[], float[], string)

    Returns the input tensor with the spatial dimensions downsampled or upsampled to a size or by a scale factor.

    Declaration
    public static FunctionalTensor Interpolate(FunctionalTensor input, int[] size = null, float[] scaleFactor = null, string mode = "nearest")
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] size

    The optional output size.

    float[] scaleFactor

    The optional output scale factors.

    string mode

    The mode used for interpolating. The options are: nearest or linear (bilinear for 2D, trilinear for 3D). bicubic maps to linear.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation resizes the spatial dimensions of the input tensor using interpolation. You must specify either size or scaleFactor (but not both). Promotes input to float type if necessary. The available modes are nearest (nearest neighbor) and linear (bilinear for 2D, trilinear for 3D). Applies the interpolation starting from dimension 2 onward (preserving batch and channel dimensions).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 4, 4), new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f }); // Shape: [1, 1, 4, 4]
    var result = Functional.Interpolate(input, size: new[] { 8, 8 }, mode: "linear");
    // Result shape: [1, 1, 8, 8] (upsampled to 8x8) with values:
    [[[[1, 1.25, 1.75, 2.25, 2.75, 3.25, 3.75, 4], [2, 2.25, 2.75, 3.25, 3.75, 4.25, 4.75, 5], [4, 4.25, 4.75, 5.25, 5.75, 6.25, 6.75, 7], [6, 6.25, 6.75, 7.25, 7.75, 8.25, 8.75, 9], [8, 8.25, 8.75, 9.25, 9.75, 10.25, 10.75, 11], [10, 10.25, 10.75, 11.25, 11.75, 12.25, 12.75, 13], [12, 12.25, 12.75, 13.25, 13.75, 14.25, 14.75, 15], [13, 13.25, 13.75, 14.25, 14.75, 15.25, 15.75, 16]]]]

    IsFinite(FunctionalTensor)

    Returns an integer tensor with elements representing if each element of input is finite.

    Declaration
    public static FunctionalTensor IsFinite(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator checks if each element of the input tensor is a finite number (not infinity or Not a Number [NaN]). Returns an integer tensor where each element is 1 if the value is finite, and 0 if the value is infinite or NaN. For integer tensors, all elements are considered finite and the result is all ones. A finite number is any value that isn't positive infinity, negative infinity, or NaN.

    Examples
    var input = Functional.Constant(new[] { 1.0f, float.PositiveInfinity, float.NaN, -5.0f });
    var result = Functional.IsFinite(input);
    // Result: [1, 0, 0, 1] (only 1.0 and -5.0 are finite)

    IsInf(FunctionalTensor)

    Returns an integer tensor with elements representing if each element of input is positive or negative infinity.

    Declaration
    public static FunctionalTensor IsInf(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator checks if each element of the input tensor is infinite (positive or negative infinity). Returns an integer tensor where each element is 1 if the value is infinite, and 0 otherwise. For integer tensors, no elements can be infinite and the result is all zeros. Not a Number (NaN) values aren't considered infinite.

    Examples
    var input = Functional.Constant(new[] { 1.0f, float.PositiveInfinity, float.NegativeInfinity, float.NaN });
    var result = Functional.IsInf(input);
    // Result: [0, 1, 1, 0] (only the infinity values return 1)

    IsNaN(FunctionalTensor)

    Returns an integer tensor with elements representing if each element of input is NaN.

    Declaration
    public static FunctionalTensor IsNaN(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator checks if each element of the input tensor is Not a Number (NaN). Returns an integer tensor where each element is 1 if the value is NaN, and 0 otherwise. For integer tensors, no elements can be NaN and the result is all zeros.

    Examples
    var input = Functional.Constant(new[] { 1.0f, float.NaN, float.PositiveInfinity, 0.0f / 0.0f });
    var result = Functional.IsNaN(input);
    // Result: [0, 1, 0, 1] (only the NaN values return 1)

    LayerNorm(FunctionalTensor, FunctionalTensor, FunctionalTensor, float)

    Returns the result of computing Layer Normalization over a mini-batch of inputs. see paper: https://arxiv.org/abs/1607.06450

    Declaration
    public static FunctionalTensor LayerNorm(FunctionalTensor input, FunctionalTensor weight, FunctionalTensor bias, float eps = 1E-05)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    FunctionalTensor bias

    The bias tensor.

    float eps

    The epsilon value used to avoid division by zero. Default is 1.0e-5.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies Layer Normalization to the input tensor. Layer normalization computes mean and variance statistics across the feature dimension for each sample independently. The normalization is then scaled and shifted by learned weight and bias parameters. Promotes all tensors to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [1, 4]
    var weight = Functional.Constant(new[] { 1.0f, 1.0f, 1.0f, 1.0f });
    var bias = Functional.Constant(new[] { 0.0f, 0.0f, 0.0f, 0.0f });
    // Normalizes across the feature dimension
    var result = Functional.LayerNorm(input, weight, bias);

    LeakyRelu(FunctionalTensor, float)

    Returns leaky_relu(input) element-wise.

    Declaration
    public static FunctionalTensor LeakyRelu(FunctionalTensor input, float negativeSlope = 0.01)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    float negativeSlope

    The negative slope value for the leaky relu. Default is 0.01.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Leaky ReLU activation function element-wise. Leaky ReLU is defined as x if x > 0, else negativeSlope * x, allowing a small gradient for negative values. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.LeakyRelu(input, negativeSlope: 0.01f);
    // Result: [-0.02, -0.01, 0.0, 1.0, 2.0]

    Lerp(FunctionalTensor, FunctionalTensor, float)

    Returns the linear interpolation input + weight * (end - input) element-wise.

    Declaration
    public static FunctionalTensor Lerp(FunctionalTensor input, FunctionalTensor end, float weight)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor end

    The second input tensor.

    float weight

    The interpolation weight.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs linear interpolation between two tensors based on a scalar weight. When weight is 0, returns input; when weight is 1, returns end. Values outside [0, 1] extrapolate.

    Examples
    var start = Functional.Constant(new[] { 0.0f, 10.0f, 20.0f });
    var end = Functional.Constant(new[] { 10.0f, 20.0f, 30.0f });
    var result = Functional.Lerp(start, end, 0.5f);
    // Result: [5.0, 15.0, 25.0] (midpoint between start and end)

    Less(FunctionalTensor, FunctionalTensor)

    Returns input < other element-wise.

    Declaration
    public static FunctionalTensor Less(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator performs element-wise less than comparison between two tensors. Returns an integer tensor where each element is 1 if input[i] < other[i], and 0 otherwise. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 2.0f, 5.0f });
    var b = Functional.Constant(new[] { 2.0f, 2.0f, 4.0f });
    var result = Functional.Less(a, b);
    // Result: [1, 0, 0]

    LessEqual(FunctionalTensor, FunctionalTensor)

    Returns input ≤ other element-wise.

    Declaration
    public static FunctionalTensor LessEqual(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input.

    FunctionalTensor other

    The second input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator performs element-wise less than or equal to comparison between two tensors. Returns an integer tensor where each element is 1 if input[i] ≤ other[i], and 0 otherwise. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 2.0f, 5.0f });
    var b = Functional.Constant(new[] { 2.0f, 2.0f, 4.0f });
    var result = Functional.LessEqual(a, b);
    // Result: [1, 1, 0] (1≤2: true, 2≤2: true, 5≤4: false)

    LinSpace(float, float, int)

    Returns a 1D tensor of size steps with values evenly spaced from the interval [start, end].

    Declaration
    public static FunctionalTensor LinSpace(float start, float end, int steps)
    Parameters
    Type Name Description
    float start

    The value of the first element.

    float end

    The value of the last element.

    int steps

    The number of elements.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a 1D tensor of dimension steps with evenly spaced values over a specified interval. The output includes the start and end values. The steps parameter determines the number of elements in the output.

    Examples
    // Create a tensor with 5 evenly spaced values from 0 to 10
    var tensor = Functional.LinSpace(0f, 10f, 5); // [0.0, 2.5, 5.0, 7.5, 10.0]
    // Create a tensor with 11 evenly spaced values from -1 to 1
    var tensor2 = Functional.LinSpace(-1f, 1f, 11); // [-1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0]

    LocalResponseNorm(FunctionalTensor, int, float, float, float)

    Returns the result of normalizing the input tensor over local input regions.

    Declaration
    public static FunctionalTensor LocalResponseNorm(FunctionalTensor input, int size, float alpha = 0.0001, float beta = 0.75, float k = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int size

    The size of the regions used for normalization.

    float alpha

    The multiplicative factor in the normalization. Default is 0.0001.

    float beta

    The exponent in the normalization. Default is 0.75.

    float k

    The additive factor in the normalization. Default is 1.0.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies Local Response Normalization (LRN) to the input tensor. LRN performs normalization over local neighborhoods across channels using the formula: output = input / (k + alpha * sum_of_squares)^beta. Computes the sum over a local region of adjacent channels determined by size. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [1, 1, 4]
    // Normalizes each position using values from adjacent channels
    var result = Functional.LocalResponseNorm(input, size: 3);

    Log(FunctionalTensor)

    Returns log(input) element-wise.

    Declaration
    public static FunctionalTensor Log(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the natural logarithm (base e) of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.718f, 7.389f });
    var result = Functional.Log(input);
    // Result: [0.0, 1.0, 2.0] (approximately ln(1), ln(e), ln(e^2))

    Log10(FunctionalTensor)

    Returns log10(input) element-wise.

    Declaration
    public static FunctionalTensor Log10(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the base-10 logarithm of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 10.0f, 100.0f });
    var result = Functional.Log10(input);
    // Result: [0.0, 1.0, 2.0]

    Log1P(FunctionalTensor)

    Returns log(input + 1) element-wise.

    Declaration
    public static FunctionalTensor Log1P(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the natural logarithm of (1 + x) for each element. This function provides better numerical precision than computing log(1 + x) for small values of x.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 1.0f, 6.389f });
    var result = Functional.Log1P(input);
    // Result: [0.0, 0.693, 2.0] (approximately ln(1), ln(2), ln(7.389))

    Log2(FunctionalTensor)

    Returns log2(input) element-wise.

    Declaration
    public static FunctionalTensor Log2(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the base-2 logarithm of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 4.0f, 8.0f });
    var result = Functional.Log2(input);
    // Result: [0.0, 1.0, 2.0, 3.0]

    LogAddExp(FunctionalTensor, FunctionalTensor)

    Returns log(e^input + e^other) element-wise.

    Declaration
    public static FunctionalTensor LogAddExp(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the logarithm of the sum of exponentials. This function provides better numerical stability than computing log(exp(x) + exp(y)) directly.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var b = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.LogAddExp(a, b);
    // Result: [1.693, 2.693, 3.693] (approximately ln(e^1+e^1), ln(e^2+e^2), ln(e^3+e^3))

    LogSoftmax(FunctionalTensor, int)

    Returns log(softmax(input)) element-wise along a specified dimension.

    Declaration
    public static FunctionalTensor LogSoftmax(FunctionalTensor input, int dim = -1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to calculate the softmax. Default is -1.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the log of the Softmax function along the specified dimension (dim). Log Softmax is defined as x_i - log(sum(e^(x_j))) for all j in the dimension. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.LogSoftmax(input, dim: 0);
    // Result: [-2.407, -1.407, -0.407]

    LogSpace(float, float, int, float)

    Returns a 1D tensor of size steps with values evenly spaced from the interval [logBase^start, logBase^end] on a logarithmic scale.

    Declaration
    public static FunctionalTensor LogSpace(float start, float end, int steps, float logBase = 10)
    Parameters
    Type Name Description
    float start

    The value of the first exponent.

    float end

    The value of the last exponent.

    int steps

    The number of elements.

    float logBase

    The base of the logarithm. Default value is 10.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with values that are evenly spaced on a logarithmic scale. Computes the output values as logBase raised to the power of evenly spaced exponents. The default base is 10.

    Examples
    // Create a tensor with 4 logarithmically spaced values from 10^1 to 10^4
    var tensor = Functional.LogSpace(1f, 4f, 4); // [10, 100, 1000, 10000]
    // Create a tensor with 5 logarithmically spaced values using base 2
    var tensor2 = Functional.LogSpace(0f, 4f, 5, 2f); // [1, 2, 4, 8, 16]

    LogicalAnd(FunctionalTensor, FunctionalTensor)

    Returns the logical AND input & other element-wise.

    Declaration
    public static FunctionalTensor LogicalAnd(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise logical AND, treating non-zero values as true and zero as false. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 0, 1, 1, 0 });
    var b = Functional.Constant(new[] { 0, 0, 1, 1 });
    var result = Functional.LogicalAnd(a, b);
    // Result: [0, 0, 1, 0] (only both true gives true)

    LogicalNot(FunctionalTensor)

    Returns the logical NOT ~input element-wise.

    Declaration
    public static FunctionalTensor LogicalNot(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise logical NOT, treating non-zero values as true and zero as false. Returns 1 (true) for zero values and 0 (false) for non-zero values.

    Examples
    var input = Functional.Constant(new[] { 0, 1, -5, 0, 10 });
    var result = Functional.LogicalNot(input);
    // Result: [1, 0, 0, 1, 0]

    LogicalOr(FunctionalTensor, FunctionalTensor)

    Returns the logical OR input | other element-wise.

    Declaration
    public static FunctionalTensor LogicalOr(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise logical OR, treating non-zero values as true and zero as false. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 0, 1, 1, 0 });
    var b = Functional.Constant(new[] { 0, 0, 1, 1 });
    var result = Functional.LogicalOr(a, b);
    // Result: [0, 1, 1, 1] (at least one true gives true)

    LogicalXor(FunctionalTensor, FunctionalTensor)

    Returns the logical XOR input ^ other element-wise.

    Declaration
    public static FunctionalTensor LogicalXor(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise logical XOR (exclusive OR), treating non-zero values as true and zero as false. Returns true when exactly one input is true. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 0, 1, 1, 0 });
    var b = Functional.Constant(new[] { 0, 0, 1, 1 });
    var result = Functional.LogicalXor(a, b);
    // Result: [0, 1, 0, 1] (exactly one true gives true)

    MatMul(FunctionalTensor, FunctionalTensor)

    Returns the matrix product input @ other.

    Declaration
    public static FunctionalTensor MatMul(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs matrix multiplication between two tensors. For 2D tensors, this is standard matrix multiplication. For higher dimensional tensors, the operation runs as a batch over the leading dimensions. Promotes input and other to float type if necessary.

    Examples
    var a = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var b = Functional.Constant(new TensorShape(2, 2), new[] { 5.0f, 6.0f, 7.0f, 8.0f });
    var result = Functional.MatMul(a, b);
    // Result: [[19.0, 22.0], [43.0, 50.0]]
    // (1*5 + 2*7 = 19, 1*6 + 2*8 = 22, 3*5 + 4*7 = 43, 3*6 + 4*8 = 50)

    Max(FunctionalTensor, FunctionalTensor)

    Returns the element-wise maximum of input and other.

    Declaration
    public static FunctionalTensor Max(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator computes the element-wise maximum between two tensors. For each element position, the output contains the larger of the two input values. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 5.0f, 3.0f });
    var b = Functional.Constant(new[] { 2.0f, 4.0f, 6.0f });
    var result = Functional.Max(a, b);
    // Result: [2.0, 5.0, 6.0] (max of each pair)

    MaxPool1D(FunctionalTensor, int, int?, int)

    Returns the result of a 1D maximum pooling of the input.

    Declaration
    public static FunctionalTensor MaxPool1D(FunctionalTensor input, int kernelSize, int? stride = null, int padding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int kernelSize

    The size of the kernel.

    int? stride

    The optional stride of the pooling. The default value is the kernel size.

    int padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 1D max pooling to the input tensor by computing the maximum value within a sliding window. The input tensor must have rank 3 with shape [batch, channels, width]. The kernel slides over the spatial dimension with the specified stride, and applies padding symmetrically at both ends. The default stride is the kernel size (non-overlapping windows).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 6), new[] { 1.0f, 3.0f, 2.0f, 5.0f, 4.0f, 6.0f }); // Shape: [1, 1, 6]
    var result = Functional.MaxPool1D(input, kernelSize: 2, stride: 2);
    // Result shape: [1, 1, 3]
    // Values: [[[3.0, 5.0, 6.0]]] (max values of [1,3], [2,5], [4,6])

    MaxPool2D(FunctionalTensor, int, int?, int)

    Returns the result of a 2D maximum pooling of the input.

    Declaration
    public static FunctionalTensor MaxPool2D(FunctionalTensor input, int kernelSize, int? stride = null, int padding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int kernelSize

    The size of the kernel.

    int? stride

    The optional stride of the pooling. The default value is the kernel size.

    int padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 2D max pooling to the input tensor by computing the maximum value within a sliding 2D window. The input tensor must have rank 4 with shape [batch, channels, height, width]. The kernel slides over the spatial dimensions with the specified stride, and applies padding uniformly on all sides. The default stride is the kernel size (non-overlapping windows).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 4, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f }); // Shape: [1, 1, 4, 4]
    var result = Functional.MaxPool2D(input, kernelSize: 2, stride: 2);
    // Result shape: [1, 1, 2, 2]
    // Values: [[[[6.0, 8.0], [14.0, 16.0]]]] (max of each 2x2 block)

    MaxPool2D(FunctionalTensor, (int, int), (int, int)?, (int, int)?)

    Returns the result of a 2D maximum pooling of the input.

    Declaration
    public static FunctionalTensor MaxPool2D(FunctionalTensor input, (int, int) kernelSize, (int, int)? stride = null, (int, int)? padding = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    (int, int) kernelSize

    The size of the kernel.

    (int, int)? stride

    The optional stride of the pooling. The default value is the kernel size.

    (int, int)? padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 2D max pooling to the input tensor by computing the maximum value within a sliding 2D window. The input tensor must have rank 4 with shape [batch, channels, height, width]. This overload allows specifying different kernelSize, stride, and padding for height and width dimensions using tuples. The default stride is the kernel size for each dimension (non-overlapping windows).

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 3, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }); // Shape: [1, 1, 3, 4]
    var result = Functional.MaxPool2D(input, kernelSize: (2, 2), stride: (1, 2));
    // Result shape: [1, 1, 2, 2]
    // Values: [[[[6, 8], [10, 12]]]]

    MaxPool3D(FunctionalTensor, int, int?, int)

    Returns the result of a 3D maximum pooling of the input.

    Declaration
    public static FunctionalTensor MaxPool3D(FunctionalTensor input, int kernelSize, int? stride = null, int padding = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int kernelSize

    The size of the kernel.

    int? stride

    The optional stride of the pooling. The default value is the kernel size.

    int padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 3D max pooling to the input tensor by computing the maximum value within a sliding 3D window. The input tensor must have rank 5 with shape [batch, channels, depth, height, width]. The kernel slides over the spatial dimensions with the specified stride, and applies padding uniformly on all sides. The default stride is the kernel size (non-overlapping windows).

    Examples
    // Create a 3D tensor with shape [1, 1, 2, 2, 2] (batch=1, channels=1, 2x2x2 volume)
    var input = Functional.Constant(new TensorShape(1, 1, 2, 2, 2), new[] { 1.0f, 2.0f,3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f });
    var result = Functional.MaxPool3D(input, kernelSize: 2, stride: 2);
    // Result shape: [1, 1, 1, 1, 1]
    // Values: [[[[[8.0]]]]] (max of all 8 elements)

    MaxPool3D(FunctionalTensor, (int, int, int), (int, int, int)?, (int, int, int)?)

    Returns the result of a 3D maximum pooling of the input.

    Declaration
    public static FunctionalTensor MaxPool3D(FunctionalTensor input, (int, int, int) kernelSize, (int, int, int)? stride = null, (int, int, int)? padding = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    (int, int, int) kernelSize

    The size of the kernel.

    (int, int, int)? stride

    The optional stride of the pooling. The default value is the kernel size.

    (int, int, int)? padding

    The amount of padding on the spatial dimensions of the input.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies 3D max pooling to the input tensor by computing the maximum value within a sliding 3D window. The input tensor must have rank 5 with shape [batch, channels, depth, height, width]. This overload allows specifying different kernelSize, stride, and padding for each spatial dimension using tuples. The default stride is the kernel size for each dimension (non-overlapping windows).

    Examples
    // Create a 3D tensor with shape [1, 1, 2, 2, 4]
    var input = Functional.Constant(new TensorShape(1, 1, 2, 2, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f });
    var result = Functional.MaxPool3D(input, kernelSize: (2, 2, 2), stride: (2, 2, 2));
    // Result shape: [1, 1, 1, 1, 2]
    // Values: [[[[[14, 16]]]]]

    Min(FunctionalTensor, FunctionalTensor)

    Returns the element-wise minimum of input and other.

    Declaration
    public static FunctionalTensor Min(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator computes the element-wise minimum between two tensors. For each element position, the output contains the smaller of the two input values. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 5.0f, 3.0f });
    var b = Functional.Constant(new[] { 2.0f, 4.0f, 6.0f });
    var result = Functional.Min(a, b);
    // Result: [1.0, 4.0, 3.0] (min of each pair)

    Mish(FunctionalTensor)

    Returns mish(input) element-wise.

    Declaration
    public static FunctionalTensor Mish(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Mish activation function element-wise. Mish is defined as x * tanh(softplus(x)) or x * tanh(ln(1 + e^x)). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Mish(input);
    // Result: [-0.252, -0.303, 0.0, 0.865, 1.943]

    MoveDim(FunctionalTensor, int, int)

    Returns the input tensor with a dimension moved from source to destination.

    Declaration
    public static FunctionalTensor MoveDim(this FunctionalTensor input, int source, int destination)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int source

    The dimension in the input tensor to move.

    int destination

    The moved dimension in the output tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator moves a single dimension of the input tensor from one position to another. This operator doesn't copy the data. It only changes the dimension order. All other dimensions maintain their relative order in the output tensor.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3, 4), new float[24]); // Shape: [2, 3, 4]
    var result = Functional.MoveDim(input, source: 1, destination: 0);
    // Result shape: [3, 2, 4] (dimension 1 moved to position 0)

    MoveDim(FunctionalTensor, int[], int[])

    Returns the input tensor with multiple dimensions moved from source to destination.

    Declaration
    public static FunctionalTensor MoveDim(this FunctionalTensor input, int[] source, int[] destination)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] source

    The dimensions in the input tensor to move.

    int[] destination

    The moved dimensions in the output tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator moves multiple dimensions of the input tensor from source positions to destination positions. The source and destination arrays must have the same length. This operation doesn't copy the data. It only changes the dimension order. Dimensions not specified in source maintain their relative order in the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3, 4, 5), new float[120]); // Shape: [2, 3, 4, 5]
    var result = Functional.MoveDim(input, source: new[] { 0, 2 }, destination: new[] { 2, 0 });
    // Result shape: [4, 3, 2, 5] (dimensions 0 and 2 swapped)

    Mul(FunctionalTensor, FunctionalTensor)

    Returns input * other element-wise.

    Declaration
    public static FunctionalTensor Mul(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise multiplication of two tensors. Promotes input and other to a compatible data type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 2.0f, 3.0f, 4.0f });
    var b = Functional.Constant(new[] { 5.0f, 6.0f, 7.0f });
    var result = Functional.Mul(a, b);
    // Result: [10.0, 18.0, 28.0]

    Multinomial(FunctionalTensor, int, int?)

    Returns an output generated from the multinomial probability distribution in the corresponding row of the input.

    Declaration
    public static FunctionalTensor Multinomial(FunctionalTensor input, int numSamples, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The probability distributions.

    int numSamples

    The number of samples.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation samples indices from a multinomial probability distribution. Each row of the input tensor represents a probability distribution, and numSamples indices are drawn from each row. Promotes input to float type if necessary. The output shape is [batch_size, numSamples] containing the sampled indices. You can provide an optional seed for reproducible results.

    Examples
    var probs = Functional.Constant(new TensorShape(1, 3), new[] { 0.1f, 0.3f, 0.6f });
    var result = Functional.Multinomial(probs, numSamples: 5, seed: 42);
    // Result: Sampled indices (0, 1, or 2) based on probabilities
    // Shape: [1, 5], values like [[2, 2, 1, 2, 0]]

    NMS(FunctionalTensor, FunctionalTensor, float, float?)

    Returns the indexes of the boxes with the highest scores, which pass the intersect-over-union test to other output boxes.

    Declaration
    public static FunctionalTensor NMS(FunctionalTensor boxes, FunctionalTensor scores, float iouThreshold, float? scoreThreshold = null)
    Parameters
    Type Name Description
    FunctionalTensor boxes

    The boxes tensor [N, 4] with (x1, y1, x2, y2) corners format with 0 ≤ x1 < x2 ≤ 1 and 0 ≤ y1 < y2 ≤ 1.

    FunctionalTensor scores

    The scores tensor [N].

    float iouThreshold

    The threshold above which to discard overlapping boxes.

    float? scoreThreshold

    (Optional) The threshold of score below which to discard boxes.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs Non-Maximum Suppression (NMS) to filter overlapping bounding boxes in object detection. Boxes with IoU (Intersection over Union) greater than iouThreshold with higher-scoring boxes are suppressed. The boxes tensor must have rank 2 with shape [N, 4] in (x1, y1, x2, y2) corner format with normalized coordinates (0 ≤ x1 < x2 ≤ 1 and 0 ≤ y1 < y2 ≤ 1). The scores tensor must have rank 1 with shape [N]. Promotes boxes and scores to float type if necessary. Optionally, boxes with scores below scoreThreshold are filtered out before NMS.

    Examples
    var boxes = Functional.Constant(new TensorShape(3, 4), new[] { 0.1f, 0.1f, 0.3f, 0.3f, 0.15f, 0.15f, 0.35f, 0.35f, 0.5f, 0.5f, 0.7f, 0.7f });
    var scores = Functional.Constant(new[] { 0.9f, 0.8f, 0.95f });
    var result = Functional.NMS(boxes, scores, iouThreshold: 0.5f, scoreThreshold: 0.7f);
    // Result: Indices of boxes kept after NMS (e.g., [2, 0])

    Narrow(FunctionalTensor, int, int, int)

    Returns the input tensor narrowed along a dimension.

    Declaration
    public static FunctionalTensor Narrow(this FunctionalTensor input, int dim, int start, int length)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to narrow.

    int start

    The start index along the dimension.

    int length

    The number of elements along the dimension.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator returns a new tensor that is a narrowed version of the input tensor along a specified dimension. The narrowing starts at the given start index and continues for length elements. All other dimensions remain unchanged. Equivalent to slicing the tensor along a single dimension.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 4, 5, 6, 7, 8 }); // Shape: [8]
    var result = Functional.Narrow(input, dim: 0, start: 2, length: 4);
    // Result: [3, 4, 5, 6] (elements from index 2 to 5)

    Narrow(FunctionalTensor, int, FunctionalTensor, FunctionalTensor)

    Returns the input tensor narrowed along a dimension.

    Declaration
    public static FunctionalTensor Narrow(this FunctionalTensor input, int dim, FunctionalTensor start, FunctionalTensor length)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to narrow.

    FunctionalTensor start

    The functional start index along the dimension.

    FunctionalTensor length

    The functional number of elements along the dimension.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator returns a new tensor that is a narrowed version of the input tensor along a specified dimension. The narrowing starts at the given start index and continues for length elements. This overload accepts functional tensors for start and length, allowing dynamic slicing determined at runtime. The start and length tensors must be integer type scalars.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 4, 5, 6, 7, 8 }); // Shape: [8]
    var start = Functional.Constant(2);
    var length = Functional.Constant(4);
    var result = Functional.Narrow(input, dim: 0, start, length);
    // Result: [3, 4, 5, 6] (dynamically determined slice)

    Neg(FunctionalTensor)

    Returns -input element-wise.

    Declaration
    public static FunctionalTensor Neg(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation negates each element in the input tensor, changing the sign.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Neg(input);
    // Result: [2.0, 1.0, 0.0, -1.0, -2.0]

    NonZero(FunctionalTensor)

    Returns the indices of the input tensor with values not equal to zero.

    Declaration
    public static FunctionalTensor NonZero(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator returns a tensor containing the indices of all non-zero elements in the input tensor. The output has shape [N, rank] where N is the number of non-zero elements and rank is the number of dimensions. Each row in the output represents the multi-dimensional index of a non-zero element.

    Examples
    var input = Functional.Constant(new[] { 0, 2, 0, 4, 5, 0 });
    var result = Functional.NonZero(input);
    // Result: [[1], [3], [4]] (indices of non-zero values 2, 4, 5)

    Normal(float, float, int[], int?)

    Returns an output generated by sampling a normal distribution.

    Declaration
    public static FunctionalTensor Normal(float mean, float std, int[] size, int? seed = null)
    Parameters
    Type Name Description
    float mean

    The mean of the normal distribution.

    float std

    The standard deviation of the normal distribution.

    int[] size

    The shape of the output tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random values from a normal (Gaussian) distribution with specified mean and standard deviation std. The output has the specified shape with values drawn from N(mean, std²). You can provide an optional seed for reproducible results.

    Examples
    var result = Functional.Normal(mean: 0.0f, std: 1.0f, size: new[] { 2, 3 }, seed: 42);
    // Result: Random values from standard normal distribution
    // Shape: [2, 3], values centered around 0 with std 1

    NormalLike(float, float, FunctionalTensor, int?)

    Returns an output generated by sampling a normal distribution with shape matching the input tensor.

    Declaration
    public static FunctionalTensor NormalLike(float mean, float std, FunctionalTensor input, int? seed = null)
    Parameters
    Type Name Description
    float mean

    The mean of the normal distribution.

    float std

    The standard deviation of the normal distribution.

    FunctionalTensor input

    The input tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random values from a normal (Gaussian) distribution with specified mean and standard deviation std. The output has the same shape as the input tensor with values drawn from N(mean, std²). You can provide an optional seed for reproducible results.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); // Shape: [2, 3]
    var result = Functional.NormalLike(mean: 0.0f, std: 1.0f, input: input, seed: 42);
    // Result: Random values from standard normal distribution with shape [2, 3]

    NotEqual(FunctionalTensor, FunctionalTensor)

    Returns input ≠ other element-wise.

    Declaration
    public static FunctionalTensor NotEqual(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator compares two tensors element-wise for inequality. Returns an integer tensor where each element is 1 if the corresponding elements aren't equal, and 0 if equal. Promotes input and other to a compatible data type if necessary. The tensors are broadcasted to a common shape.

    Examples
    var a = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var b = Functional.Constant(new[] { 1.0f, 0.0f, 3.0f });
    var result = Functional.NotEqual(a, b);
    // Result: [0, 1, 0] (false, true, false)

    OneHot(FunctionalTensor, int)

    Returns a one hot tensor with given index values that has zeros everywhere except where the index of last dimension matches the corresponding value of the input tensor, in which case it will be 1.

    Declaration
    public static FunctionalTensor OneHot(FunctionalTensor tensor, int numClasses = -1)
    Parameters
    Type Name Description
    FunctionalTensor tensor

    The index tensor.

    int numClasses

    Total number of classes. If set to -1, the number of classes will be inferred as one greater than the largest class value in the input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation creates a one-hot encoded tensor from integer indices. For each index value in the input, the corresponding position in the last dimension of the output is set to 1, while all other positions are 0. If numClasses is -1, the number of classes is inferred as max(tensor) + 1.

    Examples
    var indices = Functional.Constant(new[] { 0, 2, 1 });
    var result = Functional.OneHot(indices, numClasses: 3);
    // Result: [[1, 0, 0], [0, 0, 1], [0, 1, 0]]
    // Shape: [3, 3]

    Ones(int[], DataType)

    Returns a tensor filled with 1 with given shape size and data type dataType.

    Declaration
    public static FunctionalTensor Ones(int[] size, DataType dataType = DataType.Int)
    Parameters
    Type Name Description
    int[] size

    The shape of the tensor.

    DataType dataType

    The data type of the tensor. Default is Int.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the specified shape size with all elements initialized to 1. dataType can be either Int or Float, defaulting to Int.

    Examples
    // Create a tensor of shape [3, 4] filled with integer ones
    var intOnes = Functional.Ones(new int[] {3, 4});
    // Create a tensor of shape [2, 3, 4] filled with float ones
    var floatOnes = Functional.Ones(new int[] {2, 3, 4}, DataType.Float);

    OnesLike(FunctionalTensor, DataType)

    Returns a tensor filled with 1 with the shape of input and data type dataType.

    Declaration
    public static FunctionalTensor OnesLike(FunctionalTensor input, DataType dataType = DataType.Int)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    DataType dataType

    The data type of the tensor. Default is Int.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the same shape as the input tensor, with all elements initialized to 1. dataType can be either Int or Float, defaulting to Int.

    Examples
    var input = Functional.Constant(new TensorShape(3, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
    // Create a tensor of integer ones with the same shape as input
    var intOnes = Functional.OnesLike(input);
    // Creates a tensor of float ones with the same shape as input
    var floatOnes = Functional.OnesLike(input, DataType.Float);

    PRelu(FunctionalTensor, FunctionalTensor)

    Returns PRelu(input) element-wise.

    Declaration
    public static FunctionalTensor PRelu(FunctionalTensor input, FunctionalTensor weight)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor weight

    The weight tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Parametric Rectified Linear Unit (PReLU) activation function element-wise. PReLU is defined as x if x > 0, else weight * x. Promotes input and weight to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var weight = Functional.Constant(new[] { 0.25f });
    var result = Functional.PRelu(input, weight);
    // Result: [-0.5, -0.25, 0.0, 1.0, 2.0]

    Pad(FunctionalTensor, int[], int)

    Returns the input tensor padded with size determined by the pad array and a constant value.

    Declaration
    public static FunctionalTensor Pad(this FunctionalTensor input, int[] pad, int value)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] pad

    The padding lower and upper sizes starting from the final dimension (pad_w_lower, pad_w_upper, pad_h_lower, pad_h_upper, ...), not all dimensions need to be padded.

    int value

    The constant value to use for padding.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator pads the input tensor with a specified integer constant value. The pad array specifies padding amounts starting from the last dimension: [pad_w_lower, pad_w_upper, pad_h_lower, pad_h_upper, ...]. Fills all padded regions with the specified constant value. If the input is a float tensor, the value is automatically converted to float.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3 });
    var result = Functional.Pad(input, pad: new[] { 1, 2 }, value: -1);
    // Result: [-1, 1, 2, 3, -1, -1] (padded with -1)

    Pad(FunctionalTensor, int[], float)

    Returns the input tensor padded with size determined by the pad array and a constant value.

    Declaration
    public static FunctionalTensor Pad(this FunctionalTensor input, int[] pad, float value)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] pad

    The padding lower and upper sizes starting from the final dimension (pad_w_lower, pad_w_upper, pad_h_lower, pad_h_upper, ...), not all dimensions need to be padded.

    float value

    The constant value to use for padding.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator pads the input tensor with a specified float constant value. The pad array specifies padding amounts starting from the last dimension: [pad_w_lower, pad_w_upper, pad_h_lower, pad_h_upper, ...]. Fills all padded regions with the specified constant value. The input tensor must be float type.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.Pad(input, pad: new[] { 1, 2 }, value: -1.5f);
    // Result: [-1.5, 1.0, 2.0, 3.0, -1.5, -1.5] (padded with -1.5)

    Pad(FunctionalTensor, int[], string)

    Returns the input tensor padded with size determined by the pad array and values determined by the mode.

    Declaration
    public static FunctionalTensor Pad(this FunctionalTensor input, int[] pad, string mode)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] pad

    The padding lower and upper sizes starting from the final dimension (pad_w_lower, pad_w_upper, pad_h_lower, pad_h_upper, ...), not all dimensions need to be padded.

    string mode

    The mode to use for sampling values, should be constant, reflect, replicate or circular, for constant padding with non zero values use one of the other Pad methods.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator pads the input tensor along specified dimensions according to the given mode. The pad array specifies padding amounts starting from the last dimension: [pad_w_lower, pad_w_upper, pad_h_lower, pad_h_upper, ...]. Available modes: constant (zero padding), reflect (reflect values at boundaries), replicate (repeat edge values), circular (wrap around). For constant padding with non-zero values, use the other Pad overloads. Not all dimensions need to be padded; unspecified dimensions remain unchanged.

    Examples
    var input = Functional.Constant(new TensorShape(1, 2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var result = Functional.Pad(input, pad: new[] { 1, 1, 1, 1 }, mode: "constant");
    // Pads last two dimensions by 1 on each side with zeros
    // Result shape: [1, 4, 5]

    Permute(FunctionalTensor, int[])

    Returns the input tensor with permuted dimensions.

    Declaration
    public static FunctionalTensor Permute(this FunctionalTensor input, int[] dims)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dims

    The dimensions of the input tensor to use in the permuted output tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator reorders the dimensions of the input tensor according to the specified permutation. The dims array specifies the new order of dimensions, where dims[i] indicates which input dimension becomes output dimension i. All dimensions must be included exactly once in the permutation. This operator doesn't copy the data. It only changes the dimension order.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3, 4), new float[24]); // Shape: [2, 3, 4]
    var result = Functional.Permute(input, dims: new[] { 2, 0, 1 });
    // Result shape: [4, 2, 3] (dimensions reordered)

    PixelShuffle(FunctionalTensor, int)

    Returns the elements of the input tensor rearranged from a (∗,C×r^2,H,W) tensor to a (∗,C,H×r,W×r) tensor where r is the upscale factor.

    Declaration
    public static FunctionalTensor PixelShuffle(FunctionalTensor input, int upscaleFactor)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int upscaleFactor

    The upscale factor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation rearranges elements in a tensor for upsampling. Pixel shuffle converts depth (channels) into spatial dimensions by rearranging blocks of pixels from the channel dimension to spatial dimensions. The operation transforms shape [batch, C×r², H, W] to [batch, C, H×r, W×r] where r is the upscale factor.

    Examples
    var input = Functional.Constant(new TensorShape(1, 4, 2, 2), new float[16]); // Shape: [1, 4, 2, 2]
    var result = Functional.PixelShuffle(input, upscaleFactor: 2);
    // Result shape: [1, 1, 4, 4] (upscaled by factor of 2)

    PixelUnshuffle(FunctionalTensor, int)

    Returns the elements of the input tensor rearranged from a (∗,C,H×r,W×r) tensor to a (∗,C×r^2,H,W) tensor where r is the downscale factor.

    Declaration
    public static FunctionalTensor PixelUnshuffle(FunctionalTensor input, int downscaleFactor)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int downscaleFactor

    The downscale factor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation is the inverse of PixelShuffle(FunctionalTensor, int), rearranging spatial dimensions into the channel dimension. Pixel unshuffle converts spatial information into depth by moving blocks of pixels from spatial dimensions to the channel dimension. The operation transforms shape [batch, C, H×r, W×r] to [batch, C×r², H, W] where r is the downscale factor.

    Examples
    var input = Functional.Constant(new TensorShape(1, 1, 4, 4), new float[16]); // Shape: [1, 1, 4, 4]
    var result = Functional.PixelUnshuffle(input, downscaleFactor: 2);
    // Result shape: [1, 4, 2, 2] (downscaled by factor of 2)

    Positive(FunctionalTensor)

    Returns the input.

    Declaration
    public static FunctionalTensor Positive(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation returns the input tensor unchanged. It is the identity operation.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.Positive(input);
    // Result: [1.0, 2.0, 3.0]

    Pow(FunctionalTensor, float)

    Returns input^exponent element-wise.

    Declaration
    public static FunctionalTensor Pow(FunctionalTensor input, float exponent)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    float exponent

    The scalar exponent value.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation raises each element in the input tensor to a scalar exponent value. Promotes input to float type if necessary.

    Examples
    var base = Functional.Constant(new[] { 2.0f, 3.0f, 4.0f });
    var result = Functional.Pow(base, 2.0f);
    // Result: [4.0, 9.0, 16.0]

    Pow(FunctionalTensor, FunctionalTensor)

    Returns input^exponent element-wise.

    Declaration
    public static FunctionalTensor Pow(FunctionalTensor input, FunctionalTensor exponent)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor exponent

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation raises each element in the input tensor to the power of the corresponding element in the exponent tensor. Promotes input to float type if necessary. The tensors are broadcast to a common shape.

    Examples
    var base = Functional.Constant(new[] { 2.0f, 3.0f, 4.0f });
    var exponent = Functional.Constant(new[] { 3.0f, 2.0f, 1.0f });
    var result = Functional.Pow(base, exponent);
    // Result: [8.0, 9.0, 4.0]

    RMSNorm(FunctionalTensor, FunctionalTensor, float)

    Returns the result of computing Root Mean Square Normalization to the input tensor.

    Declaration
    public static FunctionalTensor RMSNorm(FunctionalTensor input, FunctionalTensor scale, float eps = 1E-05)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor scale

    The scale tensor.

    float eps

    The epsilon value used to avoid division by zero. Default is 1.0e-5.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies Root Mean Square Normalization (RMSNorm) to the input tensor. RMSNorm normalizes the input across the last dimension by dividing by the root mean square. The formula is: input / sqrt(mean(input²) + eps) * scale, where mean is computed over the last dimension. Promotes all tensors to float type if necessary. See paper: RMSNorm

    Examples
    var input = Functional.Constant(new TensorShape(1, 4), new[] { 4.0f, 2.0f, 1.0f, 4.0f });
    var scale = Functional.Constant(new[] { 2.0f, 1.0f, 0.5f, 1.0f });
    // Normalizes across the feature dimension
    var result = Functional.RMSNorm(input, scale);
    // Result: { 2.630, 0.658, 0.164, 1.315 }

    RSqrt(FunctionalTensor)

    Returns 1/√input element-wise.

    Declaration
    public static FunctionalTensor RSqrt(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the reciprocal of the square root of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 4.0f, 9.0f, 16.0f });
    var result = Functional.RSqrt(input);
    // Result: [1.0, 0.5, 0.333, 0.25] (approximately)

    Rad2Deg(FunctionalTensor)

    Returns the input values converted from angles in radians to degrees element-wise.

    Declaration
    public static FunctionalTensor Rad2Deg(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation converts angles from radians to degrees by multiplying each element by 180/π.

    Examples
    var radians = Functional.Constant(new[] { 0.0f, 1.571f, 3.142f, 6.283f });
    var degrees = Functional.Rad2Deg(radians);
    // Result: [0.0, 90.0, 180.0, 360.0] (approximately)

    Rand(int[], int?)

    Returns an output generated by sampling a uniform distribution on the interval [0, 1).

    Declaration
    public static FunctionalTensor Rand(int[] size, int? seed = null)
    Parameters
    Type Name Description
    int[] size

    The shape of the output tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random floating-point values uniformly distributed between 0 (inclusive) and 1 (exclusive). The output has the specified shape. You can provide an optional seed for reproducible results.

    Examples
    var result = Functional.Rand(size: new[] { 2, 3 }, seed: 42);
    // Result: Random values in [0, 1) with shape [2, 3]
    // Example: [[0.374, 0.950, 0.731], [0.598, 0.156, 0.155]]

    RandInt(int[], int, int, int?)

    Returns an output generated by sampling a uniform distribution of integers on the interval [low, high).

    Declaration
    public static FunctionalTensor RandInt(int[] size, int low, int high, int? seed = null)
    Parameters
    Type Name Description
    int[] size

    The shape of the output tensor.

    int low

    The inclusive minimum value of the interval.

    int high

    The exclusive maximum value of the interval.

    int? seed

    The optional seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random integer values uniformly distributed between low (inclusive) and high (exclusive). The output has the specified shape and integer data type. You can provide an optional seed for reproducible results.

    Examples
    var result = Functional.RandInt(size: new[] { 2, 3 }, low: 0, high: 10, seed: 42);
    // Result: Random integers in [0, 10) with shape [2, 3]
    // Example: [[3, 7, 5], [9, 1, 2]]

    RandIntLike(FunctionalTensor, int, int, int?)

    Returns an output generated by sampling a uniform distribution of integers on the interval [low, high) with shape matching the input tensor.

    Declaration
    public static FunctionalTensor RandIntLike(FunctionalTensor input, int low, int high, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int low

    The inclusive minimum value of the interval.

    int high

    The exclusive maximum value of the interval.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random integer values uniformly distributed between low (inclusive) and high (exclusive). The output has the same shape as the input tensor and integer data type. You can provide an optional seed for reproducible results.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [2, 2]
    var result = Functional.RandIntLike(input, low: 0, high: 10, seed: 42);
    // Result: Random integers in [0, 10) with shape [2, 2]

    RandLike(FunctionalTensor, int?)

    Returns an output generated by sampling a uniform distribution on the interval [0, 1) with shape matching the input tensor.

    Declaration
    public static FunctionalTensor RandLike(FunctionalTensor input, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random floating-point values uniformly distributed between 0 (inclusive) and 1 (exclusive). The output has the same shape as the input tensor. You can provide an optional seed for reproducible results.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f }); // Shape: [2, 2]
    var result = Functional.RandLike(input, seed: 42);
    // Result: Random values in [0, 1) with shape [2, 2]

    RandN(int[], int?)

    Returns an output generated by sampling a standard normal distribution.

    Declaration
    public static FunctionalTensor RandN(int[] size, int? seed = null)
    Parameters
    Type Name Description
    int[] size

    The shape of the output tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random values from a standard normal distribution (mean=0, std=1). The output has the specified shape with values drawn from N(0, 1). You can provide an optional seed for reproducible results.

    Examples
    var result = Functional.RandN(size: new[] { 2, 3 }, seed: 42);
    // Result: Random values from standard normal distribution
    // Shape: [2, 3], values centered around 0 with std 1

    RandNLike(FunctionalTensor, int?)

    Returns an output generated by sampling a standard normal distribution with shape matching the input tensor.

    Declaration
    public static FunctionalTensor RandNLike(FunctionalTensor input, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation generates random values from a standard normal distribution (mean=0, std=1). The output has the same shape as the input tensor with values drawn from N(0, 1). You can provide an optional seed for reproducible results.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); // Shape: [2, 3]
    var result = Functional.RandNLike(input, seed: 42);
    // Result: Random values from standard normal distribution with shape [2, 3]

    RandomChoice(FunctionalTensor, int[], int?)

    Returns a randomly selected values from a 1D input tensor.

    Declaration
    public static FunctionalTensor RandomChoice(FunctionalTensor input, int[] size, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor to select random values from.

    int[] size

    The shape of the output tensor.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation randomly selects elements from a 1D input tensor with uniform probability. The input must have rank 1. The output has the specified shape with values drawn randomly from the input. Sampling is done with replacement, so the same value can appear multiple times. You can provide an optional seed for reproducible results.

    Examples
    var values = Functional.Constant(new[] { 10.0f, 20.0f, 30.0f, 40.0f });
    var result = Functional.RandomChoice(values, size: new[] { 2, 3 }, seed: 42);
    // Result: Random selections from values with shape [2, 3]
    // Example: [[20.0, 40.0, 10.0], [30.0, 20.0, 40.0]]

    RandomChoice(FunctionalTensor, int[], FunctionalTensor, int?)

    Returns a randomly selected value from a 1D input tensor with probabilities given by the tensor p

    Declaration
    public static FunctionalTensor RandomChoice(FunctionalTensor input, int[] size, FunctionalTensor p, int? seed = null)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor to select random values from.

    int[] size

    The shape of the output tensor.

    FunctionalTensor p

    The probabilities tensor corresponding to the values.

    int? seed

    (Optional) The seed value for the random number generator.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation randomly selects elements from a 1D input tensor using specified probabilities. Both input and p must have rank 1 with matching lengths. The output has the specified shape with values drawn from the input. Each element in p represents the probability of selecting the corresponding element from input. Sampling is done with replacement, so the same value can appear multiple times. You can provide an optional seed for reproducible results. The output shape is size.

    Examples
    var values = Functional.Constant(new[] { 10.0f, 20.0f, 30.0f });
    var probs = Functional.Constant(new[] { 0.1f, 0.3f, 0.6f }); // Higher probability for 30.0
    var result = Functional.RandomChoice(values, size: new[] { 5 }, p: probs, seed: 42);
    // Result: More likely to contain 30.0 than 10.0 or 20.0
    // Example: [30.0, 30.0, 20.0, 30.0, 10.0]

    Ravel(FunctionalTensor)

    Returns the input tensor with its elements flattened to a single dimension.

    Declaration
    public static FunctionalTensor Ravel(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation flattens the input tensor to a 1D array containing all its elements. The elements are arranged in row-major (C-style) order. Equivalent to calling Reshape(FunctionalTensor, int[]) with shape [-1].

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.Ravel(input);
    // Result: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]

    Reciprocal(FunctionalTensor)

    Returns 1/input element-wise.

    Declaration
    public static FunctionalTensor Reciprocal(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the reciprocal (multiplicative inverse) of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 4.0f, 10.0f });
    var result = Functional.Reciprocal(input);
    // Result: [1.0, 0.5, 0.25, 0.1]

    ReduceL1(FunctionalTensor, int, bool)

    Returns the L1 norm of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceL1(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the L1 norm (sum of absolute values) along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceL1(FunctionalTensor, int[], bool)

    Returns the L1 norm of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceL1(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the L1 norm (sum of absolute values) along the specified dimensions. If keepdim is false (default), this operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { -1.0f, 2.0f, 3.0f, -4.0f });
    var result = Functional.ReduceL1(input, new[] { 1 });
    // Result: [3.0, 7.0] (|−1| + |2| = 3, |3| + |−4| = 7)

    ReduceL2(FunctionalTensor, int, bool)

    Returns the L2 norm of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceL2(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the L2 norm (Euclidean norm [square root of sum of squares]) along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceL2(FunctionalTensor, int[], bool)

    Returns the L2 norm of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceL2(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the L2 norm (Euclidean norm: square root of sum of squares) along the specified dimensions. If keepdim is false (default), this operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { 3.0f, 4.0f, 1.0f, 2.0f });
    var result = Functional.ReduceL2(input, new[] { 1 });
    // Result: [5.0, 2.236] (√(3²+4²) = 5, √(1²+2²) ≈ 2.236)

    ReduceLogSumExp(FunctionalTensor, int, bool)

    Returns the log of summed exponentials of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceLogSumExp(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes log(sum(exp(x))) along a single dimension, providing numerical stability. Promotes input to float type if necessary. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceLogSumExp(FunctionalTensor, int[], bool)

    Returns the log of summed exponentials of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceLogSumExp(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes log(sum(exp(x))) along the specified dimensions, providing numerical stability. Promotes input to float type if necessary. If keepdim is false (default), the operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var result = Functional.ReduceLogSumExp(input, new[] { 1 });
    // Result: [2.313, 4.313] (log(e¹ + e²), log(e³ + e⁴))

    ReduceMax(FunctionalTensor, int, bool)

    Returns the maximum value of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceMax(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the maximum value along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceMax(FunctionalTensor, int[], bool)

    Returns the maximum value of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceMax(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the maximum value along the specified dimensions. If keepdim is false (default), this operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 3.0f, 2.0f, 4.0f, 2.0f, 5.0f });
    var result = Functional.ReduceMax(input, new[] { 1 });
    // Result: [3.0, 5.0] (max values along dimension 1)

    ReduceMean(FunctionalTensor, int, bool)

    Returns the mean of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceMean(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the average value along a single dimension. Promotes input to float type if necessary. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceMean(FunctionalTensor, int[], bool)

    Returns the mean of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceMean(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the average value along the specified dimensions. Promotes input to float type if necessary. If keepdim is false (default), the operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.ReduceMean(input, new[] { 1 });
    // Result: [2.0, 5.0] (mean of each row)

    ReduceMin(FunctionalTensor, int, bool)

    Returns the minimum value of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceMin(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the minimum value along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceMin(FunctionalTensor, int[], bool)

    Returns the minimum value of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceMin(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the minimum value along the specified dimensions. If keepdim is false (default), this operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 3.0f, 2.0f, 4.0f, 2.0f, 5.0f });
    var result = Functional.ReduceMin(input, new[] { 1 });
    // Result: [1.0, 2.0] (min values along dimension 1)

    ReduceProd(FunctionalTensor, int, bool)

    Returns the product of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceProd(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation multiplies all elements along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceProd(FunctionalTensor, int[], bool)

    Returns the product of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceProd(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation multiplies all elements along the specified dimensions. If keepdim is false (default), the operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.ReduceProd(input, new[] { 1 });
    // Result: [6.0, 120.0] (1×2×3 = 6, 4×5×6 = 120)

    ReduceSum(FunctionalTensor, int, bool)

    Returns the sum of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceSum(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation adds all elements along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceSum(FunctionalTensor, int[], bool)

    Returns the sum of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceSum(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation adds all elements along the specified dimensions. If keepdim is false (default), the operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.ReduceSum(input, new[] { 1 });
    // Result: [6.0, 15.0] (1+2+3 = 6, 4+5+6 = 15)

    ReduceSumSquare(FunctionalTensor, int, bool)

    Returns the sum of the square of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceSumSquare(FunctionalTensor input, int dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimension in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the sum of squared values along a single dimension. If keepdim is false (default), the operation removes the reduced dimension from the output.

    ReduceSumSquare(FunctionalTensor, int[], bool)

    Returns the sum of the square of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceSumSquare(FunctionalTensor input, int[] dim, bool keepdim = false)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the sum of squared values along the specified dimensions. If keepdim is false (default), the operation removes reduced dimensions from the output.

    Examples
    var input = Functional.Constant(new TensorShape(2, 2), new[] { 1.0f, 2.0f, 3.0f, 4.0f });
    var result = Functional.ReduceSumSquare(input, new[] { 1 });
    // Result: [5.0, 25.0] (1²+2² = 5, 3²+4² = 25)

    ReduceVariance(FunctionalTensor, int, bool, float)

    Returns the variance of the elements of the input tensor along the dimension.

    Declaration
    public static FunctionalTensor ReduceVariance(FunctionalTensor input, int dim, bool keepdim = false, float correction = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    float correction

    The difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the variance along a single dimension. Promotes input to float type if necessary. If keepdim is false (default), the operation removes the reduced dimension from the output. The correction parameter adjusts degrees of freedom (the default is 1 for sample variance with Bessel's correction).

    ReduceVariance(FunctionalTensor, int[], bool, float)

    Returns the variance of the elements of the input tensor along the dimensions.

    Declaration
    public static FunctionalTensor ReduceVariance(FunctionalTensor input, int[] dim, bool keepdim = false, float correction = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions to reduce.

    bool keepdim

    Whether to keep the reduced dimensions in the output. Default is false.

    float correction

    The difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the variance along the specified dimensions. Promotes input to float type if necessary. If keepdim is false (default), the operation removes reduced dimensions from the output. The correction parameter adjusts degrees of freedom (the default is 1 for sample variance with Bessel's correction).

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f });
    var result = Functional.ReduceVariance(input, new[] { 1 });
    // Result: [1.0, 1.0] (variance of each row)

    Relu(FunctionalTensor)

    Returns relu(input) element-wise.

    Declaration
    public static FunctionalTensor Relu(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Rectified Linear Unit (ReLU) activation function element-wise. ReLU is defined as max(0, x), returning the input for positive values and zero for negative values. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Relu(input);
    // Result: [0.0, 0.0, 0.0, 1.0, 2.0]

    Relu6(FunctionalTensor)

    Returns relu6(input) element-wise.

    Declaration
    public static FunctionalTensor Relu6(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the ReLU6 activation function element-wise. ReLU6 is defined as min(max(0, x), 6), clamping values to the range [0, 6]. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, 0.0f, 3.0f, 6.0f, 8.0f });
    var result = Functional.Relu6(input);
    // Result: [0.0, 0.0, 3.0, 6.0, 6.0]

    Remainder(FunctionalTensor, FunctionalTensor)

    Returns input % other element-wise. The sign of the output is the same as that of the divider.

    Declaration
    public static FunctionalTensor Remainder(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the modulo where the sign of the result matches the sign of the divisor (other). Promotes input and other to a compatible data type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 7.0f, -7.0f, 7.0f, -7.0f });
    var b = Functional.Constant(new[] { 3.0f, 3.0f, -3.0f, -3.0f });
    var result = Functional.Remainder(a, b);
    // Result: [1.0, 2.0, -2.0, -1.0] (sign follows divisor)

    Reshape(FunctionalTensor, int[])

    Returns the input tensor elements reshaped.

    Declaration
    public static FunctionalTensor Reshape(this FunctionalTensor input, int[] shape)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] shape

    The shape of the output tensor. A negative value is inferred from the others.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator returns a tensor with the same data as the input but with a new shape. The total number of elements must remain the same. One dimension can be specified as -1, which will be automatically inferred from the other dimensions and total element count. The elements are read in row-major (C-contiguous) order and placed in the new shape.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 4, 5, 6 }); // Shape: [6]
    var result = Functional.Reshape(input, shape: new[] { 2, 3 });
    // Result shape: [2, 3] with same 6 elements
    
    var result2 = Functional.Reshape(input, shape: new[] { 3, -1 });
    // Result shape: [3, 2] (second dimension inferred)

    Round(FunctionalTensor)

    Returns [input] element-wise.

    Declaration
    public static FunctionalTensor Round(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation rounds each element in the input tensor to the nearest integer. If input is already an integer tensor, it is returned unchanged.

    Examples
    var input = Functional.Constant(new[] { -1.7f, -0.5f, 0.5f, 1.2f });
    var result = Functional.Round(input);
    // Result: [-2.0, 0.0, 0.0, 1.0]

    STFT(FunctionalTensor, int, FunctionalTensor, int, bool)

    Computes the Short-Time Fourier Transform (STFT) of the input signal.

    Declaration
    public static FunctionalTensor STFT(FunctionalTensor input, int hop_length, FunctionalTensor window, int n_fft, bool onesided)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input signal tensor.

    int hop_length

    The stride (in the signal) between two frames to be processed.

    FunctionalTensor window

    The optional window tensor that modulates a signal frame.

    int n_fft

    The size of a single frame. If window is specified, it has to be the same as the window length.

    bool onesided

    Returns only half of the DFT frequency results (real signals have a symmetric DFT spectrum).

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the Short-Time Fourier Transform (STFT) of the input signal. The input must have rank 3 with shape [batch, channels, signal_length]. If a window is provided, it must have rank 1. Promotes input and window to float type if necessary. When onesided is true, returns only positive frequencies.

    Examples
    var signal = Functional.Constant(new TensorShape(1, 8, 1), new[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f }); // Shape: [1, 8, 1]
    var window = Functional.HannWindow(windowLength: 4, periodic: true);
    var result = Functional.STFT(signal, hop_length: 2, window: window, n_fft: 4, onesided: true);
    // Result: Frequency components over time, with shape [1, 3, 3, 2]:
    // [[[[0.6, 0.0], [-0.3, 0.1], [0.0, 0.0]], [[1.0, 0.0], [-0.5, 0.1], [0.0, 0.0]], [[1.4, 0.0], [-0.7, 0.1], [0.0, 0.0]]]]

    Scatter(FunctionalTensor, int, FunctionalTensor, FunctionalTensor)

    Returns a copy of the input with the elements replaced by those from src given by the index along a dimension.

    Declaration
    public static FunctionalTensor Scatter(FunctionalTensor input, int dim, FunctionalTensor index, FunctionalTensor src)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to scatter.

    FunctionalTensor index

    The index tensor.

    FunctionalTensor src

    The source tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator creates a copy of the input tensor with specified elements replaced by values from a source tensor. The index tensor determines which elements to replace along the specified dimension. For each element in the src tensor, the corresponding index value determines where to write it in the output. The index tensor must be integer type and have the same shape as the src tensor.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 4, 5 });
    var index = Functional.Constant(new[] { 0, 2, 4 });
    var src = Functional.Constant(new[] { 10, 20, 30 });
    var result = Functional.Scatter(input, dim: 0, index, src);
    // Result: [10, 2, 20, 4, 30] (values at indices 0, 2, 4 replaced)

    ScatterAdd(FunctionalTensor, int, FunctionalTensor, FunctionalTensor)

    Returns a copy of the input with the elements updated by adding by those from src given by the index along a dimension.

    Declaration
    public static FunctionalTensor ScatterAdd(FunctionalTensor input, int dim, FunctionalTensor index, FunctionalTensor src)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to scatter.

    FunctionalTensor index

    The index tensor.

    FunctionalTensor src

    The source tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator creates a copy of the input tensor with specified elements incremented by values from a source tensor. Unlike Scatter(FunctionalTensor, int, FunctionalTensor, FunctionalTensor) which replaces values, ScatterAdd adds the source values to the existing values at the indexed positions. The index tensor determines which elements to update along the specified dimension. The index tensor must be integer type and have the same shape as the src tensor.

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 4, 5 });
    var index = Functional.Constant(new[] { 0, 2, 4 });
    var src = Functional.Constant(new[] { 10, 20, 30 });
    var result = Functional.ScatterAdd(input, dim: 0, index, src);
    // Result: [11, 2, 23, 4, 35] (values at indices 0, 2, 4 incremented)

    Select(FunctionalTensor, int, int)

    Returns the input tensor sliced along a dimension at an index.

    Declaration
    public static FunctionalTensor Select(this FunctionalTensor input, int dim, int index)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to select.

    int index

    The index along the dimension to select.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator selects a single slice from the input tensor along a specified dimension at a given index. The selected dimension is removed from the output, reducing the rank by 1. For example, selecting from a [2, 3, 4] tensor along dimension 1 at index 0 produces a [2, 4] tensor.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var result = Functional.Select(input, dim: 1, index: 1);
    // Result: [2, 5] (selects column 1 from each row)

    Select(FunctionalTensor, int, FunctionalTensor)

    Returns the input tensor sliced along a dimension at an index.

    Declaration
    public static FunctionalTensor Select(this FunctionalTensor input, int dim, FunctionalTensor index)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to select.

    FunctionalTensor index

    The functional index along the dimension to select.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator selects a single slice from the input tensor along a specified dimension at a given index. This overload accepts a functional tensor for the index, allowing dynamic selection determined at runtime. The selected dimension is removed from the output, reducing the rank by 1. The index tensor must be integer type and a scalar.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var index = Functional.Constant(1);
    var result = Functional.Select(input, dim: 1, index);
    // Result: [2, 5] (dynamically selects column 1)

    SelectScatter(FunctionalTensor, FunctionalTensor, int, int)

    Returns a copy of the input with the elements replaced by those from src at a dimension and index.

    Declaration
    public static FunctionalTensor SelectScatter(FunctionalTensor input, FunctionalTensor src, int dim, int index)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor src

    The source tensor.

    int dim

    The dimension along which to scatter.

    int index

    The index at which to scatter along the dimension.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator creates a copy of the input tensor with elements at a specific slice replaced by values from a source tensor. The src tensor is inserted at the specified index along the given dimension. The src tensor must have rank one less than the input, or have size 1 along the insertion dimension. This is the inverse operation of Select(FunctionalTensor, int, int) - it puts values back into a tensor at a specific slice.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var src = Functional.Constant(new[] { 10, 20 });
    var result = Functional.SelectScatter(input, src, dim: 1, index: 1);
    // Result: [[1, 10, 3], [4, 20, 6]] (column 1 replaced)

    Selu(FunctionalTensor)

    Returns selu(input) element-wise.

    Declaration
    public static FunctionalTensor Selu(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Scaled Exponential Linear Unit (SELU) activation function element-wise. SELU is defined as scale * (x if x > 0, else alpha * (e^x - 1)), with fixed scale ≈ 1.0507 and alpha ≈ 1.6733. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Selu(input);
    // Result: [-1.520, -1.111, 0.0, 1.0507, 2.1014]

    Sigmoid(FunctionalTensor)

    Returns sigmoid(input) element-wise.

    Declaration
    public static FunctionalTensor Sigmoid(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Sigmoid activation function element-wise. Sigmoid is defined as 1 / (1 + e^(-x)), mapping values to the range (0, 1). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Sigmoid(input);
    // Result: [0.119, 0.268, 0.5, 0.731, 0.880]

    Sign(FunctionalTensor)

    Returns the sign of the input element-wise.

    Declaration
    public static FunctionalTensor Sign(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation returns -1 for negative values, 0 for zero, and 1 for positive values.

    Examples
    var input = Functional.Constant(new[] { -5.0f, -1.0f, 0.0f, 1.0f, 5.0f });
    var result = Functional.Sign(input);
    // Result: [-1.0, -1.0, 0.0, 1.0, 1.0]

    Sin(FunctionalTensor)

    Returns sin(input) element-wise.

    Declaration
    public static FunctionalTensor Sin(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the sine of each element in the input tensor. Input is expected in radians.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 1.5708f, 3.14159f });
    var result = Functional.Sin(input);
    // Result: [0.0, 1.0, 0.0] (approximately sin(0), sin(π/2), sin(π))

    Sinh(FunctionalTensor)

    Returns sinh(input) element-wise.

    Declaration
    public static FunctionalTensor Sinh(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the hyperbolic sine of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Sinh(input);
    // Result: [-1.175, 0.0, 1.175] (approximately)

    SliceScatter(FunctionalTensor, FunctionalTensor, int, int, int, int)

    Returns a copy of the input with the elements replaced by those from src along a dimension with start, end and step.

    Declaration
    public static FunctionalTensor SliceScatter(FunctionalTensor input, FunctionalTensor src, int dim = 0, int start = 0, int end = 2147483647, int step = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor src

    The source tensor.

    int dim

    The dimension along which to scatter.

    int start

    The index of the first element to replace along the dimension.

    int end

    The end index of the scatter along the dimension.

    int step

    The step between the indices along the dimension.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator creates a copy of the input tensor with a slice of elements replaced by values from a source tensor. The replacement starts at the start index, ends before the end index, and proceeds with the given step size along the specified dimension. The src tensor must match the shape of the slice being replaced. Setting end to int.MaxValue replaces until the end of the dimension.

    Examples
    var input = Functional.Constant(new[] { 0, 0, 0, 0, 0 });
    var src = Functional.Constant(new[] { 10, 20 });
    var result = Functional.SliceScatter(input, src, dim: 0, start: 1, end: 5, step: 2);
    // Result: [0, 10, 0, 20, 0] (elements at indices 1 and 3 replaced)

    Softmax(FunctionalTensor, int)

    Returns softmax(input) element-wise along a dimension.

    Declaration
    public static FunctionalTensor Softmax(FunctionalTensor input, int dim = -1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension along which to calculate the softmax. Default is -1.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Softmax function along the specified dimension. Softmax is defined as e^(x_i) / sum(e^(x_j)) for all j in the dimension, converting values to a probability distribution that sums to 1. Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.Softmax(input, dim: 0);
    // Result: [0.0900, 0.2447, 0.6652] (sums to 1.0)

    Softplus(FunctionalTensor)

    Returns softplus(input) element-wise.

    Declaration
    public static FunctionalTensor Softplus(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Softplus activation function element-wise. Softplus is defined as ln(1 + e^x). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Softplus(input);
    // Result: [0.126, 0.313, 0.693, 1.313, 2.126]

    Softsign(FunctionalTensor)

    Returns softsign(input) element-wise.

    Declaration
    public static FunctionalTensor Softsign(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Softsign activation function element-wise. Softsign is defined as x / (1 + |x|), producing outputs in the range (-1, 1). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Softsign(input);
    // Result: [-0.666, -0.5, 0.0, 0.5, 0.666]

    Split(FunctionalTensor, int[], int)

    Returns an array of tensors by splitting the input into sections along a dimension.

    Declaration
    public static FunctionalTensor[] Split(this FunctionalTensor input, int[] sections, int dim = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] sections

    The length of each section along the dimension.

    int dim

    The dimension along which to split.

    Returns
    Type Description
    FunctionalTensor[]

    The output tensor.

    Remarks

    This operator splits the input tensor into multiple tensors along a specified dimension. The sections array specifies the size of each output tensor along the split dimension. The sum of section sizes must equal the size of the input along the split dimension. All other dimensions remain unchanged in the output tensors. This is the inverse operation of Concat(FunctionalTensor[], int).

    Examples
    var input = Functional.Constant(new[] { 1, 2, 3, 4, 5, 6 }); // Shape: [6]
    var result = Functional.Split(input, sections: new[] { 2, 3, 1 }, dim: 0);
    // result[0]: [1, 2] (length 2)
    // result[1]: [3, 4, 5] (length 3)
    // result[2]: [6] (length 1)

    Sqrt(FunctionalTensor)

    Returns √(input) element-wise.

    Declaration
    public static FunctionalTensor Sqrt(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the square root of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 1.0f, 4.0f, 9.0f, 16.0f });
    var result = Functional.Sqrt(input);
    // Result: [0.0, 1.0, 2.0, 3.0, 4.0]

    Square(FunctionalTensor)

    Returns input*input element-wise.

    Declaration
    public static FunctionalTensor Square(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the square of each element in the input tensor.

    Examples
    var input = Functional.Constant(new[] { -2.0f, -1.0f, 0.0f, 1.0f, 2.0f });
    var result = Functional.Square(input);
    // Result: [4.0, 1.0, 0.0, 1.0, 4.0]

    Squeeze(FunctionalTensor)

    Returns the input tensor with all dimensions of size 1 removed.

    Declaration
    public static FunctionalTensor Squeeze(this FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator removes all dimensions of size 1 from the input tensor. The resulting tensor has the same data but with a reduced rank. For example, a tensor of shape [1, 3, 1, 5] becomes [3, 5] after squeezing.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 1, 4), new float[12]); // Shape: [1, 3, 1, 4]
    var result = Functional.Squeeze(input);
    // Result shape: [3, 4] (singleton dimensions removed)

    Squeeze(FunctionalTensor, int[])

    Returns the input tensor with all specified dimensions of size 1 removed.

    Declaration
    public static FunctionalTensor Squeeze(this FunctionalTensor input, int[] dim)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dim

    The dimensions of size 1 to remove.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator removes only the specified dimensions of size 1 from the input tensor. Each specified dimension must have size 1, otherwise an error occurs. The resulting tensor has the same data but with a reduced rank.

    Examples
    var input = Functional.Constant(new TensorShape(1, 3, 1, 4), new float[12]); // Shape: [1, 3, 1, 4]
    var result = Functional.Squeeze(input, dim: new[] { 0, 2 });
    // Result shape: [3, 4] (dimensions 0 and 2 removed)

    Stack(FunctionalTensor[], int)

    Returns the input tensors concatenated along a new dimension.

    Declaration
    public static FunctionalTensor Stack(FunctionalTensor[] tensors, int dim = 0)
    Parameters
    Type Name Description
    FunctionalTensor[] tensors

    The input tensors.

    int dim

    The dimension along which to stack.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator stacks a sequence of tensors along a new dimension. All input tensors must have the same shape. The output rank is one greater than the input tensors, with the new dimension inserted at the specified position. Unlike Concat(FunctionalTensor[], int) which joins along an existing dimension, Stack creates a new dimension.

    Examples
    var a = Functional.Constant(new[] { 1, 2, 3 }); // Shape: [3]
    var b = Functional.Constant(new[] { 4, 5, 6 }); // Shape: [3]
    var result = Functional.Stack(new[] { a, b }, dim: 0);
    // Result shape: [2, 3], values: [[1, 2, 3], [4, 5, 6]]

    Sub(FunctionalTensor, FunctionalTensor)

    Returns input - other element-wise.

    Declaration
    public static FunctionalTensor Sub(FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation performs element-wise subtraction of two tensors. Promotes input and other to a compatible data type if necessary. The tensors are broadcast to a common shape.

    Examples
    var a = Functional.Constant(new[] { 5.0f, 7.0f, 9.0f });
    var b = Functional.Constant(new[] { 1.0f, 2.0f, 3.0f });
    var result = Functional.Sub(a, b);
    // Result: [4.0, 5.0, 6.0]

    Swish(FunctionalTensor, float)

    Returns swish(input) element-wise.

    Declaration
    public static FunctionalTensor Swish(FunctionalTensor input, float alpha = 1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    float alpha

    The alpha value for the swish. Default is 1.0.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation applies the Swish activation function element-wise. Swish is defined as x / (1 + e^(−αx)). Promotes input to float type if necessary.

    Examples
    var input = Functional.Constant(new[] { -3.0f, -1.0f, 0.0f, 1.0f, 3.0f });
    var result = Functional.Swish(input);
    // Result: [-0.142, -0.269, 0.000, 0.731, 2.858]

    Take(FunctionalTensor, FunctionalTensor)

    Returns a tensor with the elements of input at index positions.

    Declaration
    public static FunctionalTensor Take(this FunctionalTensor input, FunctionalTensor index)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    FunctionalTensor index

    The index tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator treats the input tensor as a flattened 1D array and returns elements at specified index positions. The input is first raveled (flattened) into a 1D tensor, then elements are gathered using the index tensor. The index tensor must be integer type and contain valid indices for the flattened input. The output has the same shape as the index tensor.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var index = Functional.Constant(new[] { 0, 3, 5 });
    var result = Functional.Take(input, index);
    // Result: [1, 4, 6] (elements at flattened indices 0, 3, 5)

    Tan(FunctionalTensor)

    Returns tan(input) element-wise.

    Declaration
    public static FunctionalTensor Tan(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the tangent of each element in the input tensor. Input is expected in radians.

    Examples
    var input = Functional.Constant(new[] { 0.0f, 0.785f, 1.047f });
    var result = Functional.Tan(input);
    // Result: [0.0, 1.0, 1.732] (approximately tan(0), tan(π/4), tan(π/3))

    Tanh(FunctionalTensor)

    Returns tanh(input) element-wise.

    Declaration
    public static FunctionalTensor Tanh(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation computes the hyperbolic tangent of each element in the input tensor. The output is in the range (-1, 1).

    Examples
    var input = Functional.Constant(new[] { -1.0f, 0.0f, 1.0f });
    var result = Functional.Tanh(input);
    // Result: [-0.762, 0.0, 0.762] (approximately)

    Tile(FunctionalTensor, int[])

    Returns the input tensor repeated on the dims.

    Declaration
    public static FunctionalTensor Tile(this FunctionalTensor input, int[] dims)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int[] dims

    The number of times to repeat the input tensor along each dim.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator constructs a tensor by repeating the input tensor a specified number of times along each dimension. The dims array specifies how many times to repeat along each dimension. The output shape is [input.shape[0] × dims[0], input.shape[1] × dims[1], ...].

    Examples
    var input = Functional.Constant(new TensorShape(2, 3), new[] { 1, 2, 3, 4, 5, 6 });
    var result = Functional.Tile(input, dims: new[] { 2, 1 });
    // Result shape: [4, 3] (input repeated 2 times along dimension 0)
    
    var input2 = Functional.Constant(new TensorShape(2), new[] { 1, 2 });
    var result2 = Functional.Tile(input2, dims: new[] { 2, 3 });
    // Result: shape [6, 2] with values: [[1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2]].

    TopK(FunctionalTensor, int, int, bool, bool)

    Returns the k largest elements of the input tensor along a given dimension.

    Declaration
    public static FunctionalTensor[] TopK(FunctionalTensor input, int k, int dim = -1, bool largest = true, bool sorted = true)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input.

    int k

    The number of elements to calculate.

    int dim

    The axis along which to perform the top-k operation.

    bool largest

    Whether to calculate the top-k largest elements. If this is false the layer calculates the top-k smallest elements.

    bool sorted

    Whether to return the elements in sorted order in the output tensor.

    Returns
    Type Description
    FunctionalTensor[]

    The output values and indices tensors in an array.

    Remarks

    This operator finds the top-k largest (or smallest) elements along a specified dimension of the input tensor. Returns an array containing two tensors: output 0 with the values of the top-k elements, output 1 with the indices of those elements in the original tensor. When largest is true, returns the k largest elements. When false, returns the k smallest elements. The sorted parameter controls whether to sort the output, in descending (largest=true) or ascending (largest=false) order.

    Examples
    var input = Functional.Constant(new[] { 3.0f, 1.0f, 4.0f, 1.0f, 5.0f });
    var result = Functional.TopK(input, k: 3, dim: 0, largest: true);
    // result[0]: [5.0, 4.0, 3.0] (top 3 values)
    // result[1]: [4, 2, 0] (their indices in the input)

    Transpose(FunctionalTensor, int, int)

    Returns the input tensor with two dimensions swapped.

    Declaration
    public static FunctionalTensor Transpose(this FunctionalTensor input, int dim0, int dim1)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim0

    The first dimension to swap.

    int dim1

    The second dimension to swap.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator swaps two dimensions of the input tensor. All other dimensions remain in their original positions. This operator doesn't copy the data. It only changes the dimension order. For matrices (rank 2 tensors), transposing dimensions 0 and 1 produces the standard matrix transpose.

    Examples
    var input = Functional.Constant(new TensorShape(2, 3, 4), new float[24]); // Shape: [2, 3, 4]
    var result = Functional.Transpose(input, dim0: 0, dim1: 2);
    // Result shape: [4, 3, 2] (dimensions 0 and 2 swapped)

    TriL(FunctionalTensor, int)

    Retains the lower triangular values of input matrix. The other values are zeroed.

    Declaration
    public static FunctionalTensor TriL(FunctionalTensor input, int diagonal = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int diagonal

    The integer offset of the diagonal.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation returns a tensor with the lower triangular part of the input retained and all other elements set to zero. The diagonal parameter controls which diagonal acts as the boundary: 0 for the main diagonal, positive for diagonals above, and negative for diagonals below. Keeps elements on and below the specified diagonal. Zeroes elements above the specified diagonal.

    Examples
    var input = Functional.Constant(new TensorShape(3, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f });
    var result = Functional.TriL(input);
    // Result: [[1.0, 0.0, 0.0], [4.0, 5.0, 0.0], [7.0, 8.0, 9.0]]
    
    var result2 = Functional.TriL(input, diagonal: 1);
    // Result: [[1.0, 2.0, 0.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]] (includes one diagonal above main)

    TriU(FunctionalTensor, int)

    Retains the upper triangular values of an input matrix. Zeroes the other values.

    Declaration
    public static FunctionalTensor TriU(FunctionalTensor input, int diagonal = 0)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int diagonal

    The integer offset of the diagonal.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation returns a tensor with the upper triangular part of the input retained and all other elements set to zero. The diagonal parameter controls which diagonal acts as the boundary: 0 for the main diagonal, positive for diagonals above, and negative for diagonals below. Keeps elements on and above the specified diagonal. Zeroes elements below the specified diagonal.

    Examples
    var input = Functional.Constant(new TensorShape(3, 3), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f });
    var result = Functional.TriU(input);
    // Result: [[1.0, 2.0, 3.0], [0.0, 5.0, 6.0], [0.0, 0.0, 9.0]]
    
    var result2 = Functional.TriU(input, diagonal: -1);
    // Result: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [0.0, 8.0, 9.0]] (includes one diagonal below main)

    Trunc(FunctionalTensor)

    Returns the truncated integer values of the elements of input element-wise.

    Declaration
    public static FunctionalTensor Trunc(FunctionalTensor input)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation truncates each element in the input tensor towards zero, removing the fractional part. If input is already an integer tensor, it is returned unchanged.

    Examples
    var input = Functional.Constant(new[] { -1.7f, -0.3f, 0.5f, 1.2f });
    var result = Functional.Trunc(input);
    // Result: [-1.0, 0.0, 0.0, 1.0]

    Type(FunctionalTensor, DataType)

    Returns the input cast to the data type element-wise.

    Declaration
    public static FunctionalTensor Type(this FunctionalTensor input, DataType dataType)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    DataType dataType

    The data type.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operation casts all elements of the input tensor to the specified data type. If the input already has the target data type, this operation returns the tensor unchanged. Supported data types are Int and Float.

    Examples
    var input = Functional.Constant(new[] { 1.5f, 2.7f, 3.2f });
    var result = Functional.Type(input, DataType.Int);
    // Result: [1, 2, 3] (float values truncated to integers)

    Unsqueeze(FunctionalTensor, int)

    Returns the input tensor with a new dimension of size 1 inserted.

    Declaration
    public static FunctionalTensor Unsqueeze(this FunctionalTensor input, int dim)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    int dim

    The dimension at which to insert a size 1 dimension in the output tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator inserts a new dimension of size 1 at the specified position. The resulting tensor has the same data but with rank increased by 1. This is the inverse operation of Squeeze(FunctionalTensor).

    Examples
    var input = Functional.Constant(new TensorShape(3, 4), new float[12]); // Shape: [3, 4]
    var result = Functional.Unsqueeze(input, dim: 0);
    // Result shape: [1, 3, 4] (new dimension inserted at position 0)
    var result2 = Functional.Unsqueeze(input, dim: 1);
    // Result shape: [3, 1, 4] (new dimension inserted at position 1)

    Where(FunctionalTensor, FunctionalTensor, FunctionalTensor)

    Returns condition ? input : other element-wise.

    Declaration
    public static FunctionalTensor Where(FunctionalTensor condition, FunctionalTensor input, FunctionalTensor other)
    Parameters
    Type Name Description
    FunctionalTensor condition

    The condition tensor.

    FunctionalTensor input

    The first input tensor.

    FunctionalTensor other

    The second input tensor.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    This operator performs element-wise conditional selection between two tensors. For each element, if the condition is non-zero (true), the value from input is selected; otherwise, the value from other is selected. The condition tensor must be integer type where non-zero values represent true and zero represents false. Broadcasting rules apply if the tensors have different shapes.

    Examples
    var condition = Functional.Constant(new[] { 1, 0, 1, 0 });
    var input = Functional.Constant(new[] { 10, 20, 30, 40 });
    var other = Functional.Constant(new[] { 1, 2, 3, 4 });
    var result = Functional.Where(condition, input, other);
    // Result: [10, 2, 30, 4] (selects from input where condition is 1, other where 0)

    Zeros(int[], DataType)

    Returns a tensor filled with 0 with shape size and data type dataType.

    Declaration
    public static FunctionalTensor Zeros(int[] size, DataType dataType = DataType.Int)
    Parameters
    Type Name Description
    int[] size

    The shape of the tensor.

    DataType dataType

    The data type of the tensor. Default is Int.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the specified shape (size) with all elements initialized to 0. dataType can be either Int or Float, defaulting to Int.

    Examples
    // Create a tensor of shape [3, 4] filled with integer zeros
    var intZeros = Functional.Zeros(new int[] {3, 4});
    // Create a tensor of shape [2, 3, 4] filled with float zeros
    var floatZeros = Functional.Zeros(new int[] {2, 3, 4}, DataType.Float);

    ZerosLike(FunctionalTensor, DataType)

    Returns a tensor filled with 0 with the shape of input and data type dataType.

    Declaration
    public static FunctionalTensor ZerosLike(FunctionalTensor input, DataType dataType = DataType.Int)
    Parameters
    Type Name Description
    FunctionalTensor input

    The input tensor.

    DataType dataType

    The data type of the tensor. Default is Int.

    Returns
    Type Description
    FunctionalTensor

    The output tensor.

    Remarks

    Creates a tensor with the same shape as the input tensor, with all elements initialized to 0. dataType can be either Int or Float, defaulting to Int.

    Examples
    var input = Functional.Constant(new TensorShape(3, 4), new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f });
    // Create a tensor of integer zeros with the same shape as input
    var intZeros = Functional.ZerosLike(input);
    // Creates a tensor of float zeros with the same shape as input
    var floatZeros = Functional.ZerosLike(input, DataType.Float);
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)