sparse-matrix

How to speed up my sparse matrix solver?

风格不统一 提交于 2019-12-29 03:41:08
问题 I'm writing a sparse matrix solver using the Gauss-Seidel method. By profiling, I've determined that about half of my program's time is spent inside the solver. The performance-critical part is as follows: size_t ic = d_ny + 1, iw = d_ny, ie = d_ny + 2, is = 1, in = 2 * d_ny + 1; for (size_t y = 1; y < d_ny - 1; ++y) { for (size_t x = 1; x < d_nx - 1; ++x) { d_x[ic] = d_b[ic] - d_w[ic] * d_x[iw] - d_e[ic] * d_x[ie] - d_s[ic] * d_x[is] - d_n[ic] * d_x[in]; ++ic; ++iw; ++ie; ++is; ++in; } ic +=

Concatenate sparse matrices in Python using SciPy/Numpy

人走茶凉 提交于 2019-12-28 02:39:04
问题 What would be the most efficient way to concatenate sparse matrices in Python using SciPy/Numpy? Here I used the following: >>> np.hstack((X, X2)) array([ <49998x70000 sparse matrix of type '<class 'numpy.float64'>' with 1135520 stored elements in Compressed Sparse Row format>, <49998x70000 sparse matrix of type '<class 'numpy.int64'>' with 1135520 stored elements in Compressed Sparse Row format>], dtype=object) I would like to use both predictors in a regression, but the current format is

Represent a sparse matrix in C using the CSparse Library

巧了我就是萌 提交于 2019-12-25 18:37:35
问题 I can't understand how can easily represent a sparse matrix in C using the CSparese Library. That's what I want | 6.0 0.0 2.0 | A = | 3.0 8.0 0.0 | | 6.0 0.0 1.0 | with | 40.0 | b = | 50.0 | | 30.0 | The cs Struct of the csparse is this typedef struct cs_sparse /* matrix in compressed-column or triplet form */ { csi nzmax ; /* maximum number of entries */ csi m ; /* number of rows */ csi n ; /* number of columns */ csi *p ; /* column pointers (size n+1) or col indices (size nzmax) */ csi *i ;

Computing time complexity of the sparse matrix (2)

余生长醉 提交于 2019-12-25 18:23:53
问题 I have a data set (D) of (nxd) where n=number of rows and d= number of dimensions, I create a similarity matrix (S)(nxn) by comparing each row of the data set (D) and then convert it into a sparse matrix (tx3) where t is the number of non-zero elements of the symmetric similarity matrix (S) The time complexity of creating the similarity matrix is o(n^2d) where d is some constant operation. The time complexity of converting a sparse matrix is theta(n^2) My question is: While creating the

In Julia, The eigs() function for large sparse matrix went wrong

て烟熏妆下的殇ゞ 提交于 2019-12-25 16:48:37
问题 With Julia, I created a sparse matrix with the spzeros() function, initialized the matrix with some sentences, and tried to calculate the eigenvalue of it. However, the function works well only for small sparse matrix(n<800), for a little bit larger matrix, i got some error. The code: ns = 400 # 800 H = spzeros(Complex128, ns, ns) #... initialization E, x = eigs(H) The error message after the last sentence: LoadError: Base.LinAlg.ARPACKException("unspecified ARPACK error: 1") while loading In

Performance bottleneck in Eigen program

时光总嘲笑我的痴心妄想 提交于 2019-12-25 14:23:33
问题 As a part of a larger problem, I'm running into a performance bottle neck when dealing with Sparse Matrices in Eigen. I need to subtract a floating point number ( x ) from each element in a Sparse Matrix ( G ), including the positions where the coefficients are zero. So the zero elements should have a value -x The way I do this at the moment is as follows: //calculate G x=0.01; for(int i=0;i<rows;i++){ for (int j=0; j<cols; j++) { G.coeffRef(i, j) -= x; } } When the size of G is large, this

Performance bottleneck in Eigen program

萝らか妹 提交于 2019-12-25 14:22:19
问题 As a part of a larger problem, I'm running into a performance bottle neck when dealing with Sparse Matrices in Eigen. I need to subtract a floating point number ( x ) from each element in a Sparse Matrix ( G ), including the positions where the coefficients are zero. So the zero elements should have a value -x The way I do this at the moment is as follows: //calculate G x=0.01; for(int i=0;i<rows;i++){ for (int j=0; j<cols; j++) { G.coeffRef(i, j) -= x; } } When the size of G is large, this

What is the default indexing type of scipy.sparse.csr_matrix?

瘦欲@ 提交于 2019-12-25 09:38:53
问题 scipy.sparse.csr_matrix has data , indices , and indptr attributes. What are the default dtype of indices and indptr ? For numpy , the default indexing type is numpy.intp , but that doesn't match the dtype of indices of a scipy.sparse.csr_matrix . Documentation of scipy.sparse.csr_matrix For my laptop: import numpy as np import scipy.sparse as ss a = ss.csr_matrix(np.arange(12).reshape(3,4), dtype=float) print(a.indices.dtype) print(np.intp) Result: int32 <class 'numpy.int64'> 回答1: sparse

Creating Huge Sparse Matrices in python

為{幸葍}努か 提交于 2019-12-25 09:29:42
问题 I have been using normal matrices from numpy to store a Matrix for a physics project. The size of the matrix is determined by the physical system. So for instance if the system has parameters: L=4 and N =2, then the matrix is of dimension 4C2 = 6, so the matrix is a 6x6 matrix. This is fine except for now I need larger size i.e 20C10 = 184,756. So the matrix required is now a 184756x184756 matrix, which when I try to create an empty matrix of this size gives me a memory error. (with 16GB of

Matlab Indexing Sparse Matrix

杀马特。学长 韩版系。学妹 提交于 2019-12-25 08:37:14
问题 Let's say we have the following sparse matrix defined by this 3 vectors: [lines, columns, values] = find(A) lines = 1 2 3 5 1 3 3 5 4 5 columns = 1 2 2 2 3 3 4 4 5 5 values = 3 4 7 3 1 5 9 6 2 5 What I am trying to achieve is to access the element at the position (2, 2) I know you can do values(lines == 2) ( values(columns == 2) ) which will return all the values from second row (column). My question is how can you do something like values(lines == 2 && columns == 2) to get the value at A(2,2