Skip to content

Wrapped Min and Max Functions #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 1, 2017
Merged

Wrapped Min and Max Functions #126

merged 4 commits into from
Jun 1, 2017

Conversation

ShikharJ
Copy link
Member

@isuruf Can you tell me why are the current builds failing? Everything seems to be in compliance.

@isuruf
Copy link
Member

isuruf commented Feb 25, 2017

See this error message,

Error compiling Cython file:
------------------------------------------------------------
...
    cdef symengine.vec_basic v
    cdef Basic e_
    for e in args:
        e_ = sympify(e)
        v.push_back(e_.thisptr)
    return c2py(symengine.max(v))
                              ^
------------------------------------------------------------
symengine_wrapper.pyx:2250:31: Cannot assign type 'vec_basic' to 'RCP[const Basic]'

@ShikharJ
Copy link
Member Author

I mean, isn't symengine.max supposed to take a vec_basic, or do I have to run a loop for individual elements?

@@ -417,6 +419,7 @@ cdef extern from "<symengine/functions.h>" namespace "SymEngine":
cdef RCP[const Basic] acoth(RCP[const Basic] &arg) nogil except+
cdef RCP[const Basic] function_symbol(string name, const vec_basic &arg) nogil except+
cdef RCP[const Basic] abs(RCP[const Basic] &arg) nogil except+
cdef RCP[const Basic] max(RCP[const Basic] &arg) nogil except+
Copy link
Member

Choose a reason for hiding this comment

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

This function signature is wrong

@ShikharJ ShikharJ changed the title [WIP] Wrapped Min and Max Functions Wrapped Min and Max Functions Feb 25, 2017
@ShikharJ
Copy link
Member Author

ShikharJ commented Feb 25, 2017

I think this is ready for review now @isuruf.

@ShikharJ
Copy link
Member Author

ping @isuruf

assert max({Integer(6)/3, 1}) == 2
assert max({-2, 2}) == 2
assert max({2, 2}) == 2
assert max({0.2, 0.3}) == 0.3
Copy link
Member

Choose a reason for hiding this comment

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

This is using python's min and max.

v.push_back(e_.thisptr)
return c2py(symengine.max(v))

def min(*args):
Copy link
Member

Choose a reason for hiding this comment

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

It's not good to change a function in the global namespace of python. What does sympy do?

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 2, 2017

@isuruf From what I observe, Sympy has a Max and Min class defined which inherits from MaxMinBase, which itself inherits from Expr and LatticeOp. Individual max and min functions are defined, though only as member functions, that too of some specific classes.

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 4, 2017

@isuruf What do you suggest we do of the namespace issue?

@isuruf
Copy link
Member

isuruf commented Mar 4, 2017

Same as in SymPy. We define the classes Max and Min only.

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 4, 2017

@isuruf I'am facing trouble implementing that. Min and Max both have constructors of the order Class::Class(const vec_basic &&args) which is raising issues in the builds. Can you please take a look and suggest improvements?

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 6, 2017

Ping @isuruf

@isuruf
Copy link
Member

isuruf commented Mar 6, 2017

Use min and max, don't use the constructors of Max and Min. Constructors of Max and Min are supposed to be used only when you know the result is a Max or a Min. You don't want to create a Max(1, 2)

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 6, 2017

@isuruf I'm not sure what you mean. Wouldn't using max and min bring us back to the same problem of namespace?

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 7, 2017

Ping @isuruf

@@ -1,5 +1,5 @@
from symengine import Symbol, sin, cos, sqrt, Add, Mul, function_symbol, Integer, log, E, symbols
from symengine.lib.symengine_wrapper import Subs, Derivative
from symengine.lib.symengine_wrapper import Subs, Derivative, _max, _min
Copy link
Member

Choose a reason for hiding this comment

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

We don't want _max to be the public interface.
Max can be the public interface, but for that we need to rename the existing class to _Max and make Max, a pure python class and override __new__ to return the value, like in https://github.com/symengine/symengine.py/blob/master/symengine/sympy_compat.py#L53-L54

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for clearing me up on this.

@ShikharJ
Copy link
Member Author

ShikharJ commented Mar 8, 2017

@isuruf Can you please take a look now?

Copy link
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.

Looks good to me.
Only issue is that Max can only be imported from sympy_compat. We should be able to use it from symengine_wrapper as well.

@ShikharJ ShikharJ force-pushed the MinMax branch 3 times, most recently from 24f105a to da6e5e0 Compare March 25, 2017 05:56
@ShikharJ
Copy link
Member Author

@isuruf I have added a string to address the import issues. I'd like to raise an issue for a possible workaround for the above. Can you please take a look here?

@ShikharJ
Copy link
Member Author

Ping @isuruf

@isuruf
Copy link
Member

isuruf commented Mar 29, 2017

Shifting the tests to sympy_compat is not a real solution. we need to give the user a way to use Max and Min when they do from symengine import *

@ShikharJ
Copy link
Member Author

@isuruf Shifting the tests was never intended as a solution to the import issue. It was more along the lines of current necessity. As I'm out of ideas regarding the solution of the namespace issue, I would like to raise an issue, for possible ideas regarding the same, after this is merged. I pinged for a final review of this code.

@isuruf isuruf modified the milestone: 0.3.0 May 11, 2017
@ShikharJ
Copy link
Member Author

ShikharJ commented Jun 1, 2017

+1

@isuruf isuruf merged commit e3f4bd2 into symengine:master Jun 1, 2017
@ShikharJ ShikharJ deleted the MinMax branch June 1, 2017 16:22
@ShikharJ
Copy link
Member Author

ShikharJ commented Jun 1, 2017

Thanks for guiding me through @isuruf.

@isuruf isuruf mentioned this pull request Jun 3, 2017
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.

2 participants