Reduce number of individual casts

This commit is contained in:
Adriane Boyd 2022-12-06 14:24:05 +01:00
parent 0ce5d190ff
commit ed19ece5c4
2 changed files with 6 additions and 4 deletions

View File

@ -359,11 +359,12 @@ cdef class Doc:
for annot in annotations:
if annot:
if annot is heads or annot is sent_starts or annot is ent_iobs:
annot = numpy.array(annot).astype(numpy.uint64)
for i in range(len(words)):
if attrs.ndim == 1:
attrs[i] = numpy.array(annot[i]).astype(numpy.uint64)
attrs[i] = annot[i]
else:
attrs[i, j] = numpy.array(annot[i]).astype(numpy.uint64)
attrs[i, j] = annot[i]
elif annot is morphs:
for i in range(len(words)):
morph_key = vocab.morphology.add(morphs[i])
@ -1558,8 +1559,9 @@ cdef class Doc:
for j, (attr, annot) in enumerate(token_annotations.items()):
if attr is HEAD:
annot = numpy.array(annot).astype(numpy.uint64)
for i in range(len(words)):
array[i, j] = numpy.array(annot[i]).astype(numpy.uint64)
array[i, j] = annot[i]
elif attr is MORPH:
for i in range(len(words)):
array[i, j] = self.vocab.morphology.add(annot[i])

View File

@ -462,7 +462,7 @@ def _annot2array(vocab, tok_annot, doc_annot):
types = set([type(v) for v in value])
raise TypeError(Errors.E969.format(field=key, types=types)) from None
row = [vocab.strings.add(v) for v in value]
values.append([numpy.array(v).astype(numpy.uint64) for v in row])
values.append([numpy.array(v).astype(numpy.uint64) if v < 0 else v for v in row])
array = numpy.array(values, dtype=numpy.uint64)
return attrs, array.T