Пример #1
0
        /* Compare two info structures */
        internal static size_t npy_buffer_info_cmp(npy_buffer_info_t a, npy_buffer_info_t b)
        {
            size_t c;

            c = (size_t)a.format.CompareTo(b.format);
            if (c != 0)
            {
                return(c);
            }

            c = (size_t)(a.ndim - b.ndim);
            if (c != 0)
            {
                return(c);
            }

            for (int k = 0; k < a.ndim; ++k)
            {
                c = a.shape[k] - b.shape[k];
                if (c != 0)
                {
                    return(c);
                }
                c = a.strides[k] - b.strides[k];
                if (c != 0)
                {
                    return(c);
                }
            }

            return(0);
        }
Пример #2
0
 internal static void npy_buffer_info_free(npy_buffer_info_t info)
 {
     if (info.format != null)
     {
         npy_free(info.format);
     }
     if (info.shape != null)
     {
         npy_free(info.shape);
     }
     npy_free(info);
 }
Пример #3
0
        /*
         * Global information about all active buffers
         *
         * Note: because for backward compatibility we cannot define bf_releasebuffer,
         * we must manually keep track of the additional data required by the buffers.
         */



        /* Fill in the info structure */
        internal static npy_buffer_info_t npy_buffer_info_new(NpyArray arr)
        {
            npy_buffer_info_t info;
            npy_tmp_string_t  fmt = new npy_tmp_string_t()
            {
                allocated = 0, pos = 0, s = null
            };
            int k;

            info = new npy_buffer_info_t();

            /* Fill in format */
            size_t offset           = 0;
            char   active_byteorder = '0';

            if (npy_buffer_format_string(NpyArray_DESCR(arr), fmt, arr, ref offset, ref active_byteorder) != 0)
            {
                return(null);
            }
            npy_append_char(fmt, '\0');
            info.format = fmt.s;

            /* Fill in shape and strides */
            info.ndim = NpyArray_NDIM(arr);

            if (info.ndim == 0)
            {
                info.shape   = null;
                info.strides = null;
            }
            else
            {
                info.shape   = new size_t[NpyArray_NDIM(arr)];
                info.strides = new size_t[NpyArray_NDIM(arr)];
                for (k = 0; k < NpyArray_NDIM(arr); ++k)
                {
                    info.shape[k]   = (ulong)NpyArray_DIM(arr, k);
                    info.strides[k] = (ulong)NpyArray_STRIDE(arr, k);
                }
            }

            return(info);
        }