mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-16 06:37:04 +03:00
75f7c15187
* Span/SpanGroup: wrap SpanC in shared_ptr When a Span that was retrieved from a SpanGroup was modified, these changes were not reflected in the SpanGroup because the underlying SpanC struct was copied. This change applies the solution proposed by @nrodnova, to wrap SpanC in a shared_ptr. This makes a SpanGroup and Spans derived from it share the same SpanC. So, changes made through a Span are visible in the SpanGroup as well. Fixes #9556 * Test that a SpanGroup is modified through its Spans * SpanGroup.push_back: remove nogil Modifying std::vector is not thread-safe. * C++ >= 11 does not allow const T in vector<T> * Add Span.span_c as a shorthand for Span.c.get Since this method is cdef'ed, it is only visible from Cython, so we avoid using raw pointers in Python Replace existing uses of span.c.get() to use this new method. * Fix formatting * Style fix: pointer types * SpanGroup.to_bytes: reduce number of shared_ptr::get calls * Mark SpanGroup modification test with issue Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com> Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
29 lines
632 B
Cython
29 lines
632 B
Cython
from libcpp.memory cimport shared_ptr
|
|
cimport numpy as np
|
|
|
|
from .doc cimport Doc
|
|
from ..typedefs cimport attr_t
|
|
from ..structs cimport SpanC
|
|
|
|
|
|
cdef class Span:
|
|
cdef readonly Doc doc
|
|
cdef shared_ptr[SpanC] c
|
|
cdef public _vector
|
|
cdef public _vector_norm
|
|
|
|
@staticmethod
|
|
cdef inline Span cinit(Doc doc, const shared_ptr[SpanC] &span):
|
|
cdef Span self = Span.__new__(
|
|
Span,
|
|
doc,
|
|
start=span.get().start,
|
|
end=span.get().end
|
|
)
|
|
self.c = span
|
|
return self
|
|
|
|
cpdef np.ndarray to_array(self, object features)
|
|
|
|
cdef SpanC* span_c(self)
|