ShapedArraySlice

@frozen
public struct ShapedArraySlice<Scalar> : _ShapedArrayProtocol
extension ShapedArraySlice: RandomAccessCollection, MutableCollection
extension ShapedArraySlice: CustomStringConvertible
extension ShapedArraySlice: CustomPlaygroundDisplayConvertible
extension ShapedArraySlice: CustomReflectable
extension ShapedArraySlice: ExpressibleByArrayLiteral where Scalar: TensorFlowScalar
extension ShapedArraySlice: Equatable where Scalar: Equatable
extension ShapedArraySlice: Hashable where Scalar: Hashable
extension ShapedArraySlice: Codable where Scalar: Codable

ส่วนที่ต่อเนื่องกันของ ShapedArray หรือ ShapedArraySlice

ShapedArraySlice ช่วยให้ดำเนินการได้อย่างรวดเร็วและมีประสิทธิภาพกับสไลซ์ของอินสแตนซ์ ShapedArray ที่ต่อเนื่องกัน อินสแตนซ์ ShapedArraySlice ไม่มีพื้นที่เก็บข้อมูลของตัวเอง แต่จะให้มุมมองเกี่ยวกับการจัดเก็บฐาน ShapedArray แทน ShapedArraySlice สามารถแสดงสไลซ์ได้สองประเภท: อาร์เรย์องค์ประกอบและอาร์เรย์ย่อย

อาร์เรย์องค์ประกอบเป็นองค์ประกอบย่อยของ ShapedArray โดยอันดับจะน้อยกว่าฐานหนึ่งรายการ ชิ้นส่วนอาร์เรย์องค์ประกอบได้มาโดยการจัดทำดัชนีอินสแตนซ์ ShapedArray ด้วยดัชนี Int32 เอกพจน์

ตัวอย่างเช่น:

    var matrix = ShapedArray(shape: [2, 2], scalars: [0, 1, 2, 3])
    // `matrix` represents [[0, 1], [2, 3]].

    let element = matrix[0]
    // `element` is a `ShapedArraySlice` with shape [2]. It is an element
    // array, specifically the first element in `matrix`: [0, 1].

    matrix[1] = ShapedArraySlice(shape: [2], scalars: [4, 8])
    // The second element in `matrix` has been mutated.
    // `matrix` now represents [[0, 1, 4, 8]].

อาร์เรย์ย่อยคือช่วงขององค์ประกอบที่ต่อเนื่องกันใน ShapedArray ลำดับของอาร์เรย์ย่อยจะเหมือนกับลำดับฐาน แต่มิตินำหน้าคือการนับช่วงชิ้น ชิ้นส่วนย่อยได้มาจากการสร้างดัชนี ShapedArray ด้วย Range<Int32> ที่แสดงถึงช่วงขององค์ประกอบ (ในมิตินำหน้า) เมธอดเช่น prefix(:) และ suffix(:) ที่จัดทำดัชนีภายในด้วยช่วงยังสร้างอาร์เรย์ย่อยด้วย

