本文整理汇总了Python中symengine.lib.symengine_wrapper.DenseMatrix类的典型用法代码示例。如果您正苦于以下问题:Python DenseMatrix类的具体用法?Python DenseMatrix怎么用?Python DenseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DenseMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_submatrix
def test_submatrix():
A = DenseMatrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])
assert A.submatrix(0, 0, 0, 2) == DenseMatrix(1, 3, [1, 2, 3])
assert A.submatrix(2, 2, 0, 2) == DenseMatrix(1, 3, [7, 8, 9])
assert A.submatrix(0, 1, 1, 2) == DenseMatrix(2, 2, [2, 3, 5, 6])
assert A.submatrix(1, 2, 0, 2) == DenseMatrix(2, 3, [4, 5, 6, 7, 8, 9])
示例2: test_transpose
def test_transpose():
A = DenseMatrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])
assert A.transpose() == DenseMatrix(3, 3, [1, 4, 7, 2, 5, 8, 3, 6, 9])
A = DenseMatrix(2, 2, [1, 2, 2, 1])
assert A.transpose() == A
示例3: test_DenseMatrix_symbols
def test_DenseMatrix_symbols():
x, y, z = symbols("x y z")
D = DenseMatrix(4, 4,
[1, 0, 1, 0,
0, z, y, 0,
z, 1, x, 1,
1, 1, 0, 0])
assert D.get(1, 2) == y
示例4: test_dump_real
def test_dump_real():
if not HAVE_NUMPY: # nosetests work-around
return
ref = [1, 2, 3, 4]
A = DenseMatrix(2, 2, ref)
out = np.empty(4)
A.dump_real(out)
assert np.allclose(out, ref)
示例5: test_add_scalar
def test_add_scalar():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
a = Symbol("a")
assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])
i5 = Integer(5)
assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
示例6: test_dump_complex
def test_dump_complex():
if not HAVE_NUMPY: # nosetests work-around
return
ref = [1j, 2j, 3j, 4j]
A = DenseMatrix(2, 2, ref)
out = np.empty(4, dtype=np.complex128)
A.dump_complex(out)
assert np.allclose(out, ref)
示例7: test_mul_scalar
def test_mul_scalar():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
a = Symbol("a")
assert A.mul_scalar(a) == DenseMatrix(2, 2, [a, 2*a, 3*a, 4*a])
i5 = Integer(5)
assert A.mul_scalar(i5) == DenseMatrix(2, 2, [5, 10, 15, 20])
示例8: test_jacobian
def test_jacobian():
x, y, z, t = symbols("x y z t")
J_correct = DenseMatrix(4, 4,
[1, 0, 1, 0,
0, z, y, 0,
z, 1, x, 1,
1, 1, 0, 0])
D = DenseMatrix(4, 1, [x+z, y*z, z*x+y+t, x+y])
x = DenseMatrix(4, 1, [x, y, z, t])
J = D.jacobian(x)
assert J == J_correct
示例9: test_add_scalar
def test_add_scalar():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
a = Symbol("a")
assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])
i5 = Integer(5)
assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
raises(TypeError, lambda: A + 5)
raises(TypeError, lambda: 5 + A)
示例10: test_solve
def test_solve():
A = DenseMatrix(4, 4, [1, 2, 3, 4, 2, 2, 3, 4, 3, 3, 3, 4, 9, 8, 7, 6])
b = DenseMatrix(4, 1, [10, 11, 13, 30])
y = DenseMatrix(4, 1, [1, 1, 1, 1]);
x = A.solve(b, 'LU')
assert x == y
x = A.solve(b, 'FFLU')
assert x == y
x = A.solve(b, 'FFGJ')
assert x == y
示例11: test_add_matrix
def test_add_matrix():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
B = DenseMatrix(2, 2, [1, 0, 0, 1])
assert A.add_matrix(B) == DenseMatrix(2, 2, [2, 2, 3, 5])
a = Symbol("a")
b = Symbol("b")
c = Symbol("c")
d = Symbol("d")
A = DenseMatrix(2, 2, [a + b, a - b, a, b])
B = DenseMatrix(2, 2, [a - b, a + b, -a, b])
assert A.add_matrix(B) == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])
示例12: test_mul_matrix
def test_mul_matrix():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
B = DenseMatrix(2, 2, [1, 0, 0, 1])
assert A.mul_matrix(B) == A
a = Symbol("a")
b = Symbol("b")
c = Symbol("c")
d = Symbol("d")
A = DenseMatrix(2, 2, [a, b, c, d])
B = DenseMatrix(2, 2, [1, 0, 1, 0])
assert A.mul_matrix(B) == DenseMatrix(2, 2, [a + b, 0, c + d, 0])
示例13: test_add_matrix
def test_add_matrix():
A = DenseMatrix(2, 2, [1, 2, 3, 4])
B = DenseMatrix(2, 2, [1, 0, 0, 1])
assert A.add_matrix(B) == DenseMatrix(2, 2, [2, 2, 3, 5])
a = Symbol("a")
b = Symbol("b")
c = Symbol("c")
d = Symbol("d")
A = DenseMatrix(2, 2, [a + b, a - b, a, b])
B = DenseMatrix(2, 2, [a - b, a + b, -a, b])
assert A.add_matrix(B) == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])
assert A + B == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])
C = DenseMatrix(1, 2, [a, b])
raises(ShapeError, lambda: A + C)
示例14: test_get
def test_get():
A = DenseMatrix([[1, 2], [3, 4]])
assert A.get(0, 0) == 1
assert A.get(0, 1) == 2
assert A.get(1, 1) == 4
a = Symbol("a")
b = Symbol("b")
c = Symbol("c")
d = Symbol("d")
A = DenseMatrix(2, 2, [a, b, c, d])
assert A.get(0, 0) == a
assert A.get(1, 0) == c
assert A.get(1, 1) == d
assert A.get(-1, 0) == c
assert A.get(-1, -1) == d
raises(IndexError, lambda: A.get(2, 0))
raises(IndexError, lambda: A.get(0, 2))
raises(IndexError, lambda: A.get(-3, 0))
示例15: test_inv
def test_inv():
A = DenseMatrix(2, 2, [1, 0, 0, 1])
assert A.inv() == A
A = DenseMatrix(2, 2, [1, 2, 2, 3])
B = DenseMatrix(2, 2, [-3, 2, 2, -1])
assert A.inv('LU') == B
assert A.inv('FFLU') == B
assert A.inv('GJ') == B