Skip to content

Wrap Miscellaneous Functions #172

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jul 16, 2017
Merged

Wrap Miscellaneous Functions #172

merged 1 commit into from
Jul 16, 2017

Conversation

ShikharJ
Copy link
Member

@ShikharJ ShikharJ commented Jul 8, 2017

No description provided.

@ShikharJ ShikharJ force-pushed the Misc branch 3 times, most recently from c935090 to 80c48a7 Compare July 8, 2017 23:11
cdef RCP[const symengine.Pow] a1 = symengine.rcp_static_cast_Pow(_a.thisptr)
return c2py(symengine.pow_expand(a1))

expand_pow = pow_expand
Copy link
Member Author

Choose a reason for hiding this comment

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

@isuruf Can you tell me why the above code is failing? More specifically what can be done to prevent this:

symengine_wrapper.obj : error LNK2019: unresolved external symbol "class SymEngine::RCP<class SymEngine::Basic const > __cdecl SymEngine::pow_expand(class SymEngine::RCP<class SymEngine::Pow const > const &)" (?pow_expand@SymEngine@@YA?AV?$RCP@$$CBVBasic@SymEngine@@@1@ABV?$RCP@$$CBVPow@SymEngine@@@1@@Z) referenced in function "struct _object * __cdecl __pyx_pf_9symengine_3lib_17symengine_wrapper_36pow_expand(struct _object *,struct _object *)" (?__pyx_pf_9symengine_3lib_17symengine_wrapper_36pow_expand@@YAPAU_object@@PAU1@0@Z) [C:\projects\symengine-py\build\lib.win32-2.7\symengine\lib\symengine_wrapper.vcxproj]

Copy link
Member

Choose a reason for hiding this comment

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

The first question is, why do you need them?

Copy link
Member

Choose a reason for hiding this comment

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

Besides, pow_expand, mul_expand and add_expand should be removed from the public API

Copy link
Member Author

Choose a reason for hiding this comment

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

To cater to Sympy's expand_mul.

Copy link
Member

Choose a reason for hiding this comment

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

If we really needed that we can just do expand_mul = expand.

@@ -2740,6 +2788,32 @@ def exp(x):
cdef Basic X = sympify(x)
return c2py(symengine.exp(X.thisptr))

def isqrt(n):
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need another function? Isn't sqrt enough?

raise TypeError
except TypeError:
raise ValueError('%s is not an integer' % (n,))
return result
Copy link
Member

Choose a reason for hiding this comment

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

For this, you can use SymPy's as_int as it isn't SymEngine or SymPy specific.

require(_n, Integer)
return symengine.perfect_power(deref(symengine.rcp_static_cast_Integer(_n.thisptr)))

def perfect_square(n):
Copy link
Member

Choose a reason for hiding this comment

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

Sympy uses is_square

Copy link
Member

Choose a reason for hiding this comment

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

I would rename this to is_square instead of aliasing. Two names for the same method is needed only for sympy compatibility or backwards compatibility.

@ShikharJ ShikharJ force-pushed the Misc branch 2 times, most recently from c762b0a to 53b6462 Compare July 9, 2017 22:13
@ShikharJ ShikharJ changed the title [WIP] Wrap Miscellaneous Functions Wrap Miscellaneous Functions Jul 9, 2017
@ShikharJ
Copy link
Member Author

@isuruf Can you review this?

return (c2py(<RCP[const symengine.Basic]>_r), true)
return (c2py(<RCP[const symengine.Basic]>_r), false)

integer_nthroot = i_nth_root
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@ShikharJ ShikharJ force-pushed the Misc branch 2 times, most recently from 2a90b0d to 4779a50 Compare July 13, 2017 18:13
@ShikharJ
Copy link
Member Author

Ping @isuruf.

@@ -895,6 +901,20 @@ class Symbol(Basic):
return self.__class__


class Dummy(Symbol):
Copy link
Member

Choose a reason for hiding this comment

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

This class is not tested anywhere

@isuruf
Copy link
Member

isuruf commented Jul 14, 2017

Can you add more tests?

@ShikharJ
Copy link
Member Author

Ping @isuruf.

@@ -9,7 +9,8 @@
UndefFunction, Function, FunctionSymbol as AppliedUndef,
have_numpy, true, false, Equality, Unequality, GreaterThan,
LessThan, StrictGreaterThan, StrictLessThan, Eq, Ne, Ge, Le,
Gt, Lt, GoldenRatio, Catalan, EulerGamma)
Gt, Lt, GoldenRatio, Catalan, EulerGamma, Dummy, perfect_power,
is_square, integer_nthroot, isprime, sqrt_mod, igcdex)
Copy link
Member

Choose a reason for hiding this comment

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

Functions like is_square and igcdex are not pulled in when you do from sympy import *. I'd remove them from here.

cdef int ret_val = symengine.i_nth_root(symengine.outArg_Integer(_r), deref(symengine.rcp_static_cast_Integer(_a.thisptr)), n)
if ret_val == 1:
return (c2py(<RCP[const symengine.Basic]>_r), true)
return (c2py(<RCP[const symengine.Basic]>_r), false)
Copy link
Member

Choose a reason for hiding this comment

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

return (c2py(<RCP[const symengine.Basic]>_r), ret_val == 1)

@@ -1,4 +1,5 @@
from symengine import Symbol, symbols, symarray, has_symbol
from symengine.lib.symengine_wrapper import Dummy
Copy link
Member

Choose a reason for hiding this comment

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

change this to import from symengine

@@ -3103,6 +3151,8 @@ def probab_prime_p(n, reps = 25):
require(_n, Integer)
return symengine.probab_prime_p(deref(symengine.rcp_static_cast_Integer(_n.thisptr)), reps) >= 1

isprime = probab_prime_p
Copy link
Member

Choose a reason for hiding this comment

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

This isn't tested

@ShikharJ
Copy link
Member Author

Ping @isuruf.

@isuruf isuruf merged commit 3541ffc into symengine:master Jul 16, 2017
@ShikharJ ShikharJ deleted the Misc branch July 16, 2017 14:48
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants