diff --git a/chempy/kinetics/rates.py b/chempy/kinetics/rates.py index 54556bb4..9bc0e08d 100644 --- a/chempy/kinetics/rates.py +++ b/chempy/kinetics/rates.py @@ -198,8 +198,9 @@ def heaviside(x, z): elif hasattr(backend, 'clip'): # e.g. numpy def heaviside(x, z): assert z == 0 - lx = backend.log(backend.maximum(x, tiny)) - xclp = be.clip(lx, lo, hi) + lx = backend.log(backend.maximum(backend.array(x), tiny)) + xclp = backend.clip(lx, lo, hi) + x = (xclp - lo)/(hi - lo) y = (3 - 2*x)*x*x return y else: diff --git a/chempy/kinetics/tests/test__rates.py b/chempy/kinetics/tests/test__rates.py index 3248c51a..489bde68 100644 --- a/chempy/kinetics/tests/test__rates.py +++ b/chempy/kinetics/tests/test__rates.py @@ -86,8 +86,8 @@ def test_Log10TPolyMassAction__units(): p = MassAction(Constant(kunit)*10**ShiftedTPoly([273.15*u.K, .7, .02/u.K, .003/u.K**2, .0004/u.K**3])) r = Reaction({'A': 2, 'B': 1}, {'C': 1}, p, {'B': 1}) res = p({'A': 11*u.molar, 'B': 13*u.molar, 'temperature': 298.15*u.K}, reaction=r) - ref = 10**(.7 + .02*25 + 0.003 * 25**2 + 0.0004 * 25**3) - assert abs(res - ref*13*11**2*Mps) < 1e-15 + ref = 10**(.7 + .02*25 + 0.003 * 25**2 + 0.0004 * 25**3)*13*11**2*Mps + assert abs((res - ref)/ref) < 1e-15 def test_TPolyInLog10MassAction(): diff --git a/chempy/tests/test_units.py b/chempy/tests/test_units.py index 7a4e0c09..c6224852 100644 --- a/chempy/tests/test_units.py +++ b/chempy/tests/test_units.py @@ -207,7 +207,7 @@ def test_to_unitless(): sy.exp(Ea_over_RT_uncert) T_K_sym = np.array(sy.Symbol('T_K', real=True), dtype=object) * u.K - to_unitless(T_K_sym/(298*u.K)) + assert to_unitless(T_K_sym/(298*u.K)).tolist() == [sy.Symbol('T_K', real=True)] rescale(simplified(Ea/dc.molar_gas_constant)/T_K_sym, 1) Ea_over_R_uncert = UncertainQuantity(Ea, unit_of(Ea), 0.1*Ea)/dc.molar_gas_constant to_unitless(Ea_over_R_uncert/(298*u.K)) @@ -223,7 +223,7 @@ def test_UncertainQuantity(): a = UncertainQuantity([1, 2], u.m, [.1, .2]) assert a[1] == [2.]*u.m assert (-a)[0] == [-1.]*u.m - assert (-a).uncertainty[0] == [0.1]*u.m + assert allclose((-a).uncertainty[0], [0.1]*u.m) assert (-a)[0] == (a*-1)[0] assert (-a).uncertainty[0] == (a*-1).uncertainty[0] assert allclose(a, [1, 2]*u.m)