CodeSampleX

Sample

pymatting 1.1.15: knn_laplacian

Verified sample for pypi pymatting 1.1.15: knn_laplacian. The contract ran on python 3.12 · linux debian/x64 · docker and passed.

sha256:648249314dd16233d7d95f09fbf7356420a86f5c225ebbe970c18eff81589cdc

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 pip

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify pymatting.knn_laplacian in pkg:pypi/pymatting@1.1.15
Packages
Symbols
  • pymatting.knn_laplacian
Created
2026-09-02T11:50:01Z

Contract

  1. knn_laplacian computes sparse matting Laplacian matrix with binary kernel and zero row sums
  2. knn_laplacian computes sparse matting Laplacian matrix with soft kernel
  3. knn_laplacian accepts custom n_neighbors and distance_weights parameters
  4. knn_laplacian raises ValueError when kernel is not binary or soft

Files

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

Download the source artifact (tar.gz)

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 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.
csx.json
{"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"}
pyproject.toml
[project]
name = "verify-pymatting-knn-laplacian"
version = "0.1.0"
dependencies = [
    "pymatting==1.1.15",
    "numpy",
    "scipy",
    "pillow",
    "numba",
]
requirements.txt
pymatting==1.1.15
numpy
scipy
pillow
numba
spec.json
{
  "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"
  ]
}
test/contract.py
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()

Origin Seeder

anonymous