Skip to content

minimal set of changes for returning failure to find non-zero pivot in FFGJ #457

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion cmake/FindCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IF (CYTHON_BIN)
RESULT_VARIABLE CYTHON_RESULT
OUTPUT_VARIABLE CYTHON_OUTPUT
ERROR_VARIABLE CYTHON_ERROR
)
)
if (CYTHON_RESULT EQUAL 0)
# Only if cython exits with the return code 0, we know that all is ok:
SET(Cython_FOUND TRUE)
Expand Down
9 changes: 5 additions & 4 deletions symengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@
from .lib.symengine_wrapper import ComplexMPC

if have_numpy:
from .lib.symengine_wrapper import (Lambdify, LambdifyCSE)

from .lib.symengine_wrapper import Lambdify, LambdifyCSE
def lambdify(args, exprs, **kwargs):
if isinstance(exprs, Basic):
exprs = [exprs]
return Lambdify(args, *exprs, **kwargs)
else:
def __getattr__(name):
if name == 'lambdify':
raise AttributeError("Cannot import numpy, which is required for `lambdify` to work")
if name in ('lambdify', 'Lambdify', 'LambdifyCSE'):
raise AttributeError(f"Cannot import numpy, which is required for `{name}` to work")
raise AttributeError(f"module 'symengine' has no attribute '{name}'")


Expand Down
306 changes: 153 additions & 153 deletions symengine/lib/symengine.pxd

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions symengine/lib/symengine_wrapper.in.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3998,6 +3998,10 @@ cdef class DenseMatrixBase(MatrixBase):
def solve(self, b, method='LU'):
cdef DenseMatrixBase b_ = sympify(b)
cdef DenseMatrixBase x = self.__class__(b_.nrows(), b_.ncols())
if b_.rows != self.rows:
raise ValueError("Unexpected number of rows in b")
if x.rows != self.cols:
raise ValueError("Unexpected number of rows in x")

if method.upper() == 'LU':
## solve() method of DenseMatrixBase uses LU factorization
Expand All @@ -4013,9 +4017,11 @@ cdef class DenseMatrixBase(MatrixBase):
deref(symengine.static_cast_DenseMatrix(b_.thisptr)),
deref(symengine.static_cast_DenseMatrix(x.thisptr)))
elif method.upper() == 'FFGJ':
symengine.FFGJ_solve(deref(symengine.static_cast_DenseMatrix(self.thisptr)),
failure = symengine.FFGJ_solve(deref(symengine.static_cast_DenseMatrix(self.thisptr)),
deref(symengine.static_cast_DenseMatrix(b_.thisptr)),
deref(symengine.static_cast_DenseMatrix(x.thisptr)))
if (failure != 0):
raise Exception("Underdetermined system. Failed to find non-zero pivot in column: %d" % failure)
else:
raise Exception("Unsupported method.")

Expand Down Expand Up @@ -4944,7 +4950,7 @@ def powermod_list(a, b, m):
def has_symbol(obj, symbol=None):
cdef Basic b = _sympify(obj)
cdef Basic s = _sympify(symbol)
require(s, (Symbol, FunctionSymbol))
require(s, (Symbol, FunctionSymbol, Infinity, NegativeInfinity, NaN))
if (not symbol):
return not b.free_symbols.empty()
else:
Expand Down
8 changes: 8 additions & 0 deletions symengine/tests/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ def test_as_powers_dict():
assert (x*(1/Integer(2))**y).as_powers_dict() == {x: Integer(1), Integer(2): -y}
assert (2**y).as_powers_dict() == {2: y}
assert (2**-y).as_powers_dict() == {2: -y}


def test_has():
x = Symbol('x')
assert (x + oo).has(oo)
assert (x - oo).has(-oo)
assert not (x + oo).has(-oo)
#assert not (x - oo).has(oo) <-- not sure we want to test explicitly for "x + NegativeInfinity"
11 changes: 10 additions & 1 deletion symengine/tests/test_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
have_numpy = True
except ImportError:
have_numpy = False

try:
import sympy
from sympy.core.cache import clear_cache
Expand Down Expand Up @@ -446,6 +446,15 @@ def test_solve():
x = A.solve(b, 'FFGJ')
assert x == y

B = DenseMatrix(2, 2, [0]*4)
try:
B.solve(b, 'FFGJ')
except Exception:
pass
else:
raise Exception("this operation should have raised an exception")



def test_FFLU():
A = DenseMatrix(4, 4, [1, 2, 3, 4, 2, 2, 3, 4, 3, 3, 3, 4, 9, 8, 7, 6])
Expand Down
1 change: 1 addition & 0 deletions symengine/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .lib.symengine_wrapper import Symbol, Basic

from itertools import combinations, permutations, product, product as cartes
import re as _re
import string
Expand Down
Loading