internal static void NpyArray_CopySwapFunc(VoidPtr dest, VoidPtr Source, bool swap, NpyArray arr) { if (arr == null) { return; } if (NpyArray_HASFIELDS(arr)) { NpyDict_KVPair KVPair = new NpyDict_KVPair(); NpyArray_Descr descr; NpyDict_Iter pos = new NpyDict_Iter(); descr = arr.descr; NpyDict_IterInit(pos); while (NpyDict_IterNext(descr.fields, pos, KVPair)) { NpyArray_DescrField value = KVPair.value as NpyArray_DescrField; string key = KVPair.key as string; if (null != value.title && key.CompareTo(value.title) != 0) { continue; } arr.descr = value.descr; MemCopy.GetMemcopyHelper(dest).copyswap(dest + value.offset, Source + value.offset, swap); } arr.descr = descr; return; } if (swap && arr.descr.subarray != null) { NpyArray_Descr descr = new NpyArray_Descr(NPY_TYPES.NPY_OBJECT); NpyArray_Descr newDescr = null; npy_intp num; int itemsize; descr = arr.descr; newDescr = descr.subarray._base; arr.descr = newDescr; itemsize = newDescr.elsize; num = descr.elsize / itemsize; _default_copyswap(dest, itemsize, Source, itemsize, num, swap, arr); arr.descr = descr; return; } if (Source != null) { memcpy(dest, Source, NpyArray_ITEMSIZE(arr)); } if (swap) { swapvalue(dest, NpyArray_ITEMSIZE(arr)); } return; }
internal static bool npy_arraydescr_isnative(NpyArray_Descr self) { if (self.names == null) { return(NpyArray_ISNBO(self)); } else { NpyDict_Iter pos = new NpyDict_Iter(); NpyDict_KVPair KVPair = new NpyDict_KVPair(); KVPair.key = null; KVPair.value = null; NpyDict_IterInit(pos); while (NpyDict_IterNext(self.fields, pos, KVPair)) { string key = (string)KVPair.key; NpyArray_DescrField value = (NpyArray_DescrField)KVPair.value; if (null != value.title && value.title.CompareTo(key) != 0) { continue; } if (false == npy_arraydescr_isnative(value.descr)) { return(false); } } } return(true); }
internal static NpyDict_Iter NpyArrayAccess_DictAllocIter() { NpyDict_Iter iter = new NpyDict_Iter(); NpyDict_IterInit(iter); return(iter); }
internal static NpyArray_Descr_Flags npy_descr_find_object_flag(NpyArray_Descr self) { if (self.flags != 0 || self.type_num == NPY_TYPES.NPY_OBJECT || self.kind == 'O') { return(NpyArray_Descr_Flags.NPY_OBJECT_DTYPE_FLAGS); } if (self.names != null) { NpyDict_Iter pos = new NpyDict_Iter(); NpyDict_KVPair KVPair = new NpyDict_KVPair(); KVPair.key = null; KVPair.value = null; NpyDict_IterInit(pos); while (NpyDict_IterNext(self.fields, pos, KVPair)) { string key = (string)KVPair.key; NpyArray_DescrField value = (NpyArray_DescrField)KVPair.value; if (null != value.title && value.title.CompareTo(key) != 0) { continue; } if (npy_descr_find_object_flag(value.descr) != 0) { value.descr.flags = NpyArray_Descr_Flags.NPY_OBJECT_DTYPE_FLAGS; return(NpyArray_Descr_Flags.NPY_OBJECT_DTYPE_FLAGS); } } } return(0); }
static bool _equivalent_fields(NpyDict field1, NpyDict field2) { NpyDict_Iter pos = new NpyDict_Iter(); NpyArray_DescrField value1 = null; NpyArray_DescrField value2 = null; object key = null; bool same = true; NpyDict_KVPair KVPair = new NpyDict_KVPair(); if (field1 == field2) { return(true); } if (field1 == null || field2 == null) { return(false); } if (NpyDict_Size(field1) != NpyDict_Size(field2)) { same = false; } NpyDict_IterInit(pos); while (same && NpyDict_IterNext(field1, pos, KVPair)) { value2 = (NpyArray_DescrField)NpyDict_Get(field2, key); if (null == value2 || value1.offset != value2.offset || ((null == value1.title && null != value2.title) || (null != value1.title && null == value2.title) || (null != value1.title && null != value2.title && value1.title == value2.title))) { same = false; } else if (!NpyArray_EquivTypes(value1.descr, value2.descr)) { same = false; } } return(same); }
/*--------------------------------------------------------------------------*\ * NAME: * NpyDict_IterNext() - advances to the next element and returns it * DESCRIPTION: * Advances to the next element and returns that key/value pair. If * the end is reached false is returned and key/value are set to null. * Once the iterator is at the end, calling next will continue to * result in 'false' until the iterator is re-initialized. * * Switching hash tables or modifying the hash table without re- * initializing the iterator is a bad idea. * * EFFICIENCY: * O(1) * ARGUMENTS: * hashTable - the HashTable to check * iter - prior iterator position * &key - out: next key * &value - out: next value * RETURNS: * bool - true if a key/value pair is returned, false if the * end has been reached. \*--------------------------------------------------------------------------*/ internal static bool NpyDict_IterNext(NpyDict hashTable, NpyDict_Iter iter, NpyDict_KVPair KVPair) { /* Advance to the next element in this bucket if there is one. Otherwise * find another bucket. */ if (null != iter.element) { iter.element = iter.element.next; } while (null == iter.element && iter.bucket < hashTable.numOfBuckets - 1) { iter.element = (NpyDict_KVPair)hashTable.bucketArray[++iter.bucket]; } if (null == iter.element) { KVPair.key = null; KVPair.value = null; return(false); } KVPair.key = iter.element.key; KVPair.value = iter.element.value; return(true); }
internal static NpyArray_Descr NpyArray_DescrNewByteorder(NpyArray_Descr self, char newendian) { NpyArray_Descr _new; char endian; _new = NpyArray_DescrNew(self); endian = _new.byteorder; if (endian != NPY_IGNORE) { if (newendian == NPY_SWAP) { /* swap byteorder */ if (NpyArray_ISNBO(endian)) { endian = NPY_OPPBYTE; } else { endian = NPY_NATBYTE; } _new.byteorder = endian; } else if (newendian != NPY_IGNORE) { _new.byteorder = newendian; } } if (null != _new.names) { NpyDict_KVPair KVPair = new NpyDict_KVPair(); NpyArray_Descr newdescr; NpyDict_Iter pos = new NpyDict_Iter(); NpyDict_IterInit(pos); while (NpyDict_IterNext(_new.fields, pos, KVPair)) { NpyArray_DescrField value = KVPair.value as NpyArray_DescrField; string key = KVPair.key as string; if (null != value.title && key.CompareTo(value.title) != 0) { continue; } newdescr = NpyArray_DescrNewByteorder(value.descr, newendian); if (newdescr == null) { Npy_DECREF(_new); return(null); } Npy_DECREF(value.descr); value.descr = newdescr; } } if (null != _new.subarray) { NpyArray_Descr old = _new.subarray._base; _new.subarray._base = NpyArray_DescrNewByteorder(self.subarray._base, newendian); Npy_DECREF(old); } return(_new); }
internal static void NpyArrayAccess_DictFreeIter(NpyDict_Iter iter) { npy_free(iter); }
internal static bool NpyArrayAccess_DictNext(NpyDict dict, NpyDict_Iter iter, NpyDict_KVPair KVPair) { return(NpyDict_IterNext(dict, iter, KVPair)); }
internal static void NpyDict_IterInit(NpyDict_Iter iter) { iter.bucket = -1; /* -1 because first Next() increments to 0 */ iter.element = null; }
internal static void NpyArrayAccess_DictFreeIter(NpyDict_Iter iter) { numpyinternal.NpyArrayAccess_DictFreeIter(iter); }
public static bool NpyArrayAccess_DictNext(NpyDict dict, NpyDict_Iter iter, NpyDict_KVPair KVPair) { return(numpyinternal.NpyArrayAccess_DictNext(dict, iter, KVPair)); }