예제 #1
0
def dot(din: Queue[Tuple[Uint[8], Fixp]]):
    coef_t = din.dtype.data[1]
    accum_t = Fixp[coef_t.integer + 2, coef_t.width + 2]

    return din \
        | queuemap(f=mul) \
        | accum(init=accum_t(0.0), cast=saturate) \
        | qround \
        | saturate(t=Uint[8])
예제 #2
0
def filter(din: Queue[Uint[8]], *, coeffs, precision=32):
    accum_t = Ufixp[10, 10 + precision]

    coeff = qrange(3*3) \
        | flatten \
        | rom(data=coeffs, dtype=Ufixp[0, precision])

    return czip(din, coeff) \
        | queuemap(f=mul) \
        | accum(init=accum_t(0.0), cast=saturate) \
        | qround \
        | saturate(t=Uint[8])
예제 #3
0
def filter(pixels: Queue[Uint[8]], coef: Queue[Fixp], *, window_num):
    coef_t = coef.dtype.data
    accum_t = Fixp[coef_t.integer + 2, coef_t.width + 2]

    window_cnt = replicate(window_num, 3 * 3)

    mem_wr_data = czip(qcnt(coef, running=True, w_out=4, init=0),
                       coef) | flatten

    coef_rd = qrange(window_cnt['data']) \
        | flatten \
        | sdp(wr_addr_data=mem_wr_data, depth=16)

    return czip(pixels, coef_rd) \
        | queuemap(f=mul) \
        | accum(init=accum_t(0.0), cast=saturate) \
        | qround \
        | saturate(t=Uint[8])
예제 #4
0
def test_accum_trunc_directed(sim_cls):
    def add(x, y):
        return trunc(x + y, Uint[8])

    accum_test(accum(sim_cls=sim_cls, cast=trunc), add)
예제 #5
0
def test_accum_dflt_directed(sim_cls):
    def add(x, y):
        return saturate(x + y, Uint[8])

    accum_test(accum(sim_cls=sim_cls), add)
예제 #6
0
from pygears.lib import drv, check, accum
from pygears.typing import Queue, Uint

drv(t=Queue[Uint[4]], seq=[[0, 1, 2, 3, 4]]) \
    | accum(init=Uint[8](0)) \
    | check(ref=[10])
예제 #7
0
 def accum_wrp(din):
     return accum(din, Uint[32](2))