Git Product home page Git Product logo

symengine.py's Introduction

SymEngine

Build and test symengine Build status codecov.io

SymEngine is a standalone fast C++ symbolic manipulation library. Optional thin wrappers allow usage of the library from other languages, e.g.:

Try SymEngine

Tutorials are at SymEngine.org.

Run an interactive C++ session with SymEngine using Binder.

License

All files are licensed under MIT license, see the LICENSE for more information. Third party code packaged are licensed under BSD 3-clause license (see the LICENSE file).

Mailinglist, Chat

SymEngine mailinglist: http://groups.google.com/group/symengine

Gitter

Installation

Conda package manager

conda install symengine -c conda-forge

Conan package manager

conan install --requires="symengine/[*]"

Building from source

Install prerequisites. For Debian based systems (Ubuntu etc.):

apt-get install cmake libgmp-dev

For RPM based systems (Fedora etc.):

yum install cmake gmp-devel

Install SymEngine:

mkdir build && cd build
cmake ..
make
make install

This will configure and build SymEngine in the default Release mode with all code and compiler optimizations on and then install it on your system.

Run tests:

ctest

Development

GitHub Actions checks the code in both Release and Debug mode with all possible checks, so just sending a GitHub pull request is enough and you can use any mode you want to develop it. However, the best way to develop SymEngine on Linux is to use the Debug mode with BFD support on:

cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_BFD=yes ..

This BFD support turns on nice Python-like stack traces on exceptions, assert errors or segfaults, and the Debug mode automatically turns on WITH_SYMENGINE_RCP=no (which uses Teuchos::RCP with full Debug time checking) and WITH_SYMENGINE_ASSERT=yes, so the code cannot segfault in Debug mode, as long as our style conventions (e.g. no raw pointers) are followed, which is easy to check by visual inspection of a given Pull Request. In Release mode, which is the default, the code is as performing a manual reference counting and raw pointers (and if there is a bug, it could segfault, in which case all you have to do is to turn Debug mode on and get a nice exception with a stack trace).

To make WITH_BFD=yes work, you need to install binutils-dev first, otherwise, you will get a CMake error during configuring. For Debian-based systems (Ubuntu etc.)

apt-get install binutils-dev

For RPM-based systems (Fedora etc.)

yum install binutils-devel

On OpenSuSE, you will additionally need glibc-devel.

CMake Options

Here are all the CMake options that you can use to configure the build, with their default values are indicated below:

cmake -DCMAKE_INSTALL_PREFIX:PATH="/usr/local" \  # Installation prefix
    -DCMAKE_BUILD_TYPE:STRING="Release" \         # Type of build, one of: Debug or Release
    -DWITH_BFD:BOOL=OFF \                         # Install with BFD library (requires binutils-dev)s
    -DWITH_SYMENGINE_ASSERT:BOOL=OFF \            # Test all SYMENGINE_ASSERT statements in the code
    -DWITH_SYMENGINE_RCP:BOOL=ON \                # Use our faster special implementation of RCP
    -DWITH_SYMENGINE_THREAD_SAFE:BOOL=OFF \       # Build with thread safety
    -DWITH_ECM:BOOL=OFF \                         # Build with GMP-ECM library for integer factorization
    -DWITH_PRIMESIEVE:BOOL=OFF \                  # Install with Primesieve library
    -DWITH_FLINT:BOOL=OFF \                       # Install with Flint library
    -DWITH_ARB:BOOL=OFF \                         # Install with ARB library
    -DWITH_TCMALLOC:BOOL=OFF \                    # Install with TCMalloc linked
    -DWITH_OPENMP:BOOL=OFF \                      # Install with OpenMP enabled
    -DWITH_PIRANHA:BOOL=OFF \                     # Install with Piranha library
    -DWITH_MPFR:BOOL=OFF \                        # Install with MPFR library
    -DWITH_MPC:BOOL=OFF \                         # Install with MPC library
    -DWITH_LLVM:BOOL=OFF \                        # Build with LLVM libraries
    -DWITH_SYSTEM_CEREAL:BOOL=OFF \               # Build with cereal headers from the system instead of
                                                    the vendored copy
    -DBUILD_TESTS:BOOL=ON \                       # Build with tests
    -DBUILD_BENCHMARKS:BOOL=ON \                  # Build with benchmarks
    -DBUILD_BENCHMARKS_GOOGLE:BOOL=OFF \          # Build with Google Benchmark benchmarks
    -DINTEGER_CLASS:STRING=gmp \                  # Choose storage type for Integer. one of gmp, gmpxx,
                                                    flint, piranha, boostmp
    -DBUILD_SHARED_LIBS:BOOL=OFF \                # Build a shared library.
    -DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF\ # Add dependencies to rpath when a shared lib is built
    ..

If OpenMP is enabled, then SYMENGINE_THREAD_SAFE is also enabled automatically irrespective of the user input for WITH_SYMENGINE_THREAD_SAFE.

CMake prints the value of its options at the end of the run. If you want to use a different compiler, do:

CC=clang CXX=clang++ cmake ..

If you want to set additional compilation flags, do:

CXXFLAGS="$CXXFLAGS -march=native" cmake ..

These environment variables are checked only in the first run of cmake and you have to delete the build directory or CMakeCache.txt file for these environment variables to be picked up in subsequent runs.

Using INTEGER_CLASS=boostmp would remove the dependency on gmp and use boost's multiprecision integer and rational classes. This would make boost, the only dependency and all the code would be under permissive licenses, namely, MIT, BSD 3-clause and Boost License.

Piranha (WITH_PIRANHA) depends on Boost, so it is off by default. The benchmarked code seems to depend on the order in which you execute the benchmarks in a given executable, due to internal malloc implementation. We have found that this order dependence is reduced by enabling WITH_TCMALLOC=ON and since it also speeds the benchmarks up, we recommend to always use TCMalloc when benchmarking (and the Release mode of SymEngine, which is the default).

External Libraries

Use CMAKE_PREFIX_PATH to specify the prefixes of the external libraries.

cmake -DCMAKE_PREFIX_PATH=<prefix1>;<prefix2>

If the headers and libs are not in <prefix>/include and <prefix>/lib respectively, use CMAKE_LIBRARY_PATH and CMAKE_INCLUDE_PATH.

If CMake still cannot find the library, you can specify the path to the library by doing cmake -DPKG_LIBRARY=/path/libname.so ., where PKG should be replaced with the name of the external library (GMP, ARB, BFD, FLINT, MPFR, ...). Similarly, -DPKG_INCLUDE_DIR can be used for headers.

