Exemple #1
0
 /// <summary>
 /// [ a1; a2 ]
 /// </summary>
 /// <param name="semicolon">';'</param>
 public ILArray <double> this[ILArray <double> value1, char semicolon, ILArray <double> value2]
 {
     get
     {
         return(value1.Concat(value2, 0));
         //int offset2 = value1.Size[0];
         //int dim0 = offset2 + value2.Size[0];
         //int dim1 = value1.Size[1];
         //ILArray<double> result = ILMath.zeros(dim0, dim1);
         //result[ILMath.r(0, offset2 - 1), ILMath.full] = value1;
         //result[ILMath.r(offset2, ILMath.end), ILMath.full] = value2;
         //return result;
     }
 }
Exemple #2
0
        protected static ILArray <double> sortrows(ILArray <double> ilArray, int sortedByColumnIndex)
        {
            ILArray <double> columnValues       = ilArray[ILMath.full, sortedByColumnIndex - 1];
            ILArray <int>    rowsIndices        = ILMath.empty <int>();
            ILArray <double> sortedColumnValues = ILMath.sort(columnValues, rowsIndices);

            //ILArray<double> sortedArray = ilArray[ILMath.full, 0][rowsIndices];
            ILArray <double> sortedArray = ILMath.empty(ilArray.Size[0], 0);

            for (var columnIndex = 0; columnIndex < ilArray.Size[1]; columnIndex++)
            {
                sortedArray = sortedArray.Concat(ilArray[ILMath.full, columnIndex][rowsIndices], 1);
            }

            return(sortedArray);
        }
Exemple #3
0
            //    public ILArray<double> this[ILArray<double> value1, ILArray<double> value2, ILArray<double> value3]
            //    {
            //        get
            //        {
            //            return (value1.Concat(value2, 1).Concat(value3, 1));
            //            //int dim0 = value1.Size[0];
            //            //int offset2 = value1.Size[1];
            //            //int offset3 = offset2 + value2.Size[1];
            //            //int dim1 = offset3 + value3.Size[1];
            //            //ILArray<double> result = ILMath.zeros(dim0, dim1);
            //            //result[ILMath.full, ILMath.r(0, offset2 - 1)] = value1;
            //            //result[ILMath.full, ILMath.r(offset2, offset3 - 1)] = value2;
            //            //result[ILMath.full, ILMath.r(offset3, ILMath.end)] = value3;
            //            //return result;
            //        }
            //    }

            /// <summary>
            /// [ a1, a2, a3, a4 ]
            /// </summary>
            public ILArray <double> this[ILArray <double> value1, ILArray <double> value2, ILArray <double> value3, ILArray <double> value4]
            {
                get
                {
                    return(value1.Concat(value2, 1).Concat(value3, 1).Concat(value4, 1));
                    //int dim0 = value1.Size[0];
                    //int offset2 = value1.Size[1];
                    //int offset3 = offset2 + value2.Size[1];
                    //int offset4 = offset3 + value3.Size[1];
                    //int dim1 = offset4 + value3.Size[1];
                    //ILArray<double> result = ILMath.zeros(dim0, dim1);
                    //result[ILMath.full, ILMath.r(0, offset2 - 1)] = value1;
                    //result[ILMath.full, ILMath.r(offset2, offset3 - 1)] = value2;
                    //result[ILMath.full, ILMath.r(offset3, offset4 - 1)] = value3;
                    //result[ILMath.full, ILMath.r(offset4, ILMath.end)] = value4;
                    //return result;
                }
            }
Exemple #4
0
        /// <summary>
        /// horizontal concatenation for arbitrary arrays
        /// </summary>
        /// <param name="inArrays"> arrays to be concatenated with each other. All
        /// arrays must be of the same inner type. The dimensions of all arrays
        /// must match - except the second dimension.</param>
        /// <returns>large array having all arrays in 'inArrays' placed behind each other.
        /// </returns>
        /// <remarks>The array returned may be a reference storage if all elements of 'inArrays'
        /// point to the same object instance, or a physical storage array otherwise. In the case of
        /// all elements pointing to the same object, the static member
        /// ILNumerics.Settings.ILSettings.MinimumRefDimensions will be taken into account too.
        ///
        /// Horizontal concatenation means concatenation along the second dimension.
        /// </remarks>
        public static ILArray <T> horzcat <T>(params ILArray <T>[] inArrays)
        {
            if (inArrays == null)
            {
                throw new ILArgumentException("input argument must not be null!");
            }
            if (inArrays.Length == 0 || object.Equals(inArrays[0], null))
            {
                return(ILArray <T> .empty(0, 0));
            }
            if (inArrays.Length == 1)
            {
                return(inArrays[0].C);
            }
            ILArray <T> ret = (ILArray <T>)inArrays[0].Concat(inArrays[1], 1);

            for (int i = 2; i < inArrays.Length; i++)
            {
                ret = (ILArray <T>)ret.Concat(inArrays[i], 1);
            }
            return(ret);
        }
