Esempio n. 1
0
        private IEnumerable <double> IntegrateBatch3D(string variable, Array prefetchedData, int[] prefetchedDataOrigin, IEnumerable <IPs[]> ipsArrays)
        {
            //TODO: move this method to the Utils.ArrayMean
            double integral = 0.0, weights = 0.0;

            Type dataType = prefetchedData.GetType().GetElementType();

            bool effectiveMvCheck = checkForMissingValues;

            object missingValue = dataSetInfo.GetMissingValue(variable);

            if (missingValue == null)
            {
                if (dataType == typeof(double))
                {
                    missingValue = double.NaN;
                }
                else if (dataType == typeof(float))
                {
                    missingValue = float.NaN;
                }
                else
                {
                    effectiveMvCheck = false; //switching off MV check if no MV information is available
                }
            }
            int shape1 = prefetchedData.GetLength(1);
            int shape2 = prefetchedData.GetLength(2);

            GCHandle?capturedHandle;

            capturedHandle = GCHandle.Alloc(prefetchedData, GCHandleType.Pinned);
            IntPtr prefetchedDataPtr = capturedHandle.Value.AddrOfPinnedObject();

            try
            {
                if (effectiveMvCheck)
                {
                    if (dataType == typeof(double))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DDoubleMVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                  (double)missingValue,
                                                                  ref weights, ref integral,
                                                                  prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                  ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                  ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(float))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DFloatMVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                 (float)missingValue,
                                                                 ref weights, ref integral,
                                                                 prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                 ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                 ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(Int64))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt64MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                 (Int64)missingValue,
                                                                 ref weights, ref integral,
                                                                 prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                 ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                 ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(int))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt32MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                 (int)missingValue,
                                                                 ref weights, ref integral,
                                                                 prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                 ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                 ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(short))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt16MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                 (short)missingValue,
                                                                 ref weights, ref integral,
                                                                 prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                 ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                 ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(sbyte))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt8MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                (sbyte)missingValue,
                                                                ref weights, ref integral,
                                                                prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(UInt64))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt64MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                  (UInt32)missingValue,
                                                                  ref weights, ref integral,
                                                                  prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                  ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                  ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(UInt32))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt32MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                  (UInt32)missingValue,
                                                                  ref weights, ref integral,
                                                                  prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                  ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                  ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(UInt16))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt16MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                  (UInt16)missingValue,
                                                                  ref weights, ref integral,
                                                                  prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                  ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                  ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(byte))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt8MVsCheck(prefetchedDataPtr, shape1, shape2,
                                                                 (byte)missingValue,
                                                                 ref weights, ref integral,
                                                                 prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                                 ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                                 ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException("data variable has unsupported type");
                    }
                }
                else
                {
                    if (dataType == typeof(double))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DDouble(prefetchedDataPtr, shape1, shape2,
                                                          ref weights, ref integral,
                                                          prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                          ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                          ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(float))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DFloat(prefetchedDataPtr, shape1, shape2,
                                                         ref weights, ref integral,
                                                         prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                         ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                         ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(Int64))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt64(prefetchedDataPtr, shape1, shape2,
                                                         ref weights, ref integral,
                                                         prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                         ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                         ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(int))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt32(prefetchedDataPtr, shape1, shape2,
                                                         ref weights, ref integral,
                                                         prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                         ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                         ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(short))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt16(prefetchedDataPtr, shape1, shape2,
                                                         ref weights, ref integral,
                                                         prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                         ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                         ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(sbyte))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DInt8(prefetchedDataPtr, shape1, shape2,
                                                        ref weights, ref integral,
                                                        prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                        ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                        ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(UInt64))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt64(prefetchedDataPtr, shape1, shape2,
                                                          ref weights, ref integral,
                                                          prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                          ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                          ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(UInt32))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt32(prefetchedDataPtr, shape1, shape2,
                                                          ref weights, ref integral,
                                                          prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                          ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                          ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(UInt16))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt16(prefetchedDataPtr, shape1, shape2,
                                                          ref weights, ref integral,
                                                          prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                          ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                          ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else if (dataType == typeof(byte))
                    {
                        foreach (IPs[] ips in ipsArrays)
                        {
                            if (ips == null)// out of data cell
                            {
                                yield return(double.NaN);

                                continue;
                            }
                            integral = 0.0; weights = 0.0;
                            IPsIntegral.Integrate3DUInt8(prefetchedDataPtr, shape1, shape2,
                                                         ref weights, ref integral,
                                                         prefetchedDataOrigin[0], prefetchedDataOrigin[1], prefetchedDataOrigin[2],
                                                         ips[0].Indices, ips[1].Indices, ips[2].Indices,
                                                         ips[0].Weights, ips[1].Weights, ips[2].Weights);
                            if (weights == 0.0) //only missing values in the region
                            {
                                yield return(double.NaN);
                            }
                            else
                            {
                                yield return(integral / weights);
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException("data variable has unsupported type");
                    }
                }
            }
            finally
            {
                capturedHandle.Value.Free();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Produced integrated values for a sequence of integration points
        /// </summary>
        /// <param name="variable"></param>
        /// <param name="prefetchedData"></param>
        /// <param name="prefetchedDataOrigin">The origin of prefetched array in terms of integration points domain</param>
        /// <param name="ipsArrays"></param>
        /// <returns></returns>
        public static IEnumerable <IntegrationResult> IntegrateSequenceWithMVs2D(string variable, Array prefetchedData, object missingValue, int[] prefetchedDataOrigin, IEnumerable <IPs[]> ipsArrays)
        {
            double integral = 0.0, weights = 0.0;

            Type dataType = prefetchedData.GetType().GetElementType();

            int shape1 = prefetchedData.GetLength(1);

            GCHandle?capturedHandle;

            capturedHandle = GCHandle.Alloc(prefetchedData, GCHandleType.Pinned);
            IntPtr prefetchedDataPtr = capturedHandle.Value.AddrOfPinnedObject();

            try
            {
                if (dataType == typeof(double))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DDoubleMVsCheck(prefetchedDataPtr, shape1,
                                                              (double)missingValue,
                                                              ref weights, ref integral,
                                                              prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                              ips[0].Indices, ips[1].Indices,
                                                              ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(float))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DFloatMVsCheck(prefetchedDataPtr, shape1,
                                                             (float)missingValue,
                                                             ref weights, ref integral,
                                                             prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                             ips[0].Indices, ips[1].Indices,
                                                             ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(Int64))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DInt64MVsCheck(prefetchedDataPtr, shape1,
                                                             (Int64)missingValue,
                                                             ref weights, ref integral,
                                                             prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                             ips[0].Indices, ips[1].Indices,
                                                             ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(int))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DInt32MVsCheck(prefetchedDataPtr, shape1,
                                                             (int)missingValue,
                                                             ref weights, ref integral,
                                                             prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                             ips[0].Indices, ips[1].Indices,
                                                             ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(short))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DInt16MVsCheck(prefetchedDataPtr, shape1,
                                                             (short)missingValue,
                                                             ref weights, ref integral,
                                                             prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                             ips[0].Indices, ips[1].Indices,
                                                             ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(sbyte))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DInt8MVsCheck(prefetchedDataPtr, shape1,
                                                            (sbyte)missingValue,
                                                            ref weights, ref integral,
                                                            prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                            ips[0].Indices, ips[1].Indices,
                                                            ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(UInt64))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DUInt64MVsCheck(prefetchedDataPtr, shape1,
                                                              (UInt64)missingValue,
                                                              ref weights, ref integral,
                                                              prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                              ips[0].Indices, ips[1].Indices,
                                                              ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(UInt32))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DUInt32MVsCheck(prefetchedDataPtr, shape1,
                                                              (UInt32)missingValue,
                                                              ref weights, ref integral,
                                                              prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                              ips[0].Indices, ips[1].Indices,
                                                              ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(UInt16))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DUInt16MVsCheck(prefetchedDataPtr, shape1,
                                                              (UInt16)missingValue,
                                                              ref weights, ref integral,
                                                              prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                              ips[0].Indices, ips[1].Indices,
                                                              ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else if (dataType == typeof(byte))
                {
                    foreach (IPs[] ips in ipsArrays)
                    {
                        if (ips == null)    // out of data cell
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));

                            continue;
                        }
                        integral = 0.0; weights = 0.0;
                        IPsIntegral.Integrate2DUInt8MVsCheck(prefetchedDataPtr, shape1,
                                                             (byte)missingValue,
                                                             ref weights, ref integral,
                                                             prefetchedDataOrigin[0], prefetchedDataOrigin[1],
                                                             ips[0].Indices, ips[1].Indices,
                                                             ips[0].Weights, ips[1].Weights);
                        if (weights == 0.0)     //only missing values in the region
                        {
                            yield return(new IntegrationResult(double.NaN, double.NaN));
                        }
                        else
                        {
                            yield return(new IntegrationResult(integral, weights));
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("data variable has unsupported type");
                }
            }
            finally
            {
                capturedHandle.Value.Free();
            }
        }