def clear(cls, force=True): # Wipe out the "true" SymPy cache cache.clear_cache() # Wipe out the hidden module-private SymPy caches sympy.polys.rootoftools.ComplexRootOf.clear_cache() sympy.polys.rings._ring_cache.clear() sympy.polys.fields._field_cache.clear() sympy.polys.domains.modularinteger._modular_integer_cache.clear() # Maybe trigger garbage collection if force is False: if cls.ncalls_w_force_false + 1 == cls.force_ths: # Case 1: too long since we called gc.collect, let's do it now gc.collect() cls.ncalls_w_force_false = 0 elif any(i.nbytes > cls.gc_ths for i in _SymbolCache.values()): # Case 2: we got big objects in cache, we try to reclaim memory gc.collect() cls.ncalls_w_force_false = 0 else: # We won't call gc.collect() this time cls.ncalls_w_force_false += 1 else: gc.collect() for key, obj in list(_SymbolCache.items()): if obj() is None: del _SymbolCache[key]
def teardown_module(): from sympy import cache cache.clear_cache() # Remove output file generated by test_topology_1() fname = 'omega.h5' if os.path.exists(fname): os.remove(fname)
def teardown_module(): from sympy import cache cache.clear_cache() # Remove output file generated by tests import os fname = 'domain.h5' if os.path.exists(fname): os.remove(fname)
def teardown_function(): from sympy import cache cache.clear_cache()
def teardown_module(): from sympy import cache cache.clear_cache()
def sweep_threshold(self, tie_mode="smooth"): """An iterater that yields TP, TN, FP, FN with a threshold at infinity and gradually sweeping down to negative infinity. Ties can be handeled in several ways: * smooth (preferred) - construct a smooth slanted line which interpolates the TP, TN, FP, and FN appropriately * ignore - output the instances in the order they were presented to the ScoredData instance. * sample - randomly shuffle the ties. """ if self.num_pos == 0 or self.num_neg == 0: raise AssertionError( "There must be at least one positive and one negative example. This data has %i positive(s) and %i negative(s)." % (self.num_pos, self.num_neg)) from sympy import Rational from sympy import cache def smooth_ties(ties): sum = 0 for t in ties: sum += t return [Rational(sum, len(ties))] * len(ties) def ignore_ties(ties): return ties def sample_ties(ties): return random.sample(ties, len(ties)) if tie_mode == 1 or tie_mode == "smooth": tie_mode = smooth_ties elif tie_mode == 0 or tie_mode == "ignore": tie_mode = ignore_ties elif tie_mode == 2 or tie_mode == "sample": tie_mode = sample_ties else: raise ValueError( "tie_mode must equal 'smooth_ties', 'ignore_ties', or 'sample_ties'." ) TP = FP = 0 TN = self.num_neg FN = self.num_pos yield TP, TN, FP, FN SCORES = self.score_labels.items() SCORES.sort() SCORES.reverse() for S, Ls in SCORES: if self._score_label[S] == "mixed": Ls = tie_mode(Ls) for L in Ls: #if type(L) == int: L = Rational(L) TP += L FP += 1 - L FN -= L TN -= 1 - L if int(TP) == TP: TP = int(TP) FP = int(FP) FN = int(FN) TN = int(TN) yield TP, TN, FP, FN else: yield float(TP.evalf()), float(TN.evalf()), float( FP.evalf()), float(FN.evalf()) assert (TN == 0) assert (FN == 0) cache.clear_cache()