示例#1
0
        internal static void SetField(ndarray dest, NpyArray_Descr descr, int offset, object src)
        {
            // For char arrays pad the input string.
            if (dest.Dtype.Type == NPY_TYPECHAR.NPY_CHARLTR &&
                dest.ndim > 0 && src is String)
            {
                int ndimNew = (int)dest.Dim(dest.ndim - 1);
                int ndimOld = ((String)src).Length;

                if (ndimNew > ndimOld)
                {
                    src = ((String)src).PadRight(ndimNew, ' ');
                }
            }
            ndarray srcArray;

            if (src is ndarray)
            {
                srcArray = (ndarray)src;
            }
            else if (false)
            {
                // TODO: Not handling scalars.  See arrayobject.c:111
            }
            else
            {
                dtype src_dtype = new dtype(descr);
                srcArray = np.FromAny(src, src_dtype, 0, dest.ndim, NPYARRAYFLAGS.NPY_CARRAY, null);
            }
            NpyCoreApi.Incref(descr);
            if (numpyAPI.NpyArray_SetField(dest.core, descr, offset, srcArray.core) < 0)
            {
                NpyCoreApi.CheckError();
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="descr"></param>
        /// <param name="offset"></param>
        /// <param name="src"></param>
        internal static void SetField(ndarray dest, NpyArray_Descr descr, int offset, object src)
        {
            ndarray srcArray;

            if (src is ndarray)
            {
                srcArray = (ndarray)src;
            }
            else if (false)
            {
                // TODO: Not handling scalars.  See arrayobject.c:111
            }
            else
            {
                dtype src_dtype = new dtype(descr);
                srcArray = np.FromAny(src, src_dtype, 0, dest.ndim, NPYARRAYFLAGS.NPY_CARRAY, null);
            }
            NpyCoreApi.Incref(descr);
            if (numpyAPI.NpyArray_SetField(dest.core, descr, offset, srcArray.core) < 0)
            {
                NpyCoreApi.CheckError();
            }
        }