/* W W AAA RRRR N N III N N GGG !!! ** W W A A R R NN N I NN N G G !!! ** W W W AAAAA RRRR N N N I N N N G ! ** W W W A A R R N NN I N NN G GG ** W W A A R R N N III N N GGG !!! ** ** WARNING: This file is program generated by codegenerator.py. ** ** DO NOT EDIT THIS FILE! Any changes made to this file will be lost! */ #include #include #include "libnumarray.h" #include #define NA_ACOPYN(i, o) memcpy(o, i, N) /* The following is used to copy nbytes of data for each element. ** ** As such it can be used to align any sort of data provided the ** ** output pointers used are aligned */ static int copyNbytes(long dim, long nbytes, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i, j; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i=0; i--) { otemp = PySequence_GetItem(nitersObj, i); if (PyInt_Check(otemp)) ltemp = PyInt_AsLong(otemp); else if (PyLong_Check(otemp)) ltemp = PyLong_AsLong(otemp); else return PyErr_Format(PyExc_TypeError, "copyToString: non-integer shape element"); nelements *= ltemp; niters[nniters-i-1] = ltemp; Py_DECREF(otemp); otemp = PySequence_GetItem(inbstridesObj, i); if (PyInt_Check(otemp)) inbstrides[nniters-i-1] = PyInt_AsLong(otemp); else if (PyLong_Check(otemp)) inbstrides[nniters-i-1] = PyLong_AsLong(otemp); else return PyErr_Format(PyExc_TypeError, "copyToString: non-integer stride element"); Py_DECREF(otemp); } if (!nelements) return PyString_FromStringAndSize("", 0); outbstrides[0] = nbytes; for (i=1; i= max) i -= max; static int takeNbytes(long niter, long ninargs, long noutargs, void **buffers, long *bsizes) { maybelong i, cMode, N; maybelong *scatteredstrides, *scatteredshape, **indices; char *gathered, *scattered; maybelong nindices = ninargs-4, outi = ninargs+noutargs-1; if (NA_checkIo("takeNbytes", 4, 1, MIN(ninargs, 4), noutargs)) return -1; if (nindices == 0) return 0; if (NA_checkOneCBuffer("takeNbytes", 2, buffers[0], bsizes[0], sizeof(maybelong))) return -1; else { cMode = ((maybelong *) buffers[0])[0]; N = ((maybelong *) buffers[0])[1]; } if (NA_checkOneCBuffer("takeNbytes", nindices, buffers[2], bsizes[2], sizeof(maybelong))) return -1; else { scatteredstrides = (maybelong *) buffers[2]; } if (NA_checkOneCBuffer("takeNbytes", nindices, buffers[3], bsizes[3], sizeof(maybelong))) return -1; else { scatteredshape = (maybelong *) buffers[3]; } if (NA_checkOneStriding("takeNBytes", nindices, scatteredshape, 0, scatteredstrides, bsizes[1], N, 0)) return -1; else scattered = (char *) buffers[1]; for(i=4; i= scatteredshape[j]) k = scatteredshape[j]-1; index += scatteredstrides[j]*k; } memcpy( &gathered[i*N], scattered+index, N); } break; case RAISE: for(i=0; i= scatteredshape[j]) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } index += scatteredstrides[j]*k; } memcpy( &gathered[i*N], scattered+index, N); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(takeNbytes, CFUNC_UFUNC); static int putNbytes(long niter, long ninargs, long noutargs, void **buffers, long *bsizes) { maybelong i, cMode, N; maybelong *scatteredstrides, *scatteredshape, **indices; char *gathered, *scattered; long nindices = ninargs-4, outi = ninargs+noutargs-1; if (nindices == 0) return 0; if (NA_checkIo("putNbytes", 4, 1, MIN(ninargs, 4), noutargs)) return -1; if (NA_checkOneCBuffer("putNbytes", 2, buffers[0], bsizes[0], sizeof(maybelong))) return -1; else { cMode = ((maybelong *) buffers[0])[0]; N = ((maybelong *) buffers[0])[1]; } if (NA_checkOneCBuffer("putNbytes", niter*N, buffers[1], bsizes[1], 1)) return -1; else gathered = (char *) buffers[1]; if (NA_checkOneCBuffer("putNbytes", nindices, buffers[2], bsizes[2], sizeof(maybelong))) return -1; else { scatteredstrides = (maybelong *) buffers[2]; } if (NA_checkOneCBuffer("putNbytes", nindices, buffers[3], bsizes[3], sizeof(maybelong))) return -1; else { scatteredshape = (maybelong *) buffers[3]; } for(i=4; i= scatteredshape[j]) k = scatteredshape[j]-1; index += scatteredstrides[j]*k; } memcpy( scattered+index, &gathered[i*N], N); } break; case RAISE: for(i=0; i= scatteredshape[j]) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } index += scatteredstrides[j]*k; } memcpy( scattered+index, &gathered[i*N], N); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(putNbytes, CFUNC_UFUNC); /****************** Int8 *******************/ /******************************************* * * * These copy data to a contiguous buffer. * * They do not handle non-aligned data. * * Offsets and Strides are in byte units * * * *******************************************/ static int copy1bytes(long dim, long dummy, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i= maxP) j = maxP-1; NA_ACOPY1(&population[j][i*1], &output[i*1]); } break; case RAISE: for(i=0; i= maxP)) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } NA_ACOPY1(&population[j][i*1], &output[i*1]); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(choose1bytes, CFUNC_UFUNC); /****************** Int16 *******************/ /******************************************* * * * These copy data to a contiguous buffer. * * They do not handle non-aligned data. * * Offsets and Strides are in byte units * * * *******************************************/ static int copy2bytes(long dim, long dummy, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i= maxP) j = maxP-1; NA_ACOPY2(&population[j][i*2], &output[i*2]); } break; case RAISE: for(i=0; i= maxP)) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } NA_ACOPY2(&population[j][i*2], &output[i*2]); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(choose2bytes, CFUNC_UFUNC); /****************** Int32 *******************/ /******************************************* * * * These copy data to a contiguous buffer. * * They do not handle non-aligned data. * * Offsets and Strides are in byte units * * * *******************************************/ static int copy4bytes(long dim, long dummy, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i= maxP) j = maxP-1; NA_ACOPY4(&population[j][i*4], &output[i*4]); } break; case RAISE: for(i=0; i= maxP)) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } NA_ACOPY4(&population[j][i*4], &output[i*4]); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(choose4bytes, CFUNC_UFUNC); /****************** Float64 *******************/ /******************************************* * * * These copy data to a contiguous buffer. * * They do not handle non-aligned data. * * Offsets and Strides are in byte units * * * *******************************************/ static int copy8bytes(long dim, long dummy, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i= maxP) j = maxP-1; NA_ACOPY8(&population[j][i*8], &output[i*8]); } break; case RAISE: for(i=0; i= maxP)) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } NA_ACOPY8(&population[j][i*8], &output[i*8]); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(choose8bytes, CFUNC_UFUNC); /****************** Complex64 *******************/ /******************************************* * * * These copy data to a contiguous buffer. * * They do not handle non-aligned data. * * Offsets and Strides are in byte units * * * *******************************************/ static int copy16bytes(long dim, long dummy, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i= maxP) j = maxP-1; NA_ACOPY16(&population[j][i*16], &output[i*16]); } break; case RAISE: for(i=0; i= maxP)) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } NA_ACOPY16(&population[j][i*16], &output[i*16]); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(choose16bytes, CFUNC_UFUNC); /****************** AnyType *******************/ static int chooseNbytes(long niter, long ninargs, long noutargs, void **buffers, long *bsizes) { maybelong i, cMode, maxP, N, *selector; char **population, *output; int outi = ninargs + noutargs - 1; if (NA_checkIo("chooseNbytes", 2, 1, MIN(ninargs,2), noutargs)) return -1; if (NA_checkOneCBuffer("chooseNbytes", 2, buffers[0], bsizes[0], sizeof(maybelong))) return -1; else { cMode = ((maybelong *) buffers[0])[0]; N = ((maybelong *) buffers[0])[1]; } if (NA_checkOneCBuffer("chooseNbytes", niter, buffers[1], bsizes[1], sizeof(maybelong))) return -1; else selector = (maybelong *) buffers[1]; if (ninargs-2 == 0) return 0; else maxP = ninargs-2; for(i=2; i= maxP) j = maxP-1; NA_ACOPYN(&population[j][i*N], &output[i*N]); } break; case RAISE: for(i=0; i= maxP)) { PyErr_Format(PyExc_IndexError, "Index out of range"); return -1; } NA_ACOPYN(&population[j][i*N], &output[i*N]); } break; } return 0; } SELF_CHECKED_CFUNC_DESCR(chooseNbytes, CFUNC_UFUNC); /****************** Complex32 *******************/ /******* byteswap *****/ static int byteswapComplex32(long dim, long dummy, maybelong *niters, void *input, long inboffset, maybelong *inbstrides, void *output, long outboffset, maybelong *outbstrides) { long i; char *tin = (char *) input + inboffset; char *tout = (char *) output + outboffset; if (dim == 0) { for (i=0; i