unibe-cns / NEAT

NEAT (NEural Analysis Toolkit)
Other
12 stars 15 forks source link

Issue81 #115

Closed pythonjam closed 3 years ago

pythonjam commented 3 years ago

Pull request related to issue 81. Converting expressions to rational expressions in order to prevent evaluation of Add inside exp.

WillemWybo commented 3 years ago

I have some issues. First, the C++ code didn't compile because the integers were too large, i.e.

neat/tools/simtools/net/Ionchannels.cc:476:31: error: integer literal is too large to be represented in any integer type
1.0/(pow(1015308793816973697/(2361183241434822606848*m_ca), 691752902764108157/144115188075855872) + 1);

Solved that by replacing

return sp.nsimplify(sp.parse_expr(sp.ccode(expr), evaluate=False), rational_conversion='exact')

with

return sp.nsimplify(sp.parse_expr(sp.ccode(expr), evaluate=False), tolerance=1e-15, rational_conversion='base10')

Second, the ccode printer prints a weird comment in the code i.e.:

    double z = // Not supported in C:
// pow
1.0/(pow(1015308793816973697/(2361183241434822606848*m_ca), 691752902764108157/144115188075855872) + 1.0);

This is not a problem in the actual C code, but since we also use this printing in the NEURON mod-files, this is generates an error since the syntax for comments is different.

WillemWybo commented 3 years ago

I encountered too many issues with the 'nice' approach of replacing the sympify call with something custom. Thus, I just implemented what we need in an ad-hoc manner for the C-code generation. Will leave the issue open for future reference if evaluation control in sympy is ever enhanced.