TensorShape

@frozen
public struct TensorShape : ExpressibleByArrayLiteral
extension TensorShape: Collection, MutableCollection
extension TensorShape: RandomAccessCollection
extension TensorShape: RangeReplaceableCollection
extension TensorShape: Equatable
extension TensorShape: Codable
extension TensorShape: CustomStringConvertible

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 }
  • Declaration

    public typealias Element = Int
  • Declaration

    public typealias Index = Int
  • Declaration

    public typealias Indices = Range<Int>
  • The rank of the shape (i.e. the number of dimensions).

    Declaration

    public var count: Int { get }
  • Declaration

    public var indices: Indices { get }
  • Declaration

    public var startIndex: Index { get }
  • Declaration

    public var endIndex: Index { get }
  • Declaration

    public func index(after i: Index) -> Index
  • Access the size of the i-th dimension.

    Declaration

    public subscript(position: Index) -> Element { get set }

    Parameters

    position

    The index of a dimension.

  • Access the size of the i-th dimension.

    Declaration

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

    Parameters

    index

    The index of a dimension.

  • Declaration

    public func index(_ i: Int, offsetBy distance: Int) -> Int
  • Declaration

    public func distance(from start: Int, to end: Int) -> Int
  • Declaration

    public typealias SubSequence = `Self`
  • Declaration

    public init()
  • Declaration

    public mutating mutating func append(_ newElement: Element)
  • Declaration

    public mutating mutating func append(contentsOf newElements: TensorShape)
  • Declaration

    public mutating mutating func append<S>(contentsOf newElements: S) where S : Sequence, S.Element == TensorShape.Element
  • Declaration

    public mutating func replaceSubrange<C>(
      _ subrange: Range<Index>, with newElements: C
    ) where C: Collection, Element == C.Element
  • Declaration

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

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

    public init(from decoder: Decoder) throws
  • Declaration

    public var description: String { get }