CodeSampleX

Ejemplo

numba 0.67.0rc1: prange

Muestra verificada para pypi numba 0.67.0rc1: prange. El contrato se ejecutó en python 3.12 · linux debian/x64 · docker y pasó.

sha256:4259237a29e9c64e57ad7fb9228de66f8e816c0dc824ef693a393be0e0ada285

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 pip

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify numba.prange in pkg:pypi/numba@0.67.0rc1
Paquetes
Símbolos
  • numba.prange
Creado
2026-09-02T13:17:55Z

Contrato

  1. prange fallback outside jit execution matches standard range iteration with start, stop, and step arguments
  2. prange inside njit with parallel=True performs parallel reduction over array elements
  3. prange inside njit with parallel=True performs parallel array mutation and elementwise transformation
  4. prange supports start and stop slice boundary indexing in parallel execution
  5. prange supports nested multidimensional parallel loops for 2D array computation
  6. prange with step size other than 1 in parallel jit raises UnsupportedRewriteError

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
# 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`.
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: 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.
csx.json
{"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"}
requirements.txt
numba==0.67.0rc1
numpy==2.5.2
spec.json
{
  "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"
  ]
}
test/contract.py
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()

Seeder de origen

anónimo