def ghost_to_view(self, idxs):
        """ This maps the index from the current ghost shape of the view to the view shape.
        
        :param list idxs_in: list of indices to be transformed

        .. note:: no slicing is admitted here. Preprocess ``idxs`` with :py:meth:`expand_idxs` if slicing is required.
        """
        if self.maps[self.view]['Q'] != None:
            return tuple([(i if i < N else N - 1) for i, N in zip(
                self.ghost_to_extended(idxs), self.get_view_shape())])
        else:
            idxs = idxfold(self.get_view_shape(),
                           idxunfold(self.get_ghost_shape(), idxs))
            return tuple(idxs)
    def __getitem__(self, idxs):
        """ Get item function
        :param tuple,int idxs: ((i_1,..,i_d),(j_1,..,j_d)) with respect to the unfolded mode sizes

        :returns: item at that position
        """
        if not self.init:
            raise NameError(
                "TensorToolbox.QTTmat.__getitem__: QTT not initialized correctly"
            )

        # Check for out of bounds
        if any(map(operator.ge, idxs[0], self.get_full_nrows())) or any(
                map(operator.ge, idxs[1], self.get_full_ncols())):
            raise NameError(
                "TensorToolbox.QTTmat.__getitem__: Index out of bounds")

        # Compute the index of the folding representation from the unfolded index
        return TTmat.__getitem__(
            self, (idxfold(self.get_nrows(),
                           idxunfold(self.get_full_nrows(), idxs[0])),
                   idxfold(self.get_ncols(),
                           idxunfold(self.get_full_ncols(), idxs[1]))))
    def view_to_ghost(self, idxs):
        """ This maps the index from the view to the ghost shape.
        
        :param list idxs: list of indices to be transformed

        .. note:: no slicing is admitted here. Preprocess ``idxs`` with :py:meth:`expand_idxs` if slicing is required.
        .. note:: this returns an error if the ghost shape is obtained by quantics folding, because the one view index can be pointing to many indices in the folding.
        """
        if self.maps[self.view]['Q'] != None:
            raise NotImplemented(
                "This operation is undefined because one view idx can point to many q indices"
            )
        else:
            return idxfold(self.get_ghost_shape(),
                           idxunfold(self.get_view_shape(), idxs))
Exemple #4
0
    def __getitem__(self, idxs):
        """ Get item function: indexes are entered in with respect to the unfolded mode sizes.
        """
        if not self.init:
            raise NameError(
                "TensorToolbox.QTTvec.__getitem__: QTT not initialized correctly"
            )

        # Check whether index out of bounds
        if any(map(operator.ge, idxs, self.get_global_shape())):
            raise NameError(
                "TensorToolbox.QTTvec.__getitem__: Index out of bounds")

        # Compute the index of the folding representation from the unfolded representation
        return TTvec.__getitem__(
            self,
            idxfold(self.shape(), idxunfold(self.get_global_shape(), idxs)))
Exemple #5
0
 def full_to_q(self, idxs):
     return idxfold(self.get_q_shape(), idxunfold(self.shape(), idxs))
Exemple #6
0
 def q_to_full(self, idxs):
     return idxfold(self.shape(), idxunfold(self.get_q_shape(), idxs))
 def ghost_to_extended(self, idxs):
     return idxfold(self.get_extended_shape(),
                    idxunfold(self.get_ghost_shape(), idxs))