These are chat archives for symengine/symengine

2nd
Mar 2016
Rajith Vidanaarachchi
@rajithv
Mar 02 2016 04:49

Hi,

I was adding and running some new tests on symengine cwrappers, when this was given,

terminate called after throwing an instance of 'std::runtime_error' what(): div: Division by zero Aborted (core dumped)

I wasn't doing any divisions in my new tests, but trigonometric functions are involved. I'm having trouble trying to find the place which gives the error. Some help please :)

Sumith Kulal
@Sumith1896
Mar 02 2016 05:16
@rajithv Could you link us to the relevant code?
Rajith Vidanaarachchi
@rajithv
Mar 02 2016 06:26

@Sumith1896 https://github.com/rajithv/symengine/blob/functions/symengine/tests/cwrapper/test_cwrapper.c#L455

This is the file, and my addition starts with the referenced line.

@CodeMaxx cot is defined here actually
Akash Trehan
@CodeMaxx
Mar 02 2016 12:43
@rajithv Not that definition… I mean cot(pi) is Infinity
Rajith Vidanaarachchi
@rajithv
Mar 02 2016 13:53
@CodeMaxx yes.. I misread your message. Later saw the comment on github. It was the issue. Thanks
Isuru Fernando
@isuruf
Mar 02 2016 17:37
@certik, I have enabled coverage here, https://coveralls.io/builds/5275677
Can you enable coveralls in SymEngine?
Ondřej Čertík
@certik
Mar 02 2016 17:39
@isuruf yes.
Do I do it from coveralls.io?
Isuru Fernando
@isuruf
Mar 02 2016 17:39
Yes
Ondřej Čertík
@certik
Mar 02 2016 17:42
It should be enabled now
Isuru Fernando
@isuruf
Mar 02 2016 17:42
Great. Thanks
Ondřej Čertík
@certik
Mar 02 2016 17:42
@isuruf let me know if you can access the setup.
If not, let's figure out how to add you in.
Isuru Fernando
@isuruf
Mar 02 2016 17:43
I see that it's enabled now
I sent a PR, let's see how it goes
Ondřej Čertík
@certik
Mar 02 2016 17:46
Thanks for setting this up.
Looking at the link of the coverage that you sent, we have a lot to improve.
Isuru Fernando
@isuruf
Mar 02 2016 17:46
Yes, and that's without optional dependencies as well
What dependencies should I enable for the coverage run?
We can do, mpfr, mpc, flint, arb, piranha
Ondřej Čertík
@certik
Mar 02 2016 17:48
The way it works is that a special compiler is used?
Isuru Fernando
@isuruf
Mar 02 2016 17:49
Just gcc with 2 additional flags
Ondřej Čertík
@certik
Mar 02 2016 17:49
-fprofile-arcs -ftest-coverage, those are part of a regular gcc?
Isuru Fernando
@isuruf
Mar 02 2016 17:49
yes
Ondřej Čertík
@certik
Mar 02 2016 17:50
What does GCOV_EXECUTABLE do?
What does coveralls --exclude cmake --exclude CMakeFiles --exclude symengine/utilities --gcov $GCOV_EXECUTABLE --gcov-options '\-lp' do? Upload to coveralls.io?
Isuru Fernando
@isuruf
Mar 02 2016 17:51
gcov points to the gcov executable with gcc-4.6 which is not compatible with the gcc compiler we are using
Ondřej Čertík
@certik
Mar 02 2016 17:51
But who is reading this variable?
Isuru Fernando
@isuruf
Mar 02 2016 17:51
coveralls --gcov $GCOV_EXECUTABLE
Ondřej Čertík
@certik
Mar 02 2016 17:52
ah, I missed that.
That line uploads the results to coveralls.io
There's a new check now at symengine/symengine#843
There are two settings for each repo
COVERAGE THRESHOLD FOR FAILURE
COVERAGE DECREASE THRESHOLD FOR FAILURE
Ondřej Čertík
@certik
Mar 02 2016 17:58
I see, thanks
Francesco Biscani
@bluescarni
Mar 02 2016 18:01
@isuruf are those flags different from --coverage for GCC?
Isuru Fernando
@isuruf
Mar 02 2016 18:02
Francesco Biscani
@bluescarni
Mar 02 2016 18:03
       --coverage
           This option is used to compile and link code instrumented for coverage analysis.  The option is a synonym for -fprofile-arcs
           -ftest-coverage (when compiling) and -lgcov (when linking).  See the documentation for those options for more details.

           ·   Compile the source files with -fprofile-arcs plus optimization and code generation options.  For test coverage analysis,
               use the additional -ftest-coverage option.  You do not need to profile every source file in a program.

           ·   Link your object files with -lgcov or -fprofile-arcs (the latter implies the former).

           ·   Run the program on a representative workload to generate the arc profile information.  This may be repeated any number
               of times.  You can run concurrent instances of your program, and provided that the file system supports locking, the
               data files will be correctly updated.  Also "fork" calls are detected and correctly handled (double counting will not
               happen).

           ·   For profile-directed optimizations, compile the source files again with the same optimization and code generation
               options plus -fbranch-probabilities.

           ·   For test coverage analysis, use gcov to produce human readable information from the .gcno and .gcda files.  Refer to the
               gcov documentation for further information.

           With -fprofile-arcs, for each function of your program GCC creates a program flow graph, then finds a spanning tree for the
           graph.  Only arcs that are not on the spanning tree have to be instrumented: the compiler adds code to count the number of
           times that these arcs are executed.  When an arc is the only exit or only entrance to a block, the instrumentation code can
           be added to the block; otherwise, a new basic block must be created to hold the instrumentation code.
