The following functions are available globally.

  • Computes sigmoid of the specified tensor element-wise. Specifically, computes 1 / (1 + exp(-x)).

    Declaration

    public func sigmoid<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes relu of the specified tensor element-wise. Specifically, computes max(0, x).

    Declaration

    public func relu<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the softmax of the specified tensor along the last axis. Specifically, computes exp(x) / exp(x).sum(alongAxes: -1).

    Declaration

    public func softmax<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the softmax of the specified tensor along the specified axis. Specifically, computes exp(x) / exp(x).sum(alongAxes: axis).

    Declaration

    public func softmax<T : TensorFlowFloatingPoint>(
      _ x: Tensor<T>, alongAxis axis: Int32
    ) -> Tensor<T>
  • Declaration

    public func enableTPU(serverAddress: String? = nil, infeed: Bool = true)
  • Declaration

    public func enableGPU()
  • Declaration

    public func enableCPU()
  • Executes a closure, making TensorFlow operations run on a specific kind of device.

    Declaration

    @inline(never)
    public func withDevice<R>(_ kind: DeviceKind, _ index: UInt = 0,
                              perform body: () throws -> R) rethrows -> R

    Parameters

    kind

    A kind of device to run TensorFlow operations on.

    index

    The device to run the ops on.

    body

    A closure whose TensorFlow operations are to be executed on the specified kind of device.

  • Executes a closure, allowing TensorFlow to place TensorFlow operations on any device. This should restore the default placement behavior.

    Declaration

    @inline(never)
    public func withDefaultDevice<R>(perform body: () throws -> R) rethrows -> R

    Parameters

    body

    A closure whose TensorFlow operations are to be executed on the specified kind of device.

  • Computes the mean squared error between logits and labels.

    Declaration

    public func meanSquaredError<Scalar: TensorFlowFloatingPoint>(
        predicted: Tensor<Scalar>, expected: Tensor<Scalar>
    ) -> Tensor<Scalar>

    Parameters

    logits

    One-hot encoded outputs from a neural network.

    labels

    One-hot encoded values that correspond to the correct output.

  • Computes the softmax cross entropy (categorical cross entropy) between logits and labels.

    Declaration

    public func softmaxCrossEntropy<Scalar: TensorFlowFloatingPoint>(
        logits: Tensor<Scalar>, labels: Tensor<Int32>
    ) -> Tensor<Scalar>

    Parameters

    logits

    One-hot encoded outputs from a neural network.

    labels

    Indices (zero-indexed) of the correct outputs.

  • Computes the softmax cross entropy (categorical cross entropy) between logits and labels.

    Declaration

    public func softmaxCrossEntropy<Scalar: TensorFlowFloatingPoint>(
        logits: Tensor<Scalar>, oneHotLabels: Tensor<Scalar>
    ) -> Tensor<Scalar>

    Parameters

    logits

    One-hot encoded outputs from a neural network.

    oneHotLabels

    One-hot encoded values that correspond to the correct output.

  • Computes the sigmoid cross entropy (binary cross entropy) between logits and labels.

    Declaration

    public func sigmoidCrossEntropy<Scalar: TensorFlowFloatingPoint>(
        logits: Tensor<Scalar>, labels: Tensor<Scalar>
    ) -> Tensor<Scalar>

    Parameters

    logits

    Single continuous values from 0 to 1.

    labels

    Integer values that correspond to the correct output.

  • Returns the values of the specified tensor rounded to the nearest integer, element-wise.

    Declaration

    public func round<Scalar>(_ x: Tensor<Scalar>) -> Tensor<Scalar> where Scalar : BinaryFloatingPoint, Scalar : TensorFlowScalar
  • Returns a tensor with the same shape and scalars as the specified tensor.

    Declaration

    public func identity<Scalar>(_ x: Tensor<Scalar>) -> Tensor<Scalar> where Scalar : TensorFlowScalar
  • Performs matrix multiplication with another tensor and produces the result.

    Declaration

    public func matmul<Scalar : Numeric>(
      _ lhs: Tensor<Scalar>, _ rhs: Tensor<Scalar>
    ) -> Tensor<Scalar>
  • Computes the absolute value of the specified tensor element-wise.

    Declaration

    public func abs<T>(_ x: Tensor<T>) -> Tensor<T> where T : SignedNumeric, T : TensorFlowScalar
  • Computes the natural logarithm of the specified tensor element-wise.

    Declaration

    public func log<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes sin of the specified tensor element-wise.

    Declaration

    public func sin<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes cos of the specified tensor element-wise.

    Declaration

    public func cos<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes tan of the specified tensor element-wise.

    Declaration

    public func tan<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes sinh of the specified tensor element-wise.

    Declaration

    public func sinh<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes cosh of the specified tensor element-wise.

    Declaration

    public func cosh<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes tanh of the specified tensor element-wise.

    Declaration

    public func tanh<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the square root of the specified tensor element-wise.

    Declaration

    public func sqrt<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the inverse square root of the specified tensor element-wise.

    Declaration

    public func rsqrt<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes exp of the specified tensor element-wise.

    Declaration

    public func exp<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the ceiling of the specified tensor element-wise.

    Declaration

    public func ceil<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the floor of the specified tensor element-wise.

    Declaration

    public func floor<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar
  • Computes the power of the first tensor to the second tensor.

    Declaration

    public func pow<T>(_ lhs: Tensor<T>, _ rhs: Tensor<T>) -> Tensor<T>
      where T : FloatingPoint
  • Computes the power of the scalar to the tensor, broadcasting the scalar.

    Declaration

    public func pow<T>(_ lhs: T, _ rhs: Tensor<T>) -> Tensor<T>
      where T : FloatingPoint
  • Computes the power of the tensor to the scalar, broadcasting the scalar.

    Declaration

    public func pow<T>(_ lhs: Tensor<T>, _ rhs: T) -> Tensor<T>
      where T : FloatingPoint
  • Computes the element-wise maximum of two tensors.

    Note

    max supports broadcasting.

    Declaration

    public func max<T>(_ lhs: Tensor<T>, _ rhs: Tensor<T>) -> Tensor<T>
      where T : Numeric & Comparable
  • Computes the element-wise maximum of the scalar and the tensor, broadcasting the scalar.

    Declaration

    public func max<T>(_ lhs: T, _ rhs: Tensor<T>) -> Tensor<T>
      where T : Numeric & Comparable
  • Computes the element-wise maximum of the scalar and the tensor, broadcasting the scalar.

    Declaration

    public func max<T>(_ lhs: Tensor<T>, _ rhs: T) -> Tensor<T>
      where T : Numeric & Comparable
  • Computes the element-wise minimum of two tensors.

    Note

    min supports broadcasting.

    Declaration

    public func min<T>(_ lhs: Tensor<T>, _ rhs: Tensor<T>) -> Tensor<T>
      where T : Numeric & Comparable
  • Computes the element-wise minimum of the scalar and the tensor, broadcasting the scalar.

    Declaration

    public func min<T>(_ lhs: T, _ rhs: Tensor<T>) -> Tensor<T>
      where T : Numeric & Comparable
  • Computes the element-wise minimum of the scalar and the tensor, broadcasting the scalar.

    Declaration

    public func min<T>(_ lhs: Tensor<T>, _ rhs: T) -> Tensor<T>
      where T : Numeric & Comparable
  • Computes the log-softmax of the specified tensor element-wise.

    Declaration

    public func logSoftmax<T>(_ x: Tensor<T>) -> Tensor<T> where T : FloatingPoint, T : TensorFlowScalar