8000 Added test cases for the new __array__ methods(Copy=true/false/None) · SamLubelsky/sympy@c17e6ce · GitHub
[go: up one dir, main page]

Skip to content

Commit c17e6ce

Browse files
committed
Added test cases for the new __array__ methods(Copy=true/false/None)
Currently copy=False is commented out due to a bug in numpy. see: numpy/numpy#25941 (comment)
1 parent 259ec18 commit c17e6ce

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

sympy/matrices/expressions/tests/test_matexpr.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ def test_factor_expand():
370370
# Ideally we get the first, but we at least don't want a wrong answer
371371
assert factor(expr) in [I - C, B**-1*(A**-1*(I - C)*B**-1)**-1*A**-1]
372372

373+
def test_numpy_conversion():
374+
try:
375+
from numpy import array, array_equal
376+
except ImportError:
377+
skip('NumPy must be available to test creating matrices from ndarrays')
378+
A = MatrixSymbol('A', 2, 2)
379+
np_array = array([[MatrixElement(A, 0, 0), MatrixElement(A, 1, 0)],
380+
[MatrixElement(A, 0, 1), MatrixElement(A, 1, 1)]])
381+
assert array_equal(array(A), np_array)
382+
assert array_equal(array(A, copy=True), np_array)
383+
#raises(TypeError, lambda: array(A, copy=False)) TODO: Uncomment this whenever copy variable properly passes to __array__
384+
373385

374386
def test_issue_2749():
375387
A = MatrixSymbol("A", 5, 2)

sympy/matrices/tests/test_matrixbase.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ def test_replace_map():
351351
assert N == Matrix(2, 2, lambda i, j: G(i+j))
352352
assert d == {F(0): G(0), F(1): G(1), F(2): G(2)}
353353

354+
def test_numpy_conversion():
355+
try:
356+
from numpy import array, array_equal
357+
except ImportError:
358+
skip('NumPy must be available to test creating matrices from ndarrays')
359+
A = Matrix([[1,2], [3,4]])
360+
np_array = array([[1,2], [3,4]])
361+
assert array_equal(array(A), np_array)
362+
assert array_equal(array(A, copy=True), np_array)
363+
#raises(TypeError, lambda: array(A, copy=False)) TODO: Uncomment this whenever copy variable properly passes to __array__
354364

355365
def test_rot90():
356366
A = Matrix([[1, 2], [3, 4]])

0 commit comments

Comments
 (0)
0