@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