public struct ShapedArray<Scalar> : _ShapedArrayProtocol

ShapedArray is a multi-dimensional array. It has a shape, which has type [Int] and defines the array dimensions, and uses a TensorBuffer internally as storage.

  • The dimensions of the array.

    Declaration

    public private(set) var shape: [Int]
  • Creates a ShapedArray with the same shape and scalars as the specified numpy.ndarray instance.

    Precondition

    The numpy Python package must be installed.

    Precondition

    numpyArray must have a compatible scalar dtype.

    Declaration

    public init?(numpy numpyArray: PythonObject)

    Parameters

    numpyArray

    The numpy.ndarray instance to convert.

  • Creates a numpy.ndarray instance with the same shape and scalars as this ShapedArray.

    Precondition

    The numpy Python package must be installed.

    Declaration

    public func makeNumpyArray() -> PythonObject
  • The number of dimensions of the array.

    Declaration

    var rank: Int { get }
  • The total number of scalars in the array.

    Declaration

    var scalarCount: Int { get }
  • Creates a ShapedArray with the same shape and scalars as the specified instance.

    Declaration

    init(_ other: ShapedArray)
  • Creates a ShapedArray 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: owned [Int], scalars: owned [Scalar])
  • Creates a ShapedArray with the specified shape and sequence of scalars in row-major order.

    Precondition

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

    Declaration

    init<S : Sequence>(shape: __owned [Int],
                       scalars: __shared S) where S.Element == Scalar
  • Creates a ShapedArray from a scalar value.

    Declaration

    init(_ scalar: owned Scalar)
  • Creates a ShapedArray with the specified shape and a single, repeated scalar value.

    Declaration

    @available(*, deprecated, renamed: "init(repeating:shape:﹚")
    init(shape: owned [Int], repeating repeatedValue: owned Scalar)

    Parameters

    shape

    The shape of the ShapedArray.

    repeatedValue

    The scalar value to repeat.

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

    Declaration

    init(repeating repeatedValue: owned Scalar, shape: owned [Int])

    Parameters

    repeatedValue

    The scalar value to repeat.

    shape

    The shape of the ShapedArray.

  • Declaration

    public typealias Index = Int
  • Declaration

    public typealias Element = ShapedArraySlice<Scalar>
  • Declaration

    public typealias SubSequence = ShapedArraySlice<Scalar>
  • Declaration

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

    public var startIndex: Int { get }
  • Declaration

    public var endIndex: Int { get }
  • Access the element array specified by an index in the leading dimension.

    Declaration

    public subscript(index: Int) -> Element { get set }

    Parameters

    index

    Index of the element array.

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

    Declaration

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

    Parameters

    bounds

    Contiguous range of indices.

  • Calls a closure with a pointer to the array’s contiguous storage.

    Declaration

    func withUnsafeBufferPointer<Result>(
      _ body: (UnsafeBufferPointer<Scalar>) throws -> Result
    ) rethrows -> Result

    Parameters

    body

    A closure with an UnsafeBufferPointer parameter that points to the contiguous storage for the array. If no such storage exists, it is created. If body has a return value, that value is also used as the return value for the withUnsafeBufferPointer(_:) method. The pointer argument is valid only for the duration of the method’s execution.

  • Calls the given closure with a pointer to the array’s mutable contiguous storage.

    Declaration

    mutating func withUnsafeMutableBufferPointer<Result>(
      _ body: (inout UnsafeMutableBufferPointer<Scalar>) throws -> Result
    ) rethrows -> Result

    Parameters

    body

    A closure with an UnsafeMutableBufferPointer parameter that points to the contiguous storage for the array. If no such storage exists, it is created. If body has a return value, that value is also used as the return value for the withUnsafeMutableBufferPointer(_:) method. The pointer argument is valid only for the duration of the method’s execution.

  • Declaration

    public typealias ArrayLiteralElement = _TensorElementLiteral<Scalar>
  • Declaration

    public init(arrayLiteral elements: _TensorElementLiteral<Scalar>...)
  • Declaration

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

    public func hash(into hasher: inout Hasher)
  • A textual representation of this ShapedArray.

    Note

    use fullDescription for a non-pretty-printed description showing all scalars.

    Declaration

    public var description: String { get }
  • Declaration

    public var customMirror: Mirror { get }
  • Declaration

    public init(from decoder: Decoder) throws
  • Declaration

    public func encode(to encoder: Encoder) throws