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 ati
. 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])
Declaration
func rotated(shiftingToStart i: Index) -> RotatedCollection<Self>
Parameters
i
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 ofself
. At most log(N) index offsetting operations ifself
conforms toRandomAccessCollection
; at most N such operations otherwise.
Declaration
func partitionPoint( where predicate: (Element) throws -> Bool ) rethrows -> Index
- Efficiency: At most log(N) invocations of
-
Returns
self.map(transform)
, computed in parallel on chunks of self of sizeminBatchSize
orminBatchSize + 1
.Requires
transform
is safe to call from multiple threads.Declaration
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 byselection
without reading the elements of either collection.Complexity
O(1)Declaration
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 ofbatchSize
.Declaration
public func inBatches(of batchSize: Int) -> Slices<Self>
-
Returns the
n
th position inself
.Declaration
func index(atOffset n: Int) -> Index
-
The result of collating the elements of
self
.Declaration
public var collated: Element { get }
-
Returns the elements of
self
, padded to maximal shape withpadValue
and collated.Declaration
public func paddedAndCollated<Scalar: Numeric>( with padValue: Scalar, atStart: Bool = false ) -> Element where Element == Tensor<Scalar>
Parameters
atStart
adds the padding at the beginning if this is
true
and the end otherwise. The default value isfalse
.