Skip to main content

Einmesh Logo

einops-style multi dimensional meshgrids

PyPI - Python Version Release Build status Commit activity License codecov

Installation

Simple installation from uv:

uv add einmesh

or pip:

pip install einmesh

Features

  • einops-style Meshgrid Generation: The core function einmesh allows creating multi-dimensional meshgrids (like torch.meshgrid) using a concise string pattern similar to einops.
  • Flexible Space Definitions: Users define the dimensions using various "space" objects:
    • LinSpace: Linearly spaced points.
    • LogSpace: Logarithmically spaced points.
    • UniformDistribution: Points sampled from a uniform distribution.
    • NormalDistribution: Points sampled from a normal distribution.
  • Pattern Features:
    • Named Dimensions: Pattern elements correspond to keyword arguments (e.g., einmesh("x y", x=LinSpace(...), y=LogSpace(...))).
    • Dimension Ordering: The order in the pattern determines the order/shape of the output tensors (using ij indexing convention, like NumPy).
    • Stacking (*): A * in the pattern stacks the individual coordinate tensors along a new dimension, returning a single tensor.
    • Grouping (()): Parentheses group axes for rearrangement using einops.rearrange.
    • Duplicate Names: Handles patterns like "x x y", which repeats an axis and re-samples it.
  • Output:
    • Returns a tuple of coordinate tensors if no * is present.
    • Returns a single stacked tensor if * is present.
  • Backend: Numpy, Torch and JAX are all supported! Just import the einmesh function from the backend like
from einmesh.numpy import einmesh # Creates numpy arrays
from einmesh.jax import einmesh # Creates JAX arrays
from einmesh.torch import einmesh # Creates Torch Tensors
  • Super-Lightweight: Only installation dependency is einops! At runtime backends are loaded if available.

Examples

1. Basic 2D Linear Grid

Create a simple 2D grid with linearly spaced points along x and y.

from einmesh import LinSpace
from einmesh.numpy import einmesh

# Define the spaces
x_space = LinSpace(0, 1, 10)  # 10 points from 0 to 1
y_space = LinSpace(-1, 1, 20) # 20 points from -1 to 1

# Create the meshgrid
# Output: tuple of two tensors, each with shape (10, 20) following 'ij' indexing
x_coords, y_coords = einmesh("x y", x=x_space, y=y_space)

print(f"{x_coords.shape=}")
print(f"{y_coords.shape=}")

# Output:
# x_coords.shape=(10, 20)
# y_coords.shape=(10, 20)

2. Stacked Coordinates

Create a 3D grid and stack the coordinate tensors into a single tensor.

x_space = LinSpace(0, 1, 5)
y_space = LinSpace(0, 1, 6)
z_space = LogSpace(1, 2, 7)

# Use '*' to stack the coordinates along the last dimension
# Output: single tensor with shape (5, 6, 7, 3)
coords = einmesh("x y z *", x=x_space, y=y_space, z=z_space)

print(coords.shape)
# Output: (5, 6, 7, 3)
# coords[..., 0] contains x coordinates
# coords[..., 1] contains y coordinates
# coords[..., 2] contains z coordinates

3. Using Distributions

Generate grid points by sampling from distributions.

from einmesh import UniformDistribution, NormalDistribution

# Sample 10 points uniformly between -5 and 5 for x
x_dist = UniformDistribution(-5, 5, 10)
# Sample 15 points from a normal distribution (mean=0, std=1) for y
y_dist = NormalDistribution(0, 1, 15)

# Create the meshgrid
# Output: tuple of two tensors, each with shape (10, 15)
x_samples, y_samples = einmesh("x y", x=x_dist, y=y_dist)

print(x_samples.shape, y_samples.shape)
# Output: (10, 15) (10, 15)
# Note: The points along each axis will not be sorted.

4. Duplicate Dimension Names

Use the same space definition for multiple axes.

space = LinSpace(0, 1, 5)

# 'x' space is used for both the first and second dimensions.
# Output shapes: (5, 5, 10) for each tensor
x0_coords, x1_coords, y_coords = einmesh("x x y", x=space, y=LinSpace(-1, 1, 10))

print(x0_coords.shape, x1_coords.shape, y_coords.shape)
# Output: (5, 5, 10) (5, 5, 10) (5, 5, 10)

Metadata

Release files for einmesh 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for einmesh 0.1.4
File Size Uploaded Provenance Actions
einmesh-0.1.4.tar.gz 163.2 kB Without provenance Details for einmesh-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for einmesh 0.1.4
File Interpreter ABI Platform Actions
einmesh-0.1.4-py3-none-any.whl Python 3 none any Details for einmesh-0.1.4-py3-none-any.whl

Total release size: 180.0 kB

Release files / einmesh-0.1.4.tar.gz

Download URL einmesh-0.1.4.tar.gz
Size 163.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d287b6cb06ccf91a0fa7808eb166e663d77d770d425aa27f72829f7877d35b2e
BLAKE2b-256 checksum
How to use checksums
8ef0f343bbf82234ff5cd0eeb1987f87b8a69da343501760a45bddacc928c47c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / einmesh-0.1.4-py3-none-any.whl

Download URL einmesh-0.1.4-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b306344565f42531be5ad9549e6c5f1691784fb59c5f7e59657166471bc55d1a
BLAKE2b-256 checksum
How to use checksums
8af52ac1eb4e1839a29daa005e92efdefc3c87a1d629e5776f3cfcd2b89ef0dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Security for einmesh 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page