Other Functions

The following functions are available globally.

Matrix Multiplication

  • Computes the matrix-matrix product, the vector-matrix product, the matrix-vector product or the vector-vector product of the given two tensors

    Declaration

    Swift

    public func matMul<Element, Device>(_ lhs: Tensor<Element, Device>, _ rhs: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    lhs

    left hand side operand

    rhs

    right hand side operand

Summation

  • Computes the sum of all elements in the given tensor

    Declaration

    Swift

    public func sum<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to sum

    Return Value

    Scalar, sum of all elements

  • Computes the sum along the given axes on the given tensor.

    Declaration

    Swift

    public func sum<Element, Device>(_ tensor: Tensor<Element, Device>, axes: [Int]) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to reduce

    axes

    Axes to reduce along

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the sum along the given axes on the given tensor.

    Declaration

    Swift

    public func sum<Element, Device>(_ tensor: Tensor<Element, Device>, axes: Int...) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to reduce

    axes

    Axes to reduce along

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the mean of all elements in the given tensor

    Declaration

    Swift

    public func mean<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to average

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the mean along the given axes on the given tensor.

    Declaration

    Swift

    public func mean<Element, Device>(_ tensor: Tensor<Element, Device>, axes: [Int]) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to reduce

    axes

    Axes to reduce along

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the mean along the given axes on the given tensor.

    Declaration

    Swift

    public func mean<Element, Device>(_ tensor: Tensor<Element, Device>, axes: Int...) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to reduce

    axes

    Axes to reduce along

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the variance of all elements in the given tensor

    Declaration

    Swift

    public func variance<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to average

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the variance along the given axes on the given tensor.

    Declaration

    Swift

    public func variance<Element, Device>(_ tensor: Tensor<Element, Device>, axes: [Int]) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to reduce

    axes

    Axes to reduce along

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

  • Computes the variance along the given axes on the given tensor.

    Declaration

    Swift

    public func variance<Element, Device>(_ tensor: Tensor<Element, Device>, axes: Int...) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensor

    Tensor to reduce

    axes

    Axes to reduce along

    Return Value

    Tensor with shape equal to self.shape without the given reduction axes.

Tensor Stacking

  • Stacks the given tensors into a new tensor.

    The tensors must have equal shapes except along the stacking axis.

    Declaration

    Swift

    public func stack<Element, Device>(_ tensors: [Tensor<Element, Device>], along axis: Int = 0) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType

    Parameters

    tensors

    Tensors to stack

    axis

    Axis to stack the tensors along.

Element-wise operations