Recommended options to build

For package managers

For packaging symengine it is recommended to use GMP, MPFR, MPC, FLINT, LLVM as dependencies if they are available and built with thread safety on.

cmake -DWITH_GMP=on -DWITH_MPFR=on -DWITH_MPC=on -DINTEGER_CLASS=flint -DWITH_LLVM=on
-DWITH_SYMENGINE_THREAD_SAFE=on ..

Optimized build

To build with more optimizations, you can use the above dependencies and options, and also,

CXXFLAGS="-march=native -O3" cmake -DWITH_TCMALLOC=on -DWITH_SYMENGINE_THREAD_SAFE=no ..

Developer Documentation

Please follow the C++ Style Guide when developing.

The design decisions are documented in Design.

symengine.py's People

Contributors

abhinavagarwal07 avatar alanlh avatar ayushk7102 avatar bjodah avatar cbehan avatar cclauss avatar certik avatar eendebakpt avatar erikagnvall avatar gsam avatar haozeke avatar harakas avatar ichumuh avatar isuruf avatar jcfr avatar marlin-na avatar mattwala avatar mgorny avatar midnighter avatar moraxyc avatar mtreinish avatar pbrady avatar richardotis avatar rikardn avatar rwst avatar shikharj avatar shivamvats avatar sumith1896 avatar sushant-hiray avatar thilinarmtb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symengine.py's Issues

debug build shared lib is stripped with make install

Using python setup.py install is fine but make install is not. Using readelf --debug-dump=decodedline /usr/lib64/python2.7/site-packages/symengine/lib/symengine_wrapper.so we can see the latter strips debug info from the file.

So I would explicitly decourage using make install in the documentation for such noobs as myself.

array-broadcasting in sp.lambdify, Lambdify and LambdifyCSE

