Beispiel #1
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)
Beispiel #2
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)
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