Ejemplo n.º 1
0
 private static void _aligned_strided_to_contig_size4(VoidPtr dst, long dst_stride, VoidPtr src, long src_stride, long N, long src_itemsize, NpyAuxData transferdata)
 {
     _strided_to_strided(dst, dst_stride, src, src_stride, N, src_itemsize, transferdata);
 }
Ejemplo n.º 2
0
 private static int get_decsrcref_transfer_function(bool aligned, int elsize, NpyArray_Descr src_dtype, PyArray_StridedUnaryOp out_stransfer, NpyAuxData out_transferdata, bool out_needs_api)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
 private static int get_nbo_cast_numeric_transfer_function(bool aligned, long src_stride, long dst_stride, NPY_TYPES src_type_num, NPY_TYPES dst_type_num, PyArray_StridedUnaryOp out_stransfer, NpyAuxData out_transferdata)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
 private static void _dec_src_ref_nop(VoidPtr dst, npy_intp dst_stride, VoidPtr src, npy_intp src_stride, npy_intp N, npy_intp src_itemsize, NpyAuxData transferdata)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
        private static int PyArray_GetDTypeTransferFunction(bool aligned,
                                                            npy_intp src_stride, npy_intp dst_stride,
                                                            NpyArray_Descr src_dtype, NpyArray_Descr dst_dtype,
                                                            bool move_references,
                                                            ref PyArray_StridedUnaryOp out_stransfer,
                                                            ref NpyAuxData out_transferdata,
                                                            ref bool out_needs_api)
        {
            npy_intp  src_itemsize, dst_itemsize;
            NPY_TYPES src_type_num, dst_type_num;

#if NPY_DT_DBG_TRACING
            string traceMsg = string.Format("Calculating dtype transfer from {0} to {1}", src_dtype.type_num, dst_dtype.type_num);
            Console.WriteLine(traceMsg);
#endif

            /*
             * If one of the dtypes is NULL, we give back either a src decref
             * function or a dst setzero function
             */
            if (dst_dtype == null)
            {
                if (move_references)
                {
                    return(get_decsrcref_transfer_function(aligned,
                                                           src_dtype.elsize,
                                                           src_dtype,
                                                           out_stransfer, out_transferdata,
                                                           out_needs_api));
                }
                else
                {
                    out_stransfer    = _dec_src_ref_nop;
                    out_transferdata = null;
                    return(npy_defs.NPY_SUCCEED);
                }
            }
            else if (src_dtype == null)
            {
                return(get_setdstzero_transfer_function(aligned,
                                                        dst_dtype.elsize,
                                                        dst_dtype,
                                                        out_stransfer, out_transferdata,
                                                        out_needs_api));
            }


            src_itemsize = src_dtype.elsize;
            dst_itemsize = dst_dtype.elsize;
            src_type_num = src_dtype.type_num;
            dst_type_num = dst_dtype.type_num;

            /* Common special case - number -> number NBO cast */
            if (NpyTypeNum_ISNUMBER(src_type_num) &&
                NpyTypeNum_ISNUMBER(dst_type_num) &&
                NpyArray_ISNBO(src_dtype.byteorder) &&
                NpyArray_ISNBO(dst_dtype.byteorder))
            {
                if (NpyArray_EquivTypenums(src_type_num, dst_type_num))
                {
                    out_stransfer = PyArray_GetStridedCopyFn(aligned,
                                                             src_stride, dst_stride,
                                                             src_itemsize);
                    out_transferdata = null;
                    return((out_stransfer == null) ? npy_defs.NPY_FAIL : npy_defs.NPY_SUCCEED);
                }
                else
                {
                    return(get_nbo_cast_numeric_transfer_function(aligned,
                                                                  src_stride, dst_stride,
                                                                  src_type_num, dst_type_num,
                                                                  out_stransfer, out_transferdata));
                }
            }

            /*
             * If there are no references and the data types are equivalent,
             * return a simple copy
             */
            if (NpyArray_EquivTypes(src_dtype, dst_dtype) &&
                (!NpyDataType_HASFIELDS(dst_dtype) ||
                 is_dtype_struct_simple_unaligned_layout(dst_dtype)))
            {
                /*
                 * We can't pass through the aligned flag because it's not
                 * appropriate. Consider a size-8 string, it will say it's
                 * aligned because strings only need alignment 1, but the
                 * copy function wants to know if it's alignment 8.
                 *
                 * TODO: Change align from a flag to a "best power of 2 alignment"
                 *       which holds the strongest alignment value for all
                 *       the data which will be used.
                 */
                out_stransfer = PyArray_GetStridedCopyFn(false,
                                                         src_stride, dst_stride,
                                                         src_dtype.elsize);
                out_transferdata = null;
                return(npy_defs.NPY_SUCCEED);
            }

            throw new NotImplementedException();
            return(npy_defs.NPY_SUCCEED);
        }
Ejemplo n.º 6
0
        /*
         * Assigns the array from 'src' to 'dst'. The strides must already have
         * been broadcast.
         *
         * Returns 0 on success, -1 on failure.
         */
        private static int raw_array_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)
        {
            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 [] coord          = new npy_intp[npy_defs.NPY_MAXDIMS];

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


            /* 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_PrepareTwoRawArrayIter(
                    ndim, shape,
                    dst_data, dst_strides,
                    src_data, src_strides,
                    ref ndim, shape_it,
                    ref dst_data, dst_strides_it,
                    ref src_data, src_strides_it) < 0)
            {
                return(-1);
            }

            /*
             * Overlap check for the 1D case. Higher dimensional arrays and
             * opposite strides 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];
                src_strides_it[0] = -src_strides_it[0];
                dst_strides_it[0] = -dst_strides_it[0];
            }

            /* Get the function to do the casting */
            if (PyArray_GetDTypeTransferFunction(aligned,
                                                 src_strides_it[0], dst_strides_it[0],
                                                 src_dtype, dst_dtype,
                                                 false,
                                                 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],
                          shape_it[0], src_itemsize, transferdata);
            } while (NPY_RAW_ITER_TWO_NEXT(ref idim, ndim, coord, shape_it,
                                           dst_data, dst_strides_it,
                                           src_data, src_strides_it));

            //NPY_END_THREADS;

            NPY_AUXDATA_FREE(transferdata);

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