サンプル
pymatting 1.1.15: knn_laplacian
検証済みサンプル — pypi pymatting 1.1.15: knn_laplacian. python 3.12 · linux debian/x64 · docker で contract を実行し、成功しました: knn_laplacian computes sparse matting…
sha256:648249314dd16233d7d95f09fbf7356420a86f5c225ebbe970c18eff81589cdc
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 x64 pip
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | FAIL | compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-02 |
| 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.knn_laplacian in pkg:pypi/pymatting@1.1.15
- パッケージ
- シンボル
-
- pymatting.knn_laplacian
- 作成日
- 2026-09-02T11:50:01Z
コントラクト
- knn_laplacian computes sparse matting Laplacian matrix with binary kernel and zero row sums
- knn_laplacian computes sparse matting Laplacian matrix with soft kernel
- knn_laplacian accepts custom n_neighbors and distance_weights parameters
- knn_laplacian raises ValueError when kernel is not binary or soft
ファイル
- 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.knn_laplacian 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.knn_laplacian
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:dd919fa31b80d68eb25399c61d3252630fcceee857d02c995fb2e9e8a6c1fcf2","contract":["knn_laplacian computes sparse matting Laplacian matrix with binary kernel and zero row sums","knn_laplacian computes sparse matting Laplacian matrix with soft kernel","knn_laplacian accepts custom n_neighbors and distance_weights parameters","knn_laplacian raises ValueError when kernel is not binary or soft"],"goal":"verify pymatting.knn_laplacian in pkg:pypi/pymatting@1.1.15","kind":"HOW","packages":["pkg:pypi/pymatting@1.1.15"],"schemaVersion":1,"symbols":["pymatting.knn_laplacian"]},"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/pymatting@1.1.15"],"schemaVersion":1,"subject":"pkg:pypi/pymatting@1.1.15","symbols":["pymatting.knn_laplacian"],"verifierAdapter":"python@1"}
[project]
name = "verify-pymatting-knn-laplacian"
version = "0.1.0"
dependencies = [
"pymatting==1.1.15",
"numpy",
"scipy",
"pillow",
"numba",
]
pymatting==1.1.15
numpy
scipy
pillow
numba
{
"schemaVersion": 1,
"goal": "verify pymatting.knn_laplacian in pkg:pypi/pymatting@1.1.15",
"kind": "HOW",
"packages": [
"pkg:pypi/pymatting@1.1.15"
],
"symbols": [
"pymatting.knn_laplacian"
]
}
import numpy as np
import scipy.sparse
from pymatting import knn_laplacian
def test_knn_laplacian_binary():
# Assertion 1: knn_laplacian computes sparse matting Laplacian matrix with binary kernel and zero row sums
h, w = 6, 6
img = np.zeros((h, w, 3), dtype=np.float64)
img[:, :3] = [0.1, 0.2, 0.3]
img[:, 3:] = [0.8, 0.7, 0.6]
L = knn_laplacian(img, n_neighbors=[4, 2], distance_weights=[2.0, 0.1], kernel="binary")
assert scipy.sparse.issparse(L), "L must be a sparse matrix"
assert L.shape == (h * w, h * w), f"Expected shape {(h * w, h * w)}, got {L.shape}"
row_sums = np.array(L.sum(axis=1)).flatten()
assert np.allclose(row_sums, 0.0, atol=1e-7), "Laplacian row sums must be zero"
diag = L.diagonal()
assert np.all(diag > 0), "Laplacian diagonal elements must be positive"
def test_knn_laplacian_soft():
# Assertion 2: knn_laplacian computes sparse matting Laplacian matrix with soft kernel
h, w = 6, 6
img = np.linspace(0, 1, h * w * 3, dtype=np.float64).reshape((h, w, 3))
L_soft = knn_laplacian(img, n_neighbors=[4, 2], distance_weights=[2.0, 0.1], kernel="soft")
assert scipy.sparse.issparse(L_soft), "L_soft must be a sparse matrix"
assert L_soft.shape == (h * w, h * w), f"Expected shape {(h * w, h * w)}, got {L_soft.shape}"
row_sums = np.array(L_soft.sum(axis=1)).flatten()
assert np.allclose(row_sums, 0.0, atol=1e-7), "Laplacian row sums must be zero"
def test_knn_laplacian_custom_parameters():
# Assertion 3: knn_laplacian accepts custom n_neighbors and distance_weights parameters
h, w = 6, 6
img = np.zeros((h, w, 3), dtype=np.float64)
img[0, 0] = [1.0, 1.0, 1.0]
L_custom = knn_laplacian(img, n_neighbors=[3], distance_weights=[1.0], kernel="binary")
assert scipy.sparse.issparse(L_custom)
assert L_custom.shape == (h * w, h * w)
row_sums = np.array(L_custom.sum(axis=1)).flatten()
assert np.allclose(row_sums, 0.0, atol=1e-7)
def test_knn_laplacian_invalid_kernel():
# Assertion 4: knn_laplacian raises ValueError when kernel is not binary or soft
h, w = 4, 4
img = np.zeros((h, w, 3), dtype=np.float64)
try:
knn_laplacian(img, kernel="gaussian")
assert False, "Expected ValueError for invalid kernel"
except ValueError as exc:
assert "kernel must be binary/soft" in str(exc)
def main():
test_knn_laplacian_binary()
test_knn_laplacian_soft()
test_knn_laplacian_custom_parameters()
test_knn_laplacian_invalid_kernel()
print("All contract assertions passed.")
if __name__ == "__main__":
main()
オリジンシーダー
匿名