right looks mostly the same
Isuru Fernando
@isuruf
Mar 02 2016 18:04
Ah, --coverage does linking as well. I'll do the change
Francesco Biscani
@bluescarni
Mar 02 2016 18:05
oh right
does coveralls automatically strip away coverage information for standard library headers? when I use gcov/lcov, I get coverage info for system headers as well
and boost etc.
Isuru Fernando
@isuruf
Mar 02 2016 18:10
yeah, those are not shown
Francesco Biscani
@bluescarni
Mar 02 2016 18:11
nice
Ondřej Čertík
@certik
Mar 02 2016 19:06
@isuruf it seems to be working.
Vishnu H Nair
@malayaleecoder
Mar 02 2016 19:12
@certik Can you suggest me some literature on symbolic integration to read upon?
I was going through the Calculus Module to be implemented in Symengine :)
Siddharth
@bollu
Mar 02 2016 21:04
I'm not able to find certain symbols to link to
  "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, __mpq_struct const*)", referenced from:
      SymEngine::StrPrinter::bvisit(SymEngine::Rational const&) in libsymengine.a(printer.cpp.o)
      SymEngine::StrPrinter::bvisit(SymEngine::Complex const&) in libsymengine.a(printer.cpp.o)
this is the total list
  "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, __mpq_struct const*)", referenced from:
      SymEngine::StrPrinter::bvisit(SymEngine::Rational const&) in libsymengine.a(printer.cpp.o)
      SymEngine::StrPrinter::bvisit(SymEngine::Complex const&) in libsymengine.a(printer.cpp.o)
  "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, __mpz_struct const*)", referenced from:
      SymEngine::StrPrinter::bvisit(SymEngine::Integer const&) in libsymengine.a(printer.cpp.o)
      SymEngine::StrPrinter::bvisit(SymEngine::UnivariatePolynomial const&) in libsymengine.a(printer.cpp.o)
      operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::map<std::__1::vector<int, std::__1::allocator<int> >, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>, std::__1::less<std::__1::vector<int, std::__1::allocator<int> > >, std::__1::allocator<std::__1::pair<std::__1::vector<int, std::__1::allocator<int> > const, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> > > > const&) in libsymengine.a(dict.cpp.o)
      operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::unordered_map<std::__1::vector<int, std::__1::allocator<int> >, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>, SymEngine::vec_int_hash, std::__1::equal_to<std::__1::vector<int, std::__1::allocator<int> > >, std::__1::allocator<std::__1::pair<std::__1::vector<int, std::__1::allocator<int> > const, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> > > > const&) in libsymengine.a(dict.cpp.o)
      SymEngine::UnivariateSeries::__str__() const in libsymengine.a(series_generic.cpp.o)
  "___gmpq_cmp_z", referenced from:
      SymEngine::Rational::compare(SymEngine::Basic const&) const in libsymengine.a(rational.cpp.o)
