@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 }
คำประกาศ
public init(_ tensor: Tensor<Scalar>)
คำประกาศ
public typealias ArrayLiteralElement = _TensorElementLiteral<Scalar>
คำประกาศ
public init(arrayLiteral elements: _TensorElementLiteral<Scalar>...)
คำประกาศ
public static func == (lhs: ShapedArraySlice, rhs: ShapedArraySlice) -> Bool
คำประกาศ
public func hash(into hasher: inout Hasher)
คำประกาศ
public func encode(to encoder: Encoder) throws
คำประกาศ
public init(from decoder: Decoder) throws