Commit c16a3088 authored by Pablo Piskunow's avatar Pablo Piskunow Committed by Joseph Weston
Browse files

fix KPM in cases where the operator returns a vector

parent d65a2b4a
Pipeline #2848 passed with stages
in 3 minutes and 2 seconds
......@@ -269,11 +269,11 @@ class SpectralDensity:
np.tan(np.pi/(self.num_moments + 1)))
kernel = kernel / (self.num_moments + 1)
coef_cheb = np.zeros_like(moments)
coef_cheb[0] = moments[0]
coef_cheb[1:] = 2 * moments[1:] * kernel[1:]
# transposes handle the case where operators have vector outputs
coef_cheb = np.transpose(moments.transpose() * kernel)
coef_cheb[1:] = 2 * coef_cheb[1:]
return (np.polynomial.chebyshev.chebval(
return np.transpose(np.polynomial.chebyshev.chebval(
rescaled_energy, coef_cheb) / g_e).real
def average(self, distribution_function=None):
......
......@@ -285,6 +285,9 @@ def test_kwant_op():
# same algorithms are used so these arrays are equal up to TOL
assert_allclose(np.sum(spectrum_syst.densities, axis=1),
spectrum.densities)
# test that the densities are arrays when calling the instance
e = spectrum_syst.energies
assert_allclose_sp(spectrum_syst(e), spectrum_syst.densities)
def test_kwant_op_average():
"""Check that the kwant.operator.Density gives the same result as the
......
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