示例
numba 0.67.0rc1: prange
已验证示例 — pypi numba 0.67.0rc1: prange. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: prange fallback outside jit execution matches standard range…
sha256:4259237a29e9c64e57ad7fb9228de66f8e816c0dc824ef693a393be0e0ada285
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 pip
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-02 |
案例
HOW- 目标
- verify numba.prange in pkg:pypi/numba@0.67.0rc1
- 符号
-
- numba.prange
- 创建时间
- 2026-09-02T13:17:55Z
契约
- prange fallback outside jit execution matches standard range iteration with start, stop, and step arguments
- prange inside njit with parallel=True performs parallel reduction over array elements
- prange inside njit with parallel=True performs parallel array mutation and elementwise transformation
- prange supports start and stop slice boundary indexing in parallel execution
- prange supports nested multidimensional parallel loops for 2D array computation
- prange with step size other than 1 in parallel jit raises UnsupportedRewriteError
文件
- NOTES.md
- PROMPT.md
- csx.json
- requirements.txt
- spec.json
- test/contract.py
源代码
# Numba prange parallel loop API
This sample pins `numba` 0.67.0rc1 and verifies `numba.prange` for parallel iteration in JIT-compiled functions.
The contract verifies:
- `prange` outside JIT context behaves as a drop-in replacement for standard `range` with start, stop, and step attributes.
- `prange` inside `@njit(parallel=True)` enables parallel reduction across threads.
- `prange` inside `@njit(parallel=True)` enables independent parallel array element mutation.
- `prange` supports start and stop slice boundary indexing in parallel execution.
- `prange` supports nested multi-dimensional parallel loops for 2D array computation.
- `prange` with step size other than 1 in `@njit(parallel=True)` raises `UnsupportedRewriteError`.
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: verify numba.prange in pkg:pypi/numba@0.67.0rc1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/numba@0.67.0rc1
Demonstrate these symbols/APIs:
- numba.prange
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.
{"case":{"caseId":"case:sha256:e091e9d46141a6e136c438aede7d9cbecbb11d6a8ccd7832582821f3d606e395","contract":["prange fallback outside jit execution matches standard range iteration with start, stop, and step arguments","prange inside njit with parallel=True performs parallel reduction over array elements","prange inside njit with parallel=True performs parallel array mutation and elementwise transformation","prange supports start and stop slice boundary indexing in parallel execution","prange supports nested multidimensional parallel loops for 2D array computation","prange with step size other than 1 in parallel jit raises UnsupportedRewriteError"],"goal":"verify numba.prange in pkg:pypi/numba@0.67.0rc1","kind":"HOW","packages":["pkg:pypi/numba@0.67.0rc1"],"schemaVersion":1,"symbols":["numba.prange"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/numba@0.67.0rc1"],"schemaVersion":1,"subject":"pkg:pypi/numba@0.67.0rc1","symbols":["numba.prange"],"verifierAdapter":"python@1"}
numba==0.67.0rc1
numpy==2.5.2
{
"schemaVersion": 1,
"goal": "verify numba.prange in pkg:pypi/numba@0.67.0rc1",
"kind": "HOW",
"packages": [
"pkg:pypi/numba@0.67.0rc1"
],
"symbols": [
"numba.prange"
]
}
import numpy as np
import numba
from numba import njit, prange
from numba.core.errors import UnsupportedRewriteError
def test_prange_outside_jit():
r1 = prange(5)
assert list(r1) == [0, 1, 2, 3, 4]
assert r1.start == 0 and r1.stop == 5 and r1.step == 1
r2 = prange(2, 7)
assert list(r2) == [2, 3, 4, 5, 6]
assert r2.start == 2 and r2.stop == 7 and r2.step == 1
r3 = prange(1, 10, 2)
assert list(r3) == [1, 3, 5, 7, 9]
assert r3.start == 1 and r3.stop == 10 and r3.step == 2
def test_prange_parallel_reduction():
@njit(parallel=True)
def parallel_sum(arr):
acc = 0.0
for i in prange(len(arr)):
acc += arr[i]
return acc
arr = np.linspace(1.0, 100.0, 200)
res = parallel_sum(arr)
expected = np.sum(arr)
assert np.isclose(res, expected)
def test_prange_parallel_array_mutation():
@njit(parallel=True)
def parallel_scale(arr, factor):
out = np.empty_like(arr)
for i in prange(len(arr)):
out[i] = arr[i] * factor
return out
arr = np.arange(50, dtype=np.float64)
scaled = parallel_scale(arr, 3.5)
expected = arr * 3.5
assert np.array_equal(scaled, expected)
def test_prange_slice_bounds():
@njit(parallel=True)
def parallel_slice_sum(arr, start, stop):
acc = 0.0
for i in prange(start, stop):
acc += arr[i]
return acc
arr = np.arange(100, dtype=np.float64)
res = parallel_slice_sum(arr, 15, 65)
expected = np.sum(arr[15:65])
assert np.isclose(res, expected)
def test_prange_multidimensional_nested():
@njit(parallel=True)
def parallel_matrix_add(a, b):
rows, cols = a.shape
out = np.empty((rows, cols), dtype=a.dtype)
for i in prange(rows):
for j in prange(cols):
out[i, j] = a[i, j] + b[i, j]
return out
a = np.ones((8, 8), dtype=np.float64)
b = np.full((8, 8), 2.5, dtype=np.float64)
out = parallel_matrix_add(a, b)
assert np.array_equal(out, a + b)
def test_prange_unsupported_non_unit_step_raises():
try:
@njit(parallel=True)
def bad_step(arr):
acc = 0.0
for i in prange(0, len(arr), 2):
acc += arr[i]
return acc
arr = np.arange(10, dtype=np.float64)
bad_step(arr)
assert False, "Expected UnsupportedRewriteError for non-unit step in prange"
except UnsupportedRewriteError as exc:
assert "Only constant step size of 1 is supported for prange" in str(exc)
def main():
test_prange_outside_jit()
test_prange_parallel_reduction()
test_prange_parallel_array_mutation()
test_prange_slice_bounds()
test_prange_multidimensional_nested()
test_prange_unsupported_non_unit_step_raises()
print("All contract assertions passed.")
if __name__ == "__main__":
main()
原始种子者
匿名