public struct TensorShape : ExpressibleByArrayLiteral

A struct representing the shape of a tensor.

TensorShape is a thin wrapper around an array of integers that represent shape dimensions. All tensor types use TensorShape to represent their shape.

  • The dimensions of the shape.

    Declaration

    public var dimensions: [Int]
  • Initialize with an array of dimensions. The rank of the tensor is the length of the array.

    Declaration

    public init(_ dimensions: [Int])

    Parameters

    dimensions

    The shape dimensions.

  • Initialize with a collection of dimensions. The rank of the tensor is the length of the collection.

    Declaration

    public init<C>(_ dimensions: C) where C : Collection, C.Element == Int

    Parameters

    dimensions

    The shape dimensions.

  • Initialize with an array literal representing the shape dimensions. The rank of the tensor is the number of dimensions.

    Declaration

    public init(arrayLiteral elements: Int...)

    Parameters

    dimensions

    The shape dimensions.

  • Initialize with variadic elements representing the shape dimensions. The rank of the tensor is the number of elements.

    Declaration

    public init(_ elements: Int...)

    Parameters

    dimensions

    The shape dimensions.

  • Declaration

    public init(repeating repeatedValue: Int, count: Int)
  • The rank of the shape (i.e. the number of dimensions).

    Declaration

    public var rank: Int { get }
  • The size of the shape as a contiguously stored array.

    Declaration

    public var contiguousSize: Int { get }
  • The rank of the shape (i.e. the number of dimensions).

    Declaration

    var count: Int { get }
  • Declaration

    var indices: Range<Int> { get }
  • Declaration

    var startIndex: Int { get }
  • Declaration

    var endIndex: Int { get }
  • Access the size of the i-th dimension.

    Declaration

    subscript(index: Int) -> Int { get }

    Parameters

    index

    The index of a dimension.

  • Access the size of the i-th dimension.

    Declaration

    subscript(bounds: Range<Int>) -> TensorShape { get set }

    Parameters

    index

    The index of a dimension.

  • Declaration

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

    public func encode(to encoder: Encoder) throws
  • Declaration

    public init(from decoder: Decoder) throws