public struct Tensor<Scalar> : TensorProtocol where Scalar : TensorFlowScalar
  • Creates a tensor with the specified shape, randomly sampling scalar values from a discrete uniform distribution.

    Declaration

    init<G: RandomNumberGenerator>(randomStandardUniform shape: TensorShape,
                                   generator: inout G)

    Parameters

    shape

    The dimensions of the tensor.

    generator

    Random number generator to use.

  • Creates a tensor with the specified shape, randomly sampling scalar values from a discrete uniform distribution, using the default random number generator.

    Declaration

    init(randomStandardUniform shape: TensorShape)

    Parameters

    shape

    The dimensions of the tensor.

  • Creates a tensor with the specified shape, randomly sampling scalar values from a uniform distribution between 0 and 1, using the default random number generator.

    Declaration

    init(
        randomUniform shape: TensorShape,
        seed: (Int64, Int64) = (Int64.random(in: Int64.min..<Int64.max),
                                Int64.random(in: Int64.min..<Int64.max))
    )

    Parameters

    shape

    The dimensions of the tensor.

    seed

    The seed value.

  • Creates a tensor with the specified shape, randomly sampling scalar values from a normal distribution, using the default random number generator.

    Declaration

    init(
        randomNormal shape: TensorShape,
        seed: (Int64, Int64) = (Int64.random(in: Int64.min..<Int64.max),
                                Int64.random(in: Int64.min..<Int64.max))
    )

    Parameters

    shape

    The dimensions of the tensor.

    seed

    The seed value.

  • Creates a tensor with the specified shape, randomly sampling scalar values from a uniform distribution between 0 and 1.

    Declaration

    init<G: RandomNumberGenerator>(randomUniform shape: TensorShape,
                                   generator: inout G)

    Parameters

    shape

    The dimensions of the tensor.

    generator

    Random number generator to use.

  • Creates a tensor with the specified shape, randomly sampling scalar values from a normal distribution.

    Declaration

    init<G: RandomNumberGenerator>(randomNormal shape: TensorShape,
                                   mean: Scalar = 0,
                                   stddev: Scalar = 1,
                                   generator: inout G)

    Parameters

    shape

    The dimensions of the tensor.

    mean

    The mean of the distribution.

    stddev

    The standard deviation of the distribution.

    generator

    Random number generator to use.

  • Creates a tensor by performing Glorot uniform initialization for the specified shape, randomly sampling scalar values from a uniform distribution between -limit and limit, generated by the default random number generator, where limit is sqrt(6 / (fanIn + fanOut)) and fanIn/fanOut represent the number of input and output features multiplied by the receptive field if present.

    Declaration

    init(glorotUniform shape: TensorShape,
         seed: (Int64, Int64) = (Int64.random(in: Int64.min..<Int64.max),
                                 Int64.random(in: Int64.min..<Int64.max)))

    Parameters

    shape

    The dimensions of the tensor.

  • Performs Glorot uniform initialization for the specified shape, creating a tensor by randomly sampling scalar values from a uniform distribution between -limit and limit, where limit is sqrt(6 / (fanIn + fanOut)) and fanIn/fanOut represent the number of input and output features multiplied by the receptive field if present.

    Declaration

    init<G>(glorotUniform shape: TensorShape, generator: inout G) where G : RandomNumberGenerator

    Parameters

    shape

    The dimensions of the tensor.

    generator

    Random number generator to use.

  • Computes dropout given a probability.

    Declaration

    func droppingOut(probability: Double) -> Tensor
  • Perform an element-wise type conversion from a Bool tensor.

    Declaration

    init(_ other: Tensor<Bool>)
  • A scalar zero tensor.

    Declaration

    public static var zero: Tensor { get }
  • Adds two tensors and produces their sum.

    Note

    + supports broadcasting.

    Declaration

    public static func + (lhs: Tensor, rhs: Tensor) -> Tensor
  • Subtracts one tensor from another and produces their difference.

    Note

    - supports broadcasting.

    Declaration

    public static func - (lhs: Tensor, rhs: Tensor) -> Tensor
  • Multiplies the scalar with every scalar of the tensor and produces the product.

    Declaration

    public static func * (lhs: Scalar, rhs: Tensor) -> Tensor
  • Adds the scalar to every scalar of the tensor and produces the sum.

    Declaration

    static func + (lhs: Scalar, rhs: Tensor) -> Tensor
  • Adds the scalar to every scalar of the tensor and produces the sum.

    Declaration

    static func + (lhs: Tensor, rhs: Scalar) -> Tensor
  • Subtracts the scalar from every scalar of the tensor and produces the difference.

    Declaration

    static func - (lhs: Scalar, rhs: Tensor) -> Tensor
  • Subtracts the scalar from every scalar of the tensor and produces the difference.

    Declaration

    static func - (lhs: Tensor, rhs: Scalar) -> Tensor
  • Adds two tensors and stores the result in the left-hand-side variable.

    Note

    += supports broadcasting.

    Declaration

    static func += (lhs: inout Tensor, rhs: Tensor)
  • Adds the scalar to every scalar of the tensor and stores the result in the left-hand-side variable.

    Declaration

    static func += (lhs: inout Tensor, rhs: Scalar)
  • Subtracts the second tensor from the first and stores the result in the left-hand-side variable.

    Note

    -= supports broadcasting.

    Declaration

    static func -= (lhs: inout Tensor, rhs: Tensor)
  • Subtracts the scalar from every scalar of the tensor and stores the result in the left-hand-side variable.

    Declaration

    static func -= (lhs: inout Tensor, rhs: Scalar)
  • Multiplies two tensors and produces their product.

    Note

    * supports broadcasting.

    Declaration

    static func * (lhs: Tensor, rhs: Tensor) -> Tensor
  • Multiplies the scalar with every scalar of the tensor and produces the product.

    Declaration

    static func * (lhs: Tensor, rhs: Scalar) -> Tensor
  • Multiplies two tensors and stores the result in the left-hand-side variable.

    Note

    *= supports broadcasting.

    Declaration

    static func *= (lhs: inout Tensor, rhs: Tensor)
  • Declaration

    static func *= (lhs: inout Tensor, rhs: Scalar)
  • Returns the quotient of dividing the first tensor by the second.

    Note

    / supports broadcasting.

    Declaration

    static func / (lhs: Tensor, rhs: Tensor) -> Tensor
  • Returns the quotient of dividing the scalar by the tensor, broadcasting the scalar.

    Declaration

    static func / (lhs: Scalar, rhs: Tensor) -> Tensor
  • Returns the quotient of dividing the tensor by the scalar, broadcasting the scalar.

    Declaration

    static func / (lhs: Tensor, rhs: Scalar) -> Tensor
  • Divides the first tensor by the second and stores the quotient in the left-hand-side variable.

    Declaration

    static func /= (lhs: inout Tensor, rhs: Tensor)
  • Divides the tensor by the scalar, broadcasting the scalar, and stores the quotient in the left-hand-side variable.

    Declaration

    static func /= (lhs: inout Tensor, rhs: Scalar)
  • Returns the remainder of dividing the first tensor by the second.

    Note

    % supports broadcasting.

    Declaration

    static func % (lhs: Tensor, rhs: Tensor) -> Tensor
  • Returns the remainder of dividing the tensor by the scalar, broadcasting the scalar.

    Declaration

    static func % (lhs: Tensor, rhs: Scalar) -> Tensor
  • Returns the remainder of dividing the scalar by the tensor, broadcasting the scalar.

    Declaration

    static func % (lhs: Scalar, rhs: Tensor) -> Tensor
  • Divides the first tensor by the second and stores the remainder in the left-hand-side variable.

    Declaration

    static func %= (lhs: inout Tensor, rhs: Tensor)
  • Divides the tensor by the scalar and stores the remainder in the left-hand-side variable.

    Declaration

    static func %= (lhs: inout Tensor, rhs: Scalar)
  • Performs matrix multiplication between two tensors and produces the result.

    Declaration

    static func  (lhs: Tensor, rhs: Tensor) -> Tensor
  • Computes lhs < rhs element-wise and returns a Tensor of Boolean scalars.

    Declaration

    static func .< (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs <= rhs element-wise and returns a Tensor of Boolean scalars.

    Declaration

    static func .<= (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs > rhs element-wise and returns a Tensor of Boolean scalars.

    Declaration

    static func .> (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs >= rhs element-wise and returns a Tensor of Boolean scalars.

    Declaration

    static func .>= (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs < rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .< supports broadcasting.

    Declaration

    static func .< (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs <= rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .<= supports broadcasting.

    Declaration

    static func .<= (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs > rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .> supports broadcasting.

    Declaration

    static func .> (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs >= rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .>= supports broadcasting.

    Declaration

    static func .>= (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs < rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .< supports broadcasting.

    Declaration

    static func .< (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs <= rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .<= supports broadcasting.

    Declaration

    static func .<= (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs > rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .> supports broadcasting.

    Declaration

    static func .> (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs >= rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .>= supports broadcasting.

    Declaration

    static func .>= (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically less than that of the second argument.

    Declaration

    public static func < (lhs: Tensor, rhs: Tensor) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically less than or equal to that of the second argument.

    Declaration

    public static func <= (lhs: Tensor, rhs: Tensor) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically greater than that of the second argument.

    Declaration

    public static func > (lhs: Tensor, rhs: Tensor) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically greater than or equal to that of the second argument.

    Declaration

    public static func >= (lhs: Tensor, rhs: Tensor) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically less than that of the second argument.

    Declaration

    static func < (lhs: Tensor, rhs: Scalar) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically less than or equal to that of the second argument.

    Declaration

    static func <= (lhs: Tensor, rhs: Scalar) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically greater than that of the second argument.

    Declaration

    static func > (lhs: Tensor, rhs: Scalar) -> Bool
  • Returns a Boolean value indicating whether the value of the first argument is lexicographically greater than or equal to that of the second argument.

    Declaration

    static func >= (lhs: Tensor, rhs: Scalar) -> Bool
  • Computes lhs != rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .== supports broadcasting.

    Declaration

    static func .== (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs != rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .!= supports broadcasting.

    Declaration

    static func .!= (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs == rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .== supports broadcasting.

    Declaration

    static func .== (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs != rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .!= supports broadcasting.

    Declaration

    static func .!= (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs == rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .== supports broadcasting.

    Declaration

    static func .== (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs != rhs element-wise and returns a Tensor of Boolean scalars.

    Note

    .!= supports broadcasting.

    Declaration

    static func .!= (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Returns a Tensor of Boolean values indicating whether the elements of self are approximately equal to those of other.

    Declaration

    func elementsApproximatelyEqual(_ other: Tensor,
                                    tolerance: Double = 0.00001) -> Tensor<Bool>
  • Computes !self element-wise.

    Declaration

    func elementsLogicalNot() -> Tensor
  • Computes self && other element-wise.

    Note

    && supports broadcasting.

    Declaration

    func elementsLogicalAnd(_ other: Tensor) -> Tensor
  • Computes self && other element-wise, broadcasting other.

    Declaration

    func elementsLogicalAnd(_ other: Scalar) -> Tensor
  • Computes self || other element-wise.

    Declaration

    func elementsLogicalOr(_ other: Tensor) -> Tensor
  • Computes self || other element-wise, broadcasting other.

    Declaration

    func elementsLogicalOr(_ other: Scalar) -> Tensor
  • Returns a transposed tensor, with dimensions permuted in the specified order.

    Declaration

    func transposed(
      withPermutations permutations: Tensor<Int32>
    ) -> Tensor
  • Returns a transposed tensor, with dimensions permuted in the specified order.

    Declaration

    func transposed(withPermutations permutations: [Int32]) -> Tensor
  • Returns a transposed tensor, with dimensions permuted in the specified order.

    Declaration

    func transposed(withPermutations permutations: Int32...) -> Tensor
  • Returns a transposed tensor, with dimensions permuted in reverse order.

    Declaration

    func transposed() -> Tensor
  • Concatenates tensors along the specified axis.

    Precondition

    The tensors must have the same dimensions, except for the specified axis.

    Precondition

    The axis must be in the range -rank..<rank.

    Declaration

    func concatenated(with other: Tensor, alongAxis axis: Int32 = 0) -> Tensor
  • Concatenation operator.

    Note

    ++ is a custom operator that does not exist in Swift, but does in Haskell/Scala. Its addition is not an insignificant language change and may be controversial. The existence/naming of ++ will be discussed during a later API design phase.

    Declaration

    static func ++ (lhs: Tensor, rhs: Tensor) -> Tensor
  • Computes the negation of the specified tensor element-wise.

    Declaration

    prefix static func - (rhs: Tensor) -> Tensor
  • Declaration

    func squared() -> Tensor
  • Returns a new tensor containing elements from either left or right, depending on the elements of self.

    self acts as a mask that chooses, based on the value at each scalar, whether the corresponding scalar in the output should be taken from left (if true) or right (if false).

    Precondition

    left and right must have the same shape. If left and right are scalar, then self must also be scalar. If left and right have rank greater than or equal to 1, then self must be either have the same shape as left or be a 1-D Tensor such that self.scalarCount == left[0].

    Declaration

    @available(*, deprecated, message: "Use '.replacing(with:mask:﹚' instead")
    func selecting<T>(_ left: Tensor<T>, _ right: Tensor<T>) -> Tensor<T> where T : TensorFlowScalar
  • Replaces elements of this tensor with other in the lanes where mask is true.

    Precondition

    self and other must have the same shape. If self and other are scalar, then mask must also be scalar. If self and other have rank greater than or equal to 1, then mask must be either have the same shape as self or be a 1-D Tensor such that mask.scalarCount == self.shape[0].

    Declaration

    func replacing(with other: Tensor,
                   where mask: Tensor<Bool>) -> Tensor
  • Returns true if all scalars are equal to true. Otherwise, returns false.

    Declaration

    func all() -> Bool
  • Returns true if any scalars are equal to true. Otherwise, returns false.

    Declaration

    func any() -> Bool
  • Performs a logical AND operation along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func all(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Performs a logical AND operation along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func any(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Performs a logical AND operation along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func all(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Performs a logical OR operation along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func any(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Declaration

    func min() -> Tensor
  • Declaration

    func max() -> Tensor
  • Returns the maximum values along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func max(squeezingAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the maximum values along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func max(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the minimum values along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func min(squeezingAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the minimum values along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func min(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the indices of the maximum values along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func argmax(squeezingAxis axis: Int32) -> Tensor<Int32>

    Parameters

    axes

    The dimensions to reduce.

  • Returns the indices of the minimum values along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func argmin(squeezingAxis axis: Int32) -> Tensor<Int32>

    Parameters

    axes

    The dimensions to reduce.

  • Returns the minimum along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func min(alongAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the minimum along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func min(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the minimum along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func max(alongAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the minimum along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func max(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the index of the maximum value of the flattened scalars.

    Declaration

    func argmax() -> Tensor<Int32>
  • Returns the index of the minimum value of the flattened scalars.

    Declaration

    func argmin() -> Tensor<Int32>
  • Declaration

    func mean() -> Tensor
  • Declaration

    func sum() -> Tensor
  • Declaration

    func product() -> Tensor
  • Returns the arithmetic mean along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank...rank.

    Declaration

    func mean(squeezingAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the arithmetic mean along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank...rank.

    Declaration

    func mean(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the sum along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank...rank.

    Declaration

    func sum(squeezingAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the sum along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank...rank.

    Declaration

    func sum(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the product along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank...rank.

    Declaration

    func product(squeezingAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the product along the specified axes. The reduced dimensions are removed.

    Precondition

    Each value in axes must be in the range -rank...rank.

    Declaration

    func product(squeezingAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the arithmetic mean along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func mean(alongAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the arithmetic mean along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func mean(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the sum along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func sum(alongAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the sum along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func sum(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the variance along the specified axes. The reduced dimensions are retained with value 1. Does not apply Bessel’s correction.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func variance(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the variance along the specified axes. The reduced dimensions are retained with value 1. Does not apply Bessel’s correction.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func variance(alongAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the product along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func product(alongAxes axes: [Int32]) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • Returns the product along the specified axes. The reduced dimensions are retained with value 1.

    Precondition

    Each value in axes must be in the range -rank..<rank.

    Declaration

    func product(alongAxes axes: Int32...) -> Tensor

    Parameters

    axes

    The dimensions to reduce.

  • The rank of the tensor, represented as a Tensor<Int32>.

    Declaration

    var rankTensor: Tensor<Int32> { get }
  • The dimensions of the tensor, represented as a Tensor<Int32>.

    Declaration

    var shapeTensor: Tensor<Int32> { get }
  • The number of scalars in the tensor, represented as a Tensor<Int32>.

    Declaration

    var scalarCountTensor: Tensor<Int32> { get }
  • Declaration

    func broadcast(toShape shape: Tensor<Int32>) -> Tensor
  • Declaration

    func broadcast(to shape: TensorShape) -> Tensor
  • Broadcast to the same shape as the specified Tensor.

    Precondition

    The specified shape must be compatible for broadcasting.

    Declaration

    func broadcast<OtherScalar>(like other: Tensor<OtherScalar>) -> Tensor where OtherScalar : TensorFlowScalar
  • Returns a padded tensor according to the specified padding sizes.

    Declaration

    func padded(
      forSizes sizes: [(before: Int32, after: Int32)],
      with value: Scalar = 0
    ) -> Tensor
  • Access the element tensor specified by an index in the leading dimension.

    Declaration

    subscript(index: Int32) -> Tensor { get set }

    Parameters

    index

    Index of the element tensor.

  • Access the subtensor specified by a contiguous range of indices.

    Declaration

    subscript(bounds: Range<Int32>) -> Tensor { get }

    Parameters

    bounds

    Contiguous range of indices.

  • Extracts a slice from the tensor defined by lower and upper bounds for each dimension.

    Declaration

    func slice(lowerBounds: [Int32], upperBounds: [Int32]) -> Tensor

    Parameters

    lowerBounds

    The lower bounds at each dimension.

    upperBounds

    The upper bounds at each dimension.

  • Computes the batch normalized tensor along the specified axis.

    Specifically, returns (self - mu)/(var + epsilon) * gamma + beta where mu and var are respectively the mean and variance of self along axis.

    Declaration

    func batchNormalized(
      alongAxis axis: Int32,
      offset: Tensor = Tensor(0),
      scale: Tensor = Tensor(1),
      epsilon: Scalar = 0.001
    ) -> Tensor

    Parameters

    axis

    The batch dimension.

    offset

    The offset, also known as beta.

    scale

    The scale, also known as gamma.

    epsilon

    A small value added to the denominator for numerical stability.

  • Computes a 2-D convolution using self as input, with the specified filter, strides, and padding.

    Precondition

    self must have rank 4.

    Precondition

    filter must have rank 4.

    Declaration

    func convolved2D(
      withFilter filter: Tensor,
      strides: (Int32, Int32, Int32, Int32),
      padding: Padding
    ) -> Tensor

    Parameters

    filter

    The convolution filter.

    strides

    The strides of the sliding filter for each dimension of the input.

    padding

    The padding for the operation.

  • Computes a 2-D max pooling, with the specified kernel sizes, strides, and padding.

    Declaration

    func maxPooled(
      kernelSize: (Int32, Int32, Int32, Int32),
      strides: (Int32, Int32, Int32, Int32),
      padding: Padding
    ) -> Tensor

    Parameters

    kernelSize

    The dimensions of the pooling kernel.

    strides

    The strides of the sliding filter for each dimension of the input.

    padding

    The padding for the operation.

  • Computes a 2-D average pooling, with the specified kernel sizes, strides, and padding.

    Declaration

    func averagePooled(
      kernelSize: (Int32, Int32, Int32, Int32),
      strides: (Int32, Int32, Int32, Int32),
      padding: Padding
    ) -> Tensor

    Parameters

    kernelSize

    The dimensions of the pooling kernel.

    strides

    The strides of the sliding filter for each dimension of the input.

    padding

    The padding for the operation.