Esempio n. 1
0
        internal static void NpyArray_CopySwapFunc(ICopyHelper helper, 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)
            {
                helper.memcpy(dest.data_offset, Source.data_offset, NpyArray_ITEMSIZE(arr));
            }

            if (swap)
            {
                swapvalue(dest, dest.data_offset, NpyArray_DIVSIZE(arr));
            }
            return;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Copier{T}" /> class.
        /// </summary>
        public Copier(
            ICopyRegistrations <T> copyRegistrations,
            ICopyHelper copyHelper,
            ICopyHelperRegistrationFactory factory)
        {
            copyRegistrations.NotNull(nameof(copyRegistrations));
            copyHelper.NotNull(nameof(copyHelper));
            factory.NotNull(nameof(factory));

            var registrations = factory.Create <T>();

            copyRegistrations.DoRegistrations(registrations);
            this.operations = registrations.EndRegistrations();

            this.copyHelper = copyHelper;
        }