Skip to content

Commit

Permalink
Matrix hstack/vstack improved
Browse files Browse the repository at this point in the history
Closes sympy/sympy#11944

// edited by skirpichev

Based on sympy/sympy#11951

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>
  • Loading branch information
Abdullahjavednesar authored and skirpichev committed Feb 23, 2019
1 parent f1457ad commit 5efc374
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions diofant/matrices/matrices.py
Expand Up @@ -3764,7 +3764,8 @@ def hstack(cls, *args):
[0, 1, 0, 2]])
"""
return reduce(cls.row_join, args)
_cls = type(args[0])
return reduce(_cls.row_join, args)

@classmethod
def vstack(cls, *args):
Expand All @@ -3782,7 +3783,8 @@ def vstack(cls, *args):
[0, 2]])
"""
return reduce(cls.col_join, args)
_cls = type(args[0])
return reduce(_cls.col_join, args)

def row_join(self, rhs):
"""Concatenates two matrices along self's last and rhs's first column
Expand Down
7 changes: 7 additions & 0 deletions diofant/tests/matrices/test_matrices.py
Expand Up @@ -2688,3 +2688,10 @@ def test_sympyissue_10770():
f = getattr(M, op)
new = f(m) if 'join' in op else f(42, m)
assert new == m and id(new) != id(m)


def test_sympyissue_11944():
A = Matrix([[1]])
AIm = A.as_immutable()
assert Matrix.hstack(AIm, A) == Matrix([[1, 1]])
assert Matrix.vstack(AIm, A) == Matrix([[1], [1]])

0 comments on commit 5efc374

Please sign in to comment.