def test_fcode_NumberSymbol(): p = FCodePrinter() assert fcode( Catalan ) == ' parameter (Catalan = 0.915965594177219d0)\n Catalan' assert fcode( EulerGamma ) == ' parameter (EulerGamma = 0.577215664901533d0)\n EulerGamma' assert fcode(E) == ' parameter (E = 2.71828182845905d0)\n E' assert fcode( GoldenRatio ) == ' parameter (GoldenRatio = 1.61803398874989d0)\n GoldenRatio' assert fcode(pi) == ' parameter (pi = 3.14159265358979d0)\n pi' assert fcode(pi, precision=5) == ' parameter (pi = 3.1416d0)\n pi' assert fcode(Catalan, human=False) == ({(Catalan, p._print(Catalan.evalf(15)))}, set(), ' Catalan') assert fcode(EulerGamma, human=False) == ({ (EulerGamma, p._print(EulerGamma.evalf(15))) }, set(), ' EulerGamma') assert fcode(E, human=False) == ({(E, p._print(E.evalf(15)))}, set(), ' E') assert fcode(GoldenRatio, human=False) == ({ (GoldenRatio, p._print(GoldenRatio.evalf(15))) }, set(), ' GoldenRatio') assert fcode(pi, human=False) == ({(pi, p._print(pi.evalf(15)))}, set(), ' pi') assert fcode(pi, precision=5, human=False) == ({(pi, p._print(pi.evalf(5)))}, set(), ' pi')
def test_ccode_inline_function(): g = implemented_function('g', Lambda(x, 2 * x)) assert ccode(g(x)) == '2*x' g = implemented_function('g', Lambda(x, 2 * x / Catalan)) assert ccode( g(x)) == 'double const Catalan = %s;\n2*x/Catalan' % Catalan.evalf() A = IndexedBase('A') i = Idx('i', symbols('n', integer=True)) g = implemented_function('g', Lambda(x, x * (1 + x) * (2 + x))) assert ccode(g(A[i]), assign_to=A[i]) == ('for (int i=0; i<n; i++){\n' ' A[i] = (A[i] + 1)*(A[i] + 2)*A[i];\n' '}')
def test_fcode_NumberSymbol(): p = FCodePrinter() assert fcode(Catalan) == ' parameter (Catalan = 0.915965594177219d0)\n Catalan' assert fcode(EulerGamma) == ' parameter (EulerGamma = 0.577215664901533d0)\n EulerGamma' assert fcode(E) == ' parameter (E = 2.71828182845905d0)\n E' assert fcode(GoldenRatio) == ' parameter (GoldenRatio = 1.61803398874989d0)\n GoldenRatio' assert fcode(pi) == ' parameter (pi = 3.14159265358979d0)\n pi' assert fcode( pi, precision=5) == ' parameter (pi = 3.1416d0)\n pi' assert fcode(Catalan, human=False) == ({(Catalan, p._print( Catalan.evalf(15)))}, set(), ' Catalan') assert fcode(EulerGamma, human=False) == ({(EulerGamma, p._print( EulerGamma.evalf(15)))}, set(), ' EulerGamma') assert fcode(E, human=False) == ( {(E, p._print(E.evalf(15)))}, set(), ' E') assert fcode(GoldenRatio, human=False) == ({(GoldenRatio, p._print( GoldenRatio.evalf(15)))}, set(), ' GoldenRatio') assert fcode(pi, human=False) == ( {(pi, p._print(pi.evalf(15)))}, set(), ' pi') assert fcode(pi, precision=5, human=False) == ( {(pi, p._print(pi.evalf(5)))}, set(), ' pi')