(self, state)
return False
Restore the (manual) node selection state.

        Return True if successful; False otherwise.
Restore the (manual) node selection state.
Restore the ( manual ) node selection state .
def _restore_selection(self, state):
        # type: (SelectionState) -> bool
        """
        Restore the (manual) node selection state.

        Return True if successful; False otherwise.
        """
        linkmatrix = self.linkmatrix
        if self.selection_method == 0 and self.root:
            selected, linksaved = state
            linkstruct = np.array(linksaved, dtype=float)
            selected = set(selected)  # type: Set[Tuple[int]]
            if not selected:
                return False
            if linkmatrix.shape[0] != linkstruct.shape[0]:
                return False
            # check that the linkage matrix structure matches. Use isclose for
            # the height column to account for inexact floating point math
            # (e.g. summation order in different ?gemm implementations for
            # euclidean distances, ...)
            if np.any(linkstruct[:, :2] != linkmatrix[:, :2]) or \
                    not np.all(np.isclose(linkstruct[:, 2], linkstruct[:, 2])):
                return False
            selection = []
            indices = np.array([n.value.index for n in leaves(self.root)],
                               dtype=int)
            # mapping from ranges to display (pruned) nodes
            mapping = {node.value.range: node
                       for node in postorder(self._displayed_root)}
            for node in postorder(self.root):  # type: Tree
                r = tuple(indices[node.value.first: node.value.last])
                if r in selected:
                    if node.value.range not in mapping:
                        # the node was pruned from display and cannot be
                        # selected
                        break
                    selection.append(mapping[node.value.range])
                    selected.remove(r)
                if not selected:
                    break  # found all, nothing more to do
            if selection and selected:
                # Could not restore all selected nodes (only partial match)
                return False

            self._set_selected_nodes(selection)
            return True
        return False
def _restore_selection ( self , state ) : # type: (SelectionState) -> bool linkmatrix = self . linkmatrix if self . selection_method == 0 and self . root : selected , linksaved = state linkstruct = np . array ( linksaved , dtype = float ) selected = set ( selected ) # type: Set[Tuple[int]] if not selected : return False if linkmatrix . shape [ 0 ] != linkstruct . shape [ 0 ] : return False # check that the linkage matrix structure matches. Use isclose for # the height column to account for inexact floating point math # (e.g. summation order in different ?gemm implementations for # euclidean distances, ...) if np . any ( linkstruct [ : , : 2 ] != linkmatrix [ : , : 2 ] ) or not np . all ( np . isclose ( linkstruct [ : , 2 ] , linkstruct [ : , 2 ] ) ) : return False selection = [ ] indices = np . array ( [ n . value . index for n in leaves ( self . root ) ] , dtype = int ) # mapping from ranges to display (pruned) nodes mapping = { node . value . range : node for node in postorder ( self . _displayed_root ) } for node in postorder ( self . root ) : # type: Tree r = tuple ( indices [ node . value . first : node . value . last ] ) if r in selected : if node . value . range not in mapping : # the node was pruned from display and cannot be # selected break selection . append ( mapping [ node . value . range ] ) selected . remove ( r ) if not selected : break # found all, nothing more to do if selection and selected : # Could not restore all selected nodes (only partial match) return False self . _set_selected_nodes ( selection ) return True return False