Skip to main content

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
23 votes
0 answers
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" ...
unlikely's user avatar
  • 7,123
10 votes
0 answers
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 ...
56th's user avatar
  • 201
10 votes
0 answers
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: ...
Teake Nutma's user avatar
  • 6,021
9 votes
0 answers
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 ...
Alik's user avatar
  • 91
8 votes
0 answers
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 ...
Szabolcs's user avatar
  • 236k
7 votes
0 answers
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 ...
Sjoerd Smit's user avatar
  • 23.8k
7 votes
0 answers
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 ...
Dario Rosa's user avatar
5 votes
0 answers
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 ...
Antonello Scardicchio's user avatar
5 votes
0 answers
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. ...
Szabolcs's user avatar
  • 236k
5 votes
0 answers
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: ...
Xiao's user avatar
  • 111
4 votes
0 answers
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 ...
Bob Lin's user avatar
  • 445
4 votes
0 answers
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 ...
Roopayan Ghosh's user avatar
4 votes
0 answers
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 ...
bRost03's user avatar
  • 2,082
4 votes
0 answers
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 ...
Kiril Danilchenko's user avatar
4 votes
0 answers
75 views

NetTrain doesn't accept sparse input?

The following code fails to execute: ...
Peter Richter's user avatar
4 votes
0 answers
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 ...
Jules Lamers's user avatar
  • 1,104
4 votes
0 answers
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: ...
user170231's user avatar
  • 1,621
4 votes
0 answers
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 ...
P.R.'s user avatar
  • 93
4 votes
0 answers
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, ...
Ruslan's user avatar
  • 7,172
4 votes
1 answer
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 ...
M.J.2's user avatar
  • 491
3 votes
0 answers
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: ...
S.B.MD.Khaja Moinuddin's user avatar
3 votes
0 answers
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 ...
AccidentalFourierTransform's user avatar
3 votes
0 answers
60 views

Map entries of StructuredArray

I have the following defintion arr = SymmetrizedArray[{1, 2} -> 1, {4, 4}, Antisymmetric[{1, 2}]] which gives a ...
Stan's user avatar
  • 951
3 votes
0 answers
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) ...
Federico's user avatar
  • 2,553
2 votes
0 answers
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. ...
Lelouch's user avatar
  • 543
2 votes
0 answers
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: ...
Gabriele Stevanato's user avatar
2 votes
0 answers
29 views

Threshold on triangular SparseArray

I am confused by the behavior of Threshold on sparse UpperTringularize (and LowerTringularize...
Markus Roellig's user avatar
2 votes
0 answers
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 ...
Trev's user avatar
  • 763
2 votes
0 answers
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: ...
lol's user avatar
  • 687
2 votes
0 answers
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 ...
Faz's user avatar
  • 1,817
2 votes
0 answers
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 <...
Fidel I. Schaposnik's user avatar
2 votes
0 answers
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 ...
Szabolcs's user avatar
  • 236k
2 votes
0 answers
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 ...
Mahdi Razaz's user avatar
2 votes
0 answers
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 ...
Sumit's user avatar
  • 15.9k
2 votes
0 answers
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 ...
Marius Ladegård Meyer's user avatar
2 votes
0 answers
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.
Yasha Gindikin's user avatar
1 vote
1 answer
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,...
coussin's user avatar
  • 361
1 vote
0 answers
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 ...
Todd Allen's user avatar
  • 2,124
1 vote
0 answers
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. ...
Roopayan Ghosh's user avatar
1 vote
0 answers
65 views

Parallelizing construction of sparsearray

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

Fast definition of sparse tensor

I'm defining a sparse array through ...
Daniel's user avatar
  • 509
1 vote
0 answers
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 ...
Leo's user avatar
  • 1,155
1 vote
0 answers
83 views

Why did LinearSolve give me two different results?

Given that I have a sparse array as follows: ...
Lavender's user avatar
  • 119
1 vote
0 answers
165 views

Determining the price of an option using Black-Scholes

Code for randomly generated interest rates: ...
Jake Tyler's user avatar
1 vote
0 answers
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 ...
MikeY's user avatar
  • 7,173
1 vote
0 answers
638 views

Inverse of a sparse 21x21 symbolic matrix

I am trying to compute the inverse of the following symmetric sparse(density 0.37) 21x21 matrix involving symbolic expressions in the entries(the variables ...
SlurmsMacKenzie's user avatar
1 vote
0 answers
55 views

Looking for a package for data on (sparse) uniform grids

I have large amounts of sparse 2d and 3d "volumetric" data, i.e. fixed data associated with positions in a uniform (integer coordinate) grid. I think of it as partial function $$f: \mathbb Z^n \to D.$...
masterxilo's user avatar
  • 5,739
1 vote
0 answers
653 views

How to compile code that involve sparse array?

I have the following code ...
matheorem's user avatar
  • 17.2k
0 votes
0 answers
75 views

Efficient construction of Hermitian block matrix

I need to construct large Hermitian matrices $H$, which can be built out of blocks. The matrix $H$ is of total size $Lx\times Ly$, with blocks of size $Ly$. For $Lx=5,\,Ly=3$ and $L=2$ (which is the ...
Kaio's user avatar
  • 85
0 votes
0 answers
53 views

Sparse Kronecker Product of Pauli Matricies

Suppose I have a list of Pauli matrices (X, Z and I type) paulis = {x,z,z,i,z,x,i,z}; I would like to compute a sparse array equivalent to $$x \otimes z\otimes z \...
user2757771's user avatar