A DSL-based library for unified tensor reshaping, squeezing, expanding, and transposing in JAX, TensorFlow, and NumPy.
Einshape is a Python library that provides a domain-specific language (DSL) for tensor reshaping operations, similar to how `einsum` standardizes tensor contractions. It unifies operations like reshape, squeeze, expand_dims, and transpose under a single equation-based syntax, making complex array manipulations more intuitive and less error-prone.
Machine learning researchers, data scientists, and engineers working with JAX, TensorFlow, or NumPy who frequently manipulate tensor shapes in their workflows.
Developers choose Einshape for its expressive, concise DSL that reduces boilerplate code and mental overhead compared to chaining multiple native reshaping functions, while maintaining compatibility across major numerical frameworks.
Einshape is a domain-specific language (DSL) library that provides a unified interface for tensor reshaping operations across multiple frameworks. It extends the intuitive equation syntax of einsum to operations like reshape, squeeze, expand_dims, and transpose, making tensor manipulations more expressive and consistent.
lhs->rhs equations to specify complex tensor transformations concisely....) for arbitrary ranks, groups ( ) for splitting/combining dimensions, and units (1) for squeezing/expanding.n=batch_size).einsum's approach, reducing cognitive load for users familiar with Einstein summation.Einshape aims to bring the clarity and power of DSL-based tensor operations beyond contraction to reshaping, promoting a more declarative and readable style of array manipulation.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a concise DSL similar to einsum, enabling complex transformations like batch flattening or dimension splitting in a single readable equation, as shown with examples like 'n...->n(...)' for batch flatten.
Offers separate implementations for JAX, TensorFlow, and NumPy, allowing the same reshaping logic to be reused across different backends without code changes, as demonstrated in the usage examples.
Supports runtime shape specifications via keyword arguments, enabling flexible operations like splitting dimensions with variable sizes, exemplified by 'einshape("(mn)hwc->mnhwc", x, n=batch_size)' in the README.
Includes features like ellipsis for arbitrary ranks, groups for combining/splitting dimensions, and units for squeezing/expanding, providing powerful control over tensor shapes beyond basic reshapes.
Requires separate installation of JAX or TensorFlow and adds a parsing layer, which can introduce extra computational steps and potential performance overhead compared to direct native function calls.
Currently does not support PyTorch, a major deep learning framework, reducing its utility in ecosystems that rely on PyTorch for tensor operations.
The DSL with groups, ellipsis, and units can be non-intuitive for developers not already familiar with einsum, increasing the learning curve and potential for errors in equation writing.