Skip to content

Added Function for Issue #1088 (Second Feature)#1114

Merged
isuruf merged 6 commits intosymengine:masterfrom
ShikharJ:Issue1088
Nov 13, 2016
Merged

Added Function for Issue #1088 (Second Feature)#1114
isuruf merged 6 commits intosymengine:masterfrom
ShikharJ:Issue1088

Conversation

@ShikharJ
Copy link
Copy Markdown
Member

@ShikharJ ShikharJ commented Nov 2, 2016

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));

}
}
return 0;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of comparing strings like this, I think we should just introduce some enum constants and compare integers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make the changes. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@isuruf isuruf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building up two arrays and comparing is a waste and complex. Added a suggestion for a simple fix below.

{
bool t[4] = {};
#ifdef HAVE_SYMENGINE_MPFR
t[0] = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do if (std::strcmp("mpfr", c)) return 1;

@ShikharJ
Copy link
Copy Markdown
Member Author

ShikharJ commented Nov 3, 2016

@isuruf A review of the changes?

@isuruf
Copy link
Copy Markdown
Member

isuruf commented Nov 3, 2016

@ShikharJ, can you add some tests?


// Rejecting non mpfr builds
s = "mpfr";
SYMENGINE_C_ASSERT(symengine_have_component(s));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the comment, this will fail when mpfr is not found. Use HAVE_SYMENGINE_MPFR and similar macros to test.

Copy link
Copy Markdown
Member Author

@ShikharJ ShikharJ Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I need to add another test rejecting mpfr and related builds?

Copy link
Copy Markdown
Member

@isuruf isuruf Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ShikharJ
Copy link
Copy Markdown
Member Author

ShikharJ commented Nov 3, 2016

@isuruf Any further changes?

SYMENGINE_C_ASSERT(symengine_have_component(s));
#else
SYMENGINE_C_ASSERT(!symengine_have_component(s));
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for the other components as well to increase coverage?

//! Frees the string s
void basic_str_free(char *s);

//! Returns 1 if a specific component is installed, 0 if not.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//! component can be "mpfr", "mpc", "flint" or "arb"

#ifdef HAVE_SYMENGINE_ARB
if (std::strcmp("arb", c) == 0)
return 1;
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll send in another commit with the changes.

@isuruf
Copy link
Copy Markdown
Member

isuruf commented Nov 3, 2016

@certik, can you also review?

@certik
Copy link
Copy Markdown
Contributor

certik commented Nov 3, 2016

I don't think we should be comparing strings like that. I think we should use C enums, like this:

symengine_have_component(SYMENGINE_FLINT)

where SYMENGINE_FLINT is an enum, declared in the C header file. Then inside, you change this:

#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 {} for the if statement's branches, even if it's just a one liner like this.

@isuruf
Copy link
Copy Markdown
Member

isuruf commented Nov 3, 2016

@certik, see my comment here, #1114 (comment)

@isuruf
Copy link
Copy Markdown
Member

isuruf commented Nov 3, 2016

Travis is having a heavy load for OS X. Jobs will eventually run to completion. https://www.traviscistatus.com

@ShikharJ
Copy link
Copy Markdown
Member Author

ShikharJ commented Nov 10, 2016

@certik Please take a look at the above comments and suggest any further changes, if necessary.

@certik
Copy link
Copy Markdown
Contributor

certik commented Nov 10, 2016

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.

@ShikharJ
Copy link
Copy Markdown
Member Author

ShikharJ commented Nov 10, 2016

@certik Umm, I was referring to that same thread, but @isuruf 's comment below yours. To quote:
"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."

@certik
Copy link
Copy Markdown
Contributor

certik commented Nov 10, 2016

@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 HAVE_SYMENGINE_MPFR should be used directly.

@ShikharJ ShikharJ closed this Nov 11, 2016
@ShikharJ ShikharJ reopened this Nov 11, 2016
@ShikharJ ShikharJ closed this Nov 12, 2016
@ShikharJ ShikharJ reopened this Nov 12, 2016
@ShikharJ ShikharJ closed this Nov 13, 2016
@ShikharJ ShikharJ reopened this Nov 13, 2016
@ShikharJ
Copy link
Copy Markdown
Member Author

@certik A final review?

@isuruf isuruf merged commit 46b7285 into symengine:master Nov 13, 2016
@isuruf
Copy link
Copy Markdown
Member

isuruf commented Nov 13, 2016

Thanks

@ShikharJ ShikharJ deleted the Issue1088 branch November 13, 2016 10:54
@isuruf isuruf mentioned this pull request Nov 26, 2016
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants