mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
* Add a type declaration for doc.from_array
This commit is contained in:
parent
25a8774f42
commit
aa7a964a4f
|
@ -1,5 +1,6 @@
|
||||||
cimport cython
|
cimport cython
|
||||||
from libc.string cimport memcpy, memset
|
from libc.string cimport memcpy, memset
|
||||||
|
from libc.stdint cimport uint32_t
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
import struct
|
import struct
|
||||||
|
@ -274,6 +275,7 @@ cdef class Doc:
|
||||||
cdef attr_id_t attr_id
|
cdef attr_id_t attr_id
|
||||||
cdef TokenC* tokens = self.data
|
cdef TokenC* tokens = self.data
|
||||||
cdef int length = len(array)
|
cdef int length = len(array)
|
||||||
|
cdef attr_t[:] values
|
||||||
for col, attr_id in enumerate(attrs):
|
for col, attr_id in enumerate(attrs):
|
||||||
values = array[:, col]
|
values = array[:, col]
|
||||||
if attr_id == HEAD:
|
if attr_id == HEAD:
|
||||||
|
@ -296,7 +298,8 @@ cdef class Doc:
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
byte_string = self.vocab.serializer.pack(self)
|
byte_string = self.vocab.serializer.pack(self)
|
||||||
return struct.pack('I', len(byte_string)) + byte_string
|
cdef uint32_t length = len(byte_string)
|
||||||
|
return struct.pack('I', length) + byte_string
|
||||||
|
|
||||||
def from_bytes(self, data):
|
def from_bytes(self, data):
|
||||||
self.vocab.serializer.unpack_into(data[4:], self)
|
self.vocab.serializer.unpack_into(data[4:], self)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user