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

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

• ``` handle ```

The underlying `TensorHandle`.

Note

`handle` is public to allow user defined ops, but should not normally be used otherwise.

Declaration

``public let handle: TensorHandle<Scalar>``
• ``` init(handle:) ```

Declaration

``public init(handle: TensorHandle<Scalar>)``
• ``` init(_:) ```

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

Declaration

``init(_ other: Tensor<Bool>)``
• ``` ScalarElement ```

Declaration

``public typealias ScalarElement = Scalar``
• ``` Dimensionality ```

Declaration

``public typealias Dimensionality = TensorShape``
• ``` init(dimensionality:repeating:) ```

Declaration

``public init(dimensionality: TensorShape, repeating repeatedValue: Scalar)``
• ``` +(_:_:) ```

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 two tensors and produces their product.

Note

`*` supports broadcasting.

Declaration

``public static func * (lhs: Tensor, rhs: Tensor) -> Tensor``
• ``` +(_:_:) ```

Adds the scalar to every scalar of the tensor and produces the sum.

Declaration

``public static func + (lhs: Scalar, rhs: Tensor) -> Tensor``
• ``` +(_:_:) ```

Adds the scalar to every scalar of the tensor and produces the sum.

Declaration

``public static func + (lhs: Tensor, rhs: Scalar) -> Tensor``
• ``` -(_:_:) ```

Subtracts the scalar from every scalar of the tensor and produces the difference.

Declaration

``public static func - (lhs: Scalar, rhs: Tensor) -> Tensor``
• ``` -(_:_:) ```

Subtracts the scalar from every scalar of the tensor and produces the difference.

Declaration

``public static func - (lhs: Tensor, rhs: Scalar) -> Tensor``
• ``` *(_:_:) ```

Multiplies the scalar with every scalar of the tensor and produces the product.

Declaration

``public static func * (lhs: Scalar, rhs: Tensor) -> Tensor``
• ``` *(_:_:) ```

Multiplies the scalar with every scalar of the tensor and produces the product.

Declaration

``public 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 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 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>``
• ``` elementsEqual(_:) ```

Computes `self == other` element-wise.

Note

`elementsEqual` supports broadcasting.

Declaration

``func elementsEqual(_ other: Tensor) -> Tensor<Bool>``
• ``` elementsEqual(_:) ```

Computes `self == other` element-wise, broadcasting `other`.

Declaration

``func elementsEqual(_ other: Scalar) -> Tensor<Bool>``
• ``` elementsNotEqual(_:) ```

Computes `self != other` element-wise.

Note

`elementsNotEqual` supports broadcasting.

Declaration

``func elementsNotEqual(_ other: Tensor) -> Tensor<Bool>``
• ``` elementsNotEqual(_:) ```

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``
• ``` transposed(withPermutations:) ```

Returns a transposed tensor, with dimensions permuted in the specified order.

Declaration

``````func transposed(
withPermutations permutations: Tensor<Int32>
) -> Tensor``````
• ``` transposed(withPermutations:) ```

Returns a transposed tensor, with dimensions permuted in the specified order.

Declaration

``func transposed(withPermutations permutations: Int32...) -> Tensor``
• ``` transposed() ```

Returns a transposed tensor, with dimensions permuted in reverse order.

Declaration

``func transposed() -> Tensor``
• ``` concatenated(with:) ```

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``
• ``` concatenated(with:alongAxis:) ```

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``
• ``` squared() ```

Declaration

``func squared() -> Tensor``
• ``` selecting(_:_:) ```

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``
• ``` selecting(_:_:) ```

Declaration

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

Declaration

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

Declaration

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

Declaration

``func all() -> Bool``
• ``` any() ```

Declaration

``func any() -> Bool``
• ``` all(squeezingAxes:) ```

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.
• ``` any(squeezingAxes:) ```

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.
• ``` all(alongAxes:) ```

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.
• ``` any(alongAxes:) ```

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.
• ``` min() ```

Declaration

``func min() -> Scalar``
• ``` max() ```

