Sparse-Matrix | sparse matrix using CRS | Math library
kandi X-RAY | Sparse-Matrix Summary
kandi X-RAY | Sparse-Matrix Summary
C++ implementation of sparse matrix using CRS format.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Sparse-Matrix
Sparse-Matrix Key Features
Sparse-Matrix Examples and Code Snippets
def sparse_reduce_max_v2(
sp_input, axis=None, keepdims=None, output_is_sparse=False, name=None):
"""Computes `tf.sparse.maximum` of elements across dimensions of a SparseTensor.
This is the reduction operation for the elementwise `tf.sparse
def _take_many_sparse_from_tensors_map(sparse_map_op,
sparse_handles,
rank=None,
name=None):
"""Read `SparseTensors` from a `Sparse
def sparse_reduce_max(sp_input, axis=None, keepdims=None,
reduction_axes=None, keep_dims=None):
"""Computes `tf.sparse.maximum` of elements across dimensions of a SparseTensor.
This is the reduction operation for the elemen
Community Discussions
Trending Discussions on Sparse-Matrix
QUESTION
I have to replace some columns in a sparse matrix with columns from another sparse matrix that has the same nonzero elements, just different values, based on a condition.
I am struggling with write access using iterators in Armadillo. The docs say that using sp_mat::col_iterator provides read/write access, however, when I try to write a value *it = B.col(...)
I get an error message error: no match for ‘operator=’ (operand types are ‘arma::SpValProxy >’ and ‘arma::SpSubview_col’)
. Do I have a syntax mistake or am I understanding the concept of "write access" wrong?
ANSWER
Answered 2021-Apr-29 at 13:26Looking at the (generally excellent) Armadillo documentation, I think you are up a against a design issue. Quoting
Caveats:
- to modify the non-zero elements in a safer manner, use .transform() or .for_each() instead of iterators;
- writing a zero value into a sparse matrix through an iterator will invalidate all current iterators associated with the sparse matrix row iterators for sparse matrices are only useful with Armadillo 8.500 and later versions; in earlier versions they are inefficient
QUESTION
In the following sparse matrix:
...ANSWER
Answered 2021-Mar-18 at 17:51You can specify the output size as the third input of accumarray
:
QUESTION
I have two scipy sparse matrices matrix_1 and matrix_2. Their dimensions are as follows:
...ANSWER
Answered 2021-Jan-26 at 08:07As hpaulj suggested in the comments,
QUESTION
I am need to perform transpose of a matrix(CSR) using cuSPARSE, but get “internal error”. I write my code referring to How to transpose a sparse matrix in cuSparse? and https://docs.nvidia.com/cuda/cusparse/index.html#csr2cscEx2. To make it more clearly, I am trying to perform transpose by convert the matrix from format csr to format csc.
I am running on Nvidia GeForce GTX 1080, with driver cuda_11.1.0. I am using Windows 10.
The following is my codes. You can download the folder from https://github.com/NVIDIA/CUDALibrarySamples/tree/master/cuSPARSE/sparse2dense, and replace the sparse2dense_example.c with my codes. Then configure and make using CMake, in this way maybe you can reproduce my problems.
...ANSWER
Answered 2020-Dec-09 at 15:32The error is due to the fact that you are passing pointers to host data, to a routine that intends to work on device data:
QUESTION
I have been trying different sparse solvers available in Python 3 and comparing the performance between them and also against Octave and Matlab. I have chosen both direct and iterative approaches, I will explain this more in detail below.
To generate a proper sparse matrix, with a banded structure, a Poisson's problem is solved using finite elements with squared grids of N=250, N=500 and N=1000. This results in dimensions of a matrix A=N^2xN^2 and a vector b=N^2x1, i.e., the largest NxN is a million. If one is interested in replicating my results, I have uploaded the matrices A and the vectors b in the following link (it will expire en 30 days) Get systems used here. The matrices are stored in triplets I,J,V, i.e. the first two columns are the indices for the rows and columns, respectively, and the third column are the values corresponding to such indices. Observe that there are some values in V, which are nearly zero, are left on purpose. Still, the banded structure is preserved after a "spy" matrix command in both Matlab and Python.
For comparison, I have used the following solvers:
Matlab and Octave, direct solver: The canonical x=A\b
.
Matlab and Octave, pcg solver: The preconditioned conjugated gradient, pcg solver pcg(A,b,1e-5,size(b,1))
(not preconditioner is used).
Scipy (Python), direct solver: linalg.spsolve(A, b)
where A is previously formatted in csr_matrix
format.
Scipy (Python), pcg solver: sp.linalg.cg(A, b, x0=None, tol=1e-05)
Scipy (Python), UMFPACK solver: spsolve(A, b)
using from scikits.umfpack import spsolve
. This solver is apparently available (only?) under Linux, since it make use of the libsuitesparse [Timothy Davis, Texas A&M]. In ubuntu, this has to first be installed as sudo apt-get install libsuitesparse-dev
.
Furthermore, the aforementioned python solvers are tested in:
- Windows.
- Linux.
- Mac OS.
Conditions:
- Timing is done right before and after the solution of the systems. I.e., the overhead for reading the matrices is not considered.
- Timing is done ten times for each system and an average and a standard deviation is computed.
Hardware:
- Windows and Linux: Dell intel (R) Core(TM) i7-8850H CPU @2.6GHz 2.59GHz, 32 Gb RAM DDR4.
- Mac OS: Macbook Pro retina mid 2014 intel (R) quad-core(TM) i7 2.2GHz 16 Gb Ram DDR3.
Observations:
- Matlab A\b is the fastest despite being in an older computer.
- There are notable differences between Linux and Windows versions. See for instance the direct solver at NxN=1e6. This is despite Linux is running under windows (WSL).
- One can have a huge scatter in Scipy solvers. This is, if the same solution is run several times, one of the times can just increase more than twice.
- The fastest option in python can be nearly four times slower than the Matlab running in a more limited hardware. Really?
If you want to reproduce the tests, I leave here very simple scripts. For matlab/octave:
...ANSWER
Answered 2020-Oct-20 at 12:56I will try to answer to myself. To provide an answer, I tried an even more demanding example, with a matrix of size of (N,N) of about half a million by half a million and the corresponding vector (N,1). This, however, is much less sparse (more dense) than the one provided in the question. This matrix stored in ascii is of about 1.7 Gb, compared to the one of the example, which is of about 0.25 Gb (despite its "size" is larger). See its shape here,
Then, I tried to solve Ax=b using again Matlab, Octave and Python using the aforementioned the direct solvers from scipy, the intel MKL wrapper, the UMFPACK from Tim Davis.
My first surprise is that both Matlab and Octave could solve the systems using the A\b, which is not for certain that it is a direct solver, since it chooses the best solver based on the characteristics of the matrix, see Matlab's x=A\b. However, the python's linalg.spsolve
, the MKL wrapper and the UMFPACK were throwing out-of-memory errors in Windows and Linux. In mac, the linalg.spsolve
was somehow computing a solution, and alghouth it was with a very poor performance, it never through memory errors. I wonder if the memory is handled differently depending on the OS. To me, it seems that mac swapped memory to the hard drive rather than using it from the RAM. The performance of the CG solver in Python was rather poor, compared to the matlab. However, to improve the performance in the CG solver in python, one can get a huge improvement in performance if A=0.5(A+A') is computed first (if one obviously, have a symmetric system). Using a preconditioner in Python did not help. I tried using the sp.linalg.spilu
method together with sp.linalg.LinearOperator
to compute a preconditioner, but the performance was rather poor. In matlab, one can use the incomplete Cholesky decomposition.
For the out-of-memory problem the solution was to use an LU decomposition and solve two nested systems, such as Ax=b, A=LL', y=L\b and x=y\L'.
I put here the min. solution times,
QUESTION
The following program uses Intel MKL and creates a sparse matrix from the coordinate represenation, then the matrix is exported to the CSR format.
...ANSWER
Answered 2020-Oct-16 at 14:50You need to convert your COO format to CSR beforehand.
QUESTION
I want to cast a DataFrame to sparse matrix using csr_matrix
from scipy library, but first I have to convert it to a SparseDataFrame. In previous versions of pandas I used pd.SparseDataFrame(df).to_coo()
for such purposes, but since pandas 1.0.0
this method is deprecated. Does anyone know how to perform such conversion using latest pandas api. I used this migration guide and tried various combination but still unable to achieve desired result.
Following the guide, when I do the following
ANSWER
Answered 2020-Aug-05 at 16:13IIUC and using the third link you shared, you can convert your df
data to sparse data using pd.SparseDtype
, like this
QUESTION
so my question is based on this question.
I have Twitter data where I extracted unigram features and number of orthographies features such as excalamation mark, question mark, uppercase, and lowercase. I want to stack orthographies features into transformed unigram feature. Here is my code:
...ANSWER
Answered 2020-Jun-27 at 07:48You have problems with list syntax and sparse.coo_matrix
creation.
QUESTION
I am looking for the fastest way to obtain a list of the nonzero indices of a 2D array per row and per column. The following is a working piece of code:
...ANSWER
Answered 2020-May-28 at 16:04In [182]: arr = np.array([[0,0,0,0],[1,0,0,0],[1,1,0,0],[1,1,1,0]])
QUESTION
For reference, I'm using this page. I understand the original pagerank equation
but I'm failing to understand why the sparse-matrix implementation is correct. Below is their code reproduced:
...ANSWER
Answered 2020-May-22 at 06:13This happens because in the row sums
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Sparse-Matrix
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page