[docs]classTranspose(DelayedOp):"""Delayed transposition, based on Bioconductor's ``DelayedArray::DelayedAperm`` class. This will create a matrix transpose in the 2-dimensional case; for a high-dimensional array, it will permute the dimensions. This class is intended for developers to construct new :py:class:`~delayedarray.DelayedArray.DelayedArray` instances. In general, end users should not be interacting with ``Transpose`` objects directly. """
[docs]def__init__(self,seed,perm:Optional[Tuple[int,...]]):""" Args: seed: Any object that satisfies the seed contract, see :py:class:`~delayedarray.DelayedArray.DelayedArray` for details. perm: Tuple of length equal to the dimensionality of ``seed``, containing the permutation of dimensions. If None, the dimension ordering is assumed to be reversed. """self._seed=seedcurshape=seed.shapendim=len(curshape)ifpermisnotNone:iflen(perm)!=ndim:raiseValueError("Dimensionality of 'seed' and 'perm' should be the same.")else:perm=(*range(ndim-1,-1,-1),)self._perm=permfinal_shape=[]forxinperm:final_shape.append(curshape[x])self._shape=(*final_shape,)
@propertydefshape(self)->Tuple[int,...]:""" Returns: Tuple of integers specifying the extent of each dimension of the transposed object. """returnself._shape@propertydefdtype(self)->dtype:""" Returns: NumPy type for the transposed contents, same as ``seed``. """returnself._seed.dtype@propertydefseed(self):""" Returns: The seed object. """returnself._seed@propertydefperm(self)->Tuple[int,...]:""" Returns: Permutation of dimensions in the transposition. """returnself._perm