예제 #1
0
        /// <summary>
        /// Converts a 4 dimensional dataSet to a 3 dimensional dataSet
        /// </summary>
        /// <param name="dataSet">The dataSet to fold</param>
        /// <returns></returns>
        public T[, ,] ConvertTo3D(T[, , ,] dataSet)
        {
            //A 3d matrix of only days and hours and minutes
            T[, ,] dMatrix = new T[7, 24, 60];
            T MinuteTotal = default(T);

            for (int Day = 0, dayEnd = dataSet.GetUpperBound(0) + 1, dayInMonth = DateUtility.DaysInMonth(monthInReview, yearInReview); (Day < dayEnd && Day < dayInMonth); Day++)
            {
                for (int Hour = 0, hourEnd = dataSet.GetUpperBound(1) + 1; Hour < hourEnd; Hour++)
                {
                    for (int Minute = 0, minuteEnd = dataSet.GetUpperBound(2) + 1; Minute < minuteEnd; Minute++)
                    {
                        MinuteTotal = default(T);
                        for (int Second = 0, secondEnd = dataSet.GetUpperBound(3) + 1; Second < secondEnd; Second++)
                        {
                            MinuteTotal = Operator.Add(MinuteTotal, dataSet[Day, Hour, Minute, Second]);
                        }
                        DateTime checker = new DateTime(yearInReview, monthInReview, Day + 1, Hour, Minute, 0);

                        dMatrix[(int)checker.DayOfWeek, Hour, Minute] = MinuteTotal;
                    } //Minutes
                }     //Hours
            }         //Days
            return(dMatrix);
        }
예제 #2
0
        /// <summary>
        /// Returns an inverted matrix by finding values which are equal to 0 and setting them to 1
        /// and values greater then 0 and setting them to 0
        /// </summary>
        /// <param name="dataSet">The 4 dimensional dataSet to invert</param>
        /// <returns></returns>
        public int[, , ,] GetMissingDataFromDataSet(T[, , ,] dataSet)
        {
            int dayEnd    = dataSet.GetUpperBound(0) + 1,
                monthEnd  = DateUtility.DaysInMonth(monthInReview, yearInReview),
                hourEnd   = dataSet.GetUpperBound(1) + 1,
                minuteEnd = dataSet.GetUpperBound(2) + 1,
                secondEnd = dataSet.GetUpperBound(3) + 1;

            int[, , ,] data = new int[dayEnd, hourEnd, minuteEnd, secondEnd];

            for (int day = 0; (day < dayEnd && day < monthEnd); day++)
            {
                for (int hour = 0; hour < hourEnd; hour++)
                {
                    for (int minute = 0; minute < minuteEnd; minute++)
                    {
                        for (int second = 0; second < secondEnd; second++)
                        {
                            if (Operator.IsDefault(dataSet[day, hour, minute, second]))
                            {
                                data[day, hour, minute, second] = 1;
                            }
                            else
                            {
                                data[day, hour, minute, second] = 0;
                            }
                        }
                    }
                }
            }
            return(data);
        }
예제 #3
0
    /// <summary>
    /// Gets the inclusive upper bounds of an array.
    /// </summary>
    /// <typeparam name="T">The type of values stored in the array.</typeparam>
    /// <param name="array">The array.</param>
    /// <returns>The inclusive upper bounds.</returns>
    public static Index4D GetUpperBounds <T>(this T[,,,] array)
    {
        Contracts.Requires.That(array != null);

        return(new Index4D(
                   array.GetUpperBound((int)Axis4D.X),
                   array.GetUpperBound((int)Axis4D.Y),
                   array.GetUpperBound((int)Axis4D.Z),
                   array.GetUpperBound((int)Axis4D.W)));
    }
예제 #4
0
        /// <summary>
        /// Converts a 4 dimensional dataSet to a 3 dimensional dataSet
        /// </summary>
        /// <param name="dataSet">The dataSet to fold</param>
        /// <param name="day">The day to focus</param>
        /// <returns></returns>
        public T[, ,] ConvertTo3D(T[, , ,] dataSet, DayOfWeek day)
        {
            DateTime refrencePoint = DateTime.MinValue;
            int      ZeroData      = 0;

            //A 3d matrix of only days and hours and minutes
            T[, ,] dMatrix = new T[1, 24, 60];
            T   MinuteTotal = default(T);
            int dayBound    = dataSet.GetUpperBound(0) + 1;

            for (int Day = 0; Day < dayBound; Day++)
            {
                try
                {
                    refrencePoint = new DateTime(yearInReview, monthInReview, Day + 1);
                }
                catch      //if this is invalid date
                {
                    break; //stop the loop
                }
                if (refrencePoint.DayOfWeek != day)
                {
                    continue;
                }
                for (int Hour = 0; Hour < 24; Hour++)
                {
                    for (int Minute = 0; Minute < 60; Minute++)
                    {
                        ZeroData    = 0;
                        MinuteTotal = default(T);
                        for (int Second = 0; Second < 60; Second++)
                        {
                            if (Operator.IsDefault(dataSet[Day, Hour, Minute, Second]))
                            {
                                ZeroData++;
                            }
                            MinuteTotal = Operator.Add(MinuteTotal, dataSet[Day, Hour, Minute, Second]);
                        }
                        int Correction = 60 - ZeroData;
                        int DayOccurs  = DateUtility.OccurancesOfDayInMonth(day, monthInReview, yearInReview);

                        if (!Operator.IsDefault(MinuteTotal))
                        {
                            MinuteTotal = Operator.DivideInt32(MinuteTotal, 60);
                        }

                        if (Correction < DayOccurs * 2 && Correction != 0)
                        {
                            //dMatrix[0, Hour, Minute] = GenericMath.AddChecked(MinuteTotal, GenericMath.Multiply(GenericMath.Divide(MinuteTotal, Correction), GenericMath.SubtractChecked(GenericMath.Multiply(DayOccurs, 2), Correction)));
                            dMatrix[0, Hour, Minute] = Operator.Add(MinuteTotal, Operator.MultiplyInt32(Operator.DivideInt32(MinuteTotal, Correction), Operator.Subtract(Operator.MultiplyInt32(DayOccurs, 2), Correction)));
                        }
                        else
                        {
                            dMatrix[0, Hour, Minute] = MinuteTotal;
                        }
                    } //Minutes
                }     //Hours
            }
            return(dMatrix);
        }
예제 #5
0
        /// <summary>
        /// Converts a 4 dimensional dataSet to a 3 dimensional dataSet
        /// </summary>
        /// <param name="dataSet">The dataSet to fold</param>
        /// <param name="day">The day to focus</param>
        /// <param name="hour">The hour to focus</param>
        /// <returns></returns>
        public T[, ,] ConvertTo3D(T[, , ,] dataSet, DayOfWeek day, int hour)
        {
            int ZeroData = 0;

            //A 3d matrix of only days and hours and minutes
            T[, ,] dMatrix = new T[1, 1, 60];
            T MinuteTotal = default(T);

            if (hour < 0)
            {
                throw new ArgumentOutOfRangeException("hour", "Cannot be less than 0");
            }
            if (hour > 24)
            {
                throw new ArgumentOutOfRangeException("hour", "Cannot be greater than 24");
            }
            DateTime checker  = DateTime.MinValue;
            int      dayBound = dataSet.GetUpperBound(0);

            for (int Day = 0; Day < dayBound; Day++)
            {
                checker = new DateTime(yearInReview, monthInReview, Day + 1);
                if (checker.DayOfWeek != day)
                {
                    continue;
                }
                for (int Minute = 0; Minute < 60; Minute++)
                {
                    ZeroData    = 0;
                    MinuteTotal = default(T);
                    for (int Second = 0; Second < 60; Second++)
                    {
                        if (Operator.IsDefault(dataSet[(int)day, hour, Minute, Second]))
                        {
                            ZeroData++;
                        }
                        MinuteTotal = Operator.Add(MinuteTotal, dataSet[Day, hour, Minute, Second]);
                    }

                    int Correction = 60 - ZeroData;

                    int DayOccurs = DateUtility.OccurancesOfDayInMonth(day, monthInReview, yearInReview);

                    if (!Operator.IsDefault(MinuteTotal))
                    {
                        MinuteTotal = Operator.DivideInt32(MinuteTotal, 60);
                    }

                    if (Correction != 0 && Correction < (DayOccurs * 2))
                    {
                        dMatrix[0, 0, Minute] = Operator.Add(MinuteTotal, Operator.MultiplyInt32(Operator.DivideInt32(MinuteTotal, Correction), Operator.Subtract(Operator.MultiplyInt32(DayOccurs, 2), Correction)));
                    }
                    else
                    {
                        dMatrix[0, 0, Minute] = MinuteTotal;
                    }
                }//Minutes
            }

            return(dMatrix);
        }
