-
Notifications
You must be signed in to change notification settings - Fork 67
Wrap Miscellaneous Functions #172
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
Conversation
c935090
to
80c48a7
Compare
symengine/lib/symengine_wrapper.pyx
Outdated
cdef RCP[const symengine.Pow] a1 = symengine.rcp_static_cast_Pow(_a.thisptr) | ||
return c2py(symengine.pow_expand(a1)) | ||
|
||
expand_pow = pow_expand |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
.
symengine/lib/symengine_wrapper.pyx
Outdated
@@ -2740,6 +2788,32 @@ def exp(x): | |||
cdef Basic X = sympify(x) | |||
return c2py(symengine.exp(X.thisptr)) | |||
|
|||
def isqrt(n): |
There was a problem hiding this comment.
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?
symengine/lib/symengine_wrapper.pyx
Outdated
raise TypeError | ||
except TypeError: | ||
raise ValueError('%s is not an integer' % (n,)) | ||
return result |
There was a problem hiding this comment.
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.
symengine/lib/symengine_wrapper.pyx
Outdated
require(_n, Integer) | ||
return symengine.perfect_power(deref(symengine.rcp_static_cast_Integer(_n.thisptr))) | ||
|
||
def perfect_square(n): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sympy uses is_square
There was a problem hiding this comment.
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.
c762b0a
to
53b6462
Compare
@isuruf Can you review this? |
symengine/lib/symengine_wrapper.pyx
Outdated
return (c2py(<RCP[const symengine.Basic]>_r), true) | ||
return (c2py(<RCP[const symengine.Basic]>_r), false) | ||
|
||
integer_nthroot = i_nth_root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
2a90b0d
to
4779a50
Compare
Ping @isuruf. |
@@ -895,6 +901,20 @@ class Symbol(Basic): | |||
return self.__class__ | |||
|
|||
|
|||
class Dummy(Symbol): |
There was a problem hiding this comment.
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
Can you add more tests? |
Ping @isuruf. |
symengine/__init__.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
symengine/lib/symengine_wrapper.pyx
Outdated
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) |
There was a problem hiding this comment.
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)
symengine/tests/test_symbol.py
Outdated
@@ -1,4 +1,5 @@ | |||
from symengine import Symbol, symbols, symarray, has_symbol | |||
from symengine.lib.symengine_wrapper import Dummy |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't tested
Ping @isuruf. |
No description provided.