Esempio n. 1
0
	def load(fname):
		"""
		loads the contents of the file named fname (in the Coordinate Format 
		of the Matrix Market Exchange Format) into a HyGraph instance. The
		lines of the file are interpreted as edge-number, vertex-number,
		and optional weight, just like the HyGraph constructor.

		Input Argument:
			fname:  a filename from which the HyGraph data will be loaded.
		Output Argument:
			ret:  a HyGraph instance containing the graph represented
			    by the file's contents.

		NOTE:  The Matrix Market format numbers edges and vertices from 1 to
		N.  Python and KDT number edges and vertices from 0 to N-1.  The 
		load method makes this conversion while reading the data and creating
		the graph.

		SEE ALSO:  HyGraph, save, UFget
		"""
		# Verify file exists.
		file = open(fname, 'r')
		file.close()
		
		#FIX:  crashes if any out-of-bound indices in file; easy to
		#      fall into with file being 1-based and Py being 0-based
		ret = HyGraph()
		ret._spm = pcb.pySpParMat()
		ret._spm.load(fname)
		ret._spmT = ret._spm.copy()
		ret._spmT.Transpose()
		return ret
Esempio n. 2
0
def checkmat(m, name):
    """If run on one processor it will save m. If run on multiple processors it will load the one-proc m and compare it to the argument and complain if they don't match. """
    import pyCombBLAS as pcb

    if pcb._nprocs() == 1:
        m.save("checkfile_%s" % (name))
    else:
        one = pcb.pySpParMat()
        one.load("checkfile_%s" % (name))
        test = pcb.EWiseApply(m, one, pcb.equal_to())
        if test.Count(pcb.bind2nd(pcb.equal_to(), 1)) != test.getnee():
            if pcb.root():
                print "%s failed." % (name)
Esempio n. 3
0
	def __init__(self,*args):
		"""
		creates a new HyGraph instance.  Can be called in one of the 
		following forms:

	HyGraph():  creates a HyGraph instance with no vertices or edges.  Useful
		as input for genGraph500Edges.

	HyGraph(edgeNumV, incidentVertexV, weightV, nvert, [nedge])
		create a HyGraph instance.  Each element of the first (ParVec) 
		argument denotes an edge number;  each corresponding element of
		the second (ParVec) argument denotes the number of a vertex to 
		which the edge is incident.  A single edge number can occur an 
		arbitrary number of times in the first argument; all the vertices 
		denoted for the same edge collectively define the hyperedge.  
		The third argument may be a ParVec instance or a scalar;  if a 
		ParVec, then its corresponding elements denote the weight of the
		edge for its incident vertex;  if a scalar, then it denotes the 
		weight of all edges for all incident vertices.  The nvert argument
		denotes the number of vertices in the resulting HyGraph (not all
		vertices must have incident edges).  The optional nedge argument
		denotes the number of edges in the resulting HyGraph (not all edges
		must be incident vertices).

		Input Arguments:
			edgeNumV:  a ParVec containing integers denoting the 
			    edge number of each edge.
			incidentVertexV:  a ParVec containing integers denoting 
			    incident vertices.
			weightV:  a ParVec containing double-precision floating-
			    point numbers denoting the weight of each edge incident
			    to a vertex, or a double-precision floating-point 
			    scalar denoting the weight of all edges for all
			    incident vertices.
			nvert:  an integer scalar denoting the number of vertices.
			nedge:  an optional integer scalar argument denoting the 
			    number of edges

		Output Argument:  
			ret:  a HyGraph instance

		SEE ALSO:  toParVec
		"""
		if len(args) == 0:
			self._spm = pcb.pySpParMat()
			self._spmT = pcb.pySpParMat()
		elif len(args) == 4:
			[i,j,v,nv] = args
			if len(i) != len(j):
				raise KeyError, 'first two arguments must be same length'
			if type(v) == int or type(v) == long or type(v) == float:
				v = ParVec.broadcast(len(i),v)
			ne = int(i.max()) + 1
			if j.max() > nv-1:
				raise KeyError, 'at least one second index greater than #vertices'
			self._spm = pcb.pySpParMat(ne,nv,i._dpv,j._dpv,v._dpv)
			self._spmT = self._spm.copy()
			self._spmT.Transpose()
		elif len(args) == 5:
			[i,j,v,nv,ne] = args
			if len(i) != len(j):
				raise KeyError, 'first two arguments must be same length'
			if type(v) == int or type(v) == long or type(v) == float:
				v = ParVec.broadcast(len(i),v)
			if i.max() > ne-1:
				raise KeyError, 'at least one first index greater than #edges'
			if j.max() > nv-1:
				raise KeyError, 'at least one second index greater than #vertices'
			self._spm = pcb.pySpParMat(ne,nv,i._dpv,j._dpv,v._dpv)
			self._spmT = self._spm.copy()
			self._spmT.Transpose()
		else:
			raise NotImplementedError, "only 0-, 4- and 5-argument cases supported"