MCPcopy Create free account
hub / github.com/numpy/numpy / _is_natively_aligned_at

Function _is_natively_aligned_at

numpy/core/src/multiarray/buffer.c:140–180  ·  view source on GitHub ↗

* Return non-zero if a type is aligned in each item in the given array, * AND, the descr element size is a multiple of the alignment, * AND, the array data is positioned to alignment granularity. */

Source from the content-addressed store, hash-verified

138 * AND, the array data is positioned to alignment granularity.
139 */
140static inline int
141_is_natively_aligned_at(PyArray_Descr *descr,
142 PyArrayObject *arr, Py_ssize_t offset)
143{
144 int k;
145
146 if (NPY_LIKELY(descr == PyArray_DESCR(arr))) {
147 /*
148 * If the descriptor is the arrays descriptor we can assume the
149 * array's alignment is correct.
150 */
151 assert(offset == 0);
152 if (PyArray_ISALIGNED(arr)) {
153 assert(descr->elsize % descr->alignment == 0);
154 return 1;
155 }
156 return 0;
157 }
158
159 if ((Py_ssize_t)(PyArray_DATA(arr)) % descr->alignment != 0) {
160 return 0;
161 }
162
163 if (offset % descr->alignment != 0) {
164 return 0;
165 }
166
167 if (descr->elsize % descr->alignment) {
168 return 0;
169 }
170
171 for (k = 0; k < PyArray_NDIM(arr); ++k) {
172 if (PyArray_DIM(arr, k) > 1) {
173 if (PyArray_STRIDE(arr, k) % descr->alignment != 0) {
174 return 0;
175 }
176 }
177 }
178
179 return 1;
180}
181
182/*
183 * Fill in str with an appropriate PEP 3118 format string, based on

Callers 1

_buffer_format_stringFunction · 0.85

Calls 5

PyArray_DESCRFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMFunction · 0.85
PyArray_STRIDEFunction · 0.85

Tested by

no test coverage detected