ตัวอย่างเช่น:

    let zeros = ShapedArray(repeating: 0, shape: [3, 2])
    var matrix = ShapedArray(shape: [3, 2], scalars: Array(0..<6))
    // `zeros` represents [[0, 0], [0, 0], [0, 0]].
    // `matrix` represents [[0, 1], [2, 3], [4, 5]].

    let subarray = matrix.prefix(2)
    // `subarray` is a `ShapedArraySlice` with shape [2, 2]. It is a slice
    // of the first 2 elements in `matrix` and represents [[0, 1], [2, 3]].

    matrix[0..<2] = zeros.prefix(2)
    // The first 2 elements in `matrix` have been mutated.
    // `matrix` now represents [[0, 0], [0, 0], [4, 5]].
  • จำนวนมิติของอาร์เรย์

    คำประกาศ

    public var rank: Int { get }
  • รูปร่างของอาร์เรย์

    คำประกาศ

    public var shape: [Int] { get }
  • จำนวนสเกลาร์ทั้งหมดในอาร์เรย์

    คำประกาศ

    public var scalarCount: Int { get }
  • สร้าง ShapedArraySlice ที่มีรูปร่างที่ระบุและสเกลาร์ที่อยู่ติดกันในลำดับหลักแถว

    เงื่อนไขเบื้องต้น

    จำนวนสเกลาร์ต้องเท่ากับผลคูณของขนาดของรูปร่าง

    คำประกาศ

    public init(shape: [Int], scalars: [Scalar])
  • สร้าง ShapedArraySlice ที่มีรูปร่างและลำดับของสเกลาร์ที่ระบุในลำดับแถวหลัก

    เงื่อนไขเบื้องต้น

    จำนวนสเกลาร์ต้องเท่ากับผลคูณของขนาดของรูปร่าง

    คำประกาศ

    public init<S>(shape: [Int], scalars: S) where Scalar == S.Element, S : Sequence
  • สร้าง ShapedArraySlice จากค่าสเกลาร์

    คำประกาศ

    public init(_ scalar: Scalar)
  • สร้าง ShapedArraySlice ที่มีรูปร่างที่ระบุและค่าสเกลาร์ค่าเดียวที่ทำซ้ำ

    คำประกาศ

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

    พารามิเตอร์

    repeatedValue

    ค่าสเกลาร์ที่จะทำซ้ำ

    shape

    รูปร่างของ ShapedArraySlice

  • สร้าง ShapedArraySlice ที่มีรูปร่างที่ระบุและค่าสเกลาร์ค่าเดียวที่ทำซ้ำ

    คำประกาศ

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

    พารามิเตอร์

    repeatedValue

    ค่าสเกลาร์ที่จะทำซ้ำ

    shape

    รูปร่างของ ShapedArraySlice

  • ช่วงของสเกลาร์จาก ShapedArray ฐานที่แสดงโดย ShapedArraySlice

    คำประกาศ

    var scalarRange: Range<Int> { get }
  • เรียกการปิดด้วยตัวชี้ไปยังที่เก็บข้อมูลที่อยู่ติดกันของ ShapedArraySlice

    คำประกาศ

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

    พารามิเตอร์

    body

    การปิดด้วยพารามิเตอร์ UnsafeBufferPointer ที่ชี้ไปยังที่เก็บข้อมูลที่อยู่ติดกันสำหรับ ShapedArraySlice หากไม่มีที่เก็บข้อมูลดังกล่าว ก็จะถูกสร้างขึ้น หากเนื้อหามีค่าที่ส่งคืน ค่านั้นก็จะใช้เป็นค่าที่ส่งคืนสำหรับเมธอด withUnsafeBufferPointer(_:) ด้วย อาร์กิวเมนต์ตัวชี้ใช้ได้เฉพาะในช่วงระยะเวลาของการดำเนินการของวิธีการเท่านั้น

  • เรียกการปิดที่กำหนดด้วยตัวชี้ไปยังที่เก็บข้อมูลที่อยู่ติดกันที่ไม่แน่นอนของ ShapedArraySlice

    คำประกาศ

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

    พารามิเตอร์

    body

    การปิดด้วยพารามิเตอร์ UnsafeMutableBufferPointer ที่ชี้ไปยังที่เก็บข้อมูลที่อยู่ติดกันสำหรับ ShapedArraySlice หากไม่มีที่เก็บข้อมูลดังกล่าว ก็จะถูกสร้างขึ้น ถ้าเนื้อหามีค่าที่ส่งคืน ค่านั้นก็จะใช้เป็นค่าที่ส่งคืนสำหรับเมธอด withUnsafeMutableBufferPointer(_:) ด้วย อาร์กิวเมนต์ตัวชี้ใช้ได้เฉพาะในช่วงระยะเวลาของการดำเนินการของวิธีการเท่านั้น

  • คำประกาศ

    public typealias Index = Int
  • คำประกาศ

    public typealias Element = ShapedArraySlice
  • คำประกาศ

    public typealias SubSequence = ShapedArraySlice
  • คำประกาศ

    public var indices: Range<Int> { get }
  • คำประกาศ

    public var startIndex: Int { get }
  • คำประกาศ

    public var endIndex: Int { get }
  • เข้าถึงอาร์เรย์องค์ประกอบที่ระบุโดยดัชนีในมิตินำหน้า

    คำประกาศ

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

    พารามิเตอร์

    index

    ดัชนีของอาร์เรย์องค์ประกอบ

  • เข้าถึงอาร์เรย์ย่อยที่ระบุโดยช่วงดัชนีที่อยู่ติดกัน

    คำประกาศ

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

    พารามิเตอร์

    bounds

    ช่วงดัชนีที่ต่อเนื่องกัน

  • การแสดงข้อความของ ShapedArraySlice นี้

    บันทึก

    ใช้ fullDescription สำหรับการนำเสนอที่ไม่สวยงามซึ่งแสดงสเกลาร์ทั้งหมด

    คำประกาศ

    public var description: String { get }
  • คำประกาศ

    public var playgroundDescription: Any { get }
  • คำประกาศ

    public var customMirror: Mirror { get }
มีจำหน่ายที่ `Scalar`: `TensorFlowScalar`
มีจำหน่ายที่ 'สเกลาร์': 'เท่าเทียม'
  • คำประกาศ

    public static func == (lhs: ShapedArraySlice, rhs: ShapedArraySlice) -> Bool
มีจำหน่ายที่ `Scalar`: `Hashable`
มีจำหน่ายที่ `Scalar`: `Codable`