Other Functions
The following functions are available globally.
-
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
-
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.
-
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 exponentiates the tensor.
Declaration
Swift
public func exp<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise logarithm.
Declaration
Swift
public func log<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise square root.
Declaration
Swift
public func sqrt<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise hyperbolic tangent.
Declaration
Swift
public func tanh<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise sigmoid function.
Declaration
Swift
public func sigmoid<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise sine.
Declaration
Swift
public func sin<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise cosine.
Declaration
Swift
public func cos<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise relu function.
The relu function is defined as
max(value, 0)
Declaration
Swift
public func relu<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise leaky relu function.
The leaky relu function is defined as
max(value, leakage * value)
Declaration
Swift
public func leakyRelu<Element, Device>(_ tensor: Tensor<Element, Device>, leakage: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise heaviside step function of the tensor.
The heaviside step function is defined as
value > 0 ? 1 : 0
Declaration
Swift
public func heaviside<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the softmax function along the given axis. If no axis is provided, the softmax is computed along axis 1.
Declaration
Swift
public func softmax<Element, Device>(_ tensor: Tensor<Element, Device>, axis: Int = 1) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the logarithm of the softmax function along the given axis. If no axis is provided, the log softmax is computed along axis 1.
Declaration
Swift
public func logSoftmax<Element, Device>(_ tensor: Tensor<Element, Device>, axis: Int = 1) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise GeLU activation
Declaration
Swift
public func gelu<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Element-wise exponential linear unit activation
See [Clevert et al. - Fast And Accurate Deep Network Learning By Exponential Linear Units (ELUs)](https://arxiv.org/pdf/1511.07289.pdf
Declaration
Swift
public func elu<Element, Device>(_ tensor: Tensor<Element, Device>, alpha: Tensor<Element, Device> = 1) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise Swish activation
See Ramachandran et al. - Searching for Activation Functions
Declaration
Swift
public func swishActivated<Element, Device>(_ tensor: Tensor<Element, Device>, beta: Tensor<Element, Device> = 1) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise Mish activation
See Diganta Misra - Mish: A Self Regularized Non-Monotonic Neural Activation Function
Declaration
Swift
public func mishActivated<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType
-
Computes the element-wise LiSHT activation
Declaration
Swift
public func lishtActivated<Element, Device>(_ tensor: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceType