Added Function for Issue #1088 (Second Feature)#1114
Added Function for Issue #1088 (Second Feature)#1114isuruf merged 6 commits intosymengine:masterfrom
Conversation
| } | ||
| } | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Instead of comparing strings like this, I think we should just introduce some enum constants and compare integers.
There was a problem hiding this comment.
I'll make the changes. Thanks!
There was a problem hiding this comment.
Enums are better when you have access to them via headers. This function is needed for libraries using only the shared library like SymEngine.jl which doesn't look at the headers. In that case strings are better.
When you have access to the headers, you don't need this function at all. You can just use, HAVE_SYMENGINE_MPFR to check whether it is installed.
isuruf
left a comment
There was a problem hiding this comment.
Building up two arrays and comparing is a waste and complex. Added a suggestion for a simple fix below.
symengine/cwrapper.cpp
Outdated
| { | ||
| bool t[4] = {}; | ||
| #ifdef HAVE_SYMENGINE_MPFR | ||
| t[0] = true; |
There was a problem hiding this comment.
You can do if (std::strcmp("mpfr", c)) return 1;
|
@isuruf A review of the changes? |
|
@ShikharJ, can you add some tests? |
|
|
||
| // Rejecting non mpfr builds | ||
| s = "mpfr"; | ||
| SYMENGINE_C_ASSERT(symengine_have_component(s)); |
There was a problem hiding this comment.
As mentioned in the comment, this will fail when mpfr is not found. Use HAVE_SYMENGINE_MPFR and similar macros to test.
There was a problem hiding this comment.
So I need to add another test rejecting mpfr and related builds?
There was a problem hiding this comment.
Something like this,
#ifdef HAVE_SYMENGINE_MPFR
SYMENGINE_C_ASSERT(symengine_have_component("mpfr") != 0);
#else
SYMENGINE_C_ASSERT(symengine_have_component("mpfr") == 0);
#endif|
@isuruf Any further changes? |
| SYMENGINE_C_ASSERT(symengine_have_component(s)); | ||
| #else | ||
| SYMENGINE_C_ASSERT(!symengine_have_component(s)); | ||
| #endif |
There was a problem hiding this comment.
Can you add tests for the other components as well to increase coverage?
symengine/cwrapper.h
Outdated
| //! Frees the string s | ||
| void basic_str_free(char *s); | ||
|
|
||
| //! Returns 1 if a specific component is installed, 0 if not. |
There was a problem hiding this comment.
//! component can be "mpfr", "mpc", "flint" or "arb"
| #ifdef HAVE_SYMENGINE_ARB | ||
| if (std::strcmp("arb", c) == 0) | ||
| return 1; | ||
| #endif |
There was a problem hiding this comment.
If you want to add all the components, here is a list, https://github.com/symengine/symengine/blob/master/symengine/symengine_config.h.in#L13-L41
There was a problem hiding this comment.
Thanks! I'll send in another commit with the changes.
|
@certik, can you also review? |
|
I don't think we should be comparing strings like that. I think we should use C enums, like this: where #ifdef HAVE_SYMENGINE_MPC
if (std::strcmp("mpc", c) == 0)
return 1;
#endif to this: #ifdef HAVE_SYMENGINE_MPC
if (c == SYMENGINE_MPC)
return 1;
#endif P.S. It's a good habit in C and C++ to always put braces |
|
@certik, see my comment here, #1114 (comment) |
|
Travis is having a heavy load for OS X. Jobs will eventually run to completion. https://www.traviscistatus.com |
|
@certik Please take a look at the above comments and suggest any further changes, if necessary. |
|
Hi @ShikharJ, my objection is written in this comment: #1114 (comment), I don't think we should be using strings, just compare enums, see that comment for details. |
|
@certik Umm, I was referring to that same thread, but @isuruf 's comment below yours. To quote: |
|
@ShikharJ I see. In that case, can you add that explanation + motivation as a comment into the header file? So that it's clear when this function should be used, and when |
|
@certik A final review? |
|
Thanks |
Added a function to call to indicate whether some components (namely flint, arb, mpc and mpfr) are installed or not. No tests are added (to prevent travis build failures). However the following links may be referred to for cross-checking the functionality:
(Build #9 For Rejecting Non MPFR builds)
https://travis-ci.org/ShikharJ/symengine/builds/172672603
(Build #8 For Rejecting MPFR builds)
https://travis-ci.org/ShikharJ/symengine/builds/172666980
The above tests have been conducted by patching the following lines of code:
char *s = "mpfr";
(#9)SYMENGINE_C_ASSERT(symengine_have_component(s));
(#8)SYMENGINE_C_ASSERT(!symengine_have_component(s));