Skip to content

Instantly share code, notes, and snippets.

@denis-bz
denis-bz / 0-arpack-gmres-vs-lgmres.md
Created Sep 17, 2020
ARPACK small eigenvalues: Lgmres is over 10 times faster than GMRES on shifted poisson2d
View 0-arpack-gmres-vs-lgmres.md

ARPACK small eigenvalues: Lgmres is over 10 times faster than GMRES on shifted poisson2d

Keywords: ARPACK, small eigenvalues, shift-invert, python, scipy, GMRES, LinearOperator, testcase, poisson

The problem: find eigenvalues near 0 of a LinearOperator A:

A v = λ v  # A a large sparse matrix or LinearOperator, λ near e.g. 0
evals, evecs = scipy.sparse.linalg.eigsh( A, sigma=0, k=6, v0=ones, tol=1e-5 )

To find eigenvalues near 0, ARPACK must solve A x = b many many times.

@denis-bz
denis-bz / 0-Covid19-hospitalized-Germany.md
Last active Sep 9, 2020
Covid-19 % cases hospitalized in Germany up to 6 Sept 2020
View 0-Covid19-hospitalized-Germany.md

Covid-19 cases hospitalized in Germany, March up to 6 September 2020

Keywords: Covid-19, hospitalized, Germany, plot, python

This plot shows the number of Covid-19 cases per week, the number hospitalized, and number of deaths, in Germany for weeks 10 to 36 2020:

9sep2020-Covid19-hospitalized-de-8sep

The data is taken from this report: \

@denis-bz
denis-bz / meshio-read-write-example.py
Created Aug 17, 2020
meshio-read-write-example.py 17 Aug 2020
View meshio-read-write-example.py
"""meshio-read-write-example.py
meshio.read and meshio.write_points_cells have `cells` in slightly different formats
("cells" meaning triangles in 2d, triangles + tetras in 3d)
read: mesh = a list of (type, data) ... pairs
mesh.cells_dict is the equivalent dict, [type] = data ...
write_points_cells: mesh.cells_dict (for some formats may have only 1 entry)
In both,
type: "line" "triangle" "tetra"
data: numpy arrays N x 2 or 3 or 4
@denis-bz
denis-bz / 0-How-to-make-a-Python-package-for-other-people-to-use.md
Created Jul 27, 2020
How to make a Python package for other people to use 27 Jul 2020
View 0-How-to-make-a-Python-package-for-other-people-to-use.md

How to make a Python package for other people to use

Keywords, tags: python packaging setup.py setuptools

Purpose: describe how to make a "package" of a Python program for other people to use. This introduction builds on the excellent oa-packaging-guide-preview.readthedocs.io — read that first.

@denis-bz
denis-bz / 0-eigvals-numpy-scipy.md
Last active Jul 16, 2020
Do numpy and scipy use different LAPACK drivers for eigvalsh ? 3 Jul 2020
View 0-eigvals-numpy-scipy.md

Do numpy and scipy use different LAPACK drivers for eigvalsh on macos ?

eigvals-numpy-scipy.py below runs numpy vs scipy eigvalsh on a dense random matrix:

np.linalg.eigvalsh: 201 sec
scipy.linalg.eigvalsh: 83 sec  driver ev
scipy.linalg.eigvalsh: 84 sec  driver evd

Maybe this is only on macos ?

@denis-bz
denis-bz / 0-Shift-invert-in-pictures.md
Created Jul 2, 2020
How shift-invert finds eigenvalues, in pictures 2 Jul 2020
View 0-Shift-invert-in-pictures.md

How shift-invert finds eigenvalues, in pictures

Keywords: eigenvalues, eigenvectors, shift-invert, ARPACK, scipy, python

Pictures first:

shiftinvert-randomsparse-n100

Background

@denis-bz
denis-bz / 0-umfpack-setup.py
Created Jun 26, 2020
How to make scikit-umfpack with scipy 1.5 openblas 26 Jun 2020
View 0-umfpack-setup.py
#!/usr/bin/env python
"""How to make scikit-umfpack with scipy 1.5 openblas
The scipy sparse linear solver `spsolve( A, b )` can be ~ 50 times faster
when scikit-umfpack is installedC -- see *spsolve-umfpack-random.log .
This is a bare-bones HowTo, a simple setup.py script with which `pip install` works on my mac.
(Else pip: no swig, no __umfpack*.so ??)
However I'm no setup.py maven, comments welcome
@denis-bz
denis-bz / 0-Eigplots.md
Last active Jun 20, 2020
Plots of some eigenvalues and eigenvectors 20 Jun 2020
View 0-Eigplots.md

Plots of some eigenvalues and eigenvectors

Keywords: eigenvalues, eigenvectors, test-matrix, scipy, python

Eigenvectors of Suitesparse Norris/fv1

27feb2020-Suitesparse-Norris-fv1-evecs

See SuiteSparse Matrix Collection / Norris, "Finite element modelling of human body parts, Laplace equation on a 2D mesh".

@denis-bz
denis-bz / av_sparse_blocks.py
Last active Aug 21, 2020
average e.g. 4 x 4 blocks in a sparse matrix A 16 Jun 2020
View av_sparse_blocks.py
#!/usr/bin/env python
"""average e.g. 4 x 4 blocks in a sparse matrix A
N x N -> N/4 x N/4, nnz roughly *= blksize
why: reduce big matrices to plot, q+d approximate inverse
Keywords: sparse-matrix, python, scipy, data-compression
"""
# pretty fast -- coo sums duplicate (i,j) entries
from __future__ import division, print_function
@denis-bz
denis-bz / cheblinop.py
Created Jun 7, 2020
Chebyshev series of matrices 7 Jun 2020
View cheblinop.py
#!/usr/bin/env python
"""Chebyshev series of matrices
polyD = Cheblinop( A, [c0 c1 c2 ...] ) # a LinearOperator
A: a square numpy array
| scipy.sparse matrix
| scipy.sparse LinearOperator
coefs: [c0 c1 ...] arraylike
| numpy Chebyshev polynomial T( coefs [, domain=] )
| filename to polyload
You can’t perform that action at this time.