Exemplo n.º 1
0
        /// <summary>
        ///  Horizontal concatenation
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="arrays">The arrays.</param>
        /// <returns></returns>
        public static Hyp2DArray <T> HorzCat <T>(params Hyp2DArray <T>[] arrays)
        {
            var nSize = 0;
            var mSize = arrays[0].MSize;

            foreach (var array in arrays)
            {
                nSize += array.NSize;
            }

            Hyp2DArray <T> outArray = new Hyp2DArray <T>(mSize, nSize);


            int offset = 0;

            foreach (var array in arrays)
            {
                for (int i = 0; i < array.MSize; i++)
                {
                    for (int j = 0; j < array.NSize; j++)
                    {
                        var value = array.GetValue(i, j);
                        outArray.SetValue(value, i, j + offset);
                    }
                }

                offset += array.NSize;
            }

            return(outArray);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes the specified stream fullfilling the properties.
        /// Don't use the base if you have your own strategy
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        protected override S Deserialize <S>(Stream stream)
        {
            var arrayBase  = base.Deserialize <HypArrayBase <T> >(stream);
            var dimensions = arrayBase.GetDimensions();
            var array2D    = new Hyp2DArray <T>(arrayBase.Data,
                                                dimensions[0], dimensions[1]);

            return(array2D as S);
        }
Exemplo n.º 3
0
 public static Hyp2DArray <double> Multiply(Hyp2DArray <double> a, Hyp2DArray <double> b)
 {
     throw new NotImplementedException("Not implemented yet");
     //var m = Matrix<double>.Build.Dense(a.MSize, a.NSize, a.Data);
     //var v = Matrix<double>.Build.Dense(b.MSize, b.NSize, b.Data);
     //var out1 = m * v;
     //var hypOut = new Hyp2DArray<double>(out1.RowCount, out1.ColumnCount, out1.Storage.ToColumnMajorArray());
     //return hypOut;
 }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 /// <param name="logics"></param>
 public void SetValue(T value, Hyp2DArray <bool> logics)
 {
     for (int i = 0; i < logics.GetNumberOfElements(); i++)
     {
         if (logics.Data[i])
         {
             Data[i] = value;
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Obtains the value.
        /// </summary>
        /// <param name="array3D">The array3 d.</param>
        /// <param name="arrayHeight2D">The array height2 d.</param>
        /// <returns></returns>
        public static Hyp2DArray <double> ObtainAcumulatedValue(Hyp3DArray <double> array3D, Hyp2DArray <double> arrayHeight2D)
        {
            int m = array3D.MSize;
            int n = array3D.NSize;
            Hyp2DArray <double> outMatrix = new Hyp2DArray <double>(m, n);

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double heightIndex = arrayHeight2D.GetValue(i, j);
                    outMatrix.SetValue(ObtainAcumulatedValue(array3D, heightIndex, i, j), i, j);
                }
            }
            return(outMatrix);
        }
Exemplo n.º 6
0
        public static Hyp2DArray <int> And(Hyp2DArray <double> a, Hyp2DArray <double> b)
        {
            int m = a.MSize;
            int n = a.NSize;

            var outArray = new Hyp2DArray <int>(m, n);

            for (int i = 0; i < m * n; i++)
            {
                if (a.Data[i] == 1 && b.Data[i] == 1)
                {
                    outArray.Data[i] = 1;
                }
            }
            return(outArray);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the random array.
        /// </summary>
        /// <param name="m">The m.</param>
        /// <param name="n">The n.</param>
        /// <returns></returns>
        public static Hyp2DArray <double> GetRandomArray(int m, int n)
        {
            Random randomEngine = new Random(DateTime.Now.Millisecond);

            randomEngine.NextDouble();
            Hyp2DArray <double> randomArray = new Hyp2DArray <double>(m, n);

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    randomArray.SetValue(randomEngine.NextDouble(), i, j);
                }
            }
            return(randomArray);
        }
Exemplo n.º 8
0
        public static Hyp2DArray <double> MaximumValueZDirection(Hyp3DArray <double> array3D)
        {
            int m = array3D.MSize;
            int n = array3D.NSize;
            Hyp2DArray <double> maxValueIndexMat = new Hyp2DArray <double>(m, n);

            for (int i = 0; i < array3D.MSize; i++)
            {
                for (int j = 0; j < array3D.NSize; j++)
                {
                    double maxIndexValue = MaximumValueZDirection(array3D, i, j);
                    maxValueIndexMat.SetValue(maxIndexValue, i, j);
                }
            }

            return(maxValueIndexMat);
        }