Пример #1
0
def mk_sum(elt_t):
  array_t = parakeet.ndtypes.make_array_type(elt_t, 1)
  f, b, (x,) = parakeet.build_fn([array_t], elt_t)
  n = b.len(x)
  total, total_after, merge = b.loop_var('total', b.zero(elt_t))
  def loop_body(idx):
    b.assign(total_after, b.add(total, b.index(x,idx)))
  b.loop(0, n, loop_body, merge = merge)
  b.return_(total)
  return f 
Пример #2
0
def mk_sum(elt_t):
    array_t = parakeet.ndtypes.make_array_type(elt_t, 1)
    f, b, (x, ) = parakeet.build_fn([array_t], elt_t)
    n = b.len(x)
    total, total_after, merge = b.loop_var('total', b.zero(elt_t))

    def loop_body(idx):
        b.assign(total_after, b.add(total, b.index(x, idx)))

    b.loop(0, n, loop_body, merge=merge)
    b.return_(total)
    return f
Пример #3
0
def mk_vec_add(array_t):
  elt_t = parakeet.elt_type(array_t)
  add_fn = mk_scalar_add(elt_t)
  fn, builder, inputs = parakeet.build_fn([array_t, array_t, array_t])
  x,y,z = inputs
  n = builder.len(x)
  def loop_body(idx):
    elt_x = builder.index(x, idx)
    elt_y = builder.index(y, idx)
    builder.setidx(z, idx, builder.call(add_fn, (elt_x, elt_y)))
  builder.loop(0, n, loop_body)
  builder.return_(builder.none)
  return fn 
Пример #4
0
def mk_vec_add(array_t):
    elt_t = parakeet.elt_type(array_t)
    add_fn = mk_scalar_add(elt_t)
    fn, builder, inputs = parakeet.build_fn([array_t, array_t, array_t])
    x, y, z = inputs
    n = builder.len(x)

    def loop_body(idx):
        elt_x = builder.index(x, idx)
        elt_y = builder.index(y, idx)
        builder.setidx(z, idx, builder.call(add_fn, (elt_x, elt_y)))

    builder.loop(0, n, loop_body)
    builder.return_(builder.none)
    return fn
Пример #5
0
def mk_adder(t):
    f, b, (x, y) = parakeet.build_fn([t, t], t)
    b.return_(b.add(x, y))
    return f
def mk_adder(t):
  f, b, (x,y) = parakeet.build_fn([t,t], t)
  b.return_(b.add(x,y))
  return f