def test_applying_binary_function(self):
        class MyOperator(PcbOperator):
            def test_binop(self, x, y):
                return x + y

        ops = MyOperator([Operator("test_binop", comm=True, assoc=True)])

        import kdt.pyCombBLAS as pcb
        d = pcb.pyDenseParVec(10, -5)
        s = pcb.pyDenseParVec(10, 5)

        # this applies test_binop(x,y) for x,y in s,d
        s.EWiseApply(d, ops.test_binop)

        # test to see if the op worked
        for x in xrange(10):
            self.assertEqual(s[x], 0)
Example #2
0
def bfsTreeEWise(G, root, sym=False):
	import kdt.pyCombBLAS as pcb
	
	if not sym:
		G.T()
	parents = pcb.pyDenseParVec(G.nvert(), -1)
	frontier = pcb.pySpParVec(G.nvert())
	parents[root] = root
	frontier[root] = root
	
	def iterop(vals):
		#print "visiting ",vals[2]
		# vals[0] = frontier value
		# vals[1] = parents value
		# vals[2] = index
		if (vals[1] == -1):
			# discovered new vertex. Update parents and set frontier's value to its index
			vals[1] = vals[0]
			vals[0] = vals[2]
		else:
			# vertex already discovered. Remove it from the frontier
			vals[0] = None
	
	ops = 0;
	while frontier.getnee() > 0:
		G._spm.SpMV_SelMax_inplace(frontier)
		#opss = time.time()
		#pcb.EWise(iterop, [pcb.EWise_OnlyNZ(frontier), parents, pcb.EWise_Index()])
		pcb.Graph500VectorOps(frontier, parents)
		#ops = ops + (time.time() - opss)
	
	#print "time: %fs"%(ops)
	
	if not sym:
		G.T()
	return kdt.ParVec.toParVec(parents)