def test_errstate_all_but_one(): olderr = sc.geterr() with sc.errstate(all='raise', singular='ignore'): sc.gammaln(0) with assert_raises(sc.SpecialFunctionError): sc.spence(-1.0) assert_equal(olderr, sc.geterr())
def test_errstate(): for category, error_code in _sf_error_code_map.items(): for action in _sf_error_actions: olderr = sc.geterr() with sc.errstate(**{category: action}): _check_action(_sf_error_test_function, (error_code, ), action) assert_equal(olderr, sc.geterr())
def test_errstate(): for category in _sf_error_code_map.keys(): for action in _sf_error_actions: olderr = sc.geterr() with sc.errstate(**{category: action}): _check_action(_sf_error_test_function, (_sf_error_code_map[category],), action) assert_equal(olderr, sc.geterr())
def test_seterr(): entry_err = sc.geterr() try: for category, error_code in _sf_error_code_map.items(): for action in _sf_error_actions: geterr_olderr = sc.geterr() seterr_olderr = sc.seterr(**{category: action}) assert_(geterr_olderr == seterr_olderr) newerr = sc.geterr() assert_(newerr[category] == action) geterr_olderr.pop(category) newerr.pop(category) assert_(geterr_olderr == newerr) _check_action(_sf_error_test_function, (error_code, ), action) finally: sc.seterr(**entry_err)
def test_seterr(): entry_err = sc.geterr() try: for category in _sf_error_code_map.keys(): for action in _sf_error_actions: geterr_olderr = sc.geterr() seterr_olderr = sc.seterr(**{category: action}) assert_(geterr_olderr == seterr_olderr) newerr = sc.geterr() assert_(newerr[category] == action) geterr_olderr.pop(category) newerr.pop(category) assert_(geterr_olderr == newerr) _check_action(_sf_error_test_function, (_sf_error_code_map[category],), action) finally: sc.seterr(**entry_err)
def create_profile(time, rate_constants): """ Computes a concentration profile according to the *model()* function. Parameters ---------- time : np.array Time array. rate_constants : RateConstants RateConstants object. Returns ------- profile : np.array Concentration profile matrix. """ ks = rate_constants.ks alphas = rate_constants.alphas if rate_constants.style == 'dec': s0 = np.ones(ks.shape[0]) elif rate_constants.style == 'custom': s0 = np.zeros(ks.shape) for i in range(s0.shape[1]): s0[0, i] = alphas[i] s0 = s0.flatten('F') else: # assuming a starting population of 100% for the first species s0 = np.zeros(ks.shape[0]) s0[0] = 1 time = time.reshape(-1) # sometimes odeint encounters an overflow errs = scsp.geterr() errs['overflow'] = 'ignore' scsp.seterr(**errs) profile = odeint(model, s0, time, (rate_constants, )) errs['overflow'] = 'warn' scsp.seterr(**errs) if rate_constants.style == 'custom': profile = np.split(profile, ks.shape[1], axis=1) profile = np.sum(profile, axis=0) return profile
def test_errstate_cpp_basic(): olderr = sc.geterr() with sc.errstate(underflow='raise'): with assert_raises(sc.SpecialFunctionError): sc.wrightomega(-1000) assert_equal(olderr, sc.geterr())
def test_errstate_c_basic(): olderr = sc.geterr() with sc.errstate(domain='raise'): with assert_raises(sc.SpecialFunctionError): sc.spence(-1) assert_equal(olderr, sc.geterr())
def test_errstate_pyx_basic(): olderr = sc.geterr() with sc.errstate(singular='raise'): with assert_raises(sc.SpecialFunctionError): sc.loggamma(0) assert_equal(olderr, sc.geterr())
def test_geterr(): err = sc.geterr() for key, value in err.items(): assert_(key in _sf_error_code_map.keys()) assert_(value in _sf_error_actions)