Registry / ai-ml / unfoldnd

unfoldnd

JSON →
library0.2.3pypypi✓ verified 86d ago

Unfold and fold operations for N-dimensional tensors in PyTorch, generalizing torch.nn.Unfold and torch.nn.Fold to arbitrary dimensions. Current version: 0.2.3. Released irregularly, latest in Dec 2024.

pip install unfoldnd
INSTALL
IMPORT
SIG · UNFOLDND
U
unfoldnd
ai-mlpythonv0.2.3
Install
67.2s avg
Import
6053ms
Disk
2148MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 77.1s
py 3.11
✓ —
✓ 69.7s
py 3.12
✓ —
✓ 63.6s
py 3.13
✓ —
✓ 58.2s
py 3.9
✓ —
✕ timeout
2148MB installed
● package 2148MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unfoldNd
from unfoldNd import unfoldNd
from unfoldnd import unfoldNd
Package name is 'unfoldNd' with capital N, but pip install uses all lowercase.
foldNd
from unfoldNd import foldNd

Demonstrates 3D unfolding and folding with a 3x3x3 kernel.

import torch from unfoldNd import unfoldNd, foldNd x = torch.randn(1, 3, 10, 10, 10) # N=3 kernel size 3x3x3 patches = unfoldNd(x, kernel_size=3, dilation=1, padding=0, stride=1) print(patches.shape) # torch.Size([1, 27, 512]) # Fold back (example assumes same parameters) x_reconstructed = foldNd(patches, output_size=(10,10,10), kernel_size=3, dilation=1, padding=0, stride=1) print(x_reconstructed.shape) # torch.Size([1, 3, 10, 10, 10])
Debug
Known issues
gotchaThe package name on PyPI is 'unfoldnd' (all lowercase), but the import uses 'unfoldNd' (capital N). This mismatch often causes ImportError.
fix
Use 'from unfoldNd import ...' after 'pip install unfoldnd'.
affects: all
gotchafoldNd requires explicit 'output_size' argument; it cannot be inferred from the input tensor shape. Missing it raises a TypeError.
fix
Always provide 'output_size' matching the spatial dimensions expected after folding.
affects: <0.2.0?
deprecatedVersion 0.2.0 changed the API: 'foldNd' was added and some internal parameters may differ from older versions.
fix
Update to >=0.2.0 and adjust if using fold operations.
affects: <0.2.0
gotchaThe 'dilation' parameter must be a single int or tuple matching the dimension count. Using incompatible shapes causes a RuntimeError.
fix
Ensure dilation, padding, stride are either int or tuples of length equal to the spatial dims of input.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'unfoldNd' from 'unfoldnd'
Mixing up package name (unfoldnd) with module name (unfoldNd).
fix
Run: from unfoldNd import unfoldNd
TypeError: foldNd() missing 1 required positional argument: 'output_size'
foldNd requires output_size parameter; it is not optional.
fix
Add 'output_size=(D, H, W)' (or appropriate dimensions) to the foldNd call.
RuntimeError: Expected 4D or 5D input tensor, but got 3D
unfoldNd expects at least a 4D tensor (batch, channels, spatial...).
fix
Ensure input tensor has batch and channel dimensions, e.g., reshape to (1, 1, *spatial_dims) if needed.
Upgrade
Version history
0.2.3latest on PyPI · released Dec 30, 2024
Audit
Dependencies
torchrequiredCore dependency; library operates on PyTorch tensors.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
unfoldnd — pip install unfoldnd · libregistry