Changeset 1322 for framspy


Ignore:
Timestamp:
08/09/24 05:33:09 (3 months ago)
Author:
Maciej Komosinski
Message:

Use libm.so when available to disable exceptions in pyemd, and if not (e.g., on Windows), proceed without it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/dissimilarity/density_distribution.py

    r1295 r1322  
    99    """
    1010
    11     OLD_FPEX = False # update floating point exception handling/pyemd problems (if still needed) for new python versions
    12     if OLD_FPEX:
    13         libm = cdll.LoadLibrary(find_library('m')) # for disabling/enabling floating point exceptions (division by zero occurs in the EMD library)
     11    libm = find_library('m')  # for disabling/enabling floating point exceptions (division by zero occurs in the pyemd library)
     12    if libm is not None:  # libm.so (the mathematical library) is a part of Linux ecosystem - always present
     13        libm = cdll.LoadLibrary(libm)
     14    else:
     15        print('\nWarning: The "m" library not found - floating point exceptions in pyemd may occur...\n') # but on Windows, pyemd does not seem to cause floating point exceptions
    1416    EPSILON = 0.0001
    1517   
     
    293295                dist_matrix = self.calculateDistanceMatrix(s1[0],s2[0])
    294296
    295             if self.OLD_FPEX:
    296                 self.libm.fedisableexcept(0x04)  # change default flag value - don't cause exceptions when dividing by 0 (pyemd does it)
     297            if self.libm is not None:
     298                self.libm.fedisableexcept(0x04)  # change default flag value - don't cause "Floating point exception" when dividing by 0 (pyemd does that, for example when comparing two identical histograms, i.e., two identical signatures, for example from two identical phenotypes)
    297299
    298300            if self.frequency:
     
    301303                out = emd(self.normalize(s1[1]),self.normalize(s2[1]),dist_matrix)
    302304
    303             if self.OLD_FPEX:
    304                 self.libm.feclearexcept(0x04) # restoring default flag values...
     305            if self.libm is not None:
     306                self.libm.feclearexcept(0x04)  # restoring default flag values...
    305307                self.libm.feenableexcept(0x04)
    306308
Note: See TracChangeset for help on using the changeset viewer.