Skip to content

Commit b8bfcf4

Browse files
Merge pull request sympy#17929 from oscarbenjamin/repr_elementwise
Update repr-printing of elementwise functions
2 parents 352e310 + 9f5a6e0 commit b8bfcf4

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

sympy/matrices/expressions/applyfunc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class ElementwiseApplyFunction(MatrixExpr):
1717
>>> from sympy import exp
1818
>>> X = MatrixSymbol("X", 3, 3)
1919
>>> X.applyfunc(exp)
20-
exp(X...)
20+
exp.(X)
2121
2222
Otherwise using the class constructor:
2323
2424
>>> from sympy import eye
2525
>>> expr = ElementwiseApplyFunction(exp, eye(3))
2626
>>> expr
27-
exp(Matrix([
27+
exp.(Matrix([
2828
[1, 0, 0],
2929
[0, 1, 0],
30-
[0, 0, 1]])...)
30+
[0, 0, 1]]))
3131
>>> expr.doit()
3232
Matrix([
3333
[E, 1, 1],

sympy/printing/str.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _print_MatMul(self, expr):
326326
)
327327

328328
def _print_ElementwiseApplyFunction(self, expr):
329-
return "{0}({1}...)".format(
329+
return "{0}.({1})".format(
330330
expr.function,
331331
self._print(expr.expr),
332332
)

sympy/printing/tests/test_str.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,30 @@ def test_MatrixSymbol_printing():
813813
assert str(A**3) == "A**3"
814814

815815

816+
def test_MatrixExpressions():
817+
n = Symbol('n', integer=True)
818+
X = MatrixSymbol('X', n, n)
819+
820+
assert str(X) == "X"
821+
822+
Y = X[1:2:3, 4:5:6]
823+
824+
assert str(Y) == "X[1:3, 4:6]"
825+
826+
Z = X[1:10:2]
827+
828+
assert str(Z) == "X[1:10:2, :n]"
829+
830+
# Apply function elementwise (`ElementwiseApplyFunc`):
831+
832+
expr = (X.T*X).applyfunc(sin)
833+
assert str(expr) == 'sin.(X.T*X)'
834+
835+
lamda = Lambda(x, 1/x)
836+
expr = (n*X).applyfunc(lamda)
837+
assert str(expr) == 'Lambda(_d, 1/_d).(n*X)'
838+
839+
816840
def test_Subs_printing():
817841
assert str(Subs(x, (x,), (1,))) == 'Subs(x, x, 1)'
818842
assert str(Subs(x + y, (x, y), (1, 2))) == 'Subs(x + y, (x, y), (1, 2))'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy