Esempio n. 1
0
        internal static int NpyArray_CompareFunc(VoidPtr o1, VoidPtr o2, int elSize, NpyArray npa)
        {
            dynamic d1 = o1.datap;
            dynamic d2 = o2.datap;

            return(DefaultArrayHandlers.GetArrayHandler(o1.type_num).CompareTo(d1[o1.data_offset / elSize], d2[o2.data_offset / elSize]));
        }
Esempio n. 2
0
        internal static int NpyArray_FillWithScalarFunc(VoidPtr dest, npy_intp length, VoidPtr scalar, NpyArray arr)
        {
            npy_intp dest_offset   = dest.data_offset / arr.ItemSize;
            npy_intp scalar_offset = scalar.data_offset / arr.ItemSize;

            return(DefaultArrayHandlers.GetArrayHandler(dest.type_num).ArrayFill(dest, scalar, (int)length, (int)dest_offset, (int)scalar_offset));
        }
Esempio n. 3
0
        public static NumericOperations GetOperations(UFuncOperation operationType, NumericOperation operation, NpyArray srcArray, NpyArray destArray, NpyArray operandArray)
        {
            NumericOperations operations = new NumericOperations();

            operations.operationType = operationType;
            operations.operation     = operation;

            if (srcArray != null)
            {
                operations.srcHelper       = GetNumericOperationsHelper(srcArray);
                operations._ConvertOperand = DefaultArrayHandlers.GetArrayHandler(srcArray.ItemType).MathOpConvertOperand;
            }

            if (destArray != null)
            {
                operations.destHelper      = GetNumericOperationsHelper(destArray);
                operations.destItemType    = destArray.ItemType;
                operations.destTypeIsFloat = numpyinternal.NpyTypeNum_ISFLOAT(destArray.ItemType);
            }

            if (operandArray != null)
            {
                operations.operHelper = GetNumericOperationsHelper(operandArray);
                operations.IsSrcAndOperandSameType = srcArray.ItemType == operandArray.ItemType;
            }


            return(operations);
        }
Esempio n. 4
0
        public static NumericOperations GetOperations(NumericOperation operation, NpyArray srcArray, NpyArray destArray, NpyArray operandArray)
        {
            NumericOperations operations = new NumericOperations();

            operations.operation = operation;

            if (srcArray != null)
            {
                operations.srcGetItem     = srcArray.descr.f.getitem;
                operations.srcSetItem     = srcArray.descr.f.setitem;
                operations.ConvertOperand = DefaultArrayHandlers.GetArrayHandler(srcArray.ItemType).MathOpConvertOperand;
            }

            if (destArray != null)
            {
                operations.destGetItem = destArray.descr.f.getitem;
                operations.destSetItem = destArray.descr.f.setitem;
            }

            if (operandArray != null)
            {
                operations.operandGetItem = operandArray.descr.f.getitem;
                operations.operandSetItem = operandArray.descr.f.setitem;
            }


            return(operations);
        }
        internal static ulong VoidPointer_BytesLength(VoidPtr vp)
        {
            var ArrayHandler = DefaultArrayHandlers.GetArrayHandler(vp.type_num);

            var Length = ArrayHandler.GetLength(vp) * ArrayHandler.ItemSize;

            return((ulong)(Length - vp.data_offset));
        }
        internal static int VoidPointer_Length(VoidPtr vp)
        {
            var ArrayHandler = DefaultArrayHandlers.GetArrayHandler(vp.type_num);

            var Length = ArrayHandler.GetLength(vp);

            return(Length);
        }
Esempio n. 7
0
        public NpyArray_Descr(NPY_TYPES type_num)
        {
            f             = numpyinternal.GetArrFuncs(type_num);
            byteorder     = numpyinternal.NPY_NATIVE;
            this.type_num = type_num;

            this.elsize = DefaultArrayHandlers.GetArrayHandler(type_num).ItemSize;

            this.f.nonzero = DefaultArrayHandlers.GetArrayHandler(type_num).NonZero;
        }
Esempio n. 8
0
 internal static object NpyArray_GetItemFunc(npy_intp index, NpyArray npa)
 {
     if (npa.ItemType == npa.data.type_num)
     {
         return(DefaultArrayHandlers.GetArrayHandler(npa.ItemType).GetItem(npa.data, index));
     }
     else
     {
         return(DefaultArrayHandlers.GetArrayHandler(npa.ItemType).GetItemDifferentType(npa.data, index, npa.ItemType, npa.ItemSize));
     }
 }
Esempio n. 9
0
 internal static int NpyArray_SetItemFunc(npy_intp index, object value, NpyArray npa)
 {
     if (npa.ItemType == npa.data.type_num)
     {
         return(DefaultArrayHandlers.GetArrayHandler(npa.ItemType).SetItem(npa.data, index, value));
     }
     else
     {
         return(DefaultArrayHandlers.GetArrayHandler(npa.ItemType).SetItemDifferentType(npa.data, index, value));
     }
 }
Esempio n. 10
0
        internal static VoidPtr NpyDataMem_NEW(NPY_TYPES type_num, ulong size, bool AdjustForBytes = true)
        {
            var ArrayHandler = DefaultArrayHandlers.GetArrayHandler(type_num);

            size = size / (AdjustForBytes ? (ulong)ArrayHandler.ItemSize : (ulong)1);

            VoidPtr vp = new VoidPtr();

            vp.datap    = ArrayHandler.AllocateNewArray((int)size);
            vp.type_num = type_num;
            return(vp);
        }
Esempio n. 11
0
        internal static object GetIndex(VoidPtr obj, npy_intp index)
        {
            if (index < 0)
            {
                dynamic dyndatap = obj.datap;
                index = dyndatap.Length - Math.Abs(index);
            }

            object ret = DefaultArrayHandlers.GetArrayHandler(obj.type_num).GetIndex(obj, index);

            return(ret);
        }
Esempio n. 12
0
        internal static bool NpyArray_RegisterDataType(NpyArray_Descr descr)
        {
            NpyArray_Descr    descr2;
            NPY_TYPES         typenum;
            int               i;
            NpyArray_ArrFuncs f;

            /* See if this type is already registered */
            for (i = 0; i < npy_userdescrs.Count(); i++)
            {
                descr2 = npy_userdescrs[i];
                if (descr2 == descr)
                {
                    return(true);
                }
            }
            typenum        = NPY_TYPES.NPY_USERDEF + npy_userdescrs.Count();
            descr.type_num = typenum;
            if (descr.elsize == 0)
            {
                NpyErr_SetString(npyexc_type.NpyExc_ValueError, "cannot register a flexible data-type");
                return(false);
            }
            f = descr.f;
            if (f.nonzero == null)
            {
                f.nonzero = DefaultArrayHandlers.GetArrayHandler(typenum).NonZero;
            }

            if (f.getitem == null || f.setitem == null)
            {
                NpyErr_SetString(npyexc_type.NpyExc_ValueError, "a required array function is missing.");
                return(false);
            }

            npy_userdescrs.Add(descr);
            return(true);
        }
Esempio n. 13
0
        internal static int SetIndex(VoidPtr data, npy_intp index, object invalue)
        {
            if (index < 0)
            {
                dynamic dyndatap = data.datap;
                index = dyndatap.Length - Math.Abs(index);
            }

            try
            {
                DefaultArrayHandlers.GetArrayHandler(data.type_num).SetIndex(data, index, invalue);
            }
            catch (System.OverflowException oe)
            {
                NpyErr_SetString(npyexc_type.NpyExc_OverflowError, oe.Message);
            }
            catch (Exception ex)
            {
                NpyErr_SetString(npyexc_type.NpyExc_ValueError, ex.Message);
            }

            return(1);
        }
Esempio n. 14
0
 private static int NpyArray_SortFuncTypeNum(VoidPtr data, int offset, int length)
 {
     DefaultArrayHandlers.GetArrayHandler(data.type_num).SortArray(data, offset, length);
     return(0);
 }
