Skip to content

Commit 653a3fc

Browse files
authored
Merge pull request #114 from isuruf/number2
Add is_positive, is_negative, etc and update
2 parents eb13330 + 4230938 commit 653a3fc

File tree

11 files changed

+110
-62
lines changed

11 files changed

+110
-62
lines changed

.travis.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ addons:
1111
sources:
1212
- ubuntu-toolchain-r-test
1313
packages:
14-
- libgmp-dev
15-
- libmpfr-dev
16-
- libmpc-dev
1714
- binutils-dev
1815
- g++-4.7
1916

@@ -55,34 +52,20 @@ matrix:
5552
apt:
5653
sources:
5754
- ubuntu-toolchain-r-test
58-
- boost-latest
59-
- george-edison55-precise-backports
6055
packages:
61-
- libgmp-dev
62-
- libmpfr-dev
6356
- binutils-dev
64-
- libboost-serialization1.55-dev
65-
- libboost-iostreams1.55-dev
6657
- g++-4.8
67-
- cmake
68-
- cmake-data
6958
- env: BUILD_TYPE="Debug" WITH_BFD="yes" PYTHON_VERSION="3.5" WITH_LLVM="yes"
7059
compiler: clang
7160
os: linux
7261
addons:
7362
apt:
7463
sources:
7564
- ubuntu-toolchain-r-test
76-
- llvm-toolchain-precise-3.8
77-
- george-edison55-precise-backports
7865
packages:
7966
- clang
8067
- libstdc++-4.8-dev
81-
- libgmp-dev
8268
- binutils-dev
83-
- llvm-3.8-dev
84-
- cmake
85-
- cmake-data
8669
- env: BUILD_TYPE="Release" PYTHON_VERSION="2.7"
8770
compiler: clang
8871
os: linux
@@ -109,6 +92,10 @@ matrix:
10992
install:
11093
- export PYTHON_SOURCE_DIR=`pwd`
11194
- export TEST_CPP="no"
95+
- export MAKEFLAGS="-j2"
96+
97+
# Setup travis for Python wrappers
98+
- source bin/install_travis.sh
11299

113100
- git clone https://github.com/symengine/symengine symengine-cpp
114101
- cd symengine-cpp
@@ -118,13 +105,10 @@ install:
118105
# Setup travis for C++ library
119106
- if [[ "${WITH_SAGE}" != "yes" ]]; then source bin/install_travis.sh; fi
120107

121-
# Setup travis for Python wrappers
122-
- cd $PYTHON_SOURCE_DIR
123-
- source bin/install_travis.sh
124-
125108
# Build C++ library
126-
- cd symengine-cpp
109+
- cd $PYTHON_SOURCE_DIR/symengine-cpp
127110
- bin/test_travis.sh
111+
- unset MAKEFLAGS
128112

129113
script:
130114
# Build Python wrappers and test

bin/install_travis.sh

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
#!/usr/bin/env bash
22

33
if [[ "${WITH_SAGE}" != "yes" ]]; then
4-
if [[ "${TRAVIS_OS_NAME}" != "osx" ]]; then
5-
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
6-
else
7-
wget https://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh -O miniconda.sh;
8-
fi
9-
bash miniconda.sh -b -p $our_install_dir/miniconda;
10-
export PATH="$our_install_dir/miniconda/bin:$PATH";
11-
hash -r;
12-
conda config --set always_yes yes --set changeps1 no;
13-
conda update -q conda;
14-
conda info -a;
15-
CONDA_PKGS="pip cython sympy nose pytest"
4+
# symengine's bin/install_travis.sh will install miniconda
5+
conda_pkgs="python=${PYTHON_VERSION} pip cython sympy nose pytest"
166
if [[ "${WITH_NUMPY}" == "yes" ]]; then
17-
CONDA_PKGS="${CONDA_PKGS} numpy";
7+
conda_pkgs="${conda_pkgs} numpy";
188
fi
19-
conda create -q -n test-environment python="${PYTHON_VERSION}" ${CONDA_PKGS};
20-
source activate test-environment;
219
else
2210
wget -O- https://dl.dropboxusercontent.com/u/46807346/sage-6.9-x86_64-Linux-Ubuntu_12.04_64_bit.tar.gz | tar xz
2311
SAGE_ROOT=`pwd`/sage-6.9-x86_64-Linux

