Skip to content

Instantly share code, notes, and snippets.

@pv
pv / random.dat
Created June 13, 2011 20:31
eigsh test errors
======================================================================
ERROR: test_arpack.test_hermitian_modes(True, <std-hermitian>, 'D', 2, 'LM', None, 0.5, <function aslinearoperator at 0x1314aa0>)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose-0.11.4-py2.7.egg/nose/case.py", line 186, in runTest
self.test(*self.arg)
File "/home/pauli/prj/scipy/scipy/dist/linux/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py", line 180, in eval_evec
eval, evec = eigs_func(ac, k, **kwargs)
File "/home/pauli/prj/scipy/scipy/dist/linux/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 1440, in eigsh
import numpy as np
import scipy.linalg.blas
cdef extern from "f2pyptr.h":
void *f2py_pointer(object) except NULL
ctypedef int dgemm_t(
char *transa, char *transb,
int *m, int *n, int *k,
double *alpha,
@pv
pv / cvx2d.py
Last active December 16, 2015 20:29
Determine order of 2-D convex hull points based on the neighborhood structure
import numpy as np
from scipy.spatial import ConvexHull
from scipy.sparse import coo_matrix, csgraph
def ordered_hull_idx_2d(hull):
n = hull.simplices.shape[0]
# determine order of edges in the convex hull
v = coo_matrix((np.ones(2*n), (np.repeat(np.arange(n), 2), hull.neighbors.ravel())))
facet_order = csgraph.depth_first_order(v, 0, return_predecessors=False)
@pv
pv / splder.py
Created May 2, 2013 18:43
Derivative of B-spline in Python
r"""
Show how to compute a derivative spline.
Scipy's splines are represented in terms of the standard B-spline basis
functions. In short, a spline of degree ``k`` is represented in terms of the
knots ``t`` and coefficients ``c`` by:
.. math::
s(x) = \sum_{j=-\infty}^\infty c_{j} B^k_{j}(x)
@pv
pv / sympyfformat.py
Last active December 16, 2015 22:20
Dump from Sympy to Fortran
"""
Dump matrices and whatnot from Sympy to Fortran.
P. Virtanen 2013, Public Domain.
"""
import os
import shutil
import subprocess
import argparse
@pv
pv / gist:5716332
Created June 5, 2013 19:07
Test failures in scipy/pr-2474
For 81dd41ba32d951487
-------------------------
======================================================================
ERROR: test_slicing_3 (test_base.TestCSC)
----------------------------------------------------------------------
Traceback (most recent call last):
@pv
pv / arpack-osx-failure.f
Last active December 19, 2015 00:59
An ARPACK-using program that fails on OSX if linked with Accelerate.
c ==============================
c Arpack failure with Accelerate
c ==============================
c
c Example of an ARPACK using program that fails when linked with
c Accelerate on OSX.
c
c This computes two eigenvalues of a 6x6 matrix (a randomly chosen
c one), via shift-invert with sigma=0.5. On OSX 10.8.4 (and probably
c others), the eigenvector computed for the second eigenvalue is false.
import sys
import numpy as np
from scipy.linalg.flapack import zgesdd
np.random.seed(1234)
a = np.random.standard_normal((1500, 2800)).astype(np.complex128)
print("-----ENTER-----"); sys.stdout.flush()
zgesdd(a, compute_uv=0, lwork=140600, full_matrices=0, overwrite_a=0)
print("-----EXIT-----"); sys.stdout.flush()
@pv
pv / zgesdd-rwork-overwrite.f90
Last active December 19, 2015 04:28
Lapack 3.4.2 ZGESDD RWORK array size seems wrong in their documentation. 5*MIN(M,N) is not enough, 7*MIN(m,n) seems required
!
! In ZGESDD in LAPACK 3.4.2, the documented size of the RWORK parameter for
! JOBZ='N' is apparently incorrect.
!
! This program demonstrates that LAPACK writes out-of-bounds in the RWORK array,
! which results to memory corruption and crashes in some cases.
! https://github.com/scipy/scipy/issues/2609
!
program main
@pv
pv / lol.rst
Created July 8, 2013 19:51
Restructured lol
.. |lol1| replace:: lol
.. |lol2| replace:: |lol1| |lol1| |lol1| |lol1| |lol1| |lol1| |lol1| |lol1| |lol1| |lol1| |lol1|
.. |lol3| replace:: |lol2| |lol2| |lol2| |lol2| |lol2| |lol2| |lol2| |lol2| |lol2| |lol2| |lol2|
.. |lol4| replace:: |lol3| |lol3| |lol3| |lol3| |lol3| |lol3| |lol3| |lol3| |lol3| |lol3| |lol3|
.. |lol5| replace:: |lol4| |lol4| |lol4| |lol4| |lol4| |lol4| |lol4| |lol4| |lol4| |lol4| |lol4|
.. |lol6| replace:: |lol5| |lol5| |lol5| |lol5| |lol5| |lol5| |lol5| |lol5| |lol5| |lol5| |lol5|
.. |lol7| replace:: |lol6| |lol6| |lol6| |lol6| |lol6| |lol6| |lol6| |lol6| |lol6| |lol6| |lol6|
.. |lol8| replace:: |lol6| |lol7| |lol7| |lol7| |lol7| |lol7| |lol7| |lol7| |lol7| |lol7| |lol7|
.. |lol9| replace:: |lol6| |lol8| |lol8| |lol8| |lol8| |lol8| |lol8| |lol8| |lol8| |lol8| |lol8|
.. |lol| replace:: |lol9|