Exemple #1
0
	def set(self, value):
		"""
		sets the value of every edge incident to every vertex in the 
		graph to the given value.

		Input Arguments:
			self:  a HyGraph instance, modified in place.
			value:  a scalar integer or double-precision floating-
			    point value.

		Output Argument:
			None.

		SEE ALSO:  ones
		"""
		self._spm.Apply(pcb.set(value))
		self._spmT.Apply(pcb.set(value))
		return
Exemple #2
0
def k2validate(G, root, parents):

	ret = 1;	# assume valid
	nrowG = G.getnrow();

	# calculate level in the tree for each vertex; root is at level 0
	# about the same calculation as bfsTree, but tracks levels too
	parents2 = pcb.pyDenseParVec(nrowG, -1);
	fringe = pcb.pySpParVec(nrowG);
	parents2[root] = root;
	fringe[root] = root;
	levels = pcb.pyDenseParVec(nrowG, -1);
	levels[root] = 0;

	level = 1;
	while fringe.getnee() > 0:
		fringe.setNumToInd();
		G.SpMV_SelMax_inplace(fringe);
		pcb.EWiseMult_inplacefirst(fringe, parents2, True, -1);
		#fringe.printall();
		parents2.ApplyMasked(pcb.set(0), fringe);
		parents2.add(fringe);
		levels.ApplyMasked(pcb.set(level), fringe);
		level += 1;
	
	# spec test #1
	#	Not implemented
	

	# spec test #2
	#    tree edges should be between verts whose levels differ by 1
	
	#print "starting spec test#2"
	#  root = element of parents that points to itself
	##tmp1 = parents.copy()
	##tmp1 -= pcb.pyDenseParVec.range(nrowG,0)
	##root = tmp1.FindInds_NotEqual(0);
	#treeEdges = ((parents <> -1) & (parents <> root);
	tmp1 = parents.copy();
	tmp1[root] = -1;
	treeEdges = tmp1.FindInds(pcb.bind2nd(pcb.not_equal_to(), -1));
	#treeI = parents[treeEdges]
	treeI = parents.SubsRef(treeEdges);
	#treeJ = 1..nrowG[treeEdges]
	treeJ = pcb.pyDenseParVec.range(nrowG,0).SubsRef(treeEdges);
	#if any(levels[treeI]-levels[treeJ] <> -1):
	tmp1 = levels.SubsRef(treeI);
	tmp1 -= levels.SubsRef(treeJ);
	tmp2 = tmp1.FindInds(pcb.bind2nd(pcb.not_equal_to(), -1));
	if tmp2.getnee():
		print "spec test #2 failed."
		ret = -1;

	# spec test #3
	#	Not implemented

	# spec test #4
	#	Not implemented

	# spec test #5
	#	Not implemented

	

	del G, parents, parents2, fringe, levels, tmp1, tmp2, treeEdges, treeI, treeJ
	
	return ret
Exemple #3
0
#degrees = pcb.pyDenseParVec(4, 0);
k1time = 0.0

if len(sys.argv) >= 2:
	scale = int(sys.argv[1])

if (scale < 0):
	if len(sys.argv) >= 3:
		path = sys.argv[2]
	else:
		print "Expecting a path to a matrix file as argument."
		sys.exit();

	print "loading matrix from %s"%(path)
	A.load(path)
	A.Apply(pcb.set(1))
	#print "converting to boolean" # already boolean
	#A = pcb.pySpParMatBool(A)
	n = A.getnrow()
	
	colreducer = pcb.pyDenseParVec(n, 1).sparse();
	degrees = A.SpMV_PlusTimes(colreducer).dense();

else:
	if (pcb.root()):
		print "Generating RMAT with 2**%d nodes" %(scale)
	k1time = A.GenGraph500Edges(scale)
	A.Apply(pcb.set(1))
	degrees = A.Reduce(pcb.pySpParMat.Column(), pcb.plus());
	if (pcb.root()):
		print "Generation took %lf s"%(k1time)
