Exemple #1
0
        /// <summary>
        /// Copies the source object into the destination array.  src can be
        /// any type so long as the number of elements matches dest.  In the
        /// case of strings, they will be padded with spaces if needed but
        /// can not be longer than the number of elements in dest.
        /// </summary>
        /// <param name="dest">Destination array</param>
        /// <param name="src">Source object</param>
        public static void CopyObject(ndarray dest, 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
            {
                srcArray = np.FromAny(src, dest.Dtype, 0, dest.ndim, 0, null);
            }
            NpyCoreApi.MoveInto(dest, srcArray);
        }
Exemple #2
0
        /// <summary>
        /// Copies the source object into the destination array.  src can be
        /// any type so long as the number of elements matches dest.  In the
        /// case of strings, they will be padded with spaces if needed but
        /// can not be longer than the number of elements in dest.
        /// </summary>
        /// <param name="dest">Destination array</param>
        /// <param name="src">Source object</param>
        internal static void CopyObject(ndarray dest, Object src)
        {
            ndarray srcArray;

            if (src is ndarray)
            {
                srcArray = (ndarray)src;
            }
            else if (false)
            {
                // TODO: Not handling scalars.  See arrayobject.c:111
            }
            else
            {
                srcArray = np.FromAny(src, dest.Dtype, 0, dest.ndim, 0, null);
            }
            NpyCoreApi.MoveInto(dest, srcArray);
        }