# Questions tagged [sparse-arrays]

Questions on the construction and manipulation of sparse arrays in Mathematica, with functions like SparseArray[] and Band[].

58 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1k views

### LinearSolve and Krylov Method options

I need to solve a large, sparse, linear system. At some point Method -> "Multifrontal" fails and a bit later also "Pardiso" ...
• 7,123
362 views

### Matrix-free Arnoldi method for eigensystems

I am solving a generalized eigenvalue problem $$\mathbf S\,\mathbf x = \lambda\,\mathbf M\,\mathbf x$$ w/ $\mathbf S := \mathbf B\,\mathbf A^{-1}\,\mathbf B^{T}$, and $\mathbf A$ is a sparse ...
• 201
218 views

### Bug in PositiveDefiniteMatrixQ?

Fixed in 10.1.0. Exists in at least 9.0.1 -- 10.0.2. This seems like a bug in PositiveDefiniteMatrixQ to me: ...
• 6,021
185 views

### Defining a SparseArray functions in Mathematica 13

I am defining a sparse array as a function of argument x, i.e. f[x_] = SparseArray[{1->x}, {3}] In Mathematica 12 this works perfectly, I can pass arguments and ...
• 91
146 views

### LibraryLink: Create SparseArray directly from row pointers and column indices

In Mathematica, sparse arrays use a CSR representation. Suppose I already have data in this format. Is there a way to create an MSparseArray from it directly with ...
• 236k
55 views

### Is there a way to make SparseArray distinguish between background values of different precision that are numerically equal?

To illustrate what I mean, consider the following: SparseArray[{{1} -> 1, {5} -> 1.}, Automatic, 0] // Normal {1, 0, 0, 0, 1.} As you can see, the ...
• 23.8k
191 views

### Memory usage for smallest eigenvalues

I have a bunch of hermitian matrices which are huge (of order 2^17 x 2^17) but extremely sparse so that, when I build the matrices, the usage of RAM is low (say of order 1 GB or similar). The ...
• 355
135 views

### Reproducible kernel crash using Eigensystem with Arnoldi on SparseArray

Using Arnoldi method to find some eigenvalues (say 20), with shift value taken in the middle of the spectrum, of a large sparse matrix the Kernel crashes with no error returned. The crash occurs if ...
121 views

### Trying to create rank-1 SparseArray through LibraryLink causes crash

Bug introduced in 10.0 or earlier and fixed in 11.3 When I try to create a 2D SparseArray through LibraryLink's MSparseArray_fromExplicitPositions, it works fine. ...
• 236k
780 views

### Finding eigenvalues in Mathematica: why so slow?

I am trying to find the eigensystem of a large sparse real symmetric matrix, and I only need the lowest 40 or so eigenstates. The relevant code is as follows: ...
• 111
110 views

### How to efficiently build a large sparse matrix and overloading a compiled function?

I would like to construct a large sparse matrix folding from rank-4 tensor given by the following: $\mathcal{L}_{1L}^{00}(i,j)=\mathcal{L}_{1L}^{00}(m_1,m_2;M_1,M_2)$ The indices of matrix $(i,j)$ are ...
• 445
267 views

### Insufficient memory problem in Mathematica

I am trying to initialize a 48600 x 48600 packed array from a sparse matrix and a diagonal matrix in Mathematica 8. If S1 is a sparsearray of that size then and S2 is list of 48600 length, then I am ...
128 views

### ParametricNDSolveValue with SparseArrays

I want to solve large, sparse matrix systems with ParametricNDSolveValue and was hoping to use SparseArray to speed up the computation. However I find that ParametricNDSolveValue doesn't seem to work ...
• 2,082
199 views

### Loopy Belief Propagation

I look for an efficient way to implement a Belief Propagation in Pairwise Markov Random Field. Each node is a binary random variable, and the unary potential function is ...
• 2,019
75 views

### NetTrain doesn't accept sparse input?

The following code fails to execute: ...
97 views

### Why is SparseArray atomic?

This answer tells us that functions like ReplaceAll do not straightforwardly work for the entries of sparse arrays because a ...
• 1,104
111 views

### Why isn't SparseArray working in this case?

This works: SparseArray[{{1, 1} -> 1, {2, 2} -> 2}]\ (* {{1, 0}, {0, 2}} *) This works: ...
• 1,621
653 views

### How can I force the use of sparse diagonalization methods?

When I evaluate the Eigenvalues function on a very large (e.g. 2^16 x 2^16) sparse matrix, Mathematica says something like: Because finding 65536 out of the ...
• 93
220 views

### Efficient storage of Kronecker sum of circulant matrices+diagonal matrix

I have a square matrix of the form $$M=D+\overset{N}{\underset{n=1}\bigoplus}R_n,$$ where $R_n$ are circulant matrices, $D$ is a diagonal matrix and $\oplus$ is Kronecker sum. Its size is quite big, ...
• 7,172
458 views

### How to accelerate updating some parts of sparse matrices?

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use ...
• 491
76 views

### Fastest Way to make rows and columns zero and corresponding (i,i) element 1 of a large Sparse Matrix

