CodeSampleX

Exemple

numpy 2.5.1: numpy

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

sha256:37a21ac8d7f32824bc7d29e720b19690020377a99c9831bf0e77f85714ae263d

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é python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python 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-28

Cas

HOW
Objectif
verify numpy in pkg:pypi/numpy@2.5.1
Paquets
Symboles
  • numpy
Environnement
python 3.12
Créé
2026-08-28T03:57:06Z

Contrat

  1. numpy.zeros, numpy.ones, and numpy.full allocate ndarrays with specified shapes, dtypes, and fill values.
  2. numpy ufuncs broadcast compatible shapes and support in-place writing via the out parameter.
  3. numpy.sum and numpy.mean perform reduction across specified axes with keepdims preserving dimensional rank.
  4. numpy.reshape and ndarray.T manipulate array layout while maintaining total element count and C/Fortran contiguity flags.
  5. numpy.matmul and the @ operator compute matrix products matching linear algebra dimension contraction rules.
  6. numpy.linalg.solve computes exact solutions to linear matrix systems AX = B.
  7. numpy.where applies boolean condition masks to select elements from alternative arrays or evaluate indices.

Fichiers

  • PROMPT.md
  • csx.json
  • 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 numpy in pkg:pypi/numpy@2.5.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/numpy@2.5.1
Demonstrate these symbols/APIs:
  - numpy
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:f75db267c175dbf921ab2a3babe2fb3f8e5a3e4d87993f4c9f01c7bd8d555c3a","contract":["numpy.zeros, numpy.ones, and numpy.full allocate ndarrays with specified shapes, dtypes, and fill values.","numpy ufuncs broadcast compatible shapes and support in-place writing via the out parameter.","numpy.sum and numpy.mean perform reduction across specified axes with keepdims preserving dimensional rank.","numpy.reshape and ndarray.T manipulate array layout while maintaining total element count and C/Fortran contiguity flags.","numpy.matmul and the @ operator compute matrix products matching linear algebra dimension contraction rules.","numpy.linalg.solve computes exact solutions to linear matrix systems AX = B.","numpy.where applies boolean condition masks to select elements from alternative arrays or evaluate indices."],"goal":"verify numpy in pkg:pypi/numpy@2.5.1","kind":"HOW","packages":["pkg:pypi/numpy@2.5.1"],"schemaVersion":1,"symbols":["numpy"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","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"],"verifierAdapter":"python@1"}
requirements.txt
numpy==2.5.1
spec.json
{
  "schemaVersion": 1,
  "goal": "verify numpy in pkg:pypi/numpy@2.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/numpy@2.5.1"
  ],
  "symbols": [
    "numpy"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.py
import numpy as np


def test_array_creation():
    # numpy.zeros, numpy.ones, and numpy.full allocate ndarrays with specified shapes, dtypes, and fill values
    z = np.zeros((2, 3), dtype=np.int32)
    assert z.shape == (2, 3)
    assert z.dtype == np.int32
    assert z.size == 6
    assert np.all(z == 0)

    o = np.ones((3, 2), dtype=np.float64)
    assert o.shape == (3, 2)
    assert o.dtype == np.float64
    assert np.all(o == 1.0)

    f = np.full((2, 2), 42, dtype=np.int64)
    assert f.shape == (2, 2)
    assert f.dtype == np.int64
    assert np.all(f == 42)


def test_broadcasting_and_ufuncs():
    # numpy ufuncs broadcast compatible shapes and support in-place writing via the out parameter
    a = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float64)
    b = np.array([10, 20, 30], dtype=np.float64)

    # (2, 3) + (3,) -> (2, 3) via broadcasting
    c = np.add(a, b)
    expected = np.array([[11.0, 22.0, 33.0], [14.0, 25.0, 36.0]], dtype=np.float64)
    assert np.array_equal(c, expected)

    # In-place write via out parameter
    out_buf = np.empty_like(a)
    result = np.multiply(a, 2.0, out=out_buf)
    assert result is out_buf
    assert np.array_equal(out_buf, np.array([[2.0, 4.0, 6.0], [8.0, 10.0, 12.0]]))


def test_axis_reductions():
    # numpy.sum and numpy.mean perform reduction across specified axes with keepdims preserving dimensional rank
    arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float64)

    sum_axis0 = np.sum(arr, axis=0)
    assert np.array_equal(sum_axis0, np.array([5.0, 7.0, 9.0]))
    assert sum_axis0.shape == (3,)

    sum_axis1_keep = np.sum(arr, axis=1, keepdims=True)
    assert np.array_equal(sum_axis1_keep, np.array([[6.0], [15.0]]))
    assert sum_axis1_keep.shape == (2, 1)

    mean_all = np.mean(arr)
    assert mean_all == 3.5


def test_reshaping_and_transpose():
    # numpy.reshape and ndarray.T manipulate array layout while maintaining total element count and C/Fortran contiguity flags
    arr = np.arange(6, dtype=np.int32)
    reshaped = np.reshape(arr, (2, 3))
    assert reshaped.shape == (2, 3)
    assert reshaped.flags.c_contiguous is True

    transposed = reshaped.T
    assert transposed.shape == (3, 2)
    assert transposed.flags.f_contiguous is True
    assert np.array_equal(transposed, np.array([[0, 3], [1, 4], [2, 5]]))


def test_matmul_and_linear_algebra():
    # numpy.matmul and the @ operator compute matrix products matching linear algebra dimension contraction rules
    m1 = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float64)
    m2 = np.array([[5.0, 6.0], [7.0, 8.0]], dtype=np.float64)

    prod_matmul = np.matmul(m1, m2)
    prod_operator = m1 @ m2
    expected_prod = np.array([[19.0, 22.0], [43.0, 50.0]], dtype=np.float64)

    assert np.array_equal(prod_matmul, expected_prod)
    assert np.array_equal(prod_operator, expected_prod)

    # numpy.linalg.solve computes exact solutions to linear matrix systems AX = B
    A = np.array([[3.0, 1.0], [1.0, 2.0]], dtype=np.float64)
    B = np.array([9.0, 8.0], dtype=np.float64)
    X = np.linalg.solve(A, B)
    assert np.allclose(X, np.array([2.0, 3.0]))
    assert np.allclose(A @ X, B)


def test_boolean_masking_and_where():
    # numpy.where applies boolean condition masks to select elements from alternative arrays or evaluate indices
    x = np.array([10, 20, 30, 40, 50], dtype=np.int32)
    cond = x > 25

    selected = np.where(cond, x, -1)
    assert np.array_equal(selected, np.array([-1, -1, 30, 40, 50]))

    indices = np.where(cond)
    assert np.array_equal(indices[0], np.array([2, 3, 4]))


def main():
    test_array_creation()
    test_broadcasting_and_ufuncs()
    test_axis_reductions()
    test_reshaping_and_transpose()
    test_matmul_and_linear_algebra()
    test_boolean_masking_and_where()
    print("CONTRACT PASS: verify numpy in pkg:pypi/numpy@2.5.1")


if __name__ == "__main__":
    main()

Seeder d'origine

anonyme