# \#sparsearrays

**URL:** https://discourse.julialang.org/tag/sparsearrays/1409.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Sparse 3D arrays](https://discourse.julialang.org/t/sparse-3d-arrays/16488)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 10\
**Last updated:** [September 17, 2025, 7:17am UTC](https://discourse.julialang.org/t/sparse-3d-arrays/16488 "2025-09-17T07:17:41Z")

</div>

It seems that SparseArrays only offers sparse vectors and matrices. Are there packages for higher dimensional sparse arrays? I am mainly interested in 3d.

---

## [Sparse arrays of higher order](https://discourse.julialang.org/t/sparse-arrays-of-higher-order/42875)

<div class="topic-metadata">

**Author:** [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Replies:** 4\
**Last updated:** [September 17, 2025, 2:12am UTC](https://discourse.julialang.org/t/sparse-arrays-of-higher-order/42875 "2025-09-17T02:12:46Z")

</div>

Are there any good packages which have a similar feature as SparseArrays.SparseMatrixCSC but with higher order arrays? For example, a sparse array with 3 indices or 4 indices, stored in a similar way to a sparse matrix, …

---

## [Sparse matrix multiplication for Metal](https://discourse.julialang.org/t/sparse-matrix-multiplication-for-metal/131088)

<div class="topic-metadata">

**Author:** [@Marco\_Lombardi](https://discourse.julialang.org/u/Marco_Lombardi)\
**Replies:** 15\
**Last updated:** [July 31, 2025, 5:59pm UTC](https://discourse.julialang.org/t/sparse-matrix-multiplication-for-metal/131088 "2025-07-31T17:59:44Z")

</div>

I need to perform a multiplication between two fairly large sparse matrices C = A \* B and I would like to try using the GPU for that. The problem arises in a context where A represents a fixed 2D convolution kernel, whil…

---

## [Crash of eigenvalues calculations with arpack](https://discourse.julialang.org/t/crash-of-eigenvalues-calculations-with-arpack/130983)

<div class="topic-metadata">

**Author:** [@Choleva](https://discourse.julialang.org/u/Choleva)\
**Replies:** 1\
**Last updated:** [July 23, 2025, 8:07pm UTC](https://discourse.julialang.org/t/crash-of-eigenvalues-calculations-with-arpack/130983 "2025-07-23T20:07:26Z")

</div>

I have a problem of crash of eigenvalues calculations by Arpack.v0.5.4 only if the size of the array becomes very large The bugging line of the program is (line 99) ‘’‘Eigen = eigs(Sierp3, nev=1, which=:LM, sigma=1.7)…

---

## [Fixed-structure CHOLMOD with in-place \`set\_nonzeros!\`](https://discourse.julialang.org/t/fixed-structure-cholmod-with-in-place-set-nonzeros/130922)

<div class="topic-metadata">

**Author:** [@luke-kiernan](https://discourse.julialang.org/u/luke-kiernan)\
**Replies:** 3\
**Last updated:** [July 22, 2025, 3:03am UTC](https://discourse.julialang.org/t/fixed-structure-cholmod-with-in-place-set-nonzeros/130922 "2025-07-22T03:03:22Z")

</div>

I have a large sparse matrix. Its nonzeros change over the course of the problem, but its structure doesn’t. I want to do repeated in-place Cholesky factorizations, re-using the symbolic factorization and modifying the n…

---

## [Performance discrepancy in solving sparse SPD\\dense rhs between X86 and Apple M](https://discourse.julialang.org/t/performance-discrepancy-in-solving-sparse-spd-dense-rhs-between-x86-and-apple-m/130476)

<div class="topic-metadata">

**Author:** [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Replies:** 2\
**Last updated:** [July 4, 2025, 8:06pm UTC](https://discourse.julialang.org/t/performance-discrepancy-in-solving-sparse-spd-dense-rhs-between-x86-and-apple-m/130476 "2025-07-04T20:06:43Z")

</div>

Why do I observe a 9x difference in elapsed times when I run the following on my macbook laptop using Random, SparseArrays, LinearAlgebra Random.seed!(0); A = sprand(10000,10000,5/10000) + I; A = max.(A,A'); b = rand(…

---

## [Very long time for addition of complex identity matrix to transposed sparse matrix](https://discourse.julialang.org/t/very-long-time-for-addition-of-complex-identity-matrix-to-transposed-sparse-matrix/129465)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 10\
**Last updated:** [May 31, 2025, 5:20pm UTC](https://discourse.julialang.org/t/very-long-time-for-addition-of-complex-identity-matrix-to-transposed-sparse-matrix/129465 "2025-05-31T17:20:12Z")

</div>

Hi, I am surprised by these timings on 1.10. Can it be improved? using SparseArrays, LinearAlgebra A = sprandn(90000,90000, 1e-5) @time (A + complex(0,1.) \* I); # 0.001344 seconds (13 allocations: 7.342 MiB) @time (tr…

---

## [JuMP and SparseArrays](https://discourse.julialang.org/t/jump-and-sparsearrays/129264)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 5\
**Last updated:** [May 23, 2025, 8:32am UTC](https://discourse.julialang.org/t/jump-and-sparsearrays/129264 "2025-05-23T08:32:57Z")

</div>

The background is using SparseArrays, JuMP m = Model(); @variable(m, x\[1:2\]); My question is, can I create a sparse 2-by-2 object (whatever it is) denoted A, such that A\[1, 1\] returns me x\[1\], A\[2, 1\] returns me x\[2\].…

---

## [Some thoughts on improving the doc of SparseArrays.jl](https://discourse.julialang.org/t/some-thoughts-on-improving-the-doc-of-sparsearrays-jl/128960)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 1\
**Last updated:** [May 13, 2025, 1:29pm UTC](https://discourse.julialang.org/t/some-thoughts-on-improving-the-doc-of-sparsearrays-jl/128960 "2025-05-13T13:29:17Z")

</div>

The stdlib SparseArrays.jl is mainly about SparseMatrixCSC and SparseVector. From my point of view, its doc reads a bit immature (Edit: this word was used improperly. I hadn’t learnt its meaning. I’m not an native speak…

---

## [Sparse arrays allocation versus speed](https://discourse.julialang.org/t/sparse-arrays-allocation-versus-speed/128726)

<div class="topic-metadata">

**Author:** [@Boris](https://discourse.julialang.org/u/Boris)\
**Replies:** 9\
**Last updated:** [May 13, 2025, 5:18am UTC](https://discourse.julialang.org/t/sparse-arrays-allocation-versus-speed/128726 "2025-05-13T05:18:56Z")

</div>

Hi! I have a question about allocations and speed trade-off when using Sparse Arrays. TLDR question: Sparse matrix multiplication for my case is fast, but allocates a lot of memory. Using dense matrices my code is slowe…

---

## [Error showing value of type SparseMatrixCSC](https://discourse.julialang.org/t/error-showing-value-of-type-sparsematrixcsc/128857)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 2\
**Last updated:** [May 9, 2025, 1:56am UTC](https://discourse.julialang.org/t/error-showing-value-of-type-sparsematrixcsc/128857 "2025-05-09T01:56:06Z")

</div>

It appears that there is a valid SparseMatrixCSC, but cannot be shown. julia\> using SparseArrays julia\> A = \[rand(-9:9, 2) for i in 1:2, j in 1:2\] 2×2 Matrix{Vector{Int64}}: \[-6, -1\] \[-7, -6\] \[5, 5\] \[0, -1\] juli…

---

## [Sprand fails to construct a SparseVector](https://discourse.julialang.org/t/sprand-fails-to-construct-a-sparsevector/128828)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 3\
**Last updated:** [May 8, 2025, 6:36am UTC](https://discourse.julialang.org/t/sprand-fails-to-construct-a-sparsevector/128828 "2025-05-08T06:36:36Z")

</div>

I can construct a random SparseMatrixCSC, but not a SparseVector in the same way. Where am I wrong? julia\> using SparseArrays julia\> rfn = n -\> rand(-9:.1:9, n) #1 (generic function with 1 method) julia\> sprand(7, 8, …

---

## [Why \`sprand\` does not accept a Distribution arg?](https://discourse.julialang.org/t/why-sprand-does-not-accept-a-distribution-arg/127255)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 10\
**Last updated:** [April 3, 2025, 4:02am UTC](https://discourse.julialang.org/t/why-sprand-does-not-accept-a-distribution-arg/127255 "2025-04-03T04:02:18Z")

</div>

Hi there, I wonder why this cannot work out (What is the available method currently then?). julia\> import SparseArrays.sprand as sprand julia\> import Distributions.Uniform as UD julia\> sprand(5, 6, .7) 5×6 SparseArra…

---

## [Is there a way to select the type of indices Ti with sprand()?](https://discourse.julialang.org/t/is-there-a-way-to-select-the-type-of-indices-ti-with-sprand/127259)

<div class="topic-metadata">

**Author:** [@AntoineBut](https://discourse.julialang.org/u/AntoineBut)\
**Replies:** 1\
**Last updated:** [March 22, 2025, 12:15pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-select-the-type-of-indices-ti-with-sprand/127259 "2025-03-22T12:15:21Z")

</div>

The function sprand() has methods to specify the type of the generated elements {Tv}. But a SparseArray has two type parameters, the second being the type used to stores the indices {Ti}. Does anyone have a magic trick t…

---

## [Sparse non-square linear problem](https://discourse.julialang.org/t/sparse-non-square-linear-problem/122650)

<div class="topic-metadata">

**Author:** [@Nichola](https://discourse.julialang.org/u/Nichola)\
**Replies:** 3\
**Last updated:** [November 15, 2024, 1:00am UTC](https://discourse.julialang.org/t/sparse-non-square-linear-problem/122650 "2024-11-15T01:00:17Z")

</div>

I would like to solve Ax = b where A is a sparse non-square array. For example : using SparseArrays using LinearSolve n = 3 m = 4 A = sparse(rand(ComplexF64, m, n)) b = rand(ComplexF64, m) prob = LinearProblem(A, b) …

---

## [How to use GPU acceleration to solve linear equation Ax=b](https://discourse.julialang.org/t/how-to-use-gpu-acceleration-to-solve-linear-equation-ax-b/120841)

<div class="topic-metadata">

**Author:** [@automaticvehiclerook](https://discourse.julialang.org/u/automaticvehiclerook)\
**Replies:** 9\
**Last updated:** [October 5, 2024, 5:35am UTC](https://discourse.julialang.org/t/how-to-use-gpu-acceleration-to-solve-linear-equation-ax-b/120841 "2024-10-05T05:35:07Z")

</div>

In my experiment,I want to solve the equation Ax=b on GPU to accelerate the process.I have tried the iterative solver from Kryvol.jl and cuSOLVER,but the GPU is still slower than CPU.Is that normal? using CUDA using Spa…

---

## [Memory Allocation when using mul! with sparse arrays and views](https://discourse.julialang.org/t/memory-allocation-when-using-mul-with-sparse-arrays-and-views/111276)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 4\
**Last updated:** [July 8, 2024, 6:30pm UTC](https://discourse.julialang.org/t/memory-allocation-when-using-mul-with-sparse-arrays-and-views/111276 "2024-07-08T18:30:07Z")

</div>

I am writing code which performs a five argument mul! operation (from LinearAlgebra) inside a for loop where performance is critical. When using a sparse array instead of a matrix, the operation allocates memory: julia\>…

---

## [Efficiently extracting a column of a sparse matrix](https://discourse.julialang.org/t/efficiently-extracting-a-column-of-a-sparse-matrix/114904)

<div class="topic-metadata">

**Author:** [@gtgt](https://discourse.julialang.org/u/gtgt)\
**Replies:** 3\
**Last updated:** [May 29, 2024, 3:21pm UTC](https://discourse.julialang.org/t/efficiently-extracting-a-column-of-a-sparse-matrix/114904 "2024-05-29T15:21:04Z")

</div>

Given a sparse matrix S, how can I efficiently extract the ith column of S? I know I can use @view S.nzval\[S.colptr\[i\] : S.colptr\[i + 1\] - 1\] but it’s a bit clunky.

---

## [\[ANN\] WildcardArrays.jl](https://discourse.julialang.org/t/ann-wildcardarrays-jl/112693)

<div class="topic-metadata">

**Author:** [@licioromao](https://discourse.julialang.org/u/licioromao)\
**Replies:** 0\
**Last updated:** [April 8, 2024, 7:11pm UTC](https://discourse.julialang.org/t/ann-wildcardarrays-jl/112693 "2024-04-08T19:11:17Z")

</div>

Hi all, I would like to share with you the package WildcardArrays.jl. It allows us to specify sparse matrices from text files; repeated entries can be specified using a wildcard character (’\*’). Version 0.1.0 API is des…

---

## [Are Enzyme's custom rules for sparse arrays different from regular Matrix?](https://discourse.julialang.org/t/are-enzymes-custom-rules-for-sparse-arrays-different-from-regular-matrix/112352)

<div class="topic-metadata">

**Author:** [@ToPo](https://discourse.julialang.org/u/ToPo)\
**Replies:** 3\
**Last updated:** [April 1, 2024, 6:14am UTC](https://discourse.julialang.org/t/are-enzymes-custom-rules-for-sparse-arrays-different-from-regular-matrix/112352 "2024-04-01T06:14:00Z")

</div>

I am creating custom rules for sparse arrays in Enzyme, an automatic differentiation package. The following program is a custom rule for the computation of matrix adds of type SparseMatrixCSC. using SparseArrays #-----…

---

## [\`Spy\` function behavior with sparse matrices](https://discourse.julialang.org/t/spy-function-behavior-with-sparse-matrices/112232)

<div class="topic-metadata">

**Author:** [@fimiller](https://discourse.julialang.org/u/fimiller)\
**Replies:** 2\
**Last updated:** [March 28, 2024, 1:58pm UTC](https://discourse.julialang.org/t/spy-function-behavior-with-sparse-matrices/112232 "2024-03-28T13:58:18Z")

</div>

I am trying to generate sparsity patterns for some matrices for a project. However, I cannot seem to find the necessary command to make all the sparsity patterns the same size. Below is an example and the output: A = sp…

---

## [How do you speed up the linear sparse solver in Zygote?](https://discourse.julialang.org/t/how-do-you-speed-up-the-linear-sparse-solver-in-zygote/111801)

<div class="topic-metadata">

**Author:** [@ToPo](https://discourse.julialang.org/u/ToPo)\
**Replies:** 44\
**Last updated:** [March 24, 2024, 7:18am UTC](https://discourse.julialang.org/t/how-do-you-speed-up-the-linear-sparse-solver-in-zygote/111801 "2024-03-24T07:18:47Z")

</div>

I have confirmed that the standard Julia solver (backslash) can be used in the automatic differentiation of Zygote. Below is a sample program. (This program calculates the gradient.) However, while the forward computat…

---

## [Warning/Error handling from complex, sparse array on SVD (PROPACK)](https://discourse.julialang.org/t/warning-error-handling-from-complex-sparse-array-on-svd-propack/110779)

<div class="topic-metadata">

**Author:** [@KSfairopoulos](https://discourse.julialang.org/u/KSfairopoulos)\
**Replies:** 0\
**Last updated:** [February 26, 2024, 2:16pm UTC](https://discourse.julialang.org/t/warning-error-handling-from-complex-sparse-array-on-svd-propack/110779 "2024-02-26T14:16:45Z")

</div>

Let’s assume I have a sparse matrix with complex entries. I want to perform svd on it. So, I use the Propack package (do you have any better suggestions?). I do this with the command: tsvdvals(gs, k=p), where I retain …

---

## [Krylovkit tolerance changes results drastically](https://discourse.julialang.org/t/krylovkit-tolerance-changes-results-drastically/110450)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 0\
**Last updated:** [February 20, 2024, 11:16am UTC](https://discourse.julialang.org/t/krylovkit-tolerance-changes-results-drastically/110450 "2024-02-20T11:16:17Z")

</div>

I’m writing a difficult to read code, just because I know the analytical result which is -0.274519. This value is meant to be compared with what is printed in the 4th column of this (a laptop is more than enough). When…

---

## [Help with this code (deallocation/pointers on sparse matrices)](https://discourse.julialang.org/t/help-with-this-code-deallocation-pointers-on-sparse-matrices/109574)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 31\
**Last updated:** [February 3, 2024, 9:32am UTC](https://discourse.julialang.org/t/help-with-this-code-deallocation-pointers-on-sparse-matrices/109574 "2024-02-03T09:32:46Z")

</div>

This is a follow up of a recent thread I made Sparse matrices copy arrays, do not view them I sum up all the shared ideas, with 2 code examples. This is intended as a much clearer version and prosecution of that thread,…

---

## [Fast allocation of blocks in sparse matrix](https://discourse.julialang.org/t/fast-allocation-of-blocks-in-sparse-matrix/109561)

<div class="topic-metadata">

**Author:** [@johannesnauta](https://discourse.julialang.org/u/johannesnauta)\
**Replies:** 7\
**Last updated:** [February 2, 2024, 6:34pm UTC](https://discourse.julialang.org/t/fast-allocation-of-blocks-in-sparse-matrix/109561 "2024-02-02T18:34:00Z")

</div>

When trying to generate a “super adjacency matrix”, that is an adjacency matrix where each of its entries is the identity matrix, I noticed a bottleneck when generating the sparse block-matrix. More specifically, I am t…

---

## [Sparse(kroneckersum). sparse or not?](https://discourse.julialang.org/t/sparse-kroneckersum-sparse-or-not/109521)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 0\
**Last updated:** [January 31, 2024, 2:56pm UTC](https://discourse.julialang.org/t/sparse-kroneckersum-sparse-or-not/109521 "2024-01-31T14:56:53Z")

</div>

I wrote these two sparseArrays functions: using SparseArrays using LinearAlgebra using Kronecker Sz = \[\[0.5, 0\] \[0, -0.5\]\] C = kroneckersum(Sz, Sz) D = sparse(C) display(issparse(D)) display(D) E = kronecker(Sz, Sz) …

---

## [The Optimization Problem with Nested Loops in Julia](https://discourse.julialang.org/t/the-optimization-problem-with-nested-loops-in-julia/104833)

<div class="topic-metadata">

**Author:** [@Umut\_Can\_Turhan](https://discourse.julialang.org/u/Umut_Can_Turhan)\
**Replies:** 8\
**Last updated:** [October 23, 2023, 8:02am UTC](https://discourse.julialang.org/t/the-optimization-problem-with-nested-loops-in-julia/104833 "2023-10-23T08:02:55Z")

</div>

Hi everyone, I have a problem related to the optimization problem with nested loops. I use QuantumOptics.jl (qojulia.org) module to calculate for some physical situation. First of all, let me share my code and explain it…

---

## [A sparse matrix cannot be indexed by a SVector](https://discourse.julialang.org/t/a-sparse-matrix-cannot-be-indexed-by-a-svector/104265)

<div class="topic-metadata">

**Author:** [@pinkie.ljz](https://discourse.julialang.org/u/pinkie.ljz)\
**Replies:** 4\
**Last updated:** [September 26, 2023, 3:18pm UTC](https://discourse.julialang.org/t/a-sparse-matrix-cannot-be-indexed-by-a-svector/104265 "2023-09-26T15:18:04Z")

</div>

As indicated by the topic, I intend to replace some small matrices with the StaticArrays but the global sparse matrix created by SparseArrays.jl cannot be indexed by a SVector. A simple example is given as follows. usi…

---

## [Way to make Shared-SparseArray?](https://discourse.julialang.org/t/way-to-make-shared-sparsearray/104016)

<div class="topic-metadata">

**Author:** [@Fluorite-Erbite](https://discourse.julialang.org/u/Fluorite-Erbite)\
**Replies:** 1\
**Last updated:** [September 19, 2023, 11:08am UTC](https://discourse.julialang.org/t/way-to-make-shared-sparsearray/104016 "2023-09-19T11:08:56Z")

</div>

I want to process sparse matrices in parallel. But, as far as I’ve tried, I cannot make Shared-SparseArray. Is it possible?

[Next page](https://discourse.julialang.org/tag/sparsearrays/1409.md?match_all_tags=true&page=1&tags%5B%5D=sparsearrays)
