internal static int NpyArray_RegisterCanCast(NpyArray_Descr descr, NPY_TYPES totype, NPY_SCALARKIND scalar) { if (scalar == NPY_SCALARKIND.NPY_NOSCALAR) { /* * register with cancastto * These lists won't be freed once created * -- they become part of the data-type */ if (descr.f.cancastto == null) { descr.f.cancastto = new List <NPY_TYPES>(); descr.f.cancastto.Add(NPY_TYPES.NPY_NOTYPE); } descr.f.cancastto.Add(totype); } else { /* register with cancastscalarkindto */ if (descr.f.cancastscalarkindto == null) { descr.f.cancastscalarkindto = new Dictionary <NPY_SCALARKIND, object>(); for (int i = 0; i < npy_defs.NPY_NSCALARKINDS; i++) { descr.f.cancastscalarkindto.Add((NPY_SCALARKIND)i, null); } } descr.f.cancastscalarkindto[scalar] = totype; } return(0); }
internal static int NpyArray_RegisterCanCast(NpyArray_Descr descr, NPY_TYPES totype, NPY_SCALARKIND scalar) { return(numpyinternal.NpyArray_RegisterCanCast(descr, totype, scalar)); }
internal static bool NpyArray_CanCoerceScalar(NPY_TYPES thistype, NPY_TYPES neededtype, NPY_SCALARKIND scalar) { NpyArray_Descr from; object castlist; if (scalar == NPY_SCALARKIND.NPY_NOSCALAR) { return(NpyArray_CanCastSafely(thistype, neededtype)); } from = NpyArray_DescrFromType(thistype); if (from.f.cancastscalarkindto != null) { castlist = from.f.cancastscalarkindto[scalar]; if (castlist != null) { NPY_TYPES casttype = (NPY_TYPES)castlist; while (casttype != NPY_TYPES.NPY_NOTYPE) { if (casttype++ == neededtype) { Npy_DECREF(from); return(true); } } } } Npy_DECREF(from); switch (scalar) { case NPY_SCALARKIND.NPY_BOOL_SCALAR: case NPY_SCALARKIND.NPY_OBJECT_SCALAR: return(NpyArray_CanCastSafely(thistype, neededtype)); default: if (NpyTypeNum_ISUSERDEF(neededtype)) { return(false); } switch (scalar) { case NPY_SCALARKIND.NPY_INTPOS_SCALAR: return(neededtype >= NPY_TYPES.NPY_BYTE); case NPY_SCALARKIND.NPY_INTNEG_SCALAR: return((neededtype >= NPY_TYPES.NPY_BYTE) && !(NpyTypeNum_ISUNSIGNED(neededtype))); case NPY_SCALARKIND.NPY_FLOAT_SCALAR: return(neededtype >= NPY_TYPES.NPY_FLOAT); case NPY_SCALARKIND.NPY_COMPLEX_SCALAR: return(neededtype >= NPY_TYPES.NPY_COMPLEX); default: /* should never get here... */ return(true); } } }
internal static bool NpyArray_CanCoerceScalar(NPY_TYPES thistype, NPY_TYPES neededtype, NPY_SCALARKIND scalar) { return(numpyinternal.NpyArray_CanCoerceScalar(thistype, neededtype, scalar)); }