A Bar
is associated with 0..6 Foo
s. Foo
is an extension type, like so
cdef class Foo:
cdef double fooiness
cdef void do_things(self):
self.fooiness += 1
I make copies of Bar
s very, very, very, very often. Ideally, I'd even like to be able to make copies of Bar
s concurrently with threads, without the GIL. I can define Bar
like this:
cdef class Bar:
cdef list my_foos
cdef Bar copy(self):
cdef Bar the_copy = Bar.__new__(Bar)
the_copy.my_foos[:] = self.my_foos[:]
return the_copy
but as you can imagine, the list[:] = list[:]
bit shows up bright yellow in the -a
report.
I've tried cdef Foo my_foos[6]
, but that gives me Array element cannot be a Python object
So I tried cdef Foo * my_foos[6]
, but that gave me Pointer base type cannot be a Python object
I've considered abandoning the array entirely and going with cdef Foo my_foo_1, my_foo_2...
but I'd like to iterate over my Foo
s without having to hand-unroll the loop.
Searching variations on "how do I make an array of extension types in Cython" has turned up nothing relevant - which seems strange, since having arrays of things that aren't primitives is something you'd think a lot of people would want to do. I'm probably missing something obvious.
How do I make this work?