public struct Tensor<Scalar> : TensorProtocol where Scalar : AccelerableByTensorFlow

Tensor is a multi-dimensional array used for computation. It is a wrapper around a TensorHandle.

  • Perform an element-wise type conversion from a Bool tensor.

    Declaration

    init(_ other: Tensor<Bool>)
  • Adds two tensors and produces their sum.

    Note

    + supports broadcasting.

    Declaration

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

    Note

    - supports broadcasting.

    Declaration

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

    Note

    * supports broadcasting.

    Declaration

    static func * (lhs: Tensor, 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
  • 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 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
  • 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 the scalar with every scalar of the tensor and produces the product.

    Declaration

    static func * (lhs: Scalar, 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)
  • Multiplies the scalar with every scalar of the tensor and stores the result in the left-hand-side variable.

    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 with another tensor and produces the result.

    Declaration

    func dot(_ other: Tensor) -> Tensor
  • Performs matrix multiplication between two tensors and produces the result.

    Declaration

    static func  (lhs: Tensor, rhs: Tensor) -> Tensor
  • Computes lhs < rhs element-wise.

    Note

    < supports broadcasting.

    Declaration

    static func < (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs < rhs, broadcasting rhs.

    Declaration

    static func < (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs < rhs, broadcasting lhs.

    Declaration

    static func < (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs <= rhs element-wise.

    Note

    <= supports broadcasting.

    Declaration

    static func <= (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs <= rhs, broadcasting rhs.

    Declaration

    static func <= (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs <= rhs, broadcasting rhs.

    Declaration

    static func <= (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs > rhs element-wise.

    Note

    > supports broadcasting.

    Declaration

    static func > (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs <= rhs, broadcasting rhs.

    Declaration

    static func > (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs <= rhs, broadcasting lhs.

    Declaration

    static func > (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs >= rhs element-wise.

    Note

    >= supports broadcasting.

    Declaration

    static func >= (lhs: Tensor, rhs: Tensor) -> Tensor<Bool>
  • Computes lhs >= rhs, broadcasting rhs.

    Declaration

    static func >= (lhs: Tensor, rhs: Scalar) -> Tensor<Bool>
  • Computes lhs >= rhs, broadcasting lhs.

    Declaration

    static func >= (lhs: Scalar, rhs: Tensor) -> Tensor<Bool>
  • Computes self == other element-wise.

    Note

    elementsEqual supports broadcasting.

    Declaration

    func elementsEqual(_ other: Tensor) -> Tensor<Bool>
  • Computes self == other element-wise, broadcasting other.

    Declaration

    func elementsEqual(_ other: Scalar) -> Tensor<Bool>
  • Computes self != other element-wise.

    Note

    elementsNotEqual supports broadcasting.

    Declaration

    func elementsNotEqual(_ other: Tensor) -> Tensor<Bool>
  • Computes self != other element-wise, broadcasting other.

    Declaration

    func elementsNotEqual(_ other: Scalar) -> Tensor<Bool>
  • Performs a logical NOT operation element-wise.

    Declaration

    prefix static func ! (x: Tensor) -> Tensor
  • Performs a logical AND operation element-wise.

    Note

    && supports broadcasting.

    Declaration

    static func && (lhs: Tensor, rhs: Tensor) -> Tensor
  • Performs a logical AND operation element-wise, broadcasting rhs.

    Declaration

    static func && (lhs: Tensor, rhs: Scalar) -> Tensor
  • Performs a logical AND operation element-wise, broadcasting lhs.

    Declaration

    static func && (lhs: Scalar, rhs: Tensor) -> Tensor
  • Performs a logical OR operation element-wise.

    Note

    || supports broadcasting.

    Declaration

    static func || (lhs: Tensor, rhs: Tensor) -> Tensor
  • Performs a logical OR operation element-wise, broadcasting rhs.

    Declaration

    static func || (lhs: Tensor, rhs: Scalar) -> Tensor
  • Performs a logical OR operation element-wise, broadcasting lhs.

    Declaration

    static func || (lhs: Scalar, rhs: Tensor) -> 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 reverse order.

    Declaration

    func transposed() -> Tensor
  • Concatenates tensors along the first dimension.

    Precondition

    The tensors must have the same shape, except for the leading dimension.

    Declaration

    func concatenated(with other: Tensor) -> 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) -> 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 amsk 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

    public func selecting<T>(_ left: Tensor<T>, _ right: Tensor<T>) -> Tensor<T> where T : AccelerableByTensorFlow
  • Declaration

    public func selecting<T>(_ left: T, _ right: Tensor<T>) -> Tensor<T> where T : AccelerableByTensorFlow
  • Declaration

    public func selecting<T>(_ left: Tensor<T>, _ right: T) -> Tensor<T> where T : AccelerableByTensorFlow
  • Declaration

    func all() -> Bool
  • 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() -> Scalar
  • Declaration

    func max() -> Scalar
  • 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 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 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() -> Int32
  • Returns the index of the minimum value of the flattened scalars.

    Declaration

    func argmin() -> Int32
  • Declaration

    func mean() -> Scalar
  • Declaration

    func sum() -> Scalar
  • 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 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 sum(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(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>(to other: Tensor<OtherScalar>) -> Tensor where OtherScalar : AccelerableByTensorFlow
  • Declaration

    func unbroadcast(toShape otherShape: Tensor<Int32>) -> Tensor
  • Declaration

    func unbroadcast<OtherScalar>(to other: Tensor<OtherScalar>) -> Tensor where OtherScalar : AccelerableByTensorFlow
  • Declaration

    func unbroadcast(to shape: TensorShape) -> Tensor
  • Returns a padded tensor according to the specified padding sizes.

    Declaration

    func padded(
      forSizes sizes: @autoclosure () -> [(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 }

    Parameters

    index

    Index of the element tensor.

  • Access the subdimensional tensor at the specified list of indices.

    Note

    this function is more efficient than using subscript(index:) multiple times because this produces a single GatherNd op (compared with multiple Gather ops).

    Declaration

    subscript(indices: Int32...) -> Tensor { get }

    Parameters

    indices

    List of indices.

  • 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 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.

  • Mark memory transfer to device.

    Declaration

    func toDevice() -> Tensor
  • Mark memory transfer to host.

    Declaration

    func toHost() -> Tensor
  • Perform an element-wise conversion from another Tensor.

    Declaration

    init<OtherScalar>(_ other: Tensor<OtherScalar>) where OtherScalar : Numeric, OtherScalar : AccelerableByTensorFlow
  • Creates a tensor from a scalar value.

    Declaration

    init(_ value: Scalar)
  • Creates a tensor from an array of tensors (which may themselves be scalars).

    Declaration

    init(_ elements: [Tensor])
  • Creates a 1D tensor in from contiguous scalars in row-major order.

    Precondition

    The number of scalars must equal the product of the dimensions of the shape.

    Declaration

    init(_ vector: [Scalar])

    Parameters

    vector

    The scalar contents of the tensor.

  • Creates a 1D tensor in from contiguous scalars in row-major order.

    Precondition

    The number of scalars must equal the product of the dimensions of the shape.

    Declaration

    init<C>(_ vector: C) where Scalar == C.Element, C : RandomAccessCollection

    Parameters

    vector

    The scalar contents of the tensor.

  • Creates a tensor with the specified shape and contiguous scalars in row-major order.

    Precondition

    The number of scalars must equal the product of the dimensions of the shape.

    Declaration

    init(shape: TensorShape, scalars: [Scalar])

    Parameters

    shape

    The shape of the tensor.

    scalars

    The scalar contents of the tensor.

  • Creates a tensor with the specified shape and contiguous scalars in row-major order.

    Precondition

    The number of scalars must equal the product of the dimensions of the shape.

    Declaration

    init(shape: TensorShape, scalars: UnsafeBufferPointer<Scalar>)

    Parameters

    shape

    The shape of the tensor.

    scalars

    The scalar contents of the tensor.

  • Creates a tensor with the specified shape and contiguous scalars in row-major order.

    Precondition

    The number of scalars must equal the product of the dimensions of the shape.

    Declaration

    init<C : RandomAccessCollection>(shape: TensorShape, scalars: C)
      where C.Element == Scalar

    Parameters

    shape

    The shape of the tensor.

    scalars

    The scalar contents of the tensor.

  • Creates a tensor with the specified shape and a single, repeated value.

    Declaration

    init(shape: TensorShape, repeating repeatedValue: Scalar)

    Parameters

    shape

    The dimensions of the tensor.

    repeatedValue

    The scalar value to repeat.

  • Creates a tensor by broadcasting the given scalar to a given rank with all dimensions being 1.

    Declaration

    init(broadcasting scalar: Scalar, rank: Int32)
  • The number of dimensions of the Tensor.

    Declaration

    var rank: Int32 { get }
  • The dimensions of the Tensor.

    Declaration

    var shape: TensorShape { get }
  • The number of scalars in the Tensor.

    Declaration

    var scalarCount: Int32 { get }
  • Creates a tensor with all scalars set to zero.

    Declaration

    init(zeros shape: TensorShape)

    Parameters

    shape

    The dimensions of the tensor.

  • Creates a tensor with all scalars set to one.

    Declaration

    init(ones shape: TensorShape)

    Parameters

    shape

    The dimensions of the tensor.

  • Declaration

    @inline(never)
    static func eye(
      rowCount: Int, columnCount: Int? = nil, batchShape: [Int]? = nil
    ) -> Tensor
  • Creates a 1-D tensor representing a sequence from a starting value to, but not including, an end value, stepping by the specified amount.

    Declaration

    init(rangeFrom start: Scalar, to end: Scalar, stride: Scalar)

    Parameters

    start

    The starting value to use for the sequence. If the sequence contains any values, the first one is start.

    end

    An end value to limit the sequence. end is never an element of the resulting sequence.

    stride

    The amount to step by with each iteration. stride must be positive.

  • Creates a one-hot tensor at given indices. The locations represented by indices take value onValue (1 by default), while all other locations take value offValue (0 by default). If the input indices is rank n, the new tensor will have rank n+1. The new axis is created at dimension axis (by default, the new axis is appended at the end).

    If indices is a scalar, the new tensor’s shape will be a vector of length depth.

    If indices is a vector of length features, the output shape will be: features x depth, if axis == -1 depth x features, if axis == 0

    If indices is a matrix (batch) with shape [batch, features], the output shape will be: batch x features x depth, if axis == -1 batch x depth x features, if axis == 1 depth x batch x features, if axis == 0

    Declaration

    init(oneHotAtIndices indices: Tensor<Int32>, depth: Int32,
         onValue: Scalar = 1, offValue: Scalar = 0, axis: Int = -1)

    Parameters

    indices

    A Tensor of indices.

    depth

    A scalar defining the depth of the one hot dimension.

    onValue

    A scalar defining the value at the location referred to by some index in indices.

    offValue

    A scalar defining the value at a location that is not referred to by any index in indices.

    axis

    The axis to fill. The default is -1, a new inner-most axis.

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

    Declaration

    init(randomStandardUniform shape: TensorShape, state: RandomState? = nil)

    Parameters

    shape

    The dimensions of the tensor.

    state

    The pseudorandom state in which the random numbers are being generated.

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

    Declaration

    init(randomUniform shape: TensorShape, state: RandomState? = nil)

    Parameters

    shape

    The dimensions of the tensor.

    state

    The pseudorandom state in which the random numbers are being generated.

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

    Declaration

    init(randomNormal shape: TensorShape, mean: Scalar = 0, stddev: Scalar = 1,
         state: RandomState? = nil)

    Parameters

    shape

    The dimensions of the tensor.

    mean

    The mean of the distribution.

    stddev

    The standard deviation of the distribution.

    state

    The pseudorandom state in which the random numbers are being generated.

  • Reshape to the shape of the specified Tensor.

    Precondition

    The number of scalars matches the new shape.

    Declaration

    func reshaped<T>(like other: Tensor<T>) -> Tensor where T : AccelerableByTensorFlow
  • Reshape to the specified shape.

    Precondition

    The number of scalars matches the new shape.

    Declaration

    func reshaped(to newShape: TensorShape) -> Tensor
  • Declaration

    func reshaped(toShape newShape: Tensor<Int32>) -> Tensor
  • Return a copy of the tensor collapsed into a 1-D Tensor, in row-major order.

    Declaration

    func flattened() -> Tensor
  • Returns a rank-lifted Tensor with a leading dimension of 1.

    Declaration

    func rankLifted() -> Tensor
  • Declaration

    func expandingShape(at shapeIndex: Int32) -> Tensor
  • Declaration

    func squeezingShape(at axes: Int32...) -> Tensor
  • Reshape to scalar.

    Precondition

    The tensor has exactly one scalar.

    Declaration

    func scalarized() -> Scalar
  • Returns true if rank is equal to 0 and false otherwise.

    Declaration

    var isScalar: Bool { get }
  • Returns the single scalar element if rank is equal to 0 and nil otherwise.

    Declaration

    var scalar: Scalar? { get }
  • Declaration

    public static func == (lhs: Tensor, rhs: Tensor) -> Bool
  • Declaration

    public static func != (lhs: Tensor, rhs: Tensor) -> Bool
  • Declaration

    public var description: String { get }
  • Declaration

    public var customMirror: Mirror { get }