<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateMLComponents",
  "identifier" : "/documentation/CreateMLComponents/SlidingWindows",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML Components"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents14SlidingWindowsV"
  },
  "title" : "SlidingWindows"
}
-->

# SlidingWindows

A sequence of windows on a time series shaped array.

```
struct SlidingWindows<Scalar> where Scalar : MLShapedArrayScalar
```

## Overview

The shape of each window in the sequence is `[length, featureSize]`. The sequence will return as many windows as
fit in the input. For example, an input shaped array of shape `[8, 1]` using `stride` of 1 and `length` of 4 will
produce 5 examples:

```
[[1], [2], [3], [4]]
[[2], [3], [4], [5]]
[[3], [4], [5], [6]]
[[4], [5], [6], [7]]
[[5], [6], [7], [8]]
```

## Topics

### Creating a sliding window

[`init(input: MLShapedArray<Scalar>, length: Int, stride: Int) throws`](/documentation/CreateMLComponents/SlidingWindows/init(input:length:stride:))

Creates a sliding windows sequence.

### Inspecting the sliding window

[`var endIndex: Int`](/documentation/CreateMLComponents/SlidingWindows/endIndex)

The collection’s “past the end” position–that is, the position one greater than the last valid subscript
argument.

[`let input: MLShapedArray<Scalar>`](/documentation/CreateMLComponents/SlidingWindows/input)

The input shaped array.

[`let length: Int`](/documentation/CreateMLComponents/SlidingWindows/length)

The number samples in each window.

[`var startIndex: Int`](/documentation/CreateMLComponents/SlidingWindows/startIndex)

The position of the first window.

[`let stride: Int`](/documentation/CreateMLComponents/SlidingWindows/stride)

The number of samples between windows.

### Getting the index

[`func index(Int, offsetBy: Int) -> Int`](/documentation/CreateMLComponents/SlidingWindows/index(_:offsetBy:))

Returns an index that is the specified distance from the given index.

[`func index(after: Int) -> Int`](/documentation/CreateMLComponents/SlidingWindows/index(after:))

Returns the position immediately after the given index.

[`func index(before: Int) -> Int`](/documentation/CreateMLComponents/SlidingWindows/index(before:))

Returns the position immediately before the given index.

### Getting the subscript

[`subscript(_:)`](/documentation/CreateMLComponents/SlidingWindows/subscript(_:))

Accesses a contiguous range of windows.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`RandomAccessCollection`](/documentation/Swift/RandomAccessCollection)

[`Collection`](/documentation/Swift/Collection)

[`BidirectionalCollection`](/documentation/Swift/BidirectionalCollection)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sequence`](/documentation/Swift/Sequence)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)