0

According to this link https://numpy.org/doc/stable/user/basics.rec.html#automatic-byte-offsets-and-alignment, Numpy has code to calculate the offsets of the members of a C structure.

I tried to see if I could find this code in Numpy's repository (https://github.com/numpy/numpy) but couldn't find it. Would it be possible some hints to where to look at?

  • 1
    In C you can find the offset of a `struct` member with the macro [`offsetof`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/offsetof-macro?view=msvc-170). This is part of the C Standard. – Weather Vane Nov 01 '22 at 09:04
  • Yes, I know you can use `offsetof` - I'm more interested in the algorithm that calculates the offset of members taking into account padding/packing aspects of a structure. The idea is to re-implement this algorithm in another language. This link https://numpy.org/doc/stable/user/basics.rec.html#automatic-byte-offsets-and-alignment says that Numpy people have implemented this logic but not sure where it is located in Numpy's code base. – user18371559 Nov 01 '22 at 09:38
  • 1
    I do not know where the Numpy source is, but I describe the algorithm typically used to layout structures [here](https://stackoverflow.com/a/14510919/298225). – Eric Postpischil Nov 01 '22 at 10:45
  • 1
    As your link shows this is part of `numpy` handling of structured arrays and compound dtypes. Navigating numpy's C code is not a trivial task, and I doubt if anyone who sees this question in the near future will have dug into this particular topic. I think you are on your own. – hpaulj Nov 01 '22 at 16:19

0 Answers0