CodeSampleX

示例

numba 0.67.0rc1: vectorize

已验证示例 — pypi numba 0.67.0rc1: vectorize. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: assert vectorize compiles ufunc with explicit integer and…

sha256:577410fef81fcea21ddb684de2ab824e575161ec1d6342e80adb34d6eea61413

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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.vectorize in pkg:pypi/numba@0.67.0rc1
包
符号
  • numba.vectorize
创建时间
2026-09-02T13:21:01Z

契约

  1. assert vectorize compiles ufunc with explicit integer and float signatures on scalar and 1D array inputs
  2. assert vectorize compiles dynamically without explicit signatures on invocation
  3. assert vectorize performs multi-dimensional array broadcasting
  4. assert vectorize generated ufunc supports reduce and accumulate methods
  5. assert vectorize with explicit signature raises TypeError when called with incompatible argument types

文件

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

下载源代码构件 (tar.gz)

源代码

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.vectorize 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.vectorize
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:14fc57c4238e293e2114a9c09b0ea81810c06b988bb877df1d2fc5f2c848e52b","contract":["assert vectorize compiles ufunc with explicit integer and float signatures on scalar and 1D array inputs","assert vectorize compiles dynamically without explicit signatures on invocation","assert vectorize performs multi-dimensional array broadcasting","assert vectorize generated ufunc supports reduce and accumulate methods","assert vectorize with explicit signature raises TypeError when called with incompatible argument types"],"goal":"verify numba.vectorize in pkg:pypi/numba@0.67.0rc1","kind":"HOW","packages":["pkg:pypi/numba@0.67.0rc1"],"schemaVersion":1,"symbols":["numba.vectorize"]},"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.vectorize"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-numba"
version = "0.1.0"
dependencies = [
    "llvmlite==0.49.0",
    "numba==0.67.0rc1",
    "numpy==2.5.2",
]
requirements.txt
llvmlite==0.49.0
numba==0.67.0rc1
numpy==2.5.2
spec.json
{
  "schemaVersion": 1,
  "goal": "verify numba.vectorize in pkg:pypi/numba@0.67.0rc1",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/numba@0.67.0rc1"
  ],
  "symbols": [
    "numba.vectorize"
  ],
  "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
import numba
from numba import vectorize, int64, float64


def test_vectorize_explicit_signatures():
    @vectorize([int64(int64, int64), float64(float64, float64)])
    def vec_add(x, y):
        return x + y

    # Scalar inputs
    assert vec_add(10, 20) == 30
    assert vec_add(1.5, 2.5) == 4.0

    # 1D array inputs
    a = np.array([1, 2, 3], dtype=np.int64)
    b = np.array([4, 5, 6], dtype=np.int64)
    res = vec_add(a, b)
    assert isinstance(res, np.ndarray)
    assert np.array_equal(res, np.array([5, 7, 9], dtype=np.int64))

    # Broadcasting: 1D array + scalar
    res_bcast = vec_add(a, 10)
    assert np.array_equal(res_bcast, np.array([11, 12, 13], dtype=np.int64))


def test_vectorize_dynamic_compilation():
    @vectorize
    def vec_mul(x, y):
        return x * y

    # Compiles dynamically on invocation
    res_scalar = vec_mul(3, 4)
    assert res_scalar == 12

    arr1 = np.array([1.0, 2.0, 3.0], dtype=np.float64)
    arr2 = np.array([2.0, 3.0, 4.0], dtype=np.float64)
    res_arr = vec_mul(arr1, arr2)
    assert np.allclose(res_arr, np.array([2.0, 6.0, 12.0]))


def test_vectorize_multidimensional_broadcasting():
    @vectorize([float64(float64, float64)])
    def vec_sub(x, y):
        return x - y

    mat = np.array([[10.0, 20.0, 30.0], [40.0, 50.0, 60.0]], dtype=np.float64)
    row = np.array([1.0, 2.0, 3.0], dtype=np.float64)
    res = vec_sub(mat, row)
    expected = np.array([[9.0, 18.0, 27.0], [39.0, 48.0, 57.0]], dtype=np.float64)
    assert res.shape == (2, 3)
    assert np.allclose(res, expected)


def test_vectorize_ufunc_methods():
    @vectorize([int64(int64, int64)])
    def vec_sum(x, y):
        return x + y

    arr = np.array([1, 2, 3, 4, 5], dtype=np.int64)

    # ufunc reduce method
    total = vec_sum.reduce(arr)
    assert total == 15

    # ufunc accumulate method
    accum = vec_sum.accumulate(arr)
    assert np.array_equal(accum, np.array([1, 3, 6, 10, 15], dtype=np.int64))


def test_vectorize_type_error():
    @vectorize([int64(int64, int64)])
    def vec_int_add(x, y):
        return x + y

    try:
        vec_int_add("invalid", "strings")
        assert False, "Should have raised TypeError"
    except TypeError as e:
        assert isinstance(e, TypeError)


def main():
    test_vectorize_explicit_signatures()
    test_vectorize_dynamic_compilation()
    test_vectorize_multidimensional_broadcasting()
    test_vectorize_ufunc_methods()
    test_vectorize_type_error()
    print("All vectorize contract assertions passed.")


if __name__ == "__main__":
    main()

原始种子者

匿名