MCPcopy Index your code
hub / github.com/numpy/numpy / _get_fields_and_offsets

Function _get_fields_and_offsets

numpy/lib/recfunctions.py:853–888  ·  view source on GitHub ↗

Returns a flat list of (dtype, count, offset) tuples of all the scalar fields in the dtype "dt", including nested fields, in left to right order.

(dt, offset=0)

Source from the content-addressed store, hash-verified

851 return np.dtype((a.type, dt))
852
853def _get_fields_and_offsets(dt, offset=0):
854 """
855 Returns a flat list of (dtype, count, offset) tuples of all the
856 scalar fields in the dtype "dt", including nested fields, in left
857 to right order.
858 """
859
860 # counts up elements in subarrays, including nested subarrays, and returns
861 # base dtype and count
862 def count_elem(dt):
863 count = 1
864 while dt.shape != ():
865 for size in dt.shape:
866 count *= size
867 dt = dt.base
868 return dt, count
869
870 fields = []
871 for name in dt.names:
872 field = dt.fields[name]
873 f_dt, f_offset = field[0], field[1]
874 f_dt, n = count_elem(f_dt)
875
876 if f_dt.names is None:
877 fields.append((np.dtype((f_dt, (n,))), n, f_offset + offset))
878 else:
879 subfields = _get_fields_and_offsets(f_dt, f_offset + offset)
880 size = f_dt.itemsize
881
882 for i in range(n):
883 if i == 0:
884 # optimization: avoid list comprehension if no subarray
885 fields.extend(subfields)
886 else:
887 fields.extend([(d, c, o + i * size) for d, c, o in subfields])
888 return fields
889
890def _common_stride(offsets, counts, itemsize):
891 """

Callers 2

Calls 2

count_elemFunction · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…