def test_binary_op(self): assert np.all(jt.binary(1, 2, 'maximum').data == 2) assert np.all(jt.binary([[1, 2]], [[3, 4]], 'add').data == [[4, 6]]) assert np.all(jt.less(1, 2).data) assert jt.less(1, 2).data.dtype == "bool" x = (jt.array(1) << jt.array(3)).data assert (x == 8).all() x = (jt.array(2)**jt.array(3)).data assert (x == 8).all() a = np.array([1, 2, 3]) b = np.array([7, 10, 13]) check("logical_and", a, b) check("logical_or", a, b) check("logical_xor", a, b) check("bitwise_and", a, b) check("bitwise_or", a, b) check("bitwise_xor", a, b)
def run(): start_time = time.time() fop_num = 10000 fop_input_num = (2, 3) # (i,j) -> [i,i+j] -> [2, 5] # fop_output_num = (1, 0) # [1,1] inner_op_num = (0, 3) fop_type_num = 63 # how many different fuse op input_queue_num = 15 queue = [1.0]*(input_queue_num+1) x = get_xorshf96() rand = lambda x, l, r: l+((x())&r) ops = ["add", "subtract", "multiply", "divide"] get_op = lambda x: ops[(x())&3] for i in range(fop_num): prev = bc(queue[rand(x,0,input_queue_num)]) y = get_xorshf96(x()&fop_type_num) inum = rand(y, *fop_input_num) q = [prev] for i in range(inum-1): n = bc(queue[rand(x,0,input_queue_num)]) prev = jt.binary(prev, n, get_op(y)) q.append(prev) innum = rand(y,*inner_op_num) for _ in range(innum): j = rand(y,0,len(q)-1) n = q[j] prev = jt.binary(prev, n, get_op(y)) q[j] = prev prev = rd(prev) queue[rand(x,0,input_queue_num)] = prev a = jt.array(0.0) for x in queue: a += x LOG.i("build graph", time.time()-start_time, jt.liveness_info().values()) start_time = time.time() a.sync() LOG.i("execute", time.time()-start_time)