MCPcopy Create free account
hub / github.com/PyTables/PyTables / compute_overlaps

Method compute_overlaps

tables/index.py:1914–1975  ·  view source on GitHub ↗

Compute some statistics about overlaping of slices in index. Returns ------- noverlaps : int The total number of slices that overlaps in index. multiplicity : array of int The number of times that a concrete slice overlaps with any other.

(
        self, where: RootGroup, message: str, verbose: bool
    )

Source from the content-addressed store, hash-verified

1912 return (noverlaps, multiplicity, toverlap)
1913
1914 def compute_overlaps(
1915 self, where: RootGroup, message: str, verbose: bool
1916 ) -> tuple[int, np.ndarray, float]:
1917 """Compute some statistics about overlaping of slices in index.
1918
1919 Returns
1920 -------
1921 noverlaps : int
1922 The total number of slices that overlaps in index.
1923 multiplicity : array of int
1924 The number of times that a concrete slice overlaps with any other.
1925 toverlap : float
1926 An ovelap index: the sum of the values in segment slices that
1927 overlaps divided by the entire range of values. This index is only
1928 computed for numerical types.
1929
1930 """
1931 ranges = where.ranges[:]
1932 nslices = self.nslices
1933 if self.nelementsILR > 0:
1934 # Add the ranges corresponding to the last row
1935 rangeslr = np.array([self.bebounds[0], self.bebounds[-1]])
1936 ranges = np.concatenate((ranges, [rangeslr]))
1937 nslices += 1
1938 noverlaps = 0
1939 soverlap = 0
1940 toverlap = -1
1941 multiplicity = np.zeros(shape=nslices, dtype="int_")
1942 for i in range(nslices):
1943 for j in range(i + 1, nslices):
1944 if ranges[i, 1] > ranges[j, 0]:
1945 noverlaps += 1
1946 multiplicity[j - i] += 1
1947 if self.type != "string":
1948 # Convert ranges into floats in order to allow
1949 # doing operations with them without overflows
1950 soverlap += float(ranges[i, 1]) - float(ranges[j, 0])
1951
1952 # Return the overlap as the ratio between overlaps and entire range
1953 if self.type != "string":
1954 erange = float(ranges[-1, 1]) - float(ranges[0, 0])
1955 # Check that there is an effective range of values
1956 # Beware, erange can be negative in situations where
1957 # the values are suffering overflow. This can happen
1958 # specially on big signed integer values (on overflows,
1959 # the end value will become negative!).
1960 # Also, there is no way to compute overlap ratios for
1961 # non-numerical types. So, be careful and always check
1962 # that toverlap has a positive value (it must have been
1963 # initialized to -1. before) before using it.
1964 # F. Altet 2007-01-19
1965 if erange > 0:
1966 toverlap = soverlap / erange
1967 if verbose:
1968 print("overlaps (%s):" % message, noverlaps, toverlap)
1969 print(multiplicity)
1970 # For full indexes, set the 'is_csi' flag
1971 if self.indsize == 8 and self._v_file._iswritable():

Callers 3

is_csiMethod · 0.95
do_complete_sortMethod · 0.95
swapMethod · 0.95

Calls 1

_iswritableMethod · 0.80

Tested by

no test coverage detected