ld: symbol(s) not found for architecture x86_64
I'd kill for some help
is there a separate C library that gets built so you can talk to C++ from the C library?
I really don't want to -lstdc++ in my haskell codebase because C++, is, well, nasty for extern stuff
Ondřej Čertík
@certik
Mar 02 2016 21:18
@bollu yes, here is the C library: https://github.com/symengine/symengine/blob/master/symengine/cwrapper.h that you can use.
Siddharth
@bollu
Mar 02 2016 21:19
certik: that's just the header file right? where are the .c files and what's the .so / .a file it generates?
certik: also, do you know where the overloaded << operators are defined? I need to grep through the code, but I thought asking here might be faster :)
Ondřej Čertík
@certik
Mar 02 2016 21:23
The << are defined in dict.cpp. How exactly are you compiling the code?
And what platform.
Post to whole log from scratch (cmake + make) into gist.github.com.
Siddharth
@bollu
Mar 02 2016 21:23
certik: I'm using GHC to compile some Haskell code that accesses this through the C ffi
the relevant compiler flags are -I/usr/local/include/symengine/ -lsymengine -lstdc++
I've built the library and installed it
(run both make and sudo make install)
platform is OSX
Ondřej Čertík
@certik
Mar 02 2016 21:24
It looks like you compiled symengine with libstdc++ but are then using it with libc++. This will not work. You need to use the same library for both.
Siddharth
@bollu
Mar 02 2016 21:24
ahh, thanks for spotting that!
Ondřej Čertík
@certik
Mar 02 2016 21:25
There are no C files. The C interface is implemented in cwrapper.cpp
and the symengine.so that is generated contains this C ABI.
You just call it.
Siddharth
@bollu
Mar 02 2016 21:26
certik: understood. I assumed that there was a separate C library that hid the C++ part completely
Ondřej Čertík
@certik
Mar 02 2016 21:26
Yes, this symengine.so is such a library.
Perhaps what you want is to also include the C++ standard library in symengine.so. I think g++ allows static linking, which might do that. I never tried it though.
Siddharth
@bollu
Mar 02 2016 21:28
certik: actually, how did you come to the conclusion that I compiled symengine with libstdc++ but I'm using it with libc++?
Ondřej Čertík
@certik
Mar 02 2016 21:31
It's just a guess. I would need to see the whole log.
@isuruf we can also try this: scan.coverity.com
Siddharth
@bollu
Mar 02 2016 21:34

where is this implemented?

std::ostream& operator<<(std::ostream& out, const SymEngine::Basic& p);

it's at Basic.h:229

