Hi,
I am figuring out how to use struct arrays and would very much appreciate answers to a couple quick questions.
In the example below, the Cython typed memoryview "foos" can be assigned to an cvarrayA which has format string describing the struct fields.
1) Is there a cast that would allow assigning foos = <...>cvarrayB, or some other way to just treat each element as n opaque bytes ?
2) Are there any differences in how "foos" may be used after assigning to cvarrayA vs cvarrayB? (assuming there is a way to assign to the opaque style cvarrayB)
from cython cimport view
cdef struct Foo:
int a
char b
float c
def run():
cdef Foo [:] foos
n = 5
cvarrayA = view.array(shape=(n,), itemsize=sizeof(Foo), format='T{i:a:c:b:f:c:}')
cvarrayB = view.array(shape=(n,), itemsize=sizeof(Foo), format='B')
foos = cvarrayA
print(f'assigned to A')
# foos = cvarrayB
# ValueError: Buffer dtype mismatch, expected 'int' but got 'unsigned char' in 'Foo.a'
foos = <Foo[:]>cvarrayB
# foo.pyx:24:19: Can only create cython.array from pointer or array
run()
Thanks!!
Pete