示例
pymatting 1.1.15: estimate_alpha_knn
已验证示例 — pypi pymatting 1.1.15: estimate_alpha_knn. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: assert estimate_alpha_knn computes alpha matte…
sha256:bf2647c0b6432ca1307dea0e03082130fc1f634489a7de07b6f40d2bf84bc897
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 pymatting.estimate_alpha_knn in pkg:pypi/pymatting@1.1.15
- 符号
-
- pymatting.estimate_alpha_knn
- 创建时间
- 2026-09-02T11:30:33Z
契约
- assert estimate_alpha_knn computes alpha matte bounded in [0, 1] matching trimap constraints
- assert estimate_alpha_knn supports custom laplacian_kwargs and cg_kwargs options
- assert estimate_alpha_knn raises ValueError when image and trimap dimensions do not match
- assert estimate_alpha_knn raises ValueError when trimap is missing foreground values
- assert estimate_alpha_knn raises ValueError when trimap is missing background values
文件
- PROMPT.md
- csx.json
- pyproject.toml
- requirements.txt
- spec.json
- test/contract.py
源代码
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 pymatting.estimate_alpha_knn in pkg:pypi/pymatting@1.1.15
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/pymatting@1.1.15
Demonstrate these symbols/APIs:
- pymatting.estimate_alpha_knn
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.
{"case":{"caseId":"case:sha256:b445e665952e0b9c0449c76e2a7221c6188224c861654df769a2b14d6547a496","contract":["assert estimate_alpha_knn computes alpha matte bounded in [0, 1] matching trimap constraints","assert estimate_alpha_knn supports custom laplacian_kwargs and cg_kwargs options","assert estimate_alpha_knn raises ValueError when image and trimap dimensions do not match","assert estimate_alpha_knn raises ValueError when trimap is missing foreground values","assert estimate_alpha_knn raises ValueError when trimap is missing background values"],"goal":"verify pymatting.estimate_alpha_knn in pkg:pypi/pymatting@1.1.15","kind":"HOW","packages":["pkg:pypi/pymatting@1.1.15"],"schemaVersion":1,"symbols":["pymatting.estimate_alpha_knn"]},"contractCommand":["python3","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/pymatting@1.1.15"],"schemaVersion":1,"subject":"pkg:pypi/pymatting@1.1.15","symbols":["pymatting.estimate_alpha_knn"],"verifierAdapter":"python@1"}
[project]
name = "verify-pymatting-estimate-alpha-knn"
version = "0.1.0"
dependencies = [
"pymatting==1.1.15",
]
pymatting==1.1.15
numpy
scipy
pillow
{
"schemaVersion": 1,
"goal": "verify pymatting.estimate_alpha_knn in pkg:pypi/pymatting@1.1.15",
"kind": "HOW",
"packages": [
"pkg:pypi/pymatting@1.1.15"
],
"symbols": [
"pymatting.estimate_alpha_knn"
]
}
import numpy as np
from pymatting import estimate_alpha_knn
def test_estimate_alpha_knn_basic():
h, w = 12, 12
image = np.zeros((h, w, 3), dtype=np.float64)
trimap = np.full((h, w), 0.5, dtype=np.float64)
trimap[:, :4] = 0.0
trimap[:, 8:] = 1.0
image[:, :4] = [0.1, 0.1, 0.1]
image[:, 8:] = [0.9, 0.9, 0.9]
image[:, 4:8] = [0.5, 0.5, 0.5]
alpha = estimate_alpha_knn(image, trimap)
assert alpha.shape == (h, w)
assert np.all(alpha >= -1e-5) and np.all(alpha <= 1.0 + 1e-5)
assert np.all(alpha[:, :4] < 0.1)
assert np.all(alpha[:, 8:] > 0.9)
def test_estimate_alpha_knn_custom_options():
h, w = 10, 10
image = np.zeros((h, w, 3), dtype=np.float64)
trimap = np.full((h, w), 0.5, dtype=np.float64)
trimap[:, :3] = 0.0
trimap[:, 7:] = 1.0
image[:, :3] = [0.2, 0.2, 0.2]
image[:, 7:] = [0.8, 0.8, 0.8]
image[:, 3:7] = [0.5, 0.5, 0.5]
alpha = estimate_alpha_knn(
image,
trimap,
laplacian_kwargs={"n_neighbors": [5, 5]},
cg_kwargs={"maxiter": 500, "rtol": 1e-5},
)
assert alpha.shape == (h, w)
assert np.all(alpha >= -1e-5) and np.all(alpha <= 1.0 + 1e-5)
assert np.all(alpha[:, :3] < 0.1)
assert np.all(alpha[:, 7:] > 0.9)
def test_estimate_alpha_knn_dimension_mismatch():
h, w = 10, 10
image = np.zeros((h, w, 3), dtype=np.float64)
bad_trimap = np.full((h + 2, w), 0.5, dtype=np.float64)
bad_trimap[:, :3] = 0.0
bad_trimap[:, 7:] = 1.0
try:
estimate_alpha_knn(image, bad_trimap)
assert False, "estimate_alpha_knn should have raised ValueError for mismatched dimensions"
except ValueError as exc:
assert isinstance(exc, ValueError)
def test_estimate_alpha_knn_missing_foreground():
h, w = 8, 8
image = np.zeros((h, w, 3), dtype=np.float64)
no_fg_trimap = np.zeros((h, w), dtype=np.float64)
try:
estimate_alpha_knn(image, no_fg_trimap)
assert False, "estimate_alpha_knn should have raised ValueError when foreground is missing"
except ValueError as exc:
assert isinstance(exc, ValueError)
def test_estimate_alpha_knn_missing_background():
h, w = 8, 8
image = np.zeros((h, w, 3), dtype=np.float64)
no_bg_trimap = np.ones((h, w), dtype=np.float64)
try:
estimate_alpha_knn(image, no_bg_trimap)
assert False, "estimate_alpha_knn should have raised ValueError when background is missing"
except ValueError as exc:
assert isinstance(exc, ValueError)
def main():
test_estimate_alpha_knn_basic()
test_estimate_alpha_knn_custom_options()
test_estimate_alpha_knn_dimension_mismatch()
test_estimate_alpha_knn_missing_foreground()
test_estimate_alpha_knn_missing_background()
print("All contract assertions passed.")
if __name__ == "__main__":
main()
原始种子者
匿名