symengine/lib/pywrapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ bool PyNumber::is_negative() const {
6363
bool PyNumber::is_positive() const {
6464
return PyObject_RichCompareBool(pyobject_, pymodule_->get_zero(), Py_GT) == 1;
6565
}
66+
//! \return true if complex
67+
bool PyNumber::is_complex() const {
68+
return false;
69+
}
6670

6771
//! Addition
6872
RCP<const Number> PyNumber::add(const Number &other) const {

symengine/lib/symengine.pxd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ cdef extern from "<symengine/symbol.h>" namespace "SymEngine":
273273

274274
cdef extern from "<symengine/number.h>" namespace "SymEngine":
275275
cdef cppclass Number(Basic):
276+
bool is_positive() nogil
277+
bool is_negative() nogil
278+
bool is_zero() nogil
279+
bool is_complex() nogil
276280
pass
277281
cdef cppclass NumberWrapper(Basic):
278282
pass

symengine/lib/symengine/pywrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class PyNumber : public NumberWrapper {
8080
virtual bool is_negative() const;
8181
//! \return true if positive
8282
virtual bool is_positive() const;
83+
//! \return true if complex
84+
virtual bool is_complex() const;
8385
//! return true if the number is an exact representation
8486
// false if the number is an approximation
8587
virtual bool is_exact() const { return true; };

symengine/lib/symengine_wrapper.pyx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,34 @@ cdef class Number(Basic):
720720
def is_Number(self):
721721
return True
722722

723+
@property
724+
def is_positive(self):
725+
return deref(symengine.rcp_static_cast_Number(self.thisptr)).is_positive()
726+
727+
@property
728+
def is_negative(self):
729+
return deref(symengine.rcp_static_cast_Number(self.thisptr)).is_negative()
730+
731+
@property
732+
def is_zero(self):
733+
return deref(symengine.rcp_static_cast_Number(self.thisptr)).is_zero()
734+
735+
@property
736+
def is_nonzero(self):
737+
return not (self.is_complex or self.is_zero)
738+
739+
@property
740+
def is_nonnegative(self):
741+
return not (self.is_complex or self.is_negative)
742+
743+
@property
744+
def is_nonpositive(self):
745+
return not (self.is_complex or self.is_positive)
746+
747+
@property
748+
def is_complex(self):
749+
return deref(symengine.rcp_static_cast_Number(self.thisptr)).is_complex()
750+
723751
cdef class Integer(Number):
724752

725753
@property

symengine/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ install(FILES __init__.py
55
test_eval.py
66
test_expr.py
77
test_functions.py
8-
test_integer.py
8+
test_number.py
99
test_matrices.py
1010
test_ntheory.py
1111
test_sage.py

symengine/tests/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_abs_diff():
8080
def test_Subs():
8181
x = Symbol("x")
8282
y = Symbol("y")
83-
_x = Symbol("_x")
83+
_x = Symbol("_xi_1")
8484
f = function_symbol("f", 2*x)
8585
assert f.diff(x) == 2 * Subs(Derivative(function_symbol("f", _x), [_x]), [_x], [2 * x])
8686
assert Subs(Derivative(function_symbol("f", x, y), [x]), [x, y], [_x, x]) \

symengine/tests/test_integer.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

symengine/tests/test_number.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from symengine.utilities import raises
2+
3+
from symengine import Integer, I
4+
5+
def test_integer():
6+
i = Integer(5)
7+
assert str(i) == "5"
8+
9+
def test_integer_long():
10+
i = Integer(123434444444444444444)
11+
assert str(i) == "123434444444444444444"
12+
13+
def test_integer_string():
14+
assert Integer("133") == 133
15+
16+
def test_smallfloat_valid():
17+
i = Integer(7.5)
18+
assert str(i) == "7"
19+
20+
def test_bigfloat_valid():
21+
i = Integer(13333333333333334.5)
22+
assert str(i) == "13333333333333334"
23+
24+
def test_is_conditions():
25+
i = Integer(-123)
26+
assert not i.is_zero
27+
assert not i.is_positive
28+
assert i.is_negative
29+
assert i.is_nonzero
30+
assert i.is_nonpositive
31+
assert not i.is_nonnegative
32+
assert not i.is_complex
33+
34+
i = Integer(123)
35+
assert not i.is_zero
36+
assert i.is_positive
37+
assert not i.is_negative
38+
assert i.is_nonzero
39+
assert not i.is_nonpositive
40+
assert i.is_nonnegative
41+
assert not i.is_complex
42+
43+
i = Integer(0)
44+
assert i.is_zero
45+
assert not i.is_positive
46+
assert not i.is_negative
47+
assert not i.is_nonzero
48+
assert i.is_nonpositive
49+
assert i.is_nonnegative
50+
assert not i.is_complex
51+
52+
i = Integer(1) + I
53+
assert not i.is_zero
54+
assert not i.is_positive
55+
assert not i.is_negative
56+
assert not i.is_nonzero
57+
assert not i.is_nonpositive
58+
assert not i.is_nonnegative
59+
assert i.is_complex
60+

0 commit comments

Comments
 (0)