# \`eigs\` for sparse tridiagonal matrix: Arpack.jl vs scipy

**URL:** <https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566>\
**Category:** Performance\
**Tags:** linearalgebra, python\
**Created:** [September 27, 2018, 3:27pm UTC](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566 "2018-09-27T15:27:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [September 27, 2018, 3:27pm UTC](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566/1 "2018-09-27T15:27:14Z")

</div>

**MWE:**

```julia
using LinearAlgebra, SparseArrays, Arpack, PyCall, BenchmarkTools
@pyimport scipy.sparse as pysparse
@pyimport scipy.sparse.linalg as pylinalg

N = 100_000
X = sparse(Tridiagonal(1.0:N-1, 1.0:N, 1.0:N-1))
X = X + X'
Xpy = pysparse.csc_matrix((X.nzval, X.rowval .- 1, X.colptr .- 1), shape=size(X))

@btime Arpack.eigs($X, nev=6, which=:LM); # julia
@btime pylinalg.eigs($Xpy, k=6, which=:LM); # python

# Output:
# 3.475 s (4467 allocations: 23.83 MiB)
# 3.116 s (180 allocations: 9.16 MiB)

```

I’m setting up a sparse (about 1e-5 nz entries) tridiagonal real matrix. I want to know the, say, 6 largest eigenvalues.

**Why is Julia slower here?**

AFAIU, both `scipy.sparse.linalg.eigs` and Arpack.jl’s `eigs` are using ARPACK. Correct?

Any explanation is highly appreciated!

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [September 27, 2018, 3:35pm UTC](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566/2 "2018-09-27T15:35:42Z")

</div>

One more thing: what about `scipy.sparse.linalg.eigsh`? I thought this is a ARPACK function as well but can’t find a wrapper in Arpack.jl.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [September 27, 2018, 3:52pm UTC](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566/3 "2018-09-27T15:52:06Z")

</div>

What’s the performance like if you just use a regular sparse matrix instead of tridiagonal?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [September 27, 2018, 4:04pm UTC](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566/4 "2018-09-27T16:04:41Z")

</div>

Basically the same. In fact, I tried it with random sparse matrices first.