Declaration

``func max() -> Scalar``
• ``` max(squeezingAxes:) ```

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.
• ``` min(squeezingAxes:) ```

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.
• ``` argmax(squeezingAxis:) ```

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.
• ``` argmin(squeezingAxis:) ```

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.
• ``` min(alongAxes:) ```

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.
• ``` max(alongAxes:) ```

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.
• ``` argmax() ```

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

Declaration

``func argmax() -> Int32``
• ``` argmin() ```

Returns the index of the minimum value of the flattened scalars.

Declaration

``func argmin() -> Int32``
• ``` mean() ```

Declaration

``func mean() -> Scalar``
• ``` sum() ```

Declaration

``func sum() -> Scalar``
• ``` mean(squeezingAxes:) ```

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.
• ``` sum(squeezingAxes:) ```

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.
• ``` mean(alongAxes:) ```

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.
• ``` sum(alongAxes:) ```

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

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

Declaration

``var rankTensor: Tensor<Int32> { get }``
• ``` shapeTensor ```

The dimensions of the tensor, represented as a `Tensor<Int32>`.

Declaration

``var shapeTensor: Tensor<Int32> { get }``
• ``` scalarCountTensor ```

The number of scalars in the tensor, represented as a `Tensor<Int32>`.

Declaration

``var scalarCountTensor: Tensor<Int32> { get }``
• ``` broadcast(toShape:) ```

Declaration

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

Declaration

``func broadcast(to shape: TensorShape) -> Tensor``
• ``` broadcast(like:) ```

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 : AccelerableByTensorFlow``
• ``` unbroadcast(toShape:) ```

Declaration

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

Declaration

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

Declaration

``func unbroadcast(to shape: TensorShape) -> Tensor``
• ``` padded(forSizes:with:) ```

Declaration

``````func padded(
forSizes sizes: @autoclosure () -> [(before: Int32, after: Int32)],
with value: Scalar = 0
) -> Tensor``````
• ``` subscript(_:) ```

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.
• ``` subscript(_:) ```

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.
• ``` subscript(_:) ```

Access the subtensor specified by a contiguous range of indices.

Declaration

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

Parameters

 ``` bounds ``` Contiguous range of indices.
• ``` slice(lowerBounds:upperBounds:) ```

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.
• ``` batchNormalized(alongAxis:offset:scale:epsilon:) ```

Declaration

``````func batchNormalized(
alongAxis axis: Int32,
offset: Scalar = 0,
scale: Scalar = 1,
epsilon: Scalar = 0.001
) -> Tensor``````
• ``` convolved2D(withFilter:strides:padding:) ```

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),
) -> 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.
• ``` maxPooled(kernelSize:strides:padding:) ```

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),
) -> 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.
• ``` averagePooled(kernelSize:strides:padding:) ```

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),
) -> 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.
• ``` init(_:) ```

Declaration

``init(_ array: ShapedArray<Scalar>)``
• ``` toAccelerator(shape:) ```

Mark memory transfer to accelerator.

Declaration

``func toAccelerator(shape: TensorShape) -> Tensor``

Parameters

 ``` shape ``` When sending the tensor to a TF XLA device (including TPU), must specify the tensor shape as required by XLA compilation.
• ``` toAccelerator() ```

Mark memory transfer to accelerator.

Declaration

``func toAccelerator() -> Tensor``
• ``` toHost(shape:) ```

Mark memory transfer to host.

Declaration

``func toHost(shape: TensorShape) -> Tensor``

Parameters

 ``` shape ``` When sending the tensor to a TF XLA device (including TPU), must specify the tensor shape as required by XLA compilation.
• ``` toHost() ```

Mark memory transfer to host.

Declaration

``func toHost() -> Tensor``
• ``` init(_:) ```

Perform an element-wise conversion from another `Tensor`.

Declaration

``init<OtherScalar>(_ other: Tensor<OtherScalar>) where OtherScalar : Numeric, OtherScalar : AccelerableByTensorFlow``
• ``` init(_:) ```

