CodeSampleX

Ejemplo

numpy 2.5.1: numpy

Muestra verificada para pypi numpy 2.5.1: numpy. El contrato se ejecutó en python 3.12 · linux alpine/x64 · docker y pasó: numpy.zeros, numpy.ones, and…

sha256:37a21ac8d7f32824bc7d29e720b19690020377a99c9831bf0e77f85714ae263d

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

Entornos de las ejecuciones de verificación

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

Caso

HOW
Objetivo
verify numpy in pkg:pypi/numpy@2.5.1
Paquetes
Símbolos
  • numpy
Entorno
python 3.12
Creado
2026-08-28T03:57:06Z

Contrato

  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.

Archivos

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

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

Código fuente

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 de origen

anónimo