Skip to content

Commit

Permalink
Merge pull request #458 from bjodah/DenseMatrixBase-abs
Browse files Browse the repository at this point in the history
add DenseMatrixBase.__abs__
  • Loading branch information
bjodah authored Dec 27, 2023
2 parents b0f15af + fd81a6c commit d1a50aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions symengine/lib/symengine_wrapper.in.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,9 @@ cdef class DenseMatrixBase(MatrixBase):
def __neg__(self):
return self.mul_scalar(-1)

def __abs__(self):
return self.applyfunc(abs)

def __getitem__(self, item):
if isinstance(item, slice):
if (self.ncols() == 0 or self.nrows() == 0):
Expand Down
4 changes: 3 additions & 1 deletion symengine/tests/test_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ def test_mul_scalar():
assert a * A == DenseMatrix(2, 2, [a, 2*a, 3*a, 4*a])


def test_neg():
def test_neg_abs():
A = DenseMatrix(2, 3, [1, 2, 3, 4, 5, 6])
B = DenseMatrix(2, 3, [-1, -2, -3, -4, -5, -6])
assert -A == B

assert A == abs(B)


def test_sub():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
Expand Down

0 comments on commit d1a50aa

Please sign in to comment.