Commit be09a8ac authored by Joseph Weston's avatar Joseph Weston

Merge branch 'bugfix/no-numpy-matrices' into 'master'

maint: clear up warnings in tests

See merge request !270
parents dc0070fd 73a73e61
Pipeline #14390 failed with stages
in 32 minutes and 45 seconds
......@@ -165,7 +165,7 @@ check for dependencies installed:
.test: &test
stage: test
script:
- py.test -r w --cov=kwant --cov-report term --cov-report html --flakes kwant --junitxml=tests.xml
- py.test -r w --cov=kwant --cov-report term --cov-report html --flakes kwant --junitxml=tests.xml --durations=10
artifacts:
paths:
- htmlcov
......
......@@ -119,9 +119,12 @@ if mpl_available:
phi = np.linspace(0, pi, 21)
xyz = np.c_[np.cos(phi), np.sin(phi), 0 * phi].T.reshape(-1, 1, 21)
unit_sphere = np.bmat([[xyz[0], xyz[2]], [xyz[1], xyz[0]],
[xyz[2], xyz[1]]])
unit_sphere = np.asarray(unit_sphere)
# TODO: use np.block once we depend on numpy >= 1.13.
unit_sphere = np.vstack([
np.hstack([xyz[0], xyz[2]]),
np.hstack([xyz[1], xyz[0]]),
np.hstack([xyz[2], xyz[1]]),
])
def projected_length(ax, length):
rc = np.array([ax.get_xlim3d(), ax.get_ylim3d(), ax.get_zlim3d()])
......
......@@ -13,7 +13,7 @@ __all__ = ['two_terminal_shotnoise']
def two_terminal_shotnoise(smatrix):
"""Compute the shot-noise in a two-terminal setup.
r"""Compute the shot-noise in a two-terminal setup.
In a two terminal system the shot noise is given by `tr((1 - t*t^\dagger) *
t*t^\dagger)`.
......
......@@ -16,6 +16,18 @@ def almost_identity(mat):
return np.all(abs(mat - identity(mat.shape[0])).data < 1e-10)
def _column_sum(matrix):
"""Sum the columns of a sparse matrix.
This is fully analogous to ``matrix.sum(0)``, and uses an implementation
similar to that in scipy v1.1.0, however it avoids using ``numpy.matrix``
interface and therefore does not raise a ``PendingDeprecationWarning``.
This should be removed once we depend on scipy v1.2.0, where the warning is
silenced.
"""
return matrix.T @ np.ones(matrix.shape[0])
def cond_conj(op, conj):
return op.conj() if conj else op
......@@ -106,8 +118,9 @@ class DiscreteSymmetry:
symms[i] = symm
if projectors is not None:
projectors = [p[:, np.asarray(abs(p).sum(0)).flatten() > 1e-10]
for p in projectors]
projectors = [
p[:, _column_sum(abs(p)) > 1e-10] for p in projectors
]
if not almost_identity(sum(projector.dot(projector.conj().T) for
projector in projectors)):
raise ValueError("Projectors should stack to a unitary matrix.")
......
......@@ -1302,6 +1302,7 @@ def map(sys, value, colorbar=True, cmap=None, vmin=None, vmax=None, a=None,
# Calculate the min/max bounds for the colormap.
# User-provided values take precedence.
unmasked_data = img[~img.mask].data.flatten()
unmasked_data = unmasked_data[~np.isnan(unmasked_data)]
new_vmin, new_vmax = percentile_bound(unmasked_data, vmin, vmax)
overflow_pct = 100 * np.sum(unmasked_data > new_vmax) / len(unmasked_data)
underflow_pct = 100 * np.sum(unmasked_data < new_vmin) / len(unmasked_data)
......
......@@ -555,7 +555,7 @@ class SparseSolver(metaclass=abc.ABCMeta):
def wave_function(self, sys, energy=0, args=(), check_hermiticity=True,
*, params=None):
"""
r"""
Return a callable object for the computation of the wave function
inside the scattering region.
......
......@@ -77,7 +77,6 @@ def test_operator_construction():
raises(ValueError, a, ket)
raises(ValueError, a, ket, ket)
raises(ValueError, a.act, ket)
raises(ValueError, a.act, ket, ket)
# Test failure on non-hermitian
for A in (ops.Density, ops.Current, ops.Source):
......
......@@ -261,7 +261,7 @@ def test_spectrum():
params=dict(c=1), fig_size=(10, 10), file=out)
# test 2D plot and explicitly passing axis
fig = pyplot.Figure()
fig = pyplot.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
plotter.spectrum(ham_1d, ('a', vals), ('b', 2 * vals),
params=dict(c=1), ax=ax, file=out)
......
......@@ -166,7 +166,8 @@ def test_symmetry():
syst.particle_hole = ph
syst.time_reversal = tr
wrapped = wraparound(syst)
with pytest.warns(RuntimeWarning):
wrapped = wraparound(syst)
assert wrapped.time_reversal is None
assert wrapped.particle_hole is None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment