Commit 7f5a7dc0 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

check for input length in Monatomic.n_closest

parent 32259813
Pipeline #74782 passed with stages
in 8 minutes and 3 seconds
......@@ -484,6 +484,9 @@ class Monatomic(builder.SiteFamily, Polyatomic):
sites : numpy array
An array with sites coordinates.
"""
if len(pos) != len(self.offset):
raise ValueError("Incorrect dimensionality of 'pos'.")
# TODO (Anton): transform to tinyarrays, once ta indexing is better.
return np.dot(lll.cvp(pos - self.offset, self.reduced_vecs,
n=n, group_by_length=group_by_length, rtol=rtol),
......
......@@ -27,6 +27,9 @@ def test_closest():
tag = rng.randint(10, size=(3,))
assert lat.closest(lat(*tag).pos) == tag
# Closest should raise if input has a wrong dimensionality
raises(ValueError, lattice.square().closest, [0])
def test_general():
for lat in (lattice.general(((1, 0), (0.5, 0.5))),
......
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