예제 #6
0
        /// <summary>
        /// Copies data from the <paramref name="source"/> four-dimensional array
        /// to the <paramref name="destination"/> four-dimensional array.
        /// </summary>
        /// <typeparam name="T">The kind of element used within the arrays
        /// copied.</typeparam>
        /// <param name="source">The four-dimensional array from which copying occurs.</param>
        /// <param name="destination">The four-dimensional array of <typeparamref name="T"/>
        /// elements in which the elements are received.</param>
        /// <param name="lengthA">The <see cref="Int32"/>
        /// value representing the size of the lowest order dimension
        /// of the copy operation.</param>
        /// <param name="lengthB">The <see cref="Int32"/>
        /// value representing the size of the middle lowest order dimension
        /// of the copy operation.</param>
        /// <param name="lengthC">The <see cref="Int32"/>
        /// value representing the size of the middle highest order dimension
        /// of the copy operation.</param>
        /// <param name="lengthD">The <see cref="Int32"/>
        /// value representing the size of the highest order dimension
        /// of the copy operation.</param>
        public static void TesseracticCopy <T>(this T[, , ,] source, T[, , ,] destination, int lengthA, int lengthB, int lengthC, int lengthD)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            int upperSA = source.GetUpperBound(0),
                upperSB = source.GetUpperBound(1),
                upperSC = source.GetUpperBound(2),
                upperSD = source.GetUpperBound(3);
            int upperDA = destination.GetUpperBound(0),
                upperDB = destination.GetUpperBound(1),
                upperDC = destination.GetUpperBound(2),
                upperDD = destination.GetUpperBound(3);

            int lowerSA = source.GetLowerBound(0),
                lowerSB = source.GetLowerBound(1),
                lowerSC = source.GetLowerBound(2),
                lowerSD = source.GetLowerBound(3);
            int lowerDA = destination.GetLowerBound(0),
                lowerDB = destination.GetLowerBound(1),
                lowerDC = destination.GetLowerBound(2),
                lowerDD = destination.GetLowerBound(3);

            int lengthSA = upperSA + 1 - lowerSA,
                lengthSB = upperSB + 1 - lowerSB,
                lengthSC = upperSC + 1 - lowerSC,
                lengthSD = upperSD + 1 - lowerSD;
            int lengthDA = upperDA + 1 - lowerDA,
                lengthDB = upperDB + 1 - lowerDB,
                lengthDC = upperDC + 1 - lowerDC,
                lengthDD = upperDD + 1 - lowerDD;

            if (lengthA > lengthSA || lengthA > lengthDA)
            {
                throw new ArgumentOutOfRangeException("lengthA");
            }
            if (lengthB > lengthSB || lengthB > lengthDB)
            {
                throw new ArgumentOutOfRangeException("lengthB");
            }
            if (lengthC > lengthSC || lengthC > lengthDC)
            {
                throw new ArgumentOutOfRangeException("lengthC");
            }
            if (lengthD > lengthSD || lengthD > lengthDD)
            {
                throw new ArgumentOutOfRangeException("lengthD");
            }

            lock (source)
                lock (destination)
                    Parallel.For(0, lengthA, outterIndex =>
                    {
                        for (int outterMiddleIndex = 0; outterMiddleIndex < lengthB; outterMiddleIndex++)
                        {
                            Parallel.For(0, lengthC, innerMiddleIndex =>
                            {
                                for (int innerIndex = 0; innerIndex < lengthD; innerIndex++)
                                {
                                    destination[lowerDA + outterIndex, lowerDB + outterMiddleIndex, lowerDC + innerMiddleIndex, lowerDD + innerIndex] = source[lowerSA + outterIndex, lowerSB + outterMiddleIndex, lowerSC + innerMiddleIndex, lowerSD + innerIndex];
                                }
                            });
                        }
                    });
        }
예제 #7
0
    /// <summary>
    /// Gets the index of the last element of the specified dimension in the array.
    /// </summary>
    /// <typeparam name="T">The type of values stored in the array.</typeparam>
    /// <param name="array">The array.</param>
    /// <param name="dimension">The dimension whose upper bound needs to be determined.</param>
    /// <returns>
    /// The index of the last element of the specified dimension in the array, or -1 if the specified dimension is empty.
    /// </returns>
    public static int GetUpperBound <T>(this T[,,,] array, Axis4D dimension)
    {
        Contracts.Requires.That(array != null);

        return(array.GetUpperBound((int)dimension));
    }