def test_print_as_sparse():
xvar = sympy.var('xvar')
yvar = sympy.var('yvar')
m = sympy.Matrix([[1, 2*xvar + yvar**3]])
res1 = """
# test_m
# test_m_num=2
c += 1
test_mr[c] = row+0
test_mc[c] = col+0
test_mv[c] += 1
c += 1
test_mr[c] = row+0
test_mc[c] = col+1
test_mv[c] += 2*xvar + (yvar*yvar*yvar)
"""
res1 = res1.strip()
print_as_sparse(m, 'test_m', print_file=False) == res1
print_as_sparse(m, 'test_m', print_file=False, full_symmetric=True) == res1
res2 = """
# test_m
# test_m_num=2
c += 1
test_mr[c] = row+0
test_mc[c] = col+0
test_mv[c] += 1
c += 1
test_mr[c] = row+0
test_mc[c] = col+1
test_mv[c] += (yvar*yvar*yvar) + 2*yvar
"""
res2 = res2.strip()
print_as_sparse(m, 'test_m', print_file=False, subs={xvar: yvar}) == res2
评论列表
文章目录