Exemple #5
0
		/*		public void Test_Eye() {
					int errorCode = 0;
					try {
						double[] data = new double[24];
						for (int i = 0; i < data.Length; i++)
							data[i] = i;
						ILArray<double> A = new ILArray<double>(data, 2, 3, 4);
						Success("Test_Apply successfull");
					}
					catch (Exception e) {
						Error("Test_Apply failed at errorCode: " + errorCode + " Reason: " + e.Message);
					}
				}
		*/
        public void Test_Cat() {
			int errorCode = 0;
			try {
				double[] data = new double[24];
				for (int i = 0; i < data.Length; i++)
					data[i] = i;
				ILArray<double> A = new ILArray<double>(data, 2, 3, 4);
				ILArray<double> B = A.GetShifted(3);
                ILArray<double> C = ILMath.horzcat(A, A);
                ILArray<double> CRef = ILMath.horzcat(B, B);
                double[] result = new double[48] { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 18, 19, 20, 21, 22, 23 };
                ILArray<double> Result = new ILArray<double>(result, 2, 6, 4);
                if (!Result.Equals(C)) {
                    throw new Exception("Test Cat: Test result failed: invalid values detected."); 
                }
                errorCode = 2; 
                if (!Result.Equals(CRef)) {
                    throw new Exception("Test Cat: Test result failed: invalid values detected."); 
                }
                errorCode = 3; 
                // test vertcat 
                result = new double[72] { 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 8, 9, 8, 9, 8, 9, 10, 11, 10, 11, 10, 11, 12, 13, 12, 13, 12, 13, 14, 15, 14, 15, 14, 15, 16, 17, 16, 17, 16, 17, 18, 19, 18, 19, 18, 19, 20, 21, 20, 21, 20, 21, 22, 23, 22, 23, 22, 23 };
                Result = new ILArray<double>(result, 6, 3, 4); 
                C = ILMath.vertcat(A,A,A); 
                if (!Result.Equals(C)) {
                    throw new Exception("Test Cat: Test result failed: invalid values detected."); 
                }
                errorCode = 4; 
                CRef = ILMath.vertcat(B,B,B); 
                if (!Result.Equals(C)) {
                    throw new Exception("Test Cat: Test result failed: invalid values detected."); 
                }
                // test large 
                errorCode = 5; 
                A = (ILArray<double>)ILMath.ones(1000, 1000, 10);
                Result = A.Concat(A, 2); 
                if (Result.m_dimensions.NumberOfDimensions != 3 || Result.m_dimensions[0] != 1000 || Result.m_dimensions[1] != 1000
                    || Result.m_dimensions[2] != 20) {
                    throw new Exception("Test Cat: Result dimension mismatch!");
                }
                ILArray<double> dummy = ILMath.sum(Result); 
                if (ILMath.sumall(dummy)!= 20000000) 
                    throw new Exception("sum partially wrong!");
                
                dummy = ILMath.sum(dummy); 
                if (ILMath.sumall(dummy)!= 20000000) 
                    throw new Exception("sum partially wrong!");
                
                dummy = ILMath.sum(dummy); 
                if (ILMath.sumall(dummy)!= 20000000) 
                    throw new Exception("sum partially wrong!");

                if (ILMath.sum(ILMath.sum(ILMath.sum(Result))) != 20000000) {
                    throw new Exception ("Test Cat: Invalid values detected."); 
                }
                // test Reference Concatenation
                errorCode = 6;
                B = A.GetShifted(3); 
                Result = B.Concat(B,2);
                if (Result.m_dimensions.NumberOfDimensions != 3 || Result.m_dimensions[0] != 1000 || Result.m_dimensions[1] != 1000
                    || Result.m_dimensions[2] != 20) {
                    throw new Exception("Test Cat: Result dimension mismatch!");
                }
                dummy = ILMath.sum(Result); 
                if (ILMath.sumall(dummy)!= 20000000) 
                    throw new Exception("sum partially wrong!");
                
                dummy = ILMath.sum(dummy); 
                if (ILMath.sumall(dummy)!= 20000000) 
                    throw new Exception("sum partially wrong!");
                
                dummy = ILMath.sum(dummy); 
                if (ILMath.sumall(dummy)!= 20000000) 
                    throw new Exception("sum partially wrong!");
                
                if (ILMath.sum(ILMath.sum(ILMath.sum(Result))) != 20000000) {
                    throw new Exception ("Test Cat: Invalid values detected."); 
                }
                Success("Test_Cat successfull");
			} catch (Exception e) {
                Error("Test_Cat failed at errorCode: " + errorCode + " Reason: " + e.Message);
			}
		}