Coverage for kwant/linalg/lll.py : 90%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright 2011-2013 Kwant authors. # # This file is part of Kwant. It is subject to the license terms in the file # LICENSE.rst found in the top-level directory of this distribution and at # http://kwant-project.org/license. A list of Kwant authors can be found in # the file AUTHORS.rst at the top-level directory of this distribution and at # http://kwant-project.org/authors.
"""Gram-Schmidt coefficient."""
"""Compute Gram-Schmidt decomposition on a matrix."""
"""Check if a basis is c-reduced."""
""" Calculate a reduced lattice basis using LLL algorithm.
Reduce a basis of a lattice to an almost orthonormal form. For details see e.g. http://en.wikipedia.org/wiki/LLL-algorithm.
Parameters ---------- basis : 2d array-like of floats The lattice basis vectors to be reduced. c : float Reduction parameter for the algorithm. Must be larger than 1 1/3, since otherwise a solution is not guaranteed to exist.
Returns ------- reduced_basis : numpy array The basis vectors of the LLL-reduced basis. transformation : numpy integer array Coefficient matrix for tranforming from the reduced basis to the original one. """ raise ValueError('"basis" must be a 2d array-like object.') raise ValueError('The number of basis vectors exceeds the ' 'space dimensionality.')
# Initialize values.
# Main part of LLL algorithm. c * np.linalg.norm(vecsstar[i+1]) ** 2): else:
# TODO: change to rcond=None once we depend on numpy >= 1.14. raise RuntimeError('LLL algorithm instability.') raise RuntimeError('LLL algorithm instability.')
""" Solve the n-closest vector problem for a vector, given a basis.
This algorithm performs poorly in general, so it should be supplied with LLL-reduced bases.
Parameters ---------- vec : 1d array-like of floats The lattice vectors closest to this vector are to be found. basis : 2d array-like of floats Sequence of basis vectors n : int Number of lattice vectors closest to the point that need to be found.
Returns ------- coords : numpy array An array with the coefficients of the lattice vectors closest to the requested point.
Notes ----- This function can also be used to solve the `n` shortest lattice vector problem if the `vec` is zero, and `n+1` points are requested (and the first output is ignored). """ # Calculate coordinates of the starting point in this basis. raise ValueError('`basis` must be a 2d array-like object.') # TODO: change to rcond=None once we depend on numpy >= 1.14. # Cutoff radius for n-th nearest neighbor. else:
""" Return an array of lattice vectors forming its voronoi cell.
Parameters ---------- basis : 2d array-like of floats Basis vectors for which the Voronoi neighbors have to be found.
Returns ------- voronoi_neighbors : numpy array of ints All the lattice vectors that may potentially neighbor the origin.
Notes ----- This algorithm does not calculate the minimal Voronoi cell of the lattice and can be optimized. Its main aim is flood-fill, however, and better safe than sorry. """ raise ValueError('`basis` must be a 2d array-like object.') displacements]) vertices[i] += 2 * np.array(displacements[i]) |