test_population.py 文件源码

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

项目:few 作者: lacava 项目源码 文件源码
def is_valid_program(p):
    """ checks that the accumulated program length is always greater than the
    accumulated arities, indicating that the appropriate number of arguments is
    alway present for functions. It then checks that the sum of arties +1
    exactly equals the length of the stack, indicating that there are no
    missing arguments. """
    # print("p:",p)
    arities = list(a.arity[a.in_type] for a in p)
    accu_arities = list(accumulate(arities))
    accu_len = list(np.arange(len(p))+1)
    check = list(a < b for a,b in zip(accu_arities,accu_len))
    # print("accu_arities:",accu_arities)
    # print("accu_len:",accu_len)
    # print("accu_arities < accu_len:",accu_arities<accu_len)
    return all(check) and sum([a.arity[a.in_type] for a in p]) +1 == len(p) and len(p)>0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号