internal static void NpyArray_CopyTo(NpyArray destArray, NpyArray srcArray, NPY_CASTING casting, NpyArray whereArray)
        {
            var destSize = NpyArray_Size(destArray);

            NumericOperations operations = NumericOperations.GetOperations(null, srcArray, destArray, whereArray);

            NpyArrayIterObject SrcIter   = NpyArray_BroadcastToShape(srcArray, destArray.dimensions, destArray.nd);
            NpyArrayIterObject DestIter  = NpyArray_BroadcastToShape(destArray, destArray.dimensions, destArray.nd);
            NpyArrayIterObject WhereIter = null;

            if (whereArray != null)
            {
                WhereIter = NpyArray_BroadcastToShape(whereArray, destArray.dimensions, destArray.nd);
            }

            bool whereValue = true;

            for (long i = 0; i < destSize; i++)
            {
                var srcValue = operations.srcGetItem(SrcIter.dataptr.data_offset - srcArray.data.data_offset, srcArray);

                if (WhereIter != null)
                {
                    whereValue = (bool)operations.operandGetItem(WhereIter.dataptr.data_offset - whereArray.data.data_offset, whereArray);
                }

                if (whereValue)
                {
                    operations.destSetItem(DestIter.dataptr.data_offset - destArray.data.data_offset, srcValue, destArray);
                }

                NpyArray_ITER_NEXT(SrcIter);
                NpyArray_ITER_NEXT(DestIter);
                if (WhereIter != null)
                {
                    NpyArray_ITER_NEXT(WhereIter);
                }
            }

            return;
        }
Example #2
0
        internal static void NpyArray_Place(NpyArray arr, NpyArray mask, NpyArray vals)
        {
            var arrSize  = NpyArray_Size(arr);
            var maskSize = NpyArray_Size(mask);

            if (arrSize != maskSize)
            {
                NpyErr_SetString(npyexc_type.NpyExc_ValueError, "size of mask must be same size as src arr");
                return;
            }

            NumericOperations operations = NumericOperations.GetOperations(null, mask, arr, vals);

            NpyArrayIterObject valsIter = NpyArray_IterNew(vals);
            NpyArrayIterObject arrIter  = NpyArray_IterNew(arr);
            NpyArrayIterObject maskIter = NpyArray_IterNew(mask);

            for (long i = 0; i < arrSize; i++)
            {
                bool whereValue = (bool)operations.srcGetItem(maskIter.dataptr.data_offset - mask.data.data_offset, mask);

                if (whereValue)
                {
                    var valValue = operations.operandGetItem(valsIter.dataptr.data_offset - vals.data.data_offset, vals);
                    operations.destSetItem(arrIter.dataptr.data_offset - arr.data.data_offset, valValue, arr);
                    NpyArray_ITER_NEXT(valsIter);
                }

                if (!NpyArray_ITER_NOTDONE(valsIter))
                {
                    NpyArray_ITER_RESET(valsIter);
                }

                NpyArray_ITER_NEXT(arrIter);
                NpyArray_ITER_NEXT(maskIter);
            }

            return;
        }
Example #3
0
        internal static void NpyArray_CopyTo(NpyArray destArray, NpyArray srcArray, NPY_CASTING casting, NpyArray whereArray)
        {
            var destSize = NpyArray_Size(destArray);

            NumericOperations operations = NumericOperations.GetOperations(null, srcArray, destArray, whereArray);

            NpyArrayIterObject SrcIter   = NpyArray_BroadcastToShape(srcArray, destArray.dimensions, destArray.nd);
            NpyArrayIterObject DestIter  = NpyArray_BroadcastToShape(destArray, destArray.dimensions, destArray.nd);
            NpyArrayIterObject WhereIter = null;

            if (whereArray != null)
            {
                WhereIter = NpyArray_BroadcastToShape(whereArray, destArray.dimensions, destArray.nd);
            }



            IEnumerable <NpyArrayIterObject> srcParallelIters  = NpyArray_ITER_ParallelSplit(SrcIter);
            IEnumerable <NpyArrayIterObject> destParallelIters = NpyArray_ITER_ParallelSplit(DestIter);
            IEnumerable <NpyArrayIterObject> whereParalleIters = null;

            if (WhereIter != null)
            {
                whereParalleIters = NpyArray_ITER_ParallelSplit(WhereIter);
            }

            Parallel.For(0, destParallelIters.Count(), index =>
                         //for (int index = 0; index < destParallelIters.Count(); index++) //
            {
                NpyArrayIterObject ldestIter  = destParallelIters.ElementAt(index);
                NpyArrayIterObject lsrcIter   = srcParallelIters.ElementAt(index);
                NpyArrayIterObject lwhereIter = null;
                bool whereValue = true;

                if (whereParalleIters != null)
                {
                    lwhereIter = whereParalleIters.ElementAt(index);
                }

                while (ldestIter.index < ldestIter.size)
                {
                    var srcValue = operations.srcGetItem(lsrcIter.dataptr.data_offset - srcArray.data.data_offset, srcArray);

                    if (WhereIter != null)
                    {
                        whereValue = (bool)operations.operandGetItem(lwhereIter.dataptr.data_offset - whereArray.data.data_offset, whereArray);
                    }

                    if (whereValue)
                    {
                        operations.destSetItem(ldestIter.dataptr.data_offset - destArray.data.data_offset, srcValue, destArray);
                    }

                    NpyArray_ITER_PARALLEL_NEXT(ldestIter);
                    NpyArray_ITER_PARALLEL_NEXT(lsrcIter);
                    if (lwhereIter != null)
                    {
                        NpyArray_ITER_PARALLEL_NEXT(lwhereIter);
                    }
                }
            });

            return;
        }