mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 01:46:28 +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>
12 lines
307 B
Cython
12 lines
307 B
Cython
from libcpp.memory cimport shared_ptr
|
|
from libcpp.vector cimport vector
|
|
from ..structs cimport SpanC
|
|
|
|
cdef class SpanGroup:
|
|
cdef public object _doc_ref
|
|
cdef public str name
|
|
cdef public dict attrs
|
|
cdef vector[shared_ptr[SpanC]] c
|
|
|
|
cdef void push_back(self, const shared_ptr[SpanC] &span)
|