Beispiel #1
0
    def get_rank(self):
        """Return the reference rank from the reference rank file.

        :return: Reference rank.
        :rtype: int
        :raise StoreLoad.FileNotFoundError: Raised if reference rank file not found.
        """
        if not self.exists_rank_file():
            raise StoreLoad.FileNotFoundError(
                "%s: Reference rank file not found" % str(self))
        return int(StoreLoad.load_line(self.rank_file_path))
Beispiel #2
0
    def _load_basis_g6(self):
        """Load the reference basis list from the reference file.

        :Note: The implementation depends on the reference data.

        :return: List of graph6 strings representing the reference basis.
        :rtype: list(str)
        :raise StoreLoad.FileNotFoundError: If the reference basis file is not found.
        """
        if not self.exists_basis_file():
            raise StoreLoad.FileNotFoundError(
                "%s: Reference basis file not found" % str(self))
        return StoreLoad.load_string_list(self.basis_file_path)
Beispiel #3
0
    def get_dimension(self):
        """Return the Dimension of the vector space.

        :return: int: Dimension of the vector space
        :rtype: int

        :raise StoreLoad.FileNotFoundError: Raised if no basis file found.
        """
        if not self.is_valid():
            return 0
        try:
            header = StoreLoad.load_line(self.get_basis_file_path())
            return int(header)
        except StoreLoad.FileNotFoundError:
            raise StoreLoad.FileNotFoundError(
                "Dimension unknown for %s: No basis file" % str(self))
Beispiel #4
0
    def _load_basis_g6(self):
        """Load the basis from the basis file.

        Raises an exception if no basis file found or if the dimension in the header of the basis file doesn't
        correspond to the dimension of the basis.

        :return: List of graph6 strings of canonically labeled graphs building a basis of the
            vector space.
        :rtype: list(str)
        :raise StoreLoad.FileNotFoundError: Raised if no basis file found.
        :raise ValueError: Raised if dimension in header doesn't correspond to the basis dimension.
        """
        if not self.exists_basis_file():
            raise StoreLoad.FileNotFoundError(
                "Cannot load basis, No basis file found for %s: " % str(self))
        basis_list = StoreLoad.load_string_list(self.get_basis_file_path())
        dim = int(basis_list.pop(0))
        if len(basis_list) != dim:
            raise ValueError("Basis read from file %s has wrong dimension" %
                             str(self.get_basis_file_path()))
        return basis_list
Beispiel #5
0
    def _load_matrix(self):
        """ Load the reference matrix list from the reference file.

        The implementation depends on the reference data.

        :return: (matrix_list = list((domain index, target index, value), shape = (domain dimension, target dimension))
        :rtype: tuple(list(tuple(int, int, int)), tuple(int, int))
        :raise StoreLoad.FileNotFoundError: If the reference matrix file is not found.
        :raise: ValueError: Raised in the following cases:
                End line missing.
                Negative matrix index.
                Matrix index too large.
        """
        if not self.exists_matrix_file():
            raise StoreLoad.FileNotFoundError(
                "%s: Reference basis file not found" % str(self))
        stringList = StoreLoad.load_string_list(self.matrix_file_path)
        entriesList = []
        if len(stringList) == 0:
            return ([], None)
        else:
            (d, t, z) = map(int, stringList.pop().split(" "))
            if z != 0:
                raise ValueError("End line in reference file %s is missing" %
                                 str(self))
            shape = (d, t)
            for line in stringList:
                (i, j, v) = map(int, line.split(" "))
                if i < 0 or j < 0:
                    raise ValueError("%s: Negative matrix index" % str(self))
                if i > d or j > t:
                    raise ValueError("%s Matrix index outside matrix size" %
                                     str(self))
                if i == 0 or j == 0:
                    continue
                entriesList.append((i - 1, j - 1, v))
        return (entriesList, shape)