CodeSampleX

Exemple

scipy 1.18.0: ndimage

Échantillon vérifié pour pypi scipy 1.18.0: ndimage. Le contrat s'est exécuté sur python 3.12 · linux alpine/x64 · docker et a réussi.

sha256:1abd373b80ca31003cf734e0e88817d6ad30a109a8496688134b86e3fe3bc43e

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 pip

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-27

Cas

HOW
Objectif
verify scipy.ndimage in pkg:pypi/scipy@1.18.0
Paquets
Symboles
  • scipy.ndimage
Créé
2026-08-27T19:57:50Z

Contrat

  1. assert gaussian_filter smooths multidimensional array with specified standard deviation
  2. assert label and find_objects identify contiguous connected components and return slice tuples
  3. assert binary_dilation and binary_erosion expand and shrink binary structures
  4. assert center_of_mass computes spatial centroids for labeled regions
  5. assert rotate and zoom perform array scaling and rotation transformations

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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: verify scipy.ndimage in pkg:pypi/scipy@1.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/scipy@1.18.0
Demonstrate these symbols/APIs:
  - scipy.ndimage

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:9afe217477421b616d963d6631b5bc74b0f3d771fac79127140f3ac671c8b227","contract":["assert gaussian_filter smooths multidimensional array with specified standard deviation","assert label and find_objects identify contiguous connected components and return slice tuples","assert binary_dilation and binary_erosion expand and shrink binary structures","assert center_of_mass computes spatial centroids for labeled regions","assert rotate and zoom perform array scaling and rotation transformations"],"goal":"verify scipy.ndimage in pkg:pypi/scipy@1.18.0","kind":"HOW","packages":["pkg:pypi/scipy@1.18.0"],"schemaVersion":1,"symbols":["scipy.ndimage"]},"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/scipy@1.18.0"],"schemaVersion":1,"subject":"pkg:pypi/scipy@1.18.0","symbols":["scipy.ndimage"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-scipy-ndimage"
version = "0.1.0"
dependencies = [
    "scipy==1.18.0",
    "numpy==2.5.2",
]
requirements.txt
scipy==1.18.0
numpy==2.5.2
spec.json
{
  "schemaVersion": 1,
  "goal": "verify scipy.ndimage in pkg:pypi/scipy@1.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/scipy@1.18.0"
  ],
  "symbols": [
    "scipy.ndimage"
  ]
}
test/contract.py
import numpy as np
import scipy.ndimage as ndi


def test_gaussian_filter():
    arr = np.zeros((5, 5), dtype=np.float64)
    arr[2, 2] = 1.0
    filtered = ndi.gaussian_filter(arr, sigma=1.0)
    assert filtered.shape == (5, 5)
    assert filtered[2, 2] > filtered[0, 0]
    assert np.isclose(filtered.sum(), 1.0, atol=1e-2)


def test_label_and_find_objects():
    binary_grid = np.array([
        [1, 1, 0, 0],
        [1, 1, 0, 0],
        [0, 0, 1, 1],
        [0, 0, 1, 1],
    ], dtype=np.int32)
    labeled, num_features = ndi.label(binary_grid)
    assert num_features == 2
    slices = ndi.find_objects(labeled)
    assert len(slices) == 2
    assert slices[0] == (slice(0, 2, None), slice(0, 2, None))
    assert slices[1] == (slice(2, 4, None), slice(2, 4, None))


def test_morphology_dilation_and_erosion():
    grid = np.zeros((7, 7), dtype=bool)
    grid[3, 3] = True
    struct = ndi.generate_binary_structure(2, 1)

    dilated = ndi.binary_dilation(grid, structure=struct)
    assert dilated.sum() == 5
    assert bool(dilated[3, 3]) is True
    assert bool(dilated[2, 3]) is True

    eroded = ndi.binary_erosion(dilated, structure=struct)
    assert np.array_equal(eroded, grid)


def test_center_of_mass():
    grid = np.array([
        [1, 1, 0, 0],
        [1, 1, 0, 0],
        [0, 0, 1, 1],
        [0, 0, 1, 1],
    ], dtype=np.float64)
    labeled, _ = ndi.label(grid)
    com = ndi.center_of_mass(grid, labels=labeled, index=[1, 2])
    assert np.allclose(com[0], (0.5, 0.5))
    assert np.allclose(com[1], (2.5, 2.5))


def test_geometric_transforms():
    img = np.ones((4, 4), dtype=np.float64)
    zoomed = ndi.zoom(img, zoom=2.0)
    assert zoomed.shape == (8, 8)

    rotated = ndi.rotate(img, angle=90.0, reshape=False)
    assert rotated.shape == (4, 4)


def main():
    test_gaussian_filter()
    test_label_and_find_objects()
    test_morphology_dilation_and_erosion()
    test_center_of_mass()
    test_geometric_transforms()
    print("All scipy.ndimage contract assertions passed.")


if __name__ == "__main__":
    main()

Seeder d'origine

anonyme