CodeSampleX

Sample

numpy 2.5.1: numpy.lib.stride_tricks.sliding_window_view constructs zero-copy sliding window views over ndarrays with readonly defaults and axis selection

Verified sample for pypi numpy 2.5.1: numpy.lib.stride_tricks.sliding_window_view constructs zero-copy sliding window views over ndarrays with readonly…

sha256:aa6a47dff2fd68d42bbd85e7505fd5e796c16ed9426c273ab74ccb3e2999352e

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip

Verification-run environments

Environment Contract Stages Run
python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962…
2026-08-28

Case

HOW
Goal
numpy.lib.stride_tricks.sliding_window_view constructs zero-copy sliding window views over ndarrays with readonly defaults and axis selection
Packages
Symbols
  • numpy.lib.stride_tricks.sliding_window_view
Environment
python 3.12
Created
2026-08-28T03:52:39Z

Contract

  1. sliding_window_view constructs zero-copy sliding window views over 1D arrays, appending the window dimension at the end of shape and sharing memory with the input.
  2. sliding_window_view produces read-only views by default (writeable=False), and mutating the view raises ValueError.
  3. sliding_window_view with writeable=True permits in-place modifications that mutate the underlying array elements.
  4. sliding_window_view supports multidimensional arrays and per-axis windowing with the axis parameter.
  5. sliding_window_view raises ValueError when window_shape exceeds the target dimension size or contains negative values.

Files

  • PROMPT.md
  • csx.json
  • requirements.txt
  • spec.json
  • test/contract.py

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: numpy.lib.stride_tricks.sliding_window_view constructs zero-copy sliding window views over ndarrays with readonly defaults and axis selection
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/numpy@2.5.1
Demonstrate these symbols/APIs:
  - numpy.lib.stride_tricks.sliding_window_view

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:40fb5eeda98a186534c74f1a5f4e835583691468a25a93e56c0902f0366da3fc","contract":["sliding_window_view constructs zero-copy sliding window views over 1D arrays, appending the window dimension at the end of shape and sharing memory with the input.","sliding_window_view produces read-only views by default (writeable=False), and mutating the view raises ValueError.","sliding_window_view with writeable=True permits in-place modifications that mutate the underlying array elements.","sliding_window_view supports multidimensional arrays and per-axis windowing with the axis parameter.","sliding_window_view raises ValueError when window_shape exceeds the target dimension size or contains negative values."],"goal":"numpy.lib.stride_tricks.sliding_window_view constructs zero-copy sliding window views over ndarrays with readonly defaults and axis selection","kind":"HOW","packages":["pkg:pypi/numpy@2.5.1"],"schemaVersion":1,"symbols":["numpy.lib.stride_tricks.sliding_window_view"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/numpy@2.5.1"],"schemaVersion":1,"subject":"pkg:pypi/numpy@2.5.1","symbols":["numpy.lib.stride_tricks.sliding_window_view"],"verifierAdapter":"python@1"}
requirements.txt
numpy==2.5.1
spec.json
{
  "schemaVersion": 1,
  "goal": "numpy.lib.stride_tricks.sliding_window_view constructs zero-copy sliding window views over ndarrays with readonly defaults and axis selection",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/numpy@2.5.1"
  ],
  "symbols": [
    "numpy.lib.stride_tricks.sliding_window_view"
  ]
}
test/contract.py
import numpy as np
from numpy.lib.stride_tricks import sliding_window_view


# 1. 1D sliding window view shape, contents, and memory sharing
source = np.array([10, 20, 30, 40, 50], dtype=np.int64)
w1 = sliding_window_view(source, window_shape=3)
assert w1.shape == (3, 3)
assert np.array_equal(w1, [[10, 20, 30], [20, 30, 40], [30, 40, 50]])
assert np.shares_memory(source, w1)

# 2. Read-only default (writeable=False)
assert not w1.flags.writeable
try:
    w1[0, 0] = 999
except ValueError as exc:
    assert "read-only" in str(exc).lower() or "read only" in str(exc).lower()
else:
    raise AssertionError("Mutating default sliding_window_view must raise ValueError")
assert source[0] == 10

# 3. writeable=True allows mutating underlying array
source_w = np.array([1, 2, 3, 4], dtype=np.int32)
w_mutable = sliding_window_view(source_w, window_shape=2, writeable=True)
assert w_mutable.flags.writeable
w_mutable[0, 0] = 100
assert source_w[0] == 100

# 4. Multidimensional arrays and axis selection
grid = np.arange(12, dtype=np.int32).reshape(3, 4)
# 2D window on 2D array: (3 - 2 + 1, 4 - 2 + 1, 2, 2)
w_2d = sliding_window_view(grid, window_shape=(2, 2))
assert w_2d.shape == (2, 3, 2, 2)
assert np.array_equal(w_2d[0, 0], [[0, 1], [4, 5]])
assert np.shares_memory(grid, w_2d)

# Single axis windowing on 2D array
w_axis = sliding_window_view(grid, window_shape=2, axis=1)
assert w_axis.shape == (3, 3, 2)
assert np.array_equal(w_axis[0, 0], [0, 1])
assert np.shares_memory(grid, w_axis)

# 5. Dimension boundary and negative value error checking
small_arr = np.array([1, 2, 3])
try:
    sliding_window_view(small_arr, window_shape=4)
except ValueError:
    pass
else:
    raise AssertionError("window_shape larger than array dimension must raise ValueError")

try:
    sliding_window_view(small_arr, window_shape=-1)
except ValueError:
    pass
else:
    raise AssertionError("negative window_shape must raise ValueError")

print("CONTRACT PASS: numpy.lib.stride_tricks.sliding_window_view")

Origin Seeder

anonymous