mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-06 21:30:22 +03:00
Reduce number of individual casts
This commit is contained in:
parent
0ce5d190ff
commit
ed19ece5c4
|
@ -359,11 +359,12 @@ cdef class Doc:
|
||||||
for annot in annotations:
|
for annot in annotations:
|
||||||
if annot:
|
if annot:
|
||||||
if annot is heads or annot is sent_starts or annot is ent_iobs:
|
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)):
|
for i in range(len(words)):
|
||||||
if attrs.ndim == 1:
|
if attrs.ndim == 1:
|
||||||
attrs[i] = numpy.array(annot[i]).astype(numpy.uint64)
|
attrs[i] = annot[i]
|
||||||
else:
|
else:
|
||||||
attrs[i, j] = numpy.array(annot[i]).astype(numpy.uint64)
|
attrs[i, j] = annot[i]
|
||||||
elif annot is morphs:
|
elif annot is morphs:
|
||||||
for i in range(len(words)):
|
for i in range(len(words)):
|
||||||
morph_key = vocab.morphology.add(morphs[i])
|
morph_key = vocab.morphology.add(morphs[i])
|
||||||
|
@ -1558,8 +1559,9 @@ cdef class Doc:
|
||||||
|
|
||||||
for j, (attr, annot) in enumerate(token_annotations.items()):
|
for j, (attr, annot) in enumerate(token_annotations.items()):
|
||||||
if attr is HEAD:
|
if attr is HEAD:
|
||||||
|
annot = numpy.array(annot).astype(numpy.uint64)
|
||||||
for i in range(len(words)):
|
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:
|
elif attr is MORPH:
|
||||||
for i in range(len(words)):
|
for i in range(len(words)):
|
||||||
array[i, j] = self.vocab.morphology.add(annot[i])
|
array[i, j] = self.vocab.morphology.add(annot[i])
|
||||||
|
|
|
@ -462,7 +462,7 @@ def _annot2array(vocab, tok_annot, doc_annot):
|
||||||
types = set([type(v) for v in value])
|
types = set([type(v) for v in value])
|
||||||
raise TypeError(Errors.E969.format(field=key, types=types)) from None
|
raise TypeError(Errors.E969.format(field=key, types=types)) from None
|
||||||
row = [vocab.strings.add(v) for v in value]
|
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)
|
array = numpy.array(values, dtype=numpy.uint64)
|
||||||
return attrs, array.T
|
return attrs, array.T
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user