einshape is a DSL-based reshaping library designed to unify and simplify array manipulation operations such as reshape, squeeze, expand_dims, and transpose, similar to how `einsum` unifies `matmul` and `tensordot`. It primarily targets JAX and TensorFlow frameworks. The current version is 1.0, released in December 2022, indicating a stable but currently infrequent release cadence.
pip install einshapeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic reshaping operations using `einshape` with JAX. It covers transposing dimensions, combining multiple leading dimensions, and splitting a dimension, highlighting the DSL syntax. Note that JAX must be installed separately for this example to run.
Ensure `jax` and `jaxlib` (for JAX) or `tensorflow` (for TensorFlow) are installed: `pip install jax jaxlib` or `pip install tensorflow`.
Carefully review the `einshape` documentation on DSL syntax, especially for grouped dimensions. For example, `einshape('(mn)hwc->mnhwc', x, n=batch_size)` requires `n` to be specified.Double-check the input and output dimension labels in the `einshape` equation to ensure logical consistency and proper transformation.
Install JAX and JAXlib: `pip install jax jaxlib`.
Review the `einshape` equation and the input array's shape. If splitting dimensions, ensure all necessary sizes are provided via `kwargs` (e.g., `einshape('(ab)c->abc', array, a=expected_a_size)`).Ensure all dimensions on the left-hand side are accounted for on the right-hand side. For squeezing, use `1` to denote a unit dimension to be removed, e.g., `a1b->ab` instead of `ab->a`.