Hi,
i tried to implement symengine's LambdifyCSE to speedup my code..
however, while investigating this possibility, i found that LambdifyCSE
seems to have different array-broadcasting than Lambdify (and also sympy's lambdify)

x = var('x')
funcs = [sp.cos(x)**i for i in range(5)]

#ordinary sympy
f_sympy = sp.lambdify((x), funcs, modules = 'numpy')

#ordinary symengine
f_seng = Lambdify([x], funcs)

#symengine with cse
f_seng_cse = LambdifyCSE([x], funcs)

ideally, the functions should give the same output for the same input...
however, in order to get the same output i have to do the following:
(aside of the fact that sympy's lambdify treats constants rather strange...)

a = np.array([1, 2, 3])

s1 = f_sympy(a)
s2 = f_seng(a).T
s3 = f_seng_cse(a[:,np.newaxis]).T

furthermore calling

f_seng_cse(a)

gives

"ValueError: all the input arrays must have same number of dimensions"

which is rather strange since there is only one input-array....

for higher dimensional inputs this generalizes to

a = np.array([[1,2,3],[1,2,3],[1,2,3]])
s1 = f_sympy(a)
s2 = f_seng(a).T
s3 = f_seng_cse(a[:,:,np.newaxis]).T

In order to get the same outputs with functions taking more than one input-arguments,
i have to use

x, y = var('x, y')

funcs = [sp.cos(x)**i + sp.cos(y)**i for i in range(5)]

f_sympy = sp.lambdify((x, y),funcs, modules = 'numpy')
f_seng = Lambdify([x, y], funcs)
f_seng_cse = LambdifyCSE([x, y], funcs)

a = np.array([[1,2,3],[1,2,3],[1,2,3]])

s1 = f_sympy(a, a)
s2 = np.reshape(f_seng(np.reshape(np.ravel([a,a], order = 'F'), (-1, 2), order = 'C')).T, (-1, *a.shape), order = 'F')
s3 = np.reshape(f_seng_cse(np.reshape(np.ravel([a,a], order = 'F'), (-1, 2), order = 'C')).T, (-1, *a.shape), order = 'F')

which is certainly not very readable any more...
is there any obvious reason for this or is this some kind of a bug?
or even better, could you eventually tell me a clear way on how to perform correct
array-broadcasting of multidimensional functions in LambdifyCSE ?

Thanks!

DenseMatrix functionality improvements

After a slight brush with DenseMatrix, here's some stuff I found not working that well:

  • DenseMatrix is missing __sub__, currently can do A+B, but not A-B.
  • DenseMatrix does not support left side multiple with a Basic, that is Symbol('x')*A fails. Add __rmul__ or modify Basic?
  • Adding and multiplying of DenseMatrix objects of incompatible size should result in Python errors/exceptions, not crashes.
  • Indexing of a single column or row matrix should work with a single index, like A[1].
  • Add vector specific methods like dot, norm, cross (I suppose this should be done on the symengine/C++ side actually first).

symengine.py does not correctly link to libpython

Placing a symlink to libpython in the cwd works around the problem.

~$ python -c "import symengine"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/anaconda3/lib/python3.4/site-packages/symengine/__init__.py", line 1, in <module>
    from .lib.symengine_wrapper import (Symbol, Integer, sympify, SympifyError,
ImportError: dlopen(~/anaconda3/lib/python3.4/site-packages/symengine/lib/symengine_wrapper.cpython-34m.so, 2): Library not loaded: libpython3.4m.dylib
  Referenced from: ~/anaconda3/lib/python3.4/site-packages/symengine/lib/symengine_wrapper.cpython-34m.so
  Reason: image not found

Per comments here: http://stackoverflow.com/questions/26815537/opencv-3-0-0-alpha-with-python-3-failed-to-import-cv2

~$ otool -L ~/anaconda3/lib/python3.4/site-packages/symengine/lib/symengine_wrapper.cpython-34m.so 
~/anaconda3/lib/python3.4/site-packages/symengine/lib/symengine_wrapper.cpython-34m.so:
    libpython3.4m.dylib (compatibility version 3.4.0, current version 3.4.0)
    ~/opt/gmp/lib/libgmpxx.4.dylib (compatibility version 9.0.0, current version 9.0.0)
    ~/opt/gmp/lib/libgmp.10.dylib (compatibility version 13.0.0, current version 13.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

fix memleaks

When exiting isympy (after eg from symengine import Symbol)

  0: RCPNode (map_key_void_ptr=0x35c9e80)
       Information = {T=SymEngine::Complex, ConcreteT=SymEngine::Complex, p=0x35c9e80, has_ownership=1}
       RCPNode address = 0x35f4930
       insertionNumber = 3
  1: RCPNode (map_key_void_ptr=0x35a63e0)
       Information = {T=SymEngine::Constant, ConcreteT=SymEngine::Constant, p=0x35a63e0, has_ownership=1}
       RCPNode address = 0x35f9f60
       insertionNumber = 4
  2: RCPNode (map_key_void_ptr=0x3614b50)
       Information = {T=SymEngine::Constant, ConcreteT=SymEngine::Constant, p=0x3614b50, has_ownership=1}
       RCPNode address = 0x35f1f90
       insertionNumber = 5
  3: RCPNode (map_key_void_ptr=0x3620d80)
       Information = {T=SymEngine::PyModule, ConcreteT=SymEngine::PyModule, p=0x3620d80, has_ownership=1}
       RCPNode address = 0x362a0c0
       insertionNumber = 365
  4: RCPNode (map_key_void_ptr=0x361ed40)
       Information = {T=SymEngine::PyModule, ConcreteT=SymEngine::PyModule, p=0x361ed40, has_ownership=1}
       RCPNode address = 0x36299a0
       insertionNumber = 366

The first three are from I:

#9  0x00007fffe3a36faa in Teuchos::rcp<SymEngine::Complex const> (p=0x865ed0,
    owns_mem=true)
    at /home/ralf/symengine/symengine/utilities/teuchos/Teuchos_RCP.hpp:574
#10 0x00007fffe3a36e27 in SymEngine::make_rcp<SymEngine::Complex const, SymEngine::mpq_wrapper const&, SymEngine::mpq_wrapper const&> ()
    at /home/ralf/symengine/symengine/symengine_rcp.h:369
#11 0x00007fffe3a35b41 in SymEngine::Complex::from_mpq (re=..., im=...)
    at /home/ralf/symengine/symengine/complex.cpp:80
#12 0x00007fffe3a35d5b in SymEngine::Complex::from_two_nums (re=..., im=...)
    at /home/ralf/symengine/symengine/complex.cpp:96
#13 0x00007fffe3900a03 in __static_initialization_and_destruction_0 (
    __initialize_p=1, __priority=65535)
    at /home/ralf/symengine/symengine/constants.cpp:41
#14 0x00007fffe390322a in _GLOBAL__sub_I_constants.cpp(void) ()
    at /home/ralf/symengine/symengine/constants.cpp:123

The latter two are from import:

9  0x00007fffe38b5724 in Teuchos::rcp<SymEngine::PyModule const> (p=0x1cf0ce0,
    owns_mem=true)
    at /home/ralf/lib/cmake/symengine/../../../include/symengine/utilities/teuchos/Teuchos_RCP.hpp:574
#10 0x00007fffe38af685 in SymEngine::make_rcp<SymEngine::PyModule const, _object* (*)(Teuchos::RCP<SymEngine::Basic const>), Teuchos::RCP<SymEngine::Basic const> (*)(_object*), Teuchos::RCP<SymEngine::Number const> (*)(_object*, long), Teuchos::RCP<SymEngine::Basic const> (*)(_object*, Teuchos::RCP<SymEngine::Basic const>)>(_object* (*&&)(Teuchos::RCP<SymEngine::Basic const>), Teuchos::RCP<SymEngine::Basic const> (*&&)(_object*), Teuchos::RCP<SymEngine::Number const> (*&&)(_object*, long), Teuchos::RCP<SymEngine::Basic const> (*&&)(_object*, Teuchos::RCP<SymEngine::Basic const>)) ()
    at /home/ralf/lib/cmake/symengine/../../../include/symengine/symengine_rcp.h:369
#11 0x00007fffe37e64ae in __pyx_pf_9symengine_3lib_17symengine_wrapper_10create_sympy_module (__pyx_self=0x0)
    at /home/ralf/symengine.py/symengine/lib/symengine_wrapper.cpp:22906
#12 0x00007fffe37e6363 in __pyx_pw_9symengine_3lib_17symengine_wrapper_11create_sympy_module (__pyx_self=0x0, unused=0x0)
    at /home/ralf/symengine.py/symengine/lib/symengine_wrapper.cpp:22863
#13 0x00007ffff7a4de7a in PyObject_Call () from /usr/lib64/libpython3.4m.so.1.0

lambdifying a function with imaginary unit returns Error

Hi,

i stumbled on a problem. If you take the Lamdify.py code from your benchmarks and add the imaginary unit to the code. It shows the following Error.

Traceback (most recent call last):
  File "foo.py", line 16, in <module>
    lmb_symengine = se.Lambdify(args, exprs)
  File "symengine/lib/symengine_wrapper.pyx", line 2646, in symengine.lib.symengine_wrapper.Lambdify.__cinit__ (/build/python-symengine-DwGdyH/python-symengine-0.2.0-ubuntu2/build/lib.linux-i686-3.5/symengine/lib/symengine_wrapper.cpp:66640)
RuntimeError: Not Implemented

The code is the following. If i delete the imaginary Unit I, everything is fine.

from time import clock
from sympy import I
import numpy as np
import sympy as sp
import symengine as se



x = sp.symarray('x', 14)
p = sp.symarray('p', 14)
args = np.concatenate((x, p))
exp = sp.exp

#X[1] gets the imaginary number
exprs = [sp.cos(x[0]) + I*x[1] - x[4] + 36.252574322669, x[0] - x[2] + x[3] +
        exp(x[13]) + exp(x[5]) + exp(x[6]) + exp(x[7]) + exp(x[8]) + exp(x[9])]

print(exprs)
lmb_symengine = se.Lambdify(args, exprs)
lmb_sympy = sp.lambdify(args, exprs)

Segfault on OS X El Capitan

I am on OS X El Capitan 10.11.3, running python 3.3 in a conda environment (tried python 3.4 as well, same issue). I build symengine from commit b5c453f (the one supported by symengine.py) using cmake and then python setup.py install build --symengine-dir=../symengine/ in a3acc76 of symengine.py

In [1]: from symengine import Add, var

In [2]: v = var('x')

In [3]: Add(v, v)

Segfault caught. Printing stacktrace:

Traceback (most recent call last):

Done. Exiting the program.
/Users/niso/anaconda/envs/optlang3.3/bin/python.app: line 3: 12878 Abort trap: 6           /Users/niso/anaconda/envs/optlang3.3/python.app/Contents/MacOS/python "$@"

Same problem with symengine.Mul.

Running
v + v
runs fine though, which is weird (I think).

py.test errors

I get with master and py.test -v:
(from 15 files)

___________________ ERROR collecting symengine/tests/test_var.py ___________________
import file mismatch:
imported module 'symengine.tests.test_var' has this __file__ attribute:             
  /usr/lib64/python2.7/site-packages/symengine/tests/test_var.py                    
which is not the same as the test file we want to collect:                          
  /home/ralf/symengine.py/symengine/tests/test_var.py                               
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules                                                                           

and after that:

***
*** Warning! The following Teuchos::RCPNode objects were created but have
...
  0: RCPNode (map_key_void_ptr=0x3aee840)
       Information = {T=SymEngine::Symbol, ConcreteT=SymEngine::Symbol, p=0x3aee840, has_ownership=1}
       RCPNode address = 0x3b23090
       insertionNumber = 1427
  1: RCPNode (map_key_void_ptr=0x3af0160)
       Information = {T=SymEngine::Symbol, ConcreteT=SymEngine::Symbol, p=0x3af0160, has_ownership=1}
       RCPNode address = 0x3b223c0
       insertionNumber = 8433
...
 16: RCPNode (map_key_void_ptr=0x3aeeb40)
       Information = {T=SymEngine::Symbol, ConcreteT=SymEngine::Symbol, p=0x3aeeb40, has_ownership=1}
       RCPNode address = 0x3b226e0
       insertionNumber = 8469
...

Segmentation fault on evaluating expressions

when evaluating certain strings, I get a segfault. The problem might well be due to the underlying symengine, but as I am using symengine.py, I report it here.

example string:
cos(sin(cos(sin(log(1)))-cos((sin(1)-(1*x)))))

I have built symengine with the git version as indicated in symengine_version.txt.

code for reproducing the segfault:

import symengine
from symengine import sin,cos,exp,log
x = symengine.Symbol('x')
segfault_string="cos(sin(cos(sin(log(1)))-cos((sin(1)-(1*x)))))"
expr=eval(segfault_string) #won't work

and output for the code on my machine, including python/symengine versions

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import symengine
>>> from symengine import sin,cos,exp,log
>>> x = symengine.Symbol('x')
>>> print symengine.__version__
0.1.0.dev
>>> segfault_string="cos(sin(cos(sin(log(1)))-cos((sin(1)-(1*x)))))"
>>> expr=eval(segfault_string) #won't work
Segmentation fault (core dumped)

Note (not sure if this helps)
When I manually split the string in two parts, symengine evaluates everything properly

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import symengine
>>> from symengine import sin,cos,exp,log
>>> x = symengine.Symbol('x')
>>> nested_part="-cos((sin(1)-(1*x)))"
>>> n=eval(nested_part)
>>> print n
-cos(-x + sin(1))
>>> global_expression="cos(sin(cos(sin(log(1)))-n))"
>>> e=eval(global_expression)
>>> print e
cos(sin(1 + cos(-x + sin(1))))

ImportError: symengine/lib/symengine_wrapper.so: undefined symbol:

I installed the python wrapper, and when I tried the examples

>>> from symengine import var

the following error appeared:

File "symengine/__init__.py", line 1, in <module>
    from .lib.symengine_wrapper import (Symbol, Integer, sympify, SympifyError,
ImportError: symengine/lib/symengine_wrapper.so: undefined symbol: _ZNK9SymEngine14FunctionSymbol4subsERKSt3mapIN7Teuchos3RCPIKNS_5BasicEEES6_NS_15RCPBasicKeyLessESaISt4pairIKS6_S6_EEE

I am no expert on either ubuntu system or python, so the issue might be naive, thank you

(minor) provide convenience rational creator

It's not in __init__.py and if it were tested tests would not pass. I get a Teuchos::throw_null_ptr_error from the simple Rational(-1,2).

I would consider this a blocker for any release.

Test without sympy in travis-ci

Now that tests involving sympy are skipped when sympy is not found, we can have one more test that tests symengine without sympy.

Build issues

Received a mail today saying the following. I am a bit busy with my end semesters, could somebody check on this?
"I am having a lots of problem in installing symengine wrapper for python on a Mac, do you have a guide or something?
I have correctly installed the library, or at lest i think, but not the wrapper, i attach the errors:

Giovannis-MacBook-Pro:symengine.py-master giovanniranuzzi$ sudo python setup.py install
Password:
//anaconda/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/setuptools/dist.py:285: UserWarning: Normalizing '0.1.0.dev' to '0.1.0.dev0'
running install
running build
SymEngine_DIR : /usr/local/lib/cmake/symengine
-- Python include path: //anaconda/include/python2.7
-- Python version: 2.7
-- Python install path: //anaconda/lib/python2.7/site-packages
-- Found CYTHON: cython
CMAKE_BUILD_TYPE : Release
CMAKE_CXX_FLAGS_RELEASE : -std=c++11 -Wall -Wextra -fPIC -O3 -march=native -ffast-math -funroll-loops -Wno-unused-parameter -D__extern_always_inline=inline
CMAKE_CXX_FLAGS_DEBUG : -std=c++11 -Wall -Wextra -fPIC -g -Wno-unused-parameter -ggdb
HAVE_SYMENGINE_MPFR : False
HAVE_SYMENGINE_MPC : False
HAVE_SYMENGINE_PIRANHA : False
HAVE_SYMENGINE_FLINT : False
Copying source of python wrappers into: /Users/giovanniranuzzi/Desktop/symengine.py-master
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/giovanniranuzzi/Desktop/symengine.py-master
[ 25%] Building CXX object symengine/lib/CMakeFiles/symengine_wrapper.dir/symengine_wrapper.cpp.o
/Users/giovanniranuzzi/Desktop/symengine.py-master/symengine/lib/symengine_wrapper.cpp:36461:49: error: non-const lvalue reference to type
      'SymEngine::MatrixBase' cannot bind to a value of unrelated type 'unsigned int'
  (*__pyx_v_self->__pyx_base.thisptr).submatrix(__pyx_t_4, __pyx_t_5, __pyx_t_6, __pyx_t_7, (*__pyx_v_result->__pyx_base.thisptr));
                                                ^~~~~~~~~
/usr/local/lib/cmake/symengine/../../../include/symengine/matrix.h:55:40: note: passing argument to parameter 'result' here
    virtual void submatrix(MatrixBase &result, unsigned row_start,
                                       ^
^[[A1 error generated.
make[2]: *** [symengine/lib/CMakeFiles/symengine_wrapper.dir/symengine_wrapper.cpp.o] Error 1
make[1]: *** [symengine/lib/CMakeFiles/symengine_wrapper.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 190, in <module>
    'install' : InstallWithCmake,
  File "//anaconda/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "//anaconda/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "//anaconda/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "setup.py", line 171, in run
    _install.run(self)
  File "//anaconda/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/setuptools/command/install.py", line 65, in run
  File "//anaconda/lib/python2.7/distutils/command/install.py", line 563, in run
    self.run_command('build')
  File "//anaconda/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "//anaconda/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "setup.py", line 110, in run
    self.cmake_build()
  File "setup.py", line 90, in cmake_build
    raise EnvironmentError("error building project")
EnvironmentError: error building project

probably, according with these(http://stackoverflow.com/questions/18565167/non-const-lvalue-references), is a problem of the complier, but i really don’t know haw to solve it, may you kingly help me please? Do you have any solution for these problem?"

Desired SymPy API Methods and functions

Based on a discussion on gitter, here the functions that I'd personally would love to see in symengine.py.

For Add and Mul etc.

  • .is_Add
  • .is_Mul
  • .is_Atom
  • .is_Number
  • .atoms
  • .as_coefficients_dict
  • .xreplace

and

  • sympy.Integer
  • sympy.RealNumber
  • sympy.PolynomialError

Doesn't build with latest Cython

I tested Cython==0.24 (the latest from pip) and it did not build with the following traceback.

It did work with Cython==0.22 though.

Error compiling Cython file:
------------------------------------------------------------
...
    cdef double complex[::1] cmplx_view
    if real:
        try:
            real_view = iterable
        except (ValueError, TypeError):
            real_view = cython.view.array(shape=(_size(iterable),),
                                                     ^
------------------------------------------------------------

symengine_wrapper.pyx:2464:54: Compiler crash in TransformBuiltinMethods

ModuleNode.body = StatListNode(symengine_wrapper.pyx:1:0)
StatListNode.stats[161] = StatListNode(symengine_wrapper.pyx:2455:0)
StatListNode.stats[0] = DefNode(symengine_wrapper.pyx:2455:0,
    doc = u' if iterable supports the buffer interface: return iterable,\n        if not, return a cython.view.array object (which does) ',
    modifiers = [...]/0,
    name = u'with_buffer',
    num_required_args = 1,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0')
DefNode.body = StatListNode(symengine_wrapper.pyx:2456:4)
StatListNode.stats[0] = IfStatNode(symengine_wrapper.pyx:2460:4)
IfStatNode.if_clauses[0] = IfClauseNode(symengine_wrapper.pyx:2460:7)
IfClauseNode.body = StatListNode(symengine_wrapper.pyx:2461:8)
StatListNode.stats[0] = TryExceptStatNode(symengine_wrapper.pyx:2461:8)
TryExceptStatNode.except_clauses[0] = ExceptClauseNode(symengine_wrapper.pyx:2463:8)
ExceptClauseNode.body = StatListNode(symengine_wrapper.pyx:2464:12,
    is_terminator = True)
StatListNode.stats[0] = SingleAssignmentNode(symengine_wrapper.pyx:2464:41)
SingleAssignmentNode.rhs = GeneralCallNode(symengine_wrapper.pyx:2464:41,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 8035, in compile_time_value: DictNode(symengine_wrapper.pyx:2464:47,
    is_dict_literal = True,
    is_temp = 1,
    obj_conversion_errors = [...]/0,
    reject_duplicates = True,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 7334, in compile_time_value: TupleNode(symengine_wrapper.pyx:2464:49,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6730, in compile_time_value_list: TupleNode(symengine_wrapper.pyx:2464:49,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 4981, in compile_time_value: SimpleCallNode(symengine_wrapper.pyx:2464:54,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 1783, in compile_time_value: NameNode(symengine_wrapper.pyx:2464:54,
    cf_maybe_null = True,
    is_name = True,
    name = u'_size',
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/usr/local/lib/python2.7/dist-packages/Cython/Compiler/ExprNodes.py", line 1781, in compile_time_value
    return denv.lookup(self.name)
AttributeError: 'NoneType' object has no attribute 'lookup'

Problem building with Piranha

Hi! I'm trying to build symengine.py with symengine built against piranha on OS X 10.11 El Capitan. Although symengine itself builds fine, I hit this issue when building symengine.py (both v0.2.0 and the git master branch):

In file included from /Users/jp/Programs/GitHub/Spack/spack/opt/spack/darwin-elcapitan-x86_64/clang-7.3.0-apple/symengine-develop-t5qygkkgym536nmvw6wnblly6pdyi55p/include/symengine/mp_wrapper.h:4:
/Users/jp/Programs/GitHub/Spack/spack/opt/spack/darwin-elcapitan-x86_64/clang-7.3.0-apple/symengine-develop-t5qygkkgym536nmvw6wnblly6pdyi55p/include/symengine/symengine_rcp.h:378:20: error: no matching constructor for initialization of 'const SymEngine::Integer'
    return rcp(new T(std::forward<Args>(args)...));
                   ^ ~~~~~~~~~~~~~~~~~~~~~~~~
/private/var/folders/lc/b4bjrtcn69d279m6rf4f42y00000gn/T/jp/spack-stage/spack-stage-bFCR0D/symengine.py-0.2.0/symengine/lib/symengine_wrapper.cpp:20451:105: note: in instantiation of function template specialization 'SymEngine::make_rcp<const SymEngine::Integer, int &>' requested here
    __pyx_v_self->__pyx_base.__pyx_base.thisptr = ((SymEngine::RCP<SymEngine::Basic const > )SymEngine::make_rcp<const SymEngine::Integer>(__pyx_v_i_));
                                                                                                        ^
/Users/jp/Programs/GitHub/Spack/spack/opt/spack/darwin-elcapitan-x86_64/clang-7.3.0-apple/symengine-develop-t5qygkkgym536nmvw6wnblly6pdyi55p/include/symengine/integer.h:17:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const SymEngine::Integer' for 1st argument
class Integer : public Number
      ^
/Users/jp/Programs/GitHub/Spack/spack/opt/spack/darwin-elcapitan-x86_64/clang-7.3.0-apple/symengine-develop-t5qygkkgym536nmvw6wnblly6pdyi55p/include/symengine/integer.h:208:17: note: candidate constructor not viable: no known conversion from 'int' to 'integer_class' (aka 'mp_integer<>') for 1st argument
inline Integer::Integer(integer_class i_) : i{std::move(i_)}

Build log attached. Note: I've had success in building symengine.py without piranha support activated in symengine.

expr.atoms() seems to be broken on 0.1.0.dev

In [19]: import symengine

In [20]: import sympy

In [21]: (symengine.var('x') + symengine.var('y')).atoms()
Out[21]: set()

In [22]: (sympy.var('x') + sympy.var('y')).atoms()
Out[22]: {x, y}

on symengine.py=='0.1.0.dev' and symengine==0.2.0 (both installed using conda). On #59 atoms has been checked off as done. free_symbols seems to work fine.

In [25]: (sympy.var('x') + sympy.var('y')).free_symbols
Out[25]: {x, y}

In [26]: (symengine.var('x') + symengine.var('y')).free_symbols
Out[26]: {x, y}

ValueError in LambdifyCSE

just to write this down (will look into it when time allows)

Using python3.5 ppa:symengine on Ubuntu 16.04:

>>> import symengine
>>> x, y, z = symengine.symbols('x y z')
>>> expr1, expr2 = x+y+z, x*y*z
>>> callback = symengine.LambdifyCSE([x, y, z], [expr1, expr2])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "symengine/lib/symengine_wrapper.pyx", line 2846, in symengine.lib.symengine_wrapper.LambdifyCSE (/build/python-symengine-Hx0GFi/python-symengine-0.2.0-ubuntu2/build/lib.linux-x86_64-3.5/symengine/lib/symengine_wrapper.cpp:70862)
ValueError: need more than 0 values to unpack
>>> callback = symengine.Lambdify([x, y, z], [expr1, expr2])
>>> callback([2, 3, 4])
array([  9.,  24.])

MinGW segfault on appveyor

This only happens when MinGW build in Release mode. Other compilers, Debug mode and nosetests work. Also when logged into appveyor VM, this doesn't happen

Seg Fault Running Given Lambdify Benchmark

Hi,

Upon successfully setting up symengine, running the Lambidfy.py file unfortunately immediately ended in a segfault at the lambdification line. Running the program with sys.settrace set to the 'line' function and running python inside gdb, I get the error trace below. I should note though, expand6, 6b, whereas expand2 failed. The rest required python2/csympy, the latter of which didn't exist on my system.

(gdb) run Lambdify.py
Starting program: /usr/bin/python Lambdify.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff4aa4700 (LWP 31641)]
[New Thread 0x7ffff42a3700 (LWP 31642)]
[New Thread 0x7fffefaa2700 (LWP 31643)]
Traceback (most recent call last):
File "Lambdify.py", line 11, in
x = sp.symarray('x', 14)
File "/usr/lib/python3.5/site-packages/sympy/matrices/dense.py", line 998, in symarray
@doctest_depends_on(modules=('numpy',))
TypeError: 'str' object is not callable
[Thread 0x7fffefaa2700 (LWP 31643) exited]
[Thread 0x7ffff42a3700 (LWP 31642) exited]
[Thread 0x7ffff4aa4700 (LWP 31641) exited]
[Inferior 1 (process 31637) exited with code 01]

symengine does not return unique objects for symbols with identical names

In [1]: import sympy

In [2]: id(sympy.Symbol('a'))
Out[2]: 4615360016

In [3]: id(sympy.Symbol('a'))
Out[3]: 4615360016

In [4]: import symengine

In [5]: id(symengine.Symbol('a'))
Out[5]: 4615766328

In [6]: id(symengine.Symbol('a'))
Out[6]: 4615766352

Is this intended? Unfortunately this breaks my attempts to swap sympy with symengine in a package I am working on as I am relying on sympy's behavior. On symengine.py=='0.1.0.dev' and symengine==0.2.0 (both installed using conda).

Problems with Lambdify and heterogeneous output

Using a conda environment with python-symengine == 0.3 from symengine channel:

>>> from symengine import symbols, Matrix, Lambdify
>>> args = x, y = symbols('x y')
>>> vec = Matrix([x+y, x*y])
>>> jac = vec.jacobian(Matrix(args))
>>> f = Lambdify(args, x**y, vec, jac)
>>> f([2,3])
[array([ 8.,  5.,  6.,  1.,  1.,  3.,  2.])]

came up when looking into sympy/sympy#5642
I am investigating this now.

Remove `Subs.__cinit__` and `Derivative.__cinit__`

Reason is the same as why we don't have Add.__cinit__.
Subs.__cinit__ may create non-canonical expressions. Solution would be to remove this method and add a Subs.__init__ to symengine.sympy_compat.

ImmutableDenseMatrix

DenseMatrix should be renamed to MutableDenseMatrix and ImmutableDenseMatrix should throw for methods that change the matrix.

Lambdify with multiple outputs.

Currently, Lambdify generates only one output. For LLVM backend to make full use of cse, Lambdify should be able to do this in one go.

don't delegate to SymPy on flint series exception

(I have to stack things up here to not forget them...)
Somewhere in symgenine.py this exception is not caught:

In [2]: from symengine import *

In [3]: x=Symbol('x')                      

In [4]: series(1/cos(x/log(x)), x, 0)
Out[4]: 
         2            4   
        x          5⋅x         ⎛ 6⎞
1 + ───────── + ────────── + O⎝x ⎠
         2            4       
    2⋅log (x)   24⋅log (x)  

In [5]: series(1/cos(x/log(x)), x, 0, method='symengine')
Exception (fmpq_poly_log_series). Constant term != 1.

Abort caught. Printing stacktrace:

Traceback (most recent call last):

Done.
Aborted

This SymPy test case is also interesting because, although univariate and having log(x), SymPy solves it by leaving the log as were it another symbol. This shows the cases nomally throwing exceptions with URatP... can be treated by other means.

Problem with subclassing symengine.Symbol

Hi

I'm trying to define a subclass of Symbol to add extra functionalities to the class, but keeping the arithmetic properties the same.
However when one or more of these objects are combined in an expression, e.g. added together, the resulting Add object contains instances of symengine.Symbol instead of my subclass.

import symengine

# Subclass of Symbol with an extra attribute
class Wrapper(symengine.Symbol):
    def __new__(cls, name, extra_attribute):
        return symengine.Symbol.__new__(cls, name)

    def __init__(self, name, extra_attribute):
        self.extra_attribute = extra_attribute
        super(Wrapper, self).__init__()

# I can instantiate the subclass
x = Wrapper("x", extra_attribute=3)

x.extra_attribute
>>> 3

# I then try to multiply the object by 2
two_x = 2 * x

two_x.args[1] is x
>>> False

# The argument of the expression is now a normal symengine Symbol object
type(two_x.args[1])
>>> symengine.lib.symengine_wrapper.Symbol

Is this a bug or is it intended behaviour?

Fails install with all requirements met

Hi,

I'm trying to get this installed, but I'm met with the errors listed below. I've downgrade my Cython installation to meet all the requirements, with the following versions:

  • SymEngine version (commit hash) - 253bf6b, as stated in the symengine_version.txt in the project's root
  • Cython version - 0.20.1
  • CMake version - 3.6.1

Are there any extra steps that may be necessary or perhaps stricter versions of certain tooling being required than currently stated on the README page? Thanks.

/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp: In function ‘int __pyx_pf_9symengine_3lib_17symengine_wrapper_8RealMPFR_2__cinit__(__pyx_obj_9symengine_3lib_17symengine_wrapper_RealMPFR*, PyObject*, long int, uns
igned int)’:
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:20008:3: error: ‘mpfr_class’ is not a member of ‘SymEngine’
   SymEngine::mpfr_class __pyx_v_m;
   ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:20075:3: error: ‘__pyx_v_m’ was not declared in this scope
   __pyx_v_m = SymEngine::mpfr_class(__pyx_v_i_, __pyx_v_prec, __pyx_v_base);
   ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:20075:15: error: ‘mpfr_class’ is not a member of ‘SymEngine’
   __pyx_v_m = SymEngine::mpfr_class(__pyx_v_i_, __pyx_v_prec, __pyx_v_base);
               ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:20084:133: error: ‘real_mpfr’ is not a member of ‘SymEngine’
   __pyx_v_self->__pyx_base.__pyx_base.thisptr = ((SymEngine::RCP<SymEngine::Basic const >)((SymEngine::RCP<SymEngine::Basic const >)SymEngine::real_mpfr(std::move(__pyx_v_m))));
                                                                                                                                     ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp: In function ‘PyObject* __pyx_pf_9symengine_3lib_17symengine_wrapper_8RealMPFR_4get_prec(__pyx_obj_9symengine_3lib_17symengine_wrapper_RealMPFR*)’:
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:20146:191: error: ‘const class SymEngine::RealMPFR’ has no member named ‘get_prec’; did you mean ‘get_args’?
   __pyx_t_1 = __Pyx_PyInt_From_mpfr_prec_t((*SymEngine::rcp_static_cast<const SymEngine::RealMPFR>(((SymEngine::RCP<SymEngine::Basic const > &)__pyx_v_self->__pyx_base.__pyx_base.thisptr))).get_prec()); if (unlikely(!__pyx_t_1)) {__pyx_f
ilename = __pyx_f[0]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                                                                                                                                                                                               ^~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp: In function ‘PyObject* __pyx_pf_9symengine_3lib_17symengine_wrapper_8RealMPFR_6_sympy_(__pyx_obj_9symengine_3lib_17symengine_wrapper_RealMPFR*)’:
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:20237:166: error: ‘const class SymEngine::RealMPFR’ has no member named ‘get_prec’; did you mean ‘get_args’?
   __pyx_v_prec_ = (*SymEngine::rcp_static_cast<const SymEngine::RealMPFR>(((SymEngine::RCP<SymEngine::Basic const > &)__pyx_v_self->__pyx_base.__pyx_base.thisptr))).get_prec();
                                                                                                                                                                      ^~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp: In function ‘PyObject* __pyx_pf_9symengine_3lib_17symengine_wrapper_88eval_mpfr(PyObject*, PyObject*, long int)’:
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:45554:3: error: ‘mpfr_class’ is not a member of ‘SymEngine’
   SymEngine::mpfr_class __pyx_v_a;
   ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:45594:3: error: ‘__pyx_v_a’ was not declared in this scope
   __pyx_v_a = SymEngine::mpfr_class(__pyx_v_prec);
   ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:45594:15: error: ‘mpfr_class’ is not a member of ‘SymEngine’
   __pyx_v_a = SymEngine::mpfr_class(__pyx_v_prec);
               ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:45604:5: error: ‘eval_mpfr’ is not a member of ‘SymEngine’
     SymEngine::eval_mpfr(__pyx_v_a.get_mpfr_t(), (*__pyx_v_X->thisptr), MPFR_RNDN);
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:45618:148: error: ‘real_mpfr’ is not a member of ‘SymEngine’
   __pyx_t_3 = __pyx_f_9symengine_3lib_17symengine_wrapper_c2py(((SymEngine::RCP<SymEngine::Basic const >)((SymEngine::RCP<SymEngine::Basic const >)SymEngine::real_mpfr(std::move(__pyx_v_a))))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                                                                                                                                                    ^~~~~~~~~
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp: At global scope:
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:69267:1: warning: missing initializer for member ‘PyNumberMethods::nb_matrix_multiply’ [-Wmissing-field-initializers]
 };
 ^
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:69267:1: warning: missing initializer for member ‘PyNumberMethods::nb_inplace_matrix_multiply’ [-Wmissing-field-initializers]
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:69512:1: warning: missing initializer for member ‘PyNumberMethods::nb_matrix_multiply’ [-Wmissing-field-initializers]
 };
 ^
/home/<username>/programs/symengine.py/symengine/lib/symengine_wrapper.cpp:69512:1: warning: missing initializer for member ‘PyNumberMethods::nb_inplace_matrix_multiply’ [-Wmissing-field-initializers]
output

ImmutableMatrix improvements

  File "symengine/lib/symengine_wrapper.pyx", line 2133, in symengine.lib.symengine_wrapper.DenseMatrixBase.applyfunc (/home/isuru/projects/symengine.py/symengine/lib/symengine_wrapper.cpp:54321)
  File "symengine/lib/symengine_wrapper.pyx", line 2129, in symengine.lib.symengine_wrapper.DenseMatrixBase._applyfunc (/home/isuru/projects/symengine.py/symengine/lib/symengine_wrapper.cpp:54190)
  File "symengine/lib/symengine_wrapper.pyx", line 2359, in symengine.lib.symengine_wrapper.ImmutableDenseMatrix._set (/home/isuru/projects/symengine.py/symengine/lib/symengine_wrapper.cpp:61242)
TypeError: Cannot set values of <class 'symengine.lib.symengine_wrapper.ImmutableDenseMatrix'>

cc @ShikharJ

Add `is_positive` property to Number

Also, is_zero, is_negative, is_nonzero, is_nonnegative, is_nonpositive, is_complex.
These can use the corresponding methods from C++ library.

`python setup.py install --user` yields broken installation

Installing seems to work fine:

python3 setup.py install --user build_ext  --symengine-dir=../symengine/build/
/home/cdiener/.local/lib/python3.5/site-packages/setuptools/dist.py:336: UserWarning: Normalizing '0.2.1.dev' to '0.2.1.dev0'
  normalized_version,
running install
running build
running build_ext
SymEngine_DIR : ../symengine/build/
-- Python include path: /usr/include/python3.5m
-- Python version: 3.5
-- Python install path: /home/cdiener/.local/lib/python3.5/site-packages
-- Found PYTHON: /usr/lib64/libpython3.5m.so  
-- Found CYTHON: cython
CMAKE_BUILD_TYPE        : Release
CMAKE_CXX_FLAGS_RELEASE : -std=c++11 -Wall -Wextra -fno-common -fPIC -O3 -ffast-math -funroll-loops -Wno-unused-parameter -march=native -fopenmp
CMAKE_CXX_FLAGS_DEBUG   : -std=c++11 -Wall -Wextra -fno-common -fPIC -g -Wno-unused-parameter -ggdb -fopenmp
HAVE_SYMENGINE_MPFR     : False
HAVE_SYMENGINE_MPC      : False
HAVE_SYMENGINE_PIRANHA  : False
HAVE_SYMENGINE_FLINT    : False
HAVE_SYMENGINE_LLVM     : False
Copying source of python wrappers into: /home/cdiener/scribble/symengine.py/build/lib.linux-x86_64-3.5
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cdiener/scribble/symengine.py/build/lib.linux-x86_64-3.5
[100%] Built target symengine_wrapper
running install_egg_info
running egg_info
writing dependency_links to symengine.egg-info/dependency_links.txt
writing symengine.egg-info/PKG-INFO
writing top-level names to symengine.egg-info/top_level.txt
reading manifest file 'symengine.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.hpp' under directory 'symengine'
warning: no files found matching '*.cmake' under directory 'symengine'
warning: no files found matching '*.pxi' under directory 'symengine'
warning: no files found matching '*.in' under directory 'cmake'
writing manifest file 'symengine.egg-info/SOURCES.txt'
removing '/home/cdiener/.local/lib/python3.5/site-packages/symengine-0.2.1.dev0-py3.5.egg-info' (and everything under it)
Copying symengine.egg-info to /home/cdiener/.local/lib/python3.5/site-packages/symengine-0.2.1.dev0-py3.5.egg-info
running install_scripts
SymEngine_DIR : ../symengine/build/
-- Python include path: /usr/include/python3.5m
-- Python version: 3.5
-- Python install path: /home/cdiener/.local/lib/python3.5/site-packages
-- Found CYTHON: cython
CMAKE_BUILD_TYPE        : Release
CMAKE_CXX_FLAGS_RELEASE : -std=c++11 -Wall -Wextra -fno-common -fPIC -O3 -ffast-math -funroll-loops -Wno-unused-parameter -march=native -fopenmp
CMAKE_CXX_FLAGS_DEBUG   : -std=c++11 -Wall -Wextra -fno-common -fPIC -g -Wno-unused-parameter -ggdb -fopenmp
HAVE_SYMENGINE_MPFR     : False
HAVE_SYMENGINE_MPC      : False
HAVE_SYMENGINE_PIRANHA  : False
HAVE_SYMENGINE_FLINT    : False
HAVE_SYMENGINE_LLVM     : False
Copying source of python wrappers into: /home/cdiener/scribble/symengine.py/build/lib.linux-x86_64-3.5
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cdiener/scribble/symengine.py/build/lib.linux-x86_64-3.5
[100%] Built target symengine_wrapper
Install the project...
-- Install configuration: "Release"
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/__init__.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/utilities.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/compatibility.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/sympy_compat.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/functions.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/printing.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/lib/symengine_wrapper.cpython-35m-x86_64-linux-gnu.so
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/lib/__init__.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/lib/config.pxi
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/lib/symengine.pxd
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/lib/symengine_wrapper.pxd
-- Installing: /home/cdiener/.local/include/python3.5m/symengine/pywrapper.h
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/__init__.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_arit.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_dict_basic.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_eval.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_expr.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_functions.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_number.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_matrices.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_ntheory.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_printing.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sage.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_series_expansion.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_subs.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_symbol.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sympify.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sympy_conv.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_var.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_lambdify.py
-- Installing: /home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sympy_compat.py
Listing '/home/cdiener/.local/lib/python3.5/site-packages/symengine'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/__init__.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/compatibility.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/functions.py'...
Listing '/home/cdiener/.local/lib/python3.5/site-packages/symengine/lib'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/lib/__init__.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/printing.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/sympy_compat.py'...
Listing '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/__init__.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_arit.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_dict_basic.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_eval.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_expr.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_functions.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_lambdify.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_matrices.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_ntheory.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_number.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_printing.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sage.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_series_expansion.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_subs.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_symbol.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sympify.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sympy_compat.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_sympy_conv.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/tests/test_var.py'...
Compiling '/home/cdiener/.local/lib/python3.5/site-packages/symengine/utilities.py'...

However the package is not functional afterwards:

cdiener@pest [symengine.py] ipython
Python 3.5.3 (default, May 10 2017, 15:05:55) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import symengine
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-78609076377c> in <module>()
----> 1 import symengine

~/scribble/symengine.py/symengine/__init__.py in <module>()
----> 1 from .lib.symengine_wrapper import (Symbol, sympify as S, sympify,
      2         SympifyError, Add, Mul, Pow, function_symbol, I, E, pi, oo,
      3         zoo, nan, have_mpfr, have_mpc, have_flint, have_piranha,
      4         have_llvm, Integer, Rational, Float, Number, RealNumber,
      5         RealDouble, ComplexDouble, Max, Min, DenseMatrix, Matrix,

ImportError: No module named 'symengine.lib.symengine_wrapper'

Use the SymEngine's C API instead of the C++ API

This has the following advantages:

  1. Cython only needs to be run in the C mode, so it will be much faster to compile (i.e. gcc instead of g++), and we avoid the Cython bug #66.
  2. The C wrappers will be much better tested and complete, since if we want to expose something to Python, we would have to wrap it in C, and thus Ruby/Julia and other languages can easily take advantage of this as well (and vice versa).
  3. I think the Cython code will simplify quite a bit (no template tricks, etc.)

Possible disadvantage:

  1. The result might possibly be slower than calling C++ directly in some cases. If that happens, we should think hard if there is a way to create a C wrapper with minimal overhead (I think we are already pretty good about this). I still think that the only overhead is a possible extra function call in the C wrappers --- but if an extra function call makes a difference in Python wrappers, then the code should not be in the wrappers or in Python, but rather it should be moved to symengine itself into C++.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.