Example #1
0
 private static int PyArray_GetMaskedDTypeTransferFunction(bool aligned,
                                                           npy_intp src_stride,
                                                           npy_intp dst_stride,
                                                           npy_intp mask_stride,
                                                           NpyArray_Descr src_dtype,
                                                           NpyArray_Descr dst_dtype,
                                                           NpyArray_Descr mask_dtype,
                                                           int move_references,
                                                           ref PyArray_MaskedStridedUnaryOp out_stransfer,
                                                           ref NpyAuxData out_transferdata,
                                                           ref bool out_needs_api)
 {
     return(npy_defs.NPY_SUCCEED);
 }
Example #2
0
        /*
         * Assigns the array from 'src' to 'dst, wherever the 'wheremask'
         * value is True. The strides must already have been broadcast.
         *
         * Returns 0 on success, -1 on failure.
         */
        private static int raw_array_wheremasked_assign_array(int ndim, npy_intp[] shape,
                                                              NpyArray_Descr dst_dtype, VoidPtr dst_data, npy_intp[] dst_strides,
                                                              NpyArray_Descr src_dtype, VoidPtr src_data, npy_intp[] src_strides,
                                                              NpyArray_Descr wheremask_dtype, VoidPtr wheremask_data,
                                                              npy_intp[] wheremask_strides)
        {
            int idim = 0;

            npy_intp [] shape_it             = new npy_intp[npy_defs.NPY_MAXDIMS];
            npy_intp [] dst_strides_it       = new npy_intp[npy_defs.NPY_MAXDIMS];
            npy_intp [] src_strides_it       = new npy_intp[npy_defs.NPY_MAXDIMS];
            npy_intp [] wheremask_strides_it = new npy_intp[npy_defs.NPY_MAXDIMS];
            npy_intp [] coord = new npy_intp[npy_defs.NPY_MAXDIMS];

            PyArray_MaskedStridedUnaryOp stransfer = null;
            NpyAuxData transferdata = null;
            bool       aligned, needs_api = false;
            npy_intp   src_itemsize = src_dtype.elsize;

            //NPY_BEGIN_THREADS_DEF;

            /* Check alignment */
            aligned = raw_array_is_aligned(ndim,
                                           dst_data, dst_strides, dst_dtype.alignment) &&
                      raw_array_is_aligned(ndim,
                                           src_data, src_strides, src_dtype.alignment);

            /* Use raw iteration with no heap allocation */
            if (PyArray_PrepareThreeRawArrayIter(
                    ndim, shape,
                    dst_data, dst_strides,
                    src_data, src_strides,
                    wheremask_data, wheremask_strides,
                    ref ndim, shape_it,
                    ref dst_data, dst_strides_it,
                    ref src_data, src_strides_it,
                    ref wheremask_data, wheremask_strides_it) < 0)
            {
                return(-1);
            }

            /*
             * Overlap check for the 1D case. Higher dimensional arrays cause
             * a temporary copy before getting here.
             */
            if (ndim == 1 && arrays_overlap(src_data, dst_data))
            {
                src_data               += (shape_it[0] - 1) * src_strides_it[0];
                dst_data               += (shape_it[0] - 1) * dst_strides_it[0];
                wheremask_data         += (shape_it[0] - 1) * wheremask_strides_it[0];
                src_strides_it[0]       = -src_strides_it[0];
                dst_strides_it[0]       = -dst_strides_it[0];
                wheremask_strides_it[0] = -wheremask_strides_it[0];
            }

            /* Get the function to do the casting */
            if (PyArray_GetMaskedDTypeTransferFunction(aligned,
                                                       src_strides_it[0],
                                                       dst_strides_it[0],
                                                       wheremask_strides_it[0],
                                                       src_dtype, dst_dtype, wheremask_dtype,
                                                       0,
                                                       ref stransfer, ref transferdata,
                                                       ref needs_api) != npy_defs.NPY_SUCCEED)
            {
                return(-1);
            }

            if (!needs_api)
            {
                //NPY_BEGIN_THREADS;
            }

            NPY_RAW_ITER_START(idim, ndim, coord, shape_it);
            do
            {
                /* Process the innermost dimension */
                stransfer(dst_data, dst_strides_it[0], src_data, src_strides_it[0],
                          (bool [])wheremask_data.datap, wheremask_strides_it[0],
                          shape_it[0], src_itemsize, transferdata);
            } while (NPY_RAW_ITER_THREE_NEXT(ref idim, ndim, coord, shape_it,
                                             dst_data, dst_strides_it,
                                             src_data, src_strides_it,
                                             wheremask_data, wheremask_strides_it));

            //NPY_END_THREADS;

            NPY_AUXDATA_FREE(transferdata);

            return((needs_api && NpyErr_Occurred()) ? -1 : 0);
        }