# \#sparse

**URL:** https://discourse.julialang.org/tag/sparse/368.md?match_all_tags=true&page=1&tags%5B%5D=sparse

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

**Page:** 2

---

## [Cholesky Decomposition of a Sparse Symmetric Positive Semidefinite (SPSD) Singular Matrix](https://discourse.julialang.org/t/cholesky-decomposition-of-a-sparse-symmetric-positive-semidefinite-spsd-singular-matrix/119682)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 19\
**Last updated:** [September 23, 2024, 5:31pm UTC](https://discourse.julialang.org/t/cholesky-decomposition-of-a-sparse-symmetric-positive-semidefinite-spsd-singular-matrix/119682 "2024-09-23T17:31:44Z")

</div>

Is there such equivalent for sparse matrix? I don’t see the pivoting option for SparseMatrixCSC. How would you handle a Sparse SPSD matrix? Currently I just use check = false. Probably small shift should help but i…

---

## [How to produce sparse array with conditional array comprehension](https://discourse.julialang.org/t/how-to-produce-sparse-array-with-conditional-array-comprehension/118996)

<div class="topic-metadata">

**Author:** [@juan\_hb](https://discourse.julialang.org/u/juan_hb)\
**Replies:** 6\
**Last updated:** [September 4, 2024, 7:46am UTC](https://discourse.julialang.org/t/how-to-produce-sparse-array-with-conditional-array-comprehension/118996 "2024-09-04T07:46:57Z")

</div>

When creating variable or constraint containers in JuMP, one can use conditionals and a sparse array is produced, where the entries that do not met the conditions are left empty. For example: typeof(@variable(model, \[i …

---

## [Finding \*all\* the eigenvalues of a sparse matrix?](https://discourse.julialang.org/t/finding-all-the-eigenvalues-of-a-sparse-matrix/116895)

<div class="topic-metadata">

**Author:** [@rafaelbailo](https://discourse.julialang.org/u/rafaelbailo)\
**Replies:** 24\
**Last updated:** [July 18, 2024, 9:22am UTC](https://discourse.julialang.org/t/finding-all-the-eigenvalues-of-a-sparse-matrix/116895 "2024-07-18T09:22:44Z")

</div>

Seems that LinearAlgebra.jl does not work with sparse matrices, and the libraries that do (e.g. Arpack.jl, ArnoldiMethod.jl, KrylovKit.jl) all use iterative methods, which are not efficient to find all the eigenvalues. S…

---

## [Scaling a sparse matrix row-wise and column-wise too slow](https://discourse.julialang.org/t/scaling-a-sparse-matrix-row-wise-and-column-wise-too-slow/115956)

<div class="topic-metadata">

**Author:** [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Replies:** 20\
**Last updated:** [June 23, 2024, 9:17pm UTC](https://discourse.julialang.org/t/scaling-a-sparse-matrix-row-wise-and-column-wise-too-slow/115956 "2024-06-23T21:17:22Z")

</div>

I need to scale a sparse matrix row-wise and column-wise. That is S\[i,j\] = r\[i\] \* A\[i,j\] \* c\[j\] If I write it the way you’d see it in a math book, S = spdiagm(r) \* A \* spdiagm(c) the expression takes 8x times more th…

---

## [Matrix vs. AbstractMatrix](https://discourse.julialang.org/t/matrix-vs-abstractmatrix/115912)

<div class="topic-metadata">

**Author:** [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)\
**Replies:** 3\
**Last updated:** [June 20, 2024, 10:17am UTC](https://discourse.julialang.org/t/matrix-vs-abstractmatrix/115912 "2024-06-20T10:17:59Z")

</div>

I am pondering to change the definition of the basic object DescriptorStateSpace used in the DescriptorSystems package from struct DescriptorStateSpace{T, ET \<: ETYPE{T}} \<: AbstractDescriptorStateSpace A::Matrix{T…

---

## [Best/simplest way to calculate sparse Hessian](https://discourse.julialang.org/t/best-simplest-way-to-calculate-sparse-hessian/58629)

<div class="topic-metadata">

**Author:** [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Replies:** 4\
**Last updated:** [June 10, 2024, 7:01am UTC](https://discourse.julialang.org/t/best-simplest-way-to-calculate-sparse-hessian/58629 "2024-06-10T07:01:34Z")

</div>

I’ve got a log-probability density function of multiple variables, and would like to integrate it using a Laplace approximation. To do this I need to find the function’s maximum and calculate the Hessian at that point. …

---

## [Solving DAEs with known sparsity pattern and IDA](https://discourse.julialang.org/t/solving-daes-with-known-sparsity-pattern-and-ida/114318)

<div class="topic-metadata">

**Author:** [@ataideneto](https://discourse.julialang.org/u/ataideneto)\
**Replies:** 4\
**Last updated:** [May 16, 2024, 10:51pm UTC](https://discourse.julialang.org/t/solving-daes-with-known-sparsity-pattern-and-ida/114318 "2024-05-16T22:51:55Z")

</div>

Hi everyone! Can someone provide a minimal example of how to use sparsity patterns (jac\_prototype) when solving DAEs with IDA solver? I manage to use sparsity patterns with ODEs and the julia solvers… Here are some exa…

---

## [Using @tensor with sparse tensors of SparseArrayKit.jl](https://discourse.julialang.org/t/using-tensor-with-sparse-tensors-of-sparsearraykit-jl/113686)

<div class="topic-metadata">

**Author:** [@Rodrigue](https://discourse.julialang.org/u/Rodrigue)\
**Replies:** 0\
**Last updated:** [May 1, 2024, 7:53am UTC](https://discourse.julialang.org/t/using-tensor-with-sparse-tensors-of-sparsearraykit-jl/113686 "2024-05-01T07:53:39Z")

</div>

According to the SparseArrayKit.jl documentation, sparse tensors implemented therein are compatible with the @tensor macro from the TensorOperations.jl package. The following simple code function randn\_sparse(T::Type{\<:…

---

## [Sparse matrix error with forward diff](https://discourse.julialang.org/t/sparse-matrix-error-with-forward-diff/108170)

<div class="topic-metadata">

**Author:** [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Replies:** 16\
**Last updated:** [March 29, 2024, 1:53am UTC](https://discourse.julialang.org/t/sparse-matrix-error-with-forward-diff/108170 "2024-03-29T01:53:38Z")

</div>

Hi all. I have the following MWE. I get a stackoverflow error when using a sparse matrix in a function that I am using ForwardDiff to find the gradient of. When using a dense matrix (i.e. change W1s to W1d in the anonymo…

---

## [\`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…

---

## [CSC kills the prospect of multithreading. Shouldn't Julia use CSR?](https://discourse.julialang.org/t/csc-kills-the-prospect-of-multithreading-shouldnt-julia-use-csr/102491)

<div class="topic-metadata">

**Author:** [@nvenkov1](https://discourse.julialang.org/u/nvenkov1)\
**Replies:** 47\
**Last updated:** [March 20, 2024, 7:37am UTC](https://discourse.julialang.org/t/csc-kills-the-prospect-of-multithreading-shouldnt-julia-use-csr/102491 "2024-03-20T07:37:55Z")

</div>

I recently did a rather extensive study of performance of matrix-vector (SpMV) products of sparse matrices with several different storage formats. Although I started benchmarking things in Julia, as usual, I eventually t…

---

## [Efficient ways to implement a (distributed) matrix-matrix product?](https://discourse.julialang.org/t/efficient-ways-to-implement-a-distributed-matrix-matrix-product/79466)

<div class="topic-metadata">

**Author:** [@Neo](https://discourse.julialang.org/u/Neo)\
**Replies:** 2\
**Last updated:** [February 27, 2024, 4:30pm UTC](https://discourse.julialang.org/t/efficient-ways-to-implement-a-distributed-matrix-matrix-product/79466 "2024-02-27T16:30:46Z")

</div>

There are a huge sparse matrix A and a tall-and-skinny matrix B (a set of multiple vectors). I want partition them into pieces for parallel distributed-memory matrix-matrix (matrix-vectors) multiplication. Is there any w…

---

## [Mul! vs \* benchmarks](https://discourse.julialang.org/t/mul-vs-benchmarks/110448)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 2\
**Last updated:** [February 20, 2024, 4:41pm UTC](https://discourse.julialang.org/t/mul-vs-benchmarks/110448 "2024-02-20T16:41:23Z")

</div>

I have these 4 examles I’m benchmarking: using SparseArrays using LinearAlgebra using BenchmarkTools using Random function myfun1(m::Integer, n::Integer) Random.seed!(1) A = rand(Float64, n, n) B = sparse(r…

---

## [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…

---

## [MKL package wrong results](https://discourse.julialang.org/t/mkl-package-wrong-results/110405)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 6\
**Last updated:** [February 19, 2024, 10:26pm UTC](https://discourse.julialang.org/t/mkl-package-wrong-results/110405 "2024-02-19T22:26:22Z")

</div>

I have this program. I post it as it is. If I write: using MKL using MKLSparse It gives me (that’s an iteration of results with a matrix parameter on the first column): 02 | -0.37499999999999944 | 0.0 | -0.1874999999…

---

## [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…

---

## [Double checking there is no multi-threaded dense x sparse matmul implementation](https://discourse.julialang.org/t/double-checking-there-is-no-multi-threaded-dense-x-sparse-matmul-implementation/106619)

<div class="topic-metadata">

**Author:** [@RomeoV](https://discourse.julialang.org/u/RomeoV)\
**Replies:** 7\
**Last updated:** [February 1, 2024, 9:48pm UTC](https://discourse.julialang.org/t/double-checking-there-is-no-multi-threaded-dense-x-sparse-matmul-implementation/106619 "2024-02-01T21:48:15Z")

</div>

I am in need of having very efficient dense x sparse matmul code, but it seems there is no threaded implementation of this available (only sparse x dense). I therefore wrote my own version, which achieves about 3x speedu…

---

## [Sparse matrices copy arrays, do not view them](https://discourse.julialang.org/t/sparse-matrices-copy-arrays-do-not-view-them/109505)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 18\
**Last updated:** [January 31, 2024, 9:06pm UTC](https://discourse.julialang.org/t/sparse-matrices-copy-arrays-do-not-view-them/109505 "2024-01-31T21:06:01Z")

</div>

I wrote this program, which preallocates the csc arrays. I have to do a lot of kronecker products and i wanted to re-use this arrays and to write in them. Each iteration would have a different @view inside them, but if…

---

## [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) …

---

## [Krylov based lanczos etc for sparse matrices](https://discourse.julialang.org/t/krylov-based-lanczos-etc-for-sparse-matrices/109310)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 2\
**Last updated:** [January 26, 2024, 8:31pm UTC](https://discourse.julialang.org/t/krylov-based-lanczos-etc-for-sparse-matrices/109310 "2024-01-26T20:31:34Z")

</div>

I found Home · KrylovKit.jl and it points to KrylovMethods.jl/README.md at master · JuliaInv/KrylovMethods.jl · GitHub for sparse matrices. However I don’t find any documentation. How can i use it? Does it support comp…

---

## [Some eigenpairs from a large, sparse, nonsymmetric matrix: Julia vs Matlab](https://discourse.julialang.org/t/some-eigenpairs-from-a-large-sparse-nonsymmetric-matrix-julia-vs-matlab/93742)

<div class="topic-metadata">

**Author:** [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Replies:** 22\
**Last updated:** [January 12, 2024, 4:18am UTC](https://discourse.julialang.org/t/some-eigenpairs-from-a-large-sparse-nonsymmetric-matrix-julia-vs-matlab/93742 "2024-01-12T04:18:21Z")

</div>

In the course of working through a book on frequency domain finite difference solutions for electromagnetics, I have been converting the supplied Matlab programs to Julia. For the problem of determining the modes of an …

---

## [Fast conversion from Matrix{Union{Missing, Float64}} to Sparse](https://discourse.julialang.org/t/fast-conversion-from-matrix-union-missing-float64-to-sparse/108161)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 11\
**Last updated:** [January 2, 2024, 2:10pm UTC](https://discourse.julialang.org/t/fast-conversion-from-matrix-union-missing-float64-to-sparse/108161 "2024-01-02T14:10:55Z")

</div>

I have a matrix that contains lots of missing values. I am toying with the idea of using sparsity to represent those missing values instead. However, one hurdle to easy conversion from Matrix to SparseMatrix is that the …

---

## [Matrix type for inversion](https://discourse.julialang.org/t/matrix-type-for-inversion/108107)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 2\
**Last updated:** [December 28, 2023, 9:22am UTC](https://discourse.julialang.org/t/matrix-type-for-inversion/108107 "2023-12-28T09:22:53Z")

</div>

Hi, I would like to solve a linear system A x=b where A is band by block. The bandwith can be big (~10). An example of such matrix is for example the one in the trapezoid method. I can do a LU decomposition to solve th…

---

## [Efficiently check if a sparse vector is a column of a sparse matrix](https://discourse.julialang.org/t/efficiently-check-if-a-sparse-vector-is-a-column-of-a-sparse-matrix/107861)

<div class="topic-metadata">

**Author:** [@max29](https://discourse.julialang.org/u/max29)\
**Replies:** 13\
**Last updated:** [December 21, 2023, 2:57am UTC](https://discourse.julialang.org/t/efficiently-check-if-a-sparse-vector-is-a-column-of-a-sparse-matrix/107861 "2023-12-21T02:57:47Z")

</div>

I have a sparse matrix A and a sparse vector x and want to check if the vector is a column of the matrix. using SparseArrays, BenchmarkTools A = spdiagm(1:1000); x = sparsevec(\[950\],\[950\],1000); B = Array(A); # dense y…

---

## [Sparse A\\B](https://discourse.julialang.org/t/sparse-a-b/107725)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 2\
**Last updated:** [December 17, 2023, 4:10am UTC](https://discourse.julialang.org/t/sparse-a-b/107725 "2023-12-17T04:10:11Z")

</div>

What is the best way to solve A\\B where A and B are sparse, and where the result is also known to be sparse? Right now it seems I have to do sparse(A \\ Matrix(B)).

---

## [\[ANN\] ThreadedDenseSparseMul.jl](https://discourse.julialang.org/t/ann-threadeddensesparsemul-jl/106734)

<div class="topic-metadata">

**Author:** [@RomeoV](https://discourse.julialang.org/u/RomeoV)\
**Replies:** 0\
**Last updated:** [November 26, 2023, 9:38am UTC](https://discourse.julialang.org/t/ann-threadeddensesparsemul-jl/106734 "2023-11-26T09:38:51Z")

</div>

ThreadedDenseSparseMul.jl Threaded implementation of dense-sparse matrix multiplication, built on top of Polyester.jl. Hello all, I’ve recently had a need to do C \\leftarrow C - D \* S very fast, where D and S are den…

---

## [Storing a batch of sparse matrices and multiplying them to a vector](https://discourse.julialang.org/t/storing-a-batch-of-sparse-matrices-and-multiplying-them-to-a-vector/106646)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 1\
**Last updated:** [November 24, 2023, 1:07am UTC](https://discourse.julialang.org/t/storing-a-batch-of-sparse-matrices-and-multiplying-them-to-a-vector/106646 "2023-11-24T01:07:07Z")

</div>

I store N matrices, each of size(n,n), in the array Batchm = zeros(ComplexF64, N,n,n ). Later, I retrieve the individual matrices and multiply to a vector, Batchm(index, :,:)\*v. The matrices are sparse and banded. What’…

---

## [Why does \`mul!(u, A, v)\` allocate when \`A\` is sparse and \`u, v\` are views?](https://discourse.julialang.org/t/why-does-mul-u-a-v-allocate-when-a-is-sparse-and-u-v-are-views/105995)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 9\
**Last updated:** [November 10, 2023, 12:04pm UTC](https://discourse.julialang.org/t/why-does-mul-u-a-v-allocate-when-a-is-sparse-and-u-v-are-views/105995 "2023-11-10T12:04:42Z")

</div>

I’m wondering if there is a way to avoid allocations in the following scenario: julia\> using BenchmarkTools, LinearAlgebra, SparseArrays julia\> A = sprand(2, 3, 0.5); julia\> u, v = rand(2), rand(3); julia\> @btime mul…

---

## [Populate a symmetric sparse matrix](https://discourse.julialang.org/t/populate-a-symmetric-sparse-matrix/102830)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 10\
**Last updated:** [August 15, 2023, 7:16pm UTC](https://discourse.julialang.org/t/populate-a-symmetric-sparse-matrix/102830 "2023-08-15T19:16:42Z")

</div>

Hello, I would like to populate a sparse matrix A with a function f:\\mathbb{N}\\times \\mathbb{N} \\to \\mathbb{R}, (i\_1, i\_2) \\mapsto f(i\_1, i\_2) which is symmetric, i.e. f(i\_1, i\_2) = f(i\_2, i\_1). We want to fill A such…

[Previous page](https://discourse.julialang.org/tag/sparse/368.md?match_all_tags=true&tags%5B%5D=sparse)

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