test_sympytools.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:meshless 作者: compmech 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号