Creates a tensor from a scalar value.

Declaration

``init(_ value: Scalar)``
• ``` init(_:) ```

Creates a tensor from an array of tensors (which may themselves be scalars).

Declaration

``init(_ elements: [Tensor])``
• ``` init(_:) ```

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.
• ``` init(_:) ```

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.
• ``` init(shape:scalars:) ```

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.
• ``` init(shape:scalars:) ```

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.
• ``` init(shape:scalars:) ```

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.
• ``` init(shape:repeating:) ```

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.
• ``` init(broadcasting:rank:) ```

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

Declaration

``init(broadcasting scalar: Scalar, rank: Int32)``
• ``` ArrayLiteralElement ```

The type of the elements of an array literal.

Declaration

``public typealias ArrayLiteralElement = TensorElementLiteral<Scalar>``
• ``` init(arrayLiteral:) ```

Creates a tensor initialized with the given elements.

Declaration

``public init(arrayLiteral elements: TensorElementLiteral<Scalar>...)``
• ``` rank ```

The number of dimensions of the `Tensor`.

Declaration

``var rank: Int32 { get }``
• ``` shape ```

The dimensions of the `Tensor`.

Declaration

``var shape: TensorShape { get }``
• ``` scalarCount ```

The number of scalars in the `Tensor`.

Declaration

``var scalarCount: Int32 { get }``
• ``` init(zeros:) ```

Creates a tensor with all scalars set to zero.

Declaration

``init(zeros shape: TensorShape)``

Parameters

 ``` shape ``` The dimensions of the tensor.
• ``` init(ones:) ```

Creates a tensor with all scalars set to one.

Declaration

``init(ones shape: TensorShape)``

Parameters

 ``` shape ``` The dimensions of the tensor.
• ``` eye(rowCount:columnCount:batchShape:) ```

Declaration

``````@inline(never)
static func eye(
rowCount: Int, columnCount: Int? = nil, batchShape: [Int]? = nil
) -> Tensor``````
• ``` init(rangeFrom:to:stride:) ```

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.
• ``` init(oneHotAtIndices:depth:onValue:offValue:axis:) ```

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.
• ``` init(randomStandardUniform:state:) ```

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.
• ``` init(randomUniform:state:) ```

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.
• ``` init(randomNormal:mean:stddev:state:) ```

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.
• ``` reshaped(like:) ```

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``
• ``` reshaped(to:) ```

Reshape to the specified shape.

Precondition

The number of scalars matches the new shape.

Declaration

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

Reshape to the specified `Tensor` representing a shape.

Precondition

The number of scalars matches the new shape.

Declaration

``func reshaped(toShape newShape: Tensor<Int32>) -> Tensor``
• ``` flattened() ```

Return a copy of the tensor collapsed into a 1-D `Tensor`, in row-major order.

Declaration

``func flattened() -> Tensor``
• ``` rankLifted() ```

Returns a rank-lifted `Tensor` with a leading dimension of 1.

Declaration

``func rankLifted() -> Tensor``
• ``` expandingShape(at:) ```

Returns a shape-expanded `Tensor`, with a dimension of 1 inserted at the specified shape index.

Declaration

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

Declaration

``func squeezingShape(at axes: Int32...) -> Tensor``
• ``` scalarized() ```

Reshape to scalar.

Precondition

The tensor has exactly one scalar.

Declaration

``func scalarized() -> Scalar``
• ``` isScalar ```

Returns `true` if `rank` is equal to 0 and `false` otherwise.

Declaration

``var isScalar: Bool { get }``
• ``` scalar ```

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``
• ``` description ```

Declaration

``public var description: String { get }``
• ``` playgroundDescription ```

Declaration

``public var playgroundDescription: Any { get }``
• ``` customMirror ```

Declaration

``public var customMirror: Mirror { get }``
• ``` array ```

Declaration

``var array: ShapedArray<Scalar> { get }``
• ``` scalars ```

Declaration

``var scalars: [Scalar] { get }``