Raise error for inplace resize with new vector dim (#5228)

Raise an error if there is an attempt to resize the vectors in place with
a different vector dimension.
This commit is contained in:
adrianeboyd 2020-04-02 10:43:13 +02:00 committed by GitHub
parent 0b76212831
commit d107afcffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -552,6 +552,9 @@ class Errors(object):
E191 = ("Invalid head: the head token must be from the same doc as the "
"token itself.")
E192 = ("Unable to resize vectors in place with cupy.")
E193 = ("Unable to resize vectors in place if the resized vector dimension "
"({new_dim}) is not the same as the current vector dimension "
"({curr_dim}).")
@add_codes

View File

@ -200,6 +200,8 @@ cdef class Vectors:
"""
xp = get_array_module(self.data)
if inplace:
if shape[1] != self.data.shape[1]:
raise ValueError(Errors.E193.format(new_dim=shape[1], curr_dim=self.data.shape[1]))
if xp == numpy:
self.data.resize(shape, refcheck=False)
else: