Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions symengine/lib/symengine_wrapper.in.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4073,6 +4073,10 @@ cdef class DenseMatrixBase(MatrixBase):
def diff(self, *args):
return _diff(self, *args)

def evalf(self, unsigned long prec=53, real=None):
"""Evaluate each entry using the scalar evalf precision and domain."""
return self.applyfunc(lambda x: x.evalf(prec, real))

#TODO: implement this in C++
def subs(self, *args):
cdef _DictBasic D = get_dict(*args)
Expand Down
16 changes: 15 additions & 1 deletion symengine/tests/test_matrices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from symengine import symbols, init_printing
from symengine import symbols, init_printing, RealDouble
from symengine.lib.symengine_wrapper import (DenseMatrix, Symbol, Integer,
Rational, function_symbol, I, NonSquareMatrixError, ShapeError, zeros,
ones, eye, ImmutableMatrix)
Expand Down Expand Up @@ -672,6 +672,20 @@ def test_diff():
assert result == DenseMatrix(1, 2, [2*x, 1])


def test_evalf():
x = Symbol("x")
for matrix_type in (DenseMatrix, ImmutableMatrix):
matrix = matrix_type([[x**2 / 4, 3*x]])
exact = matrix.diff(x).subs(x, 3)

result = exact.evalf(real=True)

assert type(result) is matrix_type
assert result.shape == (1, 2)
assert list(result) == [RealDouble(1.5), RealDouble(3)]
assert exact == matrix_type([[Rational(3, 2), Integer(3)]])


def test_immutablematrix():
A = ImmutableMatrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
assert A.shape == (3, 3)
Expand Down