本文整理汇总了Python中pysparse.spmatrix.ll_mat函数的典型用法代码示例。如果您正苦于以下问题:Python ll_mat函数的具体用法?Python ll_mat怎么用?Python ll_mat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ll_mat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setWeightMatrix
def setWeightMatrix(self, W):
"""
Set the weight matrix of this graph. Requires as input an ndarray with the
same dimensions as the current weight matrix. Edges are represented by
non-zero edges.
:param W: The name of the file to load.
:type W: :class:`ndarray`
"""
#Parameter.checkClass(W, numpy.ndarray)
if W.shape != (self.vList.getNumVertices(), self.vList.getNumVertices()):
raise ValueError("Weight matrix has wrong shape : " + str(W.shape))
if self.undirected and type(W) == numpy.ndarray and (W != W.T).any():
raise ValueError("Weight matrix of undirected graph must be symmetric")
self.W = spmatrix.ll_mat(self.getNumVertices(), self.getNumVertices())
if type(W) == numpy.ndarray:
rowInds, colInds = numpy.nonzero(W)
self.W.put(W[(rowInds, colInds)], rowInds, colInds)
elif isinstance(W, spmatrix.LLMatType):
self.setWeightMatrixSparse(W)
else:
raise ValueError("Invalid matrix type: " + str(type(W)))
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:26,代码来源:PySparseGraph.py
示例2: __init__
def __init__(self, **kwargs):
nrow = kwargs.get('nrow', 0)
ncol = kwargs.get('ncol', 0)
bandwidth = kwargs.get('bandwidth', 0)
matrix = kwargs.get('matrix', None)
sizeHint = kwargs.get('sizeHint', 0)
symmetric = 'symmetric' in kwargs and kwargs['symmetric']
size = kwargs.get('size',0)
if size > 0:
if nrow > 0 or ncol > 0:
if size != nrow or size != ncol:
msg = 'size argument was given but does not match '
msg += 'nrow and ncol'
raise ValueError, msg
else:
nrow = ncol = size
if matrix is not None:
self.matrix = matrix
else:
if symmetric and nrow==ncol:
if sizeHint is None:
sizeHint = nrow
if bandwidth > 0:
sizeHint += 2*(bandwidth-1)*(2*nrow-bandwidth-2)
self.matrix = spmatrix.ll_mat_sym(nrow, sizeHint)
else:
if sizeHint is None:
sizeHint = min(nrow,ncol)
if bandwidth > 0:
sizeHint = bandwidth * (2*sizeHint-bandwidth-1)/2
self.matrix = spmatrix.ll_mat(nrow, ncol, sizeHint)
开发者ID:regmi,项目名称:pysparse,代码行数:33,代码来源:pysparseMatrix.py
示例3: testEntry
def testEntry(self):
def assignUP(): self.S[0,1] = 1.0
def assignLeft(): self.S[-11,0] = 1.0
def assignRight(): self.S[10,0] = 1.0
def assignTop(): self.S[0,-11] = 1.0
def assignBottom(): self.S[0,10] = 1.0
self.A[0,0] = 1.0
self.S[0,0] = 1.0
self.failUnless(self.A[0,0] == 1.0)
self.failUnless(self.A.nnz == 1)
self.failUnless(self.S[0,0] == 1.0)
self.failUnless(self.S.nnz == 1)
self.failUnlessRaises(IndexError, assignUP)
self.A[0,0] += 1.0
self.failUnless(self.A[0,0] == 2.0)
self.failUnless(self.A.nnz == 1)
self.A[0,0] -= 2.0
self.failUnless(self.A[0,0] == 0.0)
self.failUnless(self.A.nnz == 0)
# indices out of bounds
#for f in [assignLeft, assignRight, assignTop, assignBottom]:
#for f in [assignRight, assignTop, assignBottom]:
# self.failUnlessRaises(IndexError, f)
self.failUnlessRaises(IndexError, assignRight)
self.failUnlessRaises(IndexError, assignTop)
self.failUnlessRaises(IndexError, assignBottom)
# negative indices
I = spmatrix.ll_mat(10, 10, 100)
for i in range(10):
for j in range(10):
I[i,j] = 10*i + j
for i in range(-10, 0):
for j in range(-10, 0):
self.failUnless(I[i,j] == I[10+i,10+j])
开发者ID:regmi,项目名称:pysparse,代码行数:35,代码来源:test_spmatrix.py
示例4: getSparseWeightMatrix
def getSparseWeightMatrix(self, format="lil"):
"""
Returns a weight matrix representation of the graph as a scipy sparse
lil_matrix by default. The indices in the matrix correspond to the keys
returned by getAllVertexIds. Edge labels are assigned to 1 for edges with
non-numeric values. Available formats are: lil for scipy.sparse.lil_matrix,
csr for scipy.sparse.csr_matrix, csc for scipy.sparse.csc_matrix, and
pysparse for pysparse's ll_mat.
:param format: The format of the sparse matrix.
"""
if format=="lil":
W = scipy.sparse.lil_matrix((self.size, self.size))
W = self.__populateWeightMatrix(W)
elif format=="csr":
W = scipy.sparse.lil_matrix((self.size, self.size))
W = self.__populateWeightMatrix(W)
W = W.tocsr()
elif format=="csc":
W = scipy.sparse.lil_matrix((self.size, self.size))
W = self.__populateWeightMatrix(W)
W = W.tocsc()
elif format=="pysparse":
from pysparse import spmatrix
W = spmatrix.ll_mat(self.size, self.size)
W = self.__populateWeightMatrix(W)
else:
raise ValueError("Invalid format: " + format)
return W
开发者ID:charanpald,项目名称:APGL,代码行数:30,代码来源:DictGraph.py
示例5: removeAllEdges
def removeAllEdges(self):
"""
Removes all edges from this graph.
"""
#Not sure why this doesn't work
#self.W.scale(0)
self.W = spmatrix.ll_mat(self.getNumVertices(), self.getNumVertices())
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:7,代码来源:PySparseGraph.py
示例6: _thckEvolve
def _thckEvolve(self,rhs,ans,mask,calc_rhs,old_thck,new_thck,diffu,lsrf,acab):
matrix = pysp.ll_mat(self.totpts,self.totpts)
# Boundary Conditions ---------------------------------------------------------------
self._applyULBCs(matrix,old_thck,new_thck,self.mask,calc_rhs,rhs,ans)
self._applyLRBCs(matrix,old_thck,new_thck,self.mask,calc_rhs,rhs,ans)
# Ice body
sumd = np.zeros(5,dtype=np.float)
for ns in range(1,self.mainGrid.ny-1):
for ew in range(1,self.mainGrid.nx-1):
if mask[ew,ns] != 0:
self._findSums(diffu,sumd,ew-1,ew,ns-1,ns)
# Matrix elements
self._fillMatrix(matrix,self.mask,sumd,ew,ns)
# RHS vector
if calc_rhs:
rhs[mask[ew,ns]-1] = self._calcRHS(old_thck,lsrf,acab,sumd,ew,ns)
ans[mask[ew,ns]-1] = new_thck[ew,ns]
# Solve system
self._solveSystem(matrix,rhs,ans)
# Rejig the solution onto a 2D array
self._regrid(new_thck,self.mask,ans)
# Remove negatives
new_thck[:] = np.maximum(0.0,new_thck)
开发者ID:BackupTheBerlios,项目名称:sms2009-svn,代码行数:30,代码来源:pyglimThck.py
示例7: initA
def initA(self, urt=None, nu=0, nr=0, nt=0):
'''
Create the relation matrix A
A is an adjacency matrix for the graph, where:
- graph nodes are either users, resources or tags)
- edges link either users and tags, users and resources or resources and tags
'''
# beginning positions for users, resources and tags in the matrix
self.u_beg = 0
self.r_beg = self.nu
self.t_beg = self.nu + self.nr
if urt == None:
urt = []
# total number of entities --> gives the size of the matrix
self.n = self.nu + self.nr + self.nt
# create the relation matrix A
self.A = spmatrix.ll_mat(self.n, self.n)
# create adjacency matrix in the graph
for u,r,t in urt:
i = self.u_beg + u
j = self.r_beg + r
k = self.t_beg + t
self.A[i,j] = self.A[j,i] = self.A[i,j] + 1
self.A[i,k] = self.A[k,i] = self.A[i,k] + 1
self.A[k,j] = self.A[j,k] = self.A[k,j] + 1
开发者ID:Awais22000,项目名称:folkrank,代码行数:29,代码来源:folkRank.py
示例8: _convert_mat
def _convert_mat(mtx):
from pysparse import spmatrix
A = spmatrix.ll_mat(*mtx.shape)
for i in range(mtx.indptr.shape[0] - 1):
ii = slice(mtx.indptr[i], mtx.indptr[i+1])
n_in_row = ii.stop - ii.start
A.update_add_at(mtx.data[ii], [i] * n_in_row, mtx.indices[ii])
return A
开发者ID:rc,项目名称:sfepy,代码行数:8,代码来源:eigen.py
示例9: poisson1d_vec
def poisson1d_vec(n):
L = spmatrix.ll_mat(n, n, 3*n-2)
e = numpy.ones(n)
d = numpy.arange(n, dtype=numpy.int)
L.put(2*e, d, d)
L.put(-e[1:], d[1:], d[:-1])
L.put(-e[1:], d[:-1], d[1:])
return L
开发者ID:regmi,项目名称:pysparse,代码行数:8,代码来源:poisson_vec.py
示例10: __init__
def __init__(self, size, bandwidth=0, sizeHint=None, matrix=None, storeZeros=True):
"""Creates a `_PysparseMatrix`.
:Parameters:
- `mesh`: The `Mesh` to assemble the matrix for.
- `bandwidth`: The proposed band width of the matrix.
- `storeZeros`: Instructs pysparse to store zero values if possible.
"""
sizeHint = sizeHint or size * bandwidth
if matrix is None:
tmpMatrix = spmatrix.ll_mat(1, 1, 1)
if hasattr(tmpMatrix, "storeZeros"):
matrix = spmatrix.ll_mat(size, size, sizeHint, storeZeros)
else:
matrix = spmatrix.ll_mat(size, size, sizeHint)
_PysparseMatrixBase.__init__(self, matrix=matrix)
开发者ID:huahbo,项目名称:FiPy-2.1.3,代码行数:18,代码来源:pysparseMatrix.py
示例11: profileSlicePys
def profileSlicePys(self):
A = spmatrix.ll_mat(self.N, self.N)
A.put(self.val, self.rowInds, self.colInds)
def runSlice():
for i in range(10):
sliceInds = numpy.array(numpy.random.randint(0, self.M, self.N), dtype=numpy.int32)
B = A[:, sliceInds]
ProfileUtils.profile('runSlice()', globals(), locals())
开发者ID:ElectronicRU,项目名称:sppy,代码行数:10,代码来源:arrayProfile.py
示例12: testInit
def testInit(self):
numVertices = 0
numFeatures = 1
vList = VertexList(numVertices, numFeatures)
graph = PySparseGraph(vList)
numVertices = 10
numFeatures = 1
vList = VertexList(numVertices, numFeatures)
graph = PySparseGraph(vList)
self.assertRaises(ValueError, PySparseGraph, [])
self.assertRaises(ValueError, PySparseGraph, vList, 1)
self.assertRaises(ValueError, PySparseGraph, vList, True, 1)
#Now test invalid values of W
W = scipy.sparse.csr_matrix((numVertices, numVertices))
self.assertRaises(ValueError, PySparseGraph, vList, True, W)
W = numpy.zeros((numVertices+1, numVertices))
self.assertRaises(ValueError, PySparseGraph, vList, True, W)
W = numpy.zeros((numVertices, numVertices))
W[0, 1] = 1
self.assertRaises(ValueError, PySparseGraph, vList, True, W)
W = spmatrix.ll_mat(numVertices, numVertices)
graph = PySparseGraph(vList, W=W)
self.assertTrue(isinstance(W, spmatrix.LLMatType))
#Test intialising with non-empty graph
numVertices = 10
W = spmatrix.ll_mat(numVertices, numVertices)
W[1, 0] = 1.1
W[0, 1] = 1.1
graph = PySparseGraph(numVertices, W=W)
self.assertEquals(graph[1, 0], 1.1)
#Test just specifying number of vertices
graph = PySparseGraph(numVertices)
self.assertEquals(graph.size, numVertices)
开发者ID:charanpald,项目名称:APGL,代码行数:43,代码来源:PySparseGraphTest.py
示例13: nativeAdjacencyMatrix
def nativeAdjacencyMatrix(self):
"""
Return the adjacency matrix in sparse format.
"""
A = spmatrix.ll_mat(self.vList.getNumVertices(), self.vList.getNumVertices())
nonzeros = PySparseUtils.nonzero(self.W)
A.put(1, nonzeros[0], nonzeros[1])
return A
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:10,代码来源:PySparseGraph.py
示例14: profileSumPys
def profileSumPys(self):
A = spmatrix.ll_mat(self.N, self.N)
A.put(self.val, self.rowInds, self.colInds)
def runSum():
for i in range(1000):
i = PySparseUtils.sum(A)
print(i)
ProfileUtils.profile('runSum()', globals(), locals())
开发者ID:ElectronicRU,项目名称:sppy,代码行数:10,代码来源:arrayProfile.py
示例15: profileGetNonZerosPys
def profileGetNonZerosPys(self):
A = spmatrix.ll_mat(self.N, self.N)
A.put(self.val, self.rowInds, self.colInds)
def runNonZeros():
for i in range(1000):
(rows, cols) = PySparseUtils.nonzero(A)
nzVals = numpy.zeros(len(rows))
A.take(nzVals, rows, cols)
ProfileUtils.profile('runNonZeros()', globals(), locals())
开发者ID:ElectronicRU,项目名称:sppy,代码行数:11,代码来源:arrayProfile.py
示例16: convert_mat
def convert_mat(mtx):
"""
Converts a scipy matrix "mtx" to a pysparse matrix.
"""
mtx = mtx.tocsr()
A = spmatrix.ll_mat(*mtx.shape)
for i in xrange( mtx.indptr.shape[0] - 1 ):
ii = slice( mtx.indptr[i], mtx.indptr[i+1] )
n_in_row = ii.stop - ii.start
A.update_add_at( mtx.data[ii], [i] * n_in_row, mtx.indices[ii] )
return A
开发者ID:certik,项目名称:schroedinger,代码行数:11,代码来源:schroedinger.py
示例17: inDegreeSequence
def inDegreeSequence(self):
"""
Return a vector of the (in)degree sequence for each vertex.
"""
A = self.nativeAdjacencyMatrix()
j = spmatrix.ll_mat(self.vList.getNumVertices(), 1)
j[:, 0] = 1
degrees = spmatrix.dot(A, j)
degrees = PysparseMatrix(matrix=degrees)
degrees = numpy.array(degrees.getNumpyArray().ravel(), numpy.int)
return degrees
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:12,代码来源:PySparseGraph.py
示例18: __init__
def __init__(self, rows, cols, bandwidth=0, sizeHint=None, matrix=None, storeZeros=True):
"""Instantiates and wraps a pysparse `ll_mat` matrix
:Parameters:
- `rows`: The number of matrix rows
- `cols`: The number of matrix columns
- `bandwidth`: The proposed band width of the matrix.
- `sizeHint`: estimate of the number of non-zeros
- `matrix`: pre-assembled `ll_mat` to use for storage
- `storeZeros`: Instructs pysparse to store zero values if possible.
"""
sizeHint = sizeHint or max(rows, cols) * bandwidth
if matrix is None:
tmpMatrix = spmatrix.ll_mat(1, 1, 1)
if hasattr(tmpMatrix, 'storeZeros'):
matrix = spmatrix.ll_mat(rows, cols, sizeHint, storeZeros)
else:
matrix = spmatrix.ll_mat(rows, cols, sizeHint)
_PysparseMatrix.__init__(self, matrix=matrix)
开发者ID:usnistgov,项目名称:fipy,代码行数:21,代码来源:pysparseMatrix.py
示例19: poisson2d_vec
def poisson2d_vec(n):
n2 = n*n
L = spmatrix.ll_mat(n2, n2, 5*n2-4*n)
d = numpy.arange(n2, dtype=numpy.int)
L.put(4.0, d)
L.put(-1.0, d[:-n], d[n:])
L.put(-1.0, d[n:], d[:-n])
for i in xrange(n):
di = d[i*n:(i+1)*n]
L.put(-1.0, di[1:], di[:-1])
L.put(-1.0, di[:-1], di[1:])
return L
开发者ID:anadahalli,项目名称:csc-pysparse,代码行数:12,代码来源:poisson2dvec.py
示例20: testCompressStress
def testCompressStress(self):
n = 20
A = spmatrix.ll_mat(n, n)
for k in range(20):
for i in range(n*n/2):
i = random.randrange(n)
j = random.randrange(n)
A[i, j] = 1.0
for i in range(n*n/2):
i = random.randrange(n)
j = random.randrange(n)
A[i, j] = 0.0
开发者ID:regmi,项目名称:pysparse,代码行数:12,代码来源:test_spmatrix.py
注:本文中的pysparse.spmatrix.ll_mat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论