Beispiel #1
0
        /// <summary>Sort an array of unsigned integers.</summary>
        public void Sort(int maxShiftWidth = 32)
        {
            Profiler.BeginSample("RadixSort");
            uint      mask       = 1;
            int       valueCount = na_values.Length;
            JobHandle jobHandle;

            for (int m = 0; m < maxShiftWidth; m++)
            {
                radixBitCheckJob.mask = mask;
                jobHandle             = radixBitCheckJob.Schedule(valueCount, Jobx.XL_BATCH_SIZE);
                jobHandle.Complete();

                trueSumScanJob.InclusiveSumScan();
                falseSumScanJob.InclusiveSumScan();
                radixSortShuffleJob.lastFalseIdx = na_falsePrefixSum[valueCount - 1];

                jobHandle = radixSortShuffleJob.Schedule(valueCount, Jobx.XL_BATCH_SIZE);
                jobHandle.Complete();
                na_values.CopyFrom(na_sortedValues);
                na_indices.CopyFrom(na_sortedIndices);

                mask <<= 1;
            }
            Profiler.EndSample();
        }
        public void SumScanJobTest()
        {
            int[] array = new int[ARRAY_COUNT];
            for (int i = 0; i < ARRAY_COUNT; i++)
            {
                array[i] = GenerateRandomInt();
            }

            NativeArray <int> na_array   = new NativeArray <int>(array, Allocator.TempJob);
            SumScanJob        sumScanJob = new SumScanJob(ref na_array);

            sumScanJob.InclusiveSumScan();

            // using serial inclusive sum scan method to make sure that the parallel method works
            int sum = 0;

            for (int i = 0; i < ARRAY_COUNT; i++)
            {
                sum += array[i];
                Assert.AreEqual(sum, na_array[i]);
            }

            na_array.Dispose();
            sumScanJob.Dispose();
        }