I have a 5552 by 5552 sparse matrix: ...
64 views

### Computing the invariant factors of a sparse matrix

Let M be a sparse $n\times m$ integral matrix, where $nm$ is very large. The goal is to compute its invariant factors. The naïve approach ...
60 views

### Map entries of StructuredArray

I have the following defintion arr = SymmetrizedArray[{1, 2} -> 1, {4, 4}, Antisymmetric[{1, 2}]] which gives a ...
• 951
116 views

### Det and MatrixRank freezes on SparseArray with nonzero default value

Bug introduced in 7.0 or earlier and fixed in 9.0.1 or earlier Why does the following simple code never come to an end (at least with version 8) ...
• 2,553
69 views

### Performance of multiplying two identity matrices

I am running Mathematica 13.3.1.0 on a M1 Mac, and I ran the following codes to check on the time spent on matrix multiplication. ...
• 543
68 views

### Dot product of arrays that are members of the same list

Lets say I have a list of n arrays: n=3; list = Table[RandomInteger[{-10, 10}, {2, 2}], n]; I would like to calculate the matrix corresponding to: ...
29 views

### Threshold on triangular SparseArray

I am confused by the behavior of Threshold on sparse UpperTringularize (and LowerTringularize...
• 7,713
56 views

### Implementing array with partial cyclic data?

I'd like to construct an array where some columns are cyclic. As an illustrative example, take Table[Mod[k, 2^i], {k, 2^10}, {i, 0, 10}] //Grid, where the vast ...
• 763
264 views

### What is the fastest way to get the lowest eigenvalue and corresponding eigenstate in Mathematica?

I tried to use the Arnoldi method to get the smallest eigenvalue and corresponding eigenstate for large matrix. However, Arnoldi did not give me the desired result: ...
• 687
142 views

### How to construct a time-dependent matrix quickly?

In the process of discretization of a 4D PDE, I need to construct a final sparse matrix $B$, which is very large (I denoted by $\text{size}$ here) and time-dependent, viz, some of its entries change ...
• 1,817
51 views

### Odd behavior of ArrayReshape with SparseArrays

I am trying to understand why I am seeing inconsistent results when using ArrayReshape on a SparseArray vs. a normal nested <...
• 2,055
50 views

### Is it safe to change MSparseArrays which lack column indices?

I am using sparse arrays with LibraryLink. I noticed that when MSparseArray_fromExplicitPositions and MSparseArray_fromMTensor ...
• 236k
128 views

### How to speed up summing a large number of vectors

First let me explain what I am trying to do in my code. Assume that I send a very short chirp (2,000 ms long) into a domain filled with 20,000 particles randomly scattered in the domain. The ...
• 357
518 views

### Approximate inverse of large sparse matrix with small diagonal element

I need to find inverse of a large sparse matrix with small diagonal element. I follow this question - Is there any way to obtain an approximate inverse for very large sparse matrices? and try to use ...
• 15.9k
219 views

### Memory used by SparseArray objects

In dealing with a quantum mechanics problem, I am representing some many-body states in two different ways in Mathematica. For two parameters n and ...
536 views

### The Jacobi-Davidson method

Does any implementation of the Jacobi-Davidson method for Mathematica exist? A highly parallelized version for sparse matrices would be of special interest.
1 vote
58 views

### Arnoldi method for generalized eigenvalue problem with sparse matrices

I would like to solve a generalized eigenvalue problem involving sparse matrices using the Arnoldi method. I would like to use the Arnoldi method in the hope of speeding up the calculation. Problem is,...
• 361
1 vote
59 views

### Erratic behavior retrieving large data (several tens of gigabytes) that has been serialized by Mathematica

Hardware: PC with 256GB RAM OS: Windows 10 Mathematica: Version 13.0.1 One of my projects has led to the creation of a SparseArray whose ByteCount is ~ 35GB in RAM. At the time of creation the ...
• 2,124
1 vote
33 views

### Why does Sparsearray diagonalization by Krylov technique become slower for very large sizes?

Here is an example sparse matrix, taken from example Hamiltonian, which was a question I asked before in this forum. ...
1 vote
65 views

### Parallelizing construction of sparsearray

I'm constructing sparse arrays where blocks of each array are results of the integral defined in integralList ...
• 63
1 vote
90 views

### Fast definition of sparse tensor

I'm defining a sparse array through ...
• 509
1 vote
64 views

### How to apply PolynomialMod to a SparseArray?

I have a list bdrs of SparseArrays, whose entries are polynomials in the variable t with ...
• 1,155
1 vote
83 views

### Why did LinearSolve give me two different results?

Given that I have a sparse array as follows: ...
• 119
1 vote
165 views

### Determining the price of an option using Black-Scholes

Code for randomly generated interest rates: ...
1 vote
210 views

### Inverse of Sparse Diagonal Array not Sparse

Kind of bummed that when I take the inverse of a matrix that is a diagonal sparse array, the result in not a sparse array. Further, the time to compute the inverse is the same as the time to compute ...
• 7,173
1 vote