python - 使用 PyGears 框架编译 python 代码

标签 python pygears

目前我正在 PyGears 中编写我的第一个代码,但我对如何编译代码感到困惑。我是像普通的 Python 代码一样编译它,还是需要一些奇特的工具?

最佳答案

是的,您应该能够像普通的 Python 代码一样编译它。如果您使用的是 python3,它应该看起来像这样。

假设我们有模块 darken.py

from pygears import gear
from pygears.typing import Ufixp, Uint
from pygears.lib import drv, collect
from pygears.sim import sim, cosim


@gear
def darken(din, *, gain):
    return din * Ufixp[0, 8](gain)


res = []

drv(t=Uint[8], seq=[12, 23, 255]) \
    | darken(gain=0.5) \
    | float \
    | collect(result=res)

cosim('/darken', 'verilator', outdir='./home/stefan/test/output')
sim()

print(res)

我们可以在终端内运行命令

python3 darken.py

输出应该是

-          /darken/mul [INFO]: Running sim with seed: 167830386130148172
0                      [INFO]: -------------- Simulation start --------------
103                      [INFO]: ----------- Simulation done ---------------
103                      [INFO]: Elapsed: 0.01
[6.0, 11.5, 127.5]

关于python - 使用 PyGears 框架编译 python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64607280/

相关文章:

windows - 如何在 WSL 上安装 PyGears - Ubuntu 20.04 LTS

python - PyGears 元组和元组之间的区别

python - 有没有办法用 Python 创建 Eclipse 插件?

python - 避免全局变量但也避免太多函数参数(Python)

python - 显示numpy数组由rgb(255,255,255)组成作为图像,为什么它输出纯黑色而不是纯白色?

python - pandas groupby,然后按列的值选择一行(例如,最小值、最大值)

python - 使用 Python 检查互联网连接