Esempio n. 15
0
        private static int GetTypeSize(NPY_TYPES type_num)
        {
            int ItemSize = 0;

            switch (type_num)
            {
            case NPY_TYPES.NPY_BOOL:
            {
                ItemSize = sizeof(bool);
                break;
            }

            case NPY_TYPES.NPY_BYTE:
            {
                ItemSize = sizeof(sbyte);
                break;
            }

            case NPY_TYPES.NPY_UBYTE:
            {
                ItemSize = sizeof(byte);
                break;
            }

            case NPY_TYPES.NPY_INT16:
            {
                ItemSize = sizeof(Int16);
                break;
            }

            case NPY_TYPES.NPY_UINT16:
            {
                ItemSize = sizeof(UInt16);
                break;
            }

            case NPY_TYPES.NPY_INT32:
            {
                ItemSize = sizeof(Int32);
                break;
            }

            case NPY_TYPES.NPY_UINT32:
            {
                ItemSize = sizeof(UInt32);
                break;
            }

            case NPY_TYPES.NPY_INT64:
            {
                ItemSize = sizeof(Int64);
                break;
            }

            case NPY_TYPES.NPY_UINT64:
            {
                ItemSize = sizeof(UInt64);
                break;
            }

            case NPY_TYPES.NPY_FLOAT:
            {
                ItemSize = sizeof(float);
                break;
            }

            case NPY_TYPES.NPY_DOUBLE:
            case NPY_TYPES.NPY_COMPLEXREAL:
            case NPY_TYPES.NPY_COMPLEXIMAG:
            {
                ItemSize = sizeof(double);
                break;
            }

            case NPY_TYPES.NPY_DECIMAL:
            {
                ItemSize = sizeof(decimal);
                break;
            }

            case NPY_TYPES.NPY_COMPLEX:
            {
                if (__ComplexSize < 0)
                {
                    __ComplexSize = DefaultArrayHandlers.GetArrayHandler(NPY_TYPES.NPY_COMPLEX).ItemSize;
                }
                ItemSize = __ComplexSize;
                break;
            }

            case NPY_TYPES.NPY_BIGINT:
            {
                if (__BigIntSize < 0)
                {
                    __BigIntSize = DefaultArrayHandlers.GetArrayHandler(NPY_TYPES.NPY_BIGINT).ItemSize;
                }
                ItemSize = __BigIntSize;
                break;
            }

            case NPY_TYPES.NPY_OBJECT:
            {
                if (__ObjectSize < 0)
                {
                    __ObjectSize = DefaultArrayHandlers.GetArrayHandler(NPY_TYPES.NPY_OBJECT).ItemSize;
                }
                ItemSize = __ObjectSize;
                break;
            }

            case NPY_TYPES.NPY_STRING:
            {
                if (__StringSize < 0)
                {
                    __StringSize = DefaultArrayHandlers.GetArrayHandler(NPY_TYPES.NPY_STRING).ItemSize;
                }
                ItemSize = __StringSize;
                break;
            }
            }

            return(ItemSize);
        }
Esempio n. 16
0
 internal static void SetArrayHandler(NPY_TYPES ItemType, IArrayHandlers Handlers)
 {
     DefaultArrayHandlers.SetArrayHandler(ItemType, Handlers);
 }
Esempio n. 17
0
 internal static npy_intp NpyArray_ArgMaxFunc(VoidPtr ip, npy_intp startIndex, npy_intp endIndex)
 {
     return(DefaultArrayHandlers.GetArrayHandler(ip.type_num).ArgMax(ip.datap, startIndex, endIndex));
 }
Esempio n. 18
0
 internal static IArrayHandlers GetArrayHandler(NPY_TYPES ItemType)
 {
     return(DefaultArrayHandlers.GetArrayHandler(ItemType));
 }
Esempio n. 19
0
 static numpyinternal()
 {
     DefaultArrayHandlers.Initialize();
 }