Have a question? Connect with the community at the TensorFlow Forum Visit Forum


extension Collection
extension Collection where Element: Collatable
  • Returns a view of this collection with the elements reordered such the element at the given position ends up first.

    The subsequence of the collection up to i is shifted to after the subsequence starting at i. The order of the elements within each partition is otherwise unchanged.

    let a = [10, 20, 30, 40, 50, 60, 70]
    let r = a.rotated(shiftingToStart: 3)
    // r.elementsEqual([40, 50, 60, 70, 10, 20, 30])


    func rotated(shiftingToStart i: Index) -> RotatedCollection<Self>



    The position in the collection that should be first in the result. i must be a valid index of the collection.

    Return Value

    A rotated view on the elements of this collection, such that the element at i is first.

  • Declaration

    func stablyPartitioned(
      isSuffixElement p: (Element) -> Bool
    ) -> [Element]
  • Returns the index of the first element in the collection that matches the predicate.

    The collection must already be partitioned according to the predicate, as if self.partition(by: predicate) had already been called.

    • Efficiency: At most log(N) invocations of predicate, where N is the length of self. At most log(N) index offsetting operations if self conforms to RandomAccessCollection; at most N such operations otherwise.


    func partitionPoint(
      where predicate: (Element) throws -> Bool
    ) rethrows -> Index
  • Returns self.map(transform), computed in parallel on chunks of self of size minBatchSize or minBatchSize + 1.


    transform is safe to call from multiple threads.


    func concurrentMap<B>(
      minBatchSize: Int = 1,
      _ transform: (Element) -> B
    ) -> [B]
  • Returns a collection of elements of self at the positions and in the order specified by selection without reading the elements of either collection.




    public func sampled<Selection: Collection>(at selection: Selection)
      -> Sampling<Self, Selection>
  • Returns the longest non-overlapping slices of self, starting with its first element, having a maximum length of batchSize.


    public func inBatches(of batchSize: Int) -> Slices<Self>
  • Returns the nth position in self.


    func index(atOffset n: Int) -> Index
  • The result of collating the elements of self.


    public var collated: Element { get }
  • Returns the elements of self, padded to maximal shape with padValue and collated.


    public func paddedAndCollated<Scalar: Numeric>(
      with padValue: Scalar, atStart: Bool = false
    ) -> Element
    where Element == Tensor<Scalar>



    adds the padding at the beginning if this is true and the end otherwise. The default value is false.