Ondřej Čertík
@certik
Mar 02 2016 21:35
It's in basic-inl.h
Siddharth
@bollu
Mar 02 2016 21:35
ah, crap, it's inlined
hm, do you know how the linker behaves with inlined code?
compiler + linker
does it respect inline and expand it for sure?
finding out why ld isn't able to find these instances might get ugly
Ondřej Čertík
@certik
Mar 02 2016 21:40
Typically the error that you are seeing is caused by compiling a C++ library, and then using the same header files and compiling them with a different C++ standard library.
However, if these are the only errors, they all reference symbols from the GMP library.
Siddharth
@bollu
Mar 02 2016 21:40
certik: but isn't it weird then, that it's able to find instances of everything else? I'll check against what I'm compiling in the previous case
Ondřej Čertík
@certik
Mar 02 2016 21:41
This happens if the GMP library is compiled with a different compiler/standard library for symengine, and then you change something from your own code.
Siddharth
@bollu
Mar 02 2016 21:41
certik: yes, these are the only errors which is why I'm pizzled
Ondřej Čertík
@certik
Mar 02 2016 21:41
Are you linking -lgmpxx?
Siddharth
@bollu
Mar 02 2016 21:42
nope, I'll do that
thanks :)
Ondřej Čertík
@certik
Mar 02 2016 21:42
how did you compile gmpxx?
Siddharth
@bollu
Mar 02 2016 21:43
I'm not sure, I assumed that the symengine build compiled it for me. I haven't been linking to it though. After linking to it, there's only one missing symbol: ___gmpq_cmp_z
  "___gmpq_cmp_z", referenced from:
      SymEngine::Rational::compare(SymEngine::Basic const&) const in libsymengine.a(rational.cpp.o)
Ondřej Čertík
@certik
Mar 02 2016 21:43
I thought you said you were linking to it.
symengine doesn't build gmp. The cmake says where it uses it from.
Siddharth
@bollu
Mar 02 2016 21:44
ah, I see. It looks like I have GMP though, probably from another source (since I'm able to link to it)
and no, the compiler flags I was using was:
-I/usr/local/include/symengine/ -lsymengine -lstdc++
along with other GHC flags
Ondřej Čertík
@certik
Mar 02 2016 21:45
You have to link -lgmp -lgmpxx
Siddharth
@bollu
Mar 02 2016 21:45

I now changed it to

-I/usr/local/include/symengine/ -lsymengine  -lstdc++ -lgmpxx

There's one symbol missing now:

  "___gmpq_cmp_z", referenced from:
      SymEngine::Rational::compare(SymEngine::Basic const&) const in libsymengine.a(rational.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
yep, that solved it!
are there any more libraries that I'm missing by any chance?
and thanks for the help :D
Ondřej Čertík
@certik
Mar 02 2016 21:45
by default symengine only uses gmp.
you can optionally configure it to use a lot more.
Siddharth
@bollu
Mar 02 2016 21:46
cool, thanks!
And neat, I can print the symEngine ASCII logo from Haskell
Ondřej Čertík
@certik
Mar 02 2016 21:47
Perfect!
Siddharth
@bollu
Mar 02 2016 21:48
hm, I guess I can start binding the basic structs from today. I'll replicate all of the Julia bindings in hopefully the next few days
then I can work on expanding the C wrapper
does that sound like a decent plan of action?
Ondřej Čertík
@certik
Mar 02 2016 21:50
@bollu yes, that sounds like a great plan.
can you post your code somewhere? we can have a look and help.
Siddharth
@bollu
Mar 02 2016 21:51
yep, I'm uploading it to github right now
give me a few minutes
certik: I'll be setting up CI for this as well, and writing unit tests in Haskell. Plus, I'll get the ball rolling on uploading the package to Hackage (Haskell's package distribution infrastructure)
Ondřej Čertík
@certik
Mar 02 2016 21:53
@bollu excellent. Yes, once things mature, we can move the project under the symengine organization.
Siddharth
@bollu
Mar 02 2016 21:53
cool, sounds like a plan.
Siddharth
@bollu
Mar 02 2016 21:58
what's the license for all this code?
Siddharth
@bollu
Mar 02 2016 22:06
@certik: Here's the github repo: https://github.com/bollu/symengine.hs
This is the part that does the binding: https://github.com/bollu/symengine.hs/blob/master/src/Lib.hs
I'll clean it up once I get some sleep (it's 4AM ish here)