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

Function _strided_byte_swap

numpy/core/src/multiarray/ctors.c:370–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368}
369
370NPY_NO_EXPORT void
371_strided_byte_swap(void *p, npy_intp stride, npy_intp n, int size)
372{
373 char *a, *b, c = 0;
374 int j, m;
375
376 switch(size) {
377 case 1: /* no byteswap necessary */
378 break;
379 case 4:
380 if (npy_is_aligned((void*)((npy_intp)p | stride), sizeof(npy_uint32))) {
381 for (a = (char*)p; n > 0; n--, a += stride) {
382 npy_uint32 * a_ = (npy_uint32 *)a;
383 *a_ = npy_bswap4(*a_);
384 }
385 }
386 else {
387 for (a = (char*)p; n > 0; n--, a += stride) {
388 npy_bswap4_unaligned(a);
389 }
390 }
391 break;
392 case 8:
393 if (npy_is_aligned((void*)((npy_intp)p | stride), sizeof(npy_uint64))) {
394 for (a = (char*)p; n > 0; n--, a += stride) {
395 npy_uint64 * a_ = (npy_uint64 *)a;
396 *a_ = npy_bswap8(*a_);
397 }
398 }
399 else {
400 for (a = (char*)p; n > 0; n--, a += stride) {
401 npy_bswap8_unaligned(a);
402 }
403 }
404 break;
405 case 2:
406 if (npy_is_aligned((void*)((npy_intp)p | stride), sizeof(npy_uint16))) {
407 for (a = (char*)p; n > 0; n--, a += stride) {
408 npy_uint16 * a_ = (npy_uint16 *)a;
409 *a_ = npy_bswap2(*a_);
410 }
411 }
412 else {
413 for (a = (char*)p; n > 0; n--, a += stride) {
414 npy_bswap2_unaligned(a);
415 }
416 }
417 break;
418 default:
419 m = size/2;
420 for (a = (char *)p; n > 0; n--, a += stride - m) {
421 b = a + (size - 1);
422 for (j = 0; j < m; j++) {
423 c=*a; *a++ = *b; *b-- = c;
424 }
425 }
426 break;
427 }

Callers 2

byte_swap_vectorFunction · 0.85
PyArray_LexSortFunction · 0.85

Calls 7

npy_is_alignedFunction · 0.85
npy_bswap4Function · 0.85
npy_bswap4_unalignedFunction · 0.85
npy_bswap8Function · 0.85
npy_bswap8_unalignedFunction · 0.85
npy_bswap2Function · 0.85
npy_bswap2_unalignedFunction · 0.85

Tested by

no test coverage detected