Example #1
0
        internal static NpyArray NpyArray_View(NpyArray self, NpyArray_Descr newDescr, object subtype)
        {
            NpyArray newArr = null;

            Npy_INCREF(NpyArray_DESCR(self));
            newArr = NpyArray_NewFromDescr(NpyArray_DESCR(self),
                                           NpyArray_NDIM(self), NpyArray_DIMS(self),
                                           NpyArray_STRIDES(self),
                                           NpyArray_BYTES(self),
                                           NpyArray_FLAGS(self),
                                           false,
                                           subtype, Npy_INTERFACE(self));
            if (newArr == null)
            {
                return(null);
            }

            newArr.SetBase(self);
            Npy_INCREF(self);
            Debug.Assert(null == newArr.base_obj);

            if (newDescr != null)
            {
                /* TODO: unwrap type. */
                if (NpyArray_SetDescr(newArr, newDescr) < 0)
                {
                    Npy_DECREF(newArr);
                    Npy_DECREF(newDescr);
                    return(null);
                }
                Npy_DECREF(newDescr);
            }
            return(newArr);
        }
Example #2
0
        //
        // Returns a view of a using prototype as the interfaceData when creating the wrapper.
        // This will return the same subtype as prototype and use prototype in the __array_finalize__ call.
        //
        internal static NpyArray NpyArrayAccess_ViewLike(NpyArray a, NpyArray prototype)
        {
            Npy_INCREF(a.descr);
            NpyArray ret = NpyArray_NewFromDescr(a.descr, a.nd, a.dimensions, a.strides, a.data, a.flags, false, null, Npy_INTERFACE(prototype));

            ret.SetBase(a);
            Npy_INCREF(a);

            return(ret);
        }
Example #3
0
 internal static void NpyArrayAccess_ClearUPDATEIFCOPY(NpyArray self)
 {
     if (NpyArray_CHKFLAGS(self, NPYARRAYFLAGS.NPY_UPDATEIFCOPY))
     {
         if (self.base_arr != null)
         {
             self.base_arr.flags &= ~NPYARRAYFLAGS.NPY_WRITEABLE;
             Npy_DECREF(self.base_arr);
             self.SetBase(null);
         }
         self.flags &= ~NPYARRAYFLAGS.NPY_UPDATEIFCOPY;
     }
 }
 internal static NpyArray NpyArray_BASE_ARRAY_Update(NpyArray arr, NpyArray newArr)
 {
     arr.SetBase(arr);
     return(arr.base_arr);
 }