def k2Validate(G, start, parents):
	good = True
	
	[valid, levels] = G.isBfsTree(start, parents)
	#	isBfsTree implements Graph500 tests 1 and 2 
	if not valid:
		if kdt.master():
			print "isBfsTree detected failure of Graph500 test %d" % abs(ret)
		return False

	# Spec test #3:
	# every input edge has vertices whose levels differ by no more than 1
	edgeMax = kdt.SpParVec.toSpParVec(G._spm.SpMV_SelMax(levels.toSpParVecAll()._spv))
	edgeMin = -kdt.SpParVec.toSpParVec(G._spm.SpMV_SelMax((-levels).toSpParVecAll()._spv))
	if ((edgeMax-edgeMin) > 1).any():
		if kdt.master():
			print "At least one graph edge has endpoints whose levels differ by more than one"
		good = False

	# Spec test #4:
	# the BFS tree spans a connected component's vertices (== all edges 
	# either have both endpoints in the tree or not in the tree, or 
	# source is not in tree and destination is the root)

	# set not-in-tree vertices' levels to -2
	import pyCombBLAS as pcb
	levels._dpv.Apply(pcb.ifthenelse(pcb.bind2nd(pcb.equal_to(),-1), pcb.set(-2), pcb.identity()))
	edgeMax = kdt.SpParVec.toSpParVec(G._spm.SpMV_SelMax(levels.toSpParVecAll()._spv))
	edgeMin = -kdt.SpParVec.toSpParVec(G._spm.SpMV_SelMax((-levels).toSpParVecAll()._spv))
	if ((edgeMax-edgeMin) > 1).any():
		if kdt.master():
			print "The tree does not span exactly the connected component, root=%d"
		good = False

	# Spec test #5:
	# a vertex and its parent are joined by an edge of the original graph,
	# except for the root, which has no parent in the tree
	Gnv = G.nvert(); Gne = G.nedge()
	[Gi, Gj, ign] = G.toParVec()
	del ign
	# non-root tree vertices == NRT Vs
	NRTVs = (levels!=-2) & (parents!=kdt.ParVec.range(Gnv))
	nNRTVs = NRTVs.nnz()
	TGi = kdt.ParVec.range(nNRTVs)
	TGj1 = kdt.ParVec.range(Gnv)[NRTVs]
	TGj2 = parents[NRTVs]
	M = max(Gne, Gnv)
	#FIX:  really should use SpParMats here, as don't need spm and spmT	
	tmpG1 = kdt.HyGraph(TGi, TGj1, 1, M, Gnv)
	tmpG2 = kdt.HyGraph(TGi, TGj2, 1, M, Gnv)
	tmpG1._spm  += tmpG2._spm
	tmpG1._spmT += tmpG2._spmT
	del tmpG2
	tmpG3 = kdt.HyGraph(Gi, Gj, 1, M, Gnv)
	tmpG4 = kdt.DiGraph()
	tmpG4._spm = tmpG1._spm.SpMM(tmpG3._spmT)  #!?  not tmp3._spmT ?
	maxIncid = tmpG4.max(kdt.DiGraph.Out)[kdt.ParVec.range(Gnv) < nNRTVs]
	if (maxIncid != 2).any():
		if kdt.master():
			print "At least one vertex and its parent are not joined by an original edge"
		good = False

	return good
Exemple #5
0
	def degree(self):
		"""
		calculates the degree of each vertex of the passed HyGraph instance.

		Input Arguments:
			self:  a HyGraph instance

		Output Argument:
			ret:  a ParVec instance with each element containing the
			    degree of the corresponding vertex.

		SEE ALSO:  sum 
		"""
		if self.nedge() == 0:
			return ParVec.zeros(self.nvert())
		ret = self._spm.Reduce(pcb.pySpParMat.Column(),pcb.plus(), pcb.ifthenelse(pcb.bind2nd(pcb.not_equal_to(), 0), pcb.set(1), pcb.set(0)))
		return ParVec.toParVec(ret)
Exemple #6
0
	def npin(self):
		"""
		calculates the cardinality of each edge of the passed HyGraph 
		instance.

		Input Arguments:
			self:  a HyGraph instance

		Output Argument:
			ret:  a ParVec instance with each element containing the
			    cardinality of the corresponding edge.

		SEE ALSO:  rank, antirank 
		"""
		if self.nedge() == 0:
			return ParVec.zeros(self.nedge())
		ret = self._spm.Reduce(pcb.pySpParMat.Row(),pcb.plus(), pcb.ifthenelse(pcb.bind2nd(pcb.not_equal_to(), 0), pcb.set(1), pcb.set(0)))
		return ParVec.toParVec(ret)