private void Test_SortSpeed(int length)
        {
            try {
                ILArray <double> ResILN = null, ResCLR = null, A = null;
                long             durILN = 0, durCLR = 0;
                Misc.ILPerformer p = new ILNumerics.Misc.ILPerformer();
                for (int i = 0; i < 10; i++)
                {
                    A = ILMath.randn(length, 1);
                    p.Tic();
                    ILMath.sort(A);
                    p.Toc();
                    durILN += p.Duration;
                    ResCLR  = A.C;
                    p.Tic();
                    Array.Sort(ResCLR.m_data);
                    p.Toc();
                    durCLR += p.Duration;
                }
                ResILN = ILMath.sort(A);
                if (!ResCLR.Equals(ResILN))
                {
                    throw new Exception("invalid values!");
                }
                Info(String.Format("ILNumerics.Net sort {1} needed: {0}ms", durILN / 10, A.Dimensions.ToString()));
                Info(String.Format("CLR Array.Sort {1} needed: {0}ms", durCLR / 10, A.Dimensions.ToString()));
                // descending
                durCLR = 0; durILN = 0;
                IComparer comparer = new DescComparerDouble();
                for (int i = 0; i < 10; i++)
                {
                    A = ILMath.randn(length, 1);
                    p.Tic();
                    ResILN = ILMath.sort(A, true);
                    p.Toc();
                    durILN += p.Duration;
                    ResCLR  = A.C;
                    p.Tic();
                    Array.Sort(ResCLR.m_data, comparer);
                    p.Toc();
                    durCLR += p.Duration;
                }
                if (!ResCLR.Equals(ResILN))
                {
                    throw new Exception("invalid values!");
                }

                Info(String.Format("ILNumerics.Net sort {1} desc, needed: {0}ms", durILN / 10, A.Dimensions.ToString()));
                Info(String.Format("CLR Array.Sort {1} desc, needed: {0}ms", durCLR / 10, A.Dimensions.ToString()));
            } catch (Exception e) {
                Error(0, e.Message);
            }
        }
Exemple #2
0
        private void Test_SortSpeed(int length) {
            try {
                ILArray<double> ResILN = null, ResCLR = null, A = null; 
                long durILN = 0, durCLR = 0; 
                Misc.ILPerformer p = new ILNumerics.Misc.ILPerformer(); 
                for (int i = 0; i < 10; i++) {
                    A = ILMath.randn(length,1);
                    p.Tic(); 
                    ILMath.sort(A); 
                    p.Toc(); 
                    durILN += p.Duration; 
                    ResCLR = A.C; 
                    p.Tic(); 
                    Array.Sort(ResCLR.m_data); 
                    p.Toc(); 
                    durCLR += p.Duration; 
                }
                ResILN = ILMath.sort(A);
                if (!ResCLR.Equals(ResILN)) 
                    throw new Exception("invalid values!"); 
                Info(String.Format("ILNumerics.Net sort {1} needed: {0}ms",durILN / 10,A.Dimensions.ToString())); 
                Info(String.Format("CLR Array.Sort {1} needed: {0}ms",durCLR / 10,A.Dimensions.ToString())); 
                // descending 
                durCLR = 0; durILN = 0; 
                IComparer comparer = new DescComparerDouble(); 
                for (int i = 0; i < 10; i++) {
                    A = ILMath.randn(length,1);
                    p.Tic(); 
                    ResILN = ILMath.sort(A,true); 
                    p.Toc(); 
                    durILN += p.Duration; 
                    ResCLR = A.C; 
                    p.Tic(); 
                    Array.Sort(ResCLR.m_data,comparer); 
                    p.Toc(); 
                    durCLR += p.Duration; 
                }
                if (!ResCLR.Equals(ResILN)) 
                    throw new Exception("invalid values!"); 
 
                Info(String.Format("ILNumerics.Net sort {1} desc, needed: {0}ms",durILN / 10,A.Dimensions.ToString())); 
                Info(String.Format("CLR Array.Sort {1} desc, needed: {0}ms",durCLR / 10,A.Dimensions.ToString())); 


            } catch (Exception e) {
                Error(0, e.Message); 
            }
        }
Exemple #3
0
        public void Test_tmpPerfCount() {
            double [] data = new double[1000*1000*10];
            ILArray<double> A = new ILArray<double>(data, 1000, 1000, 10);
            ILPerformer p = new ILPerformer(); 
                        
            p.Tic();
            for (int i = 0; i < 10000000; i++) {
                A.getBaseIndex(i); 
            }
            p.Toc();
            Info("1000x1000x10: dense GetBaseIndex needed: " + p.Duration + " ms");

            ILIterator<double> it = A.CreateIterator();
            p.Tic();
            do {
                it.Increment(); 
            } while(!it.IsAtStart());
            p.Toc();
            Info("1000x1000x10: dense Iterator needed: " + p.Duration + " ms");
            
            A = (ILArray<double>)A[1,""];
            p.Tic();
            for (int i = 0; i < 10000000; i++) {
                A.getBaseIndex(i);
            }
            p.Toc();
            Info("1000x1000x10: ref. GetBaseIndex needed: " + p.Duration + " ms");

            it = A.CreateIterator();
            p.Tic();
            do {
                it.Increment();
            } while (!it.IsAtStart());
            p.Toc();
            Info("1000x1000x10: ref Iterator needed: " + p.Duration + " ms");
            p.Tic(); 
        }
Exemple #4
0
 public void Test_LDA_Performance200k_10() {
     int errorCode = 0; 
     try {
         LDA lda = new LDA();
         ILArray<double> X = ILMath.horzcat(ILMath.randn(2,200000)*2.0,ILMath.randn(2,200000)*-2.0);  
         ILLogicalArray labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1,100000), ILMath.zeros(1,100000))); 
         labels = labels.Concat( ILMath.tological( ILMath.zeros(1,100000).Concat( ILMath.ones(1,100000),1)),0);  
         ILPerformer timer = new ILPerformer(); 
         timer.Tic();  LDA.Hyperplane C; 
         for (int i = 0; i < 10; i ++) {
            C = lda.TrainLDA(X,labels,0.4);  
         }
         timer.Toc();
         Info("Test_LDA_Performance2: data: 2x200000 run 10 times in: " + timer.Duration + "ms"); 
         Success();
     }catch(Exception e) {
         Error(errorCode,e.Message);
     }
 }
Exemple #5
0
 public void Test_LDA_Performance2000_var(int rep) {
     int errorCode = 0; 
     try {
         LDA lda = new LDA();
         ILArray<double> X = ILMath.horzcat(ILMath.randn(2,2000)*2.0,ILMath.randn(2,2000)*-2.0);  
         ILLogicalArray labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1,2000), ILMath.zeros(1,2000))); 
         labels = labels.Concat( ILMath.tological( ILMath.zeros(1,2000).Concat( ILMath.ones(1,2000),1)),0);  
         ILPerformer timer = new ILPerformer(); 
         LDA.Hyperplane C; 
         int oldRefMin = ILNumerics.Settings.ILSettings.MinimumRefDimensions; 
         ILNumerics.Settings.ILSettings.MinimumRefDimensions = 2;
         timer.Tic();  
         for (int i = 0; i < rep; i ++) {
            C = lda.TrainLDA(X,labels,0.4);  
         }
         timer.Toc();
         Info("Test_LDA_Performance: with reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms"); 
         ILNumerics.Settings.ILSettings.MinimumRefDimensions = 3; 
         timer.Tic();  
         for (int i = 0; i < rep; i ++) {
            C = lda.TrainLDA(X,labels,0.4);  
         }
         timer.Toc();
         ILNumerics.Settings.ILSettings.MinimumRefDimensions = oldRefMin; 
         Info("Test_LDA_Performance: without reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms"); 
         Success();
     }catch(Exception e) {
         Error(errorCode,e.Message);
     }
 }
Exemple #6
0
        public void Test_Iterator_Performance() {
            int errorCode = 0;
            // success? 
            try {
				double[] data = new double[4 * 3 * 2] {0, 1,2,3,4,5,6,7,8,9,10
										,11,12,13,14,15,16,17,18,19,20,21,22,23 };
				ILArray<double> A = new ILArray<double>(data, 4,3,2);
				ILArray<double> Ar = (ILArray<double>)A.GetShifted(2); 
				ILPerformer p = new ILPerformer();
				int counter = 0; 
				ILIterator<double> it = A.CreateIterator(ILIteratorPositions.ILEnd, 0);
				ILIterator<double> it1 = Ar.CreateIterator(ILIteratorPositions.ILEnd, 2);
				double val = 0.0; 
				do {
					if (it.Increment() != counter++)
						throw new Exception("invalid iterator value!"); 
				} while (!it.IsAtEnd());
				// shifted (1) physical
				errorCode = 1; 
				double[] results = new double[24] {0,4,8,12,16,20,1,5,9,13,17,21
										,2,6,10,14,18,22,3,7,11,15,19,23};
				it = A.CreateIterator(ILIteratorPositions.ILEnd, 1);
				counter = 0; 
				do {
					if (it.Increment() != results[counter])
						throw new Exception("invalid phy iterator value!");
					if (it1.Increment() != results[counter++])
						throw new Exception("invalid ref iterator value!");
				} while (!it.IsAtEnd());
				results = new double[24] {0,4,8,12,16,20,1,5,9,13,17,21
										,2,6,10,14,18,22,3,7,11,15,19,23};

				data = new double[1000 * 1000 * 10];
				A = new ILArray<double>(data, 1000, 1000, 10);
                //// test the IEnumerable way of doing this
                //errorCode = 1;
				
                //p.Tic();
                //foreach (double v in A) {
                //    val = v;
                //}
                //p.Toc();
                //Info("[1000 x 1000 x 10] IEnumarable 'foreach' Iterator: " + p.ToString());

				errorCode = 2; 
				// iterate the classic way: 
                val = 2.23;
				double dura = 0.0, dura1= 0.0;
				double itIncCounter = 0.0;
				it = A.CreateIterator(ILIteratorPositions.ILStart, 0);
				it1 = A.CreateIterator(ILIteratorPositions.ILStart, 1);
				ILPerformer p1 = new ILPerformer();
				do {
					p1.Tic();
					val = it1.Increment();
					p1.Toc();
					dura1 += p1.Duration; // outer time needed 
					
					p.Tic();
					val = it.Increment();
					p.Toc();
					//dummy += Environment.TickCount - it.Dummy;  // internal time needed 
					dura += p.Duration; // outer time needed 
					itIncCounter++;
				} while (itIncCounter < data.Length);
				Info("[1000 x 1000 x 10] ILIterator Phys leadDim: 0 ->" 
					+ dura.ToString() + " leadDim: 1 ->" + dura1.ToString() 
					+ " incCount:" + itIncCounter);

				errorCode = 3;
				ILArray<double> B = (ILArray<double>)A.T;
				p.Tic();
				it = B.CreateIterator(ILIteratorPositions.ILStart, 0);
				it1 = B.CreateIterator(ILIteratorPositions.ILStart, 1);
                dura = 0.0; dura1 = 0.0; itIncCounter = 0; 
				do {
					p1.Tic();
					val = it1.Increment();
					p1.Toc();
					dura1 += p1.Duration; // outer time needed 

					p.Tic();
					val = it.Increment();
					p.Toc();
					//dummy += Environment.TickCount - it.Dummy;  // internal time needed 
					dura += p.Duration; // outer time needed 
					itIncCounter++;
				} while (itIncCounter < data.Length);
				p.Toc();
				Info("[1000 x 1000 x 10] ILIterator - Ref. leadDim: 0 ->"
					+ dura.ToString() + " leadDim: 1 ->" + dura1.ToString()
					+ " incCount:" + itIncCounter);


				Success("Test_Iterator_Performance successful.");
            } catch (Exception e) {
                Error("Test_Iterator_Performance failed at step: " + errorCode + " Msg: " + e.Message);
            }
        }
		public void Test_DivideDouble() {
			int errorCode = 0;
			// success?  
			try {
				ILPerformer p = new ILPerformer();
				double[] data1 = new double[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
				double[] data2 = new double[10] { 11, 12, -13, 14, 15, 16, -17, 18, 19, 110 };
				double tmp = ((double)13.0) / ((double)3.0); 
                double[] results = new double[18] { 11.0000,(double)-13.0/(double)3.0,15.0/5.0,19.0/9.0,11
								,3.0000,6.0000,3.5000,16.0/6.0,11.0000,6.0000,16.0/6.0,11.0000
													,-13.0/3.0,3.0000,19.0/9.0,11.0000,3.0000};
				ILArray<double> C = new ILArray<double>(data1, 2, 5);
				ILArray<double> B = new ILArray<double>(data2, 2, 5);
				ILArray<double> R = new ILArray<double>(results, 6, 3);
				ILArray<double> BR = (ILArray<double>)B[1,"0:1,0;0,1,2,4,0,2"];
				ILArray<double> CR = (ILArray<double>)C[1,"0:1,0;0,1,2,4,0,2"];
				C = (ILArray<double>)CR.T.T;
				B = (ILArray<double>)BR.T.T;
				C.Detach();
				B.Detach();
				ILArray<double> A = B/C;
				errorCode = 1;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = B/CR;
				errorCode = 2;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = BR/CR;
				errorCode = 3;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = BR/CR;
				errorCode = 4;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				Success("Test_DivideDouble successful. (" + p.Toc() + "ms needed)");
			}
			catch (Exception e) {
				Error("Test_DivideDouble failed at step: " + errorCode + " Msg: " + e.Message);
			}
		}
        public void Test_MatrixMultiply() {
			int errorCode = 0;
			// success? 
			try {
				ILPerformer p = new ILPerformer();
				double[] data1 = new double[120]; 
				double[] data2 = new double[120];
                double[] results = new double[36] { 177840,180120,182400,184680,186960,189240,180120,182440,
                    184760,187080,189400,191720,182400,184760,187120,189480,191840,194200,184680,187080,
                    189480,191880,194280,196680,186960,189400,191840,194280,196720,199160,189240,191720,
                    194200,196680,199160,201640};
                for (int i = 0; i < 120; i++) {
                    data1[i] = i;
                    data2[i] = i * 2;
                }
                ILDA A = new ILDA(data1, 6, 20);
                ILDA BR = new ILDA(data2, 6, 20);
                ILDA ResultExpect = new ILDA(results, 6,6);
				ILDA Result = null;
				ILDA AR = A.T.T;
                ILDA B = BR.T;
                B.Detach(); 
				BR = B.T.T;
				errorCode = 0;
                p.Tic(); 
                Result = ILMath.multiply(A , B);
                p.Toc();
				errorCode = 1;
                if (Result.Dimensions.NumberOfDimensions != 2)
					throw new Exception("Wrong number of results dimensions!");
				errorCode = 2;
                if (Result.Dimensions[0] != 6 ||Result.Dimensions[1] != 6)
					throw new Exception("Wrong result's size!");
				errorCode = 3;
                if (!Result.Equals(ResultExpect))
                    throw new Exception("Wrong results values!");
                Info("Test_MatrixMultiplyDouble succeeded: phy/phy " + p.ToString() + "ms needed");
                errorCode = 4;
				p.Tic(); 
				if (!ResultExpect.Equals(ILMath.multiply(AR, BR)))
                    throw new Exception("Wrong data value on ref/ref");
				p.Toc();
				Info("Test_MatrixMultiplyDouble succeeded: ref/ref " + p.ToString() + "ms needed");
                // test if wrong dimensions throw exceptions 
				try {
					ILMath.multiply (A, AR);
					throw new InvalidOperationException();
				} catch (Exception e) {
					if (e is InvalidOperationException)
						throw new Exception("Dimensions should be forced to match!");
				}
                data1 = new double[1000 * 2000];
                A = new ILDA(data1, 1000, 2000);
                B = new ILDA(data1, 2000, 1000);
                p.Tic();
                Result = ILMath.multiply(A, B);
                p.Toc();
                Info("Test_MatrixMultiply 1000x2000: phy/phy " + p.ToString() + "ms needed");
                Info("TODO: Implement test MatrixMultiply with reference storages!!"); 

                errorCode = 5; 
                ILArray<float> fA = new ILArray<float>(new float[12] {1f,2f,3f,4f,5f,6f,7f,8f,9f,10f,11f,12f},4,3); 
                ILArray<float> fB = new ILArray<float>(new float[12] {17f,18f,19f,20f,21f,22f,23f,24f,25f,26f,27f,28f},3,4); 
                ILArray<float> fRes = new ILArray<float>(new float[16] {278f,332f,386f,440f,323f,386f,449f,512f,368f,440,512f,584f,413f,494f,575f,656f},4,4); 
                if (ILMath.norm(fRes - ILMath.multiply(fA, fB)) > 1.0e-10) 
                    throw new Exception ("Test_MatrixMultiply: invalid values detected!");
                
                errorCode = 6; 
                ILArray<complex> zA = ILMath.real2complex(ILMath.vector(1,12),ILMath.vector(-1,-1,-12)); 
                ILArray<complex> zB = ILMath.real2complex(ILMath.vector(17,28),ILMath.vector(-17,-1,-28)); 
                //{new complex (0 , 0.5560), new complex (0, 0.6640), new complex (0, 0.7720), new complex (0, 0.8800), new complex (0,  0.6460), new complex (0,  0.7720), new complex (0,  0.8980), new complex (0,  1.0240), new complex (0,  0.7360), new complex (0,  0.8800),new complex(0,1.0240),new complex(0,1.1680),new complex(0,0.8260),new complex(0,0.9880),new complex(0,1.1500),new complex(0,1.3120)}
                ILArray<complex> zRes = ILMath.real2complex(ILMath.zeros(1,16), new ILArray<double>(new double[]{556,664,772,880,646,772,898,1024,736,880,1024,1168,826,988,1150,1312}) * (-1) ); 
                zA = ILMath.reshape(zA,4,3); 
                zB = ILMath.reshape(zB,3,4); 
                zRes = ILMath.reshape(zRes,4,4); 

                if (ILMath.norm(zRes - ILMath.multiply(zA, zB)) > 1.0e-10) 
                    throw new Exception ("Test_MatrixMultiply: invalid values detected!");
                
                errorCode = 7; 
                ILArray<fcomplex> cA = ILMath.real2fcomplex(ILMath.vector(1,12),ILMath.vector(-1,-1,-12)); 
                ILArray<fcomplex> cB = ILMath.real2fcomplex(ILMath.vector(17,28),ILMath.vector(-17,-1,-28)); 
                ILArray<fcomplex> cRes = ILMath.real2fcomplex(ILMath.zeros(1,16), new ILArray<double>(new double[]{556,664,772,880,646,772,898,1024,736,880,1024,1168,826,988,1150,1312}) * (-1) ); 
                cA = ILMath.reshape(cA,4,3); 
                cB = ILMath.reshape(cB,3,4); 
                cRes = ILMath.reshape(cRes,4,4); 

                if (ILMath.norm(cRes - ILMath.multiply(cA, cB)) > 1.0e-10)
                    throw new Exception ("Test_MatrixMultiply: invalid values detected!");
                
                Success("Test_MatrixMultiply successful.");
			} catch (Exception e) {
                Error("Test_MatrixMultiply failed at step: " + errorCode + " Msg: " + e.Message);
			}
		}
Exemple #9
0
        ///// <summary>
        ///// Cosmetic function for website display
        ///// </summary>
        ///// <param name="A">arbitrary input</param>
        ///// <returns>array as result of this test</returns>
        ///// <remarks>This function is for testing 
        ///// only. It's usefull to demonstrate some 
        ///// arrays stuff.</remarks>
        //public ILArray<double> MyTest (ILArray<double> A) {
        //    if (A.IsMatrix && ILMath.ishermitian(A)) {
        //        return A + 0.2 / A * A.T; 
        //    } else if (A.Dimensions[1] > 5) {
        //        ILArray<int> ind = new int[]{3,2,1,5,0,2}; 
        //        return ILMath.randn(1,20,30) * A[0,i,null]; 
        //    }
        //    ILArray<double> ret 
        //        = ILMath.ones(10,20); 
        //    return ret.R;
        //}

        public void Test_EnumeratorIT() {
            int errorCode = 1; 
            try  {
                ILArray<double> A = ILMath.counter(4,3,2); 
                ILArray<double> Res = ILMath.zeros(4,3,2); 
                int pos = 0; 
                ILPerformer p = new ILPerformer();
                foreach (double a in A.Iterator(0)) {
                    Res[pos++] = a; 
                }
                if (!Res.Equals(A))
                    throw new Exception ("Enumerator: invalid values detected!"); 
                errorCode = 2; 
                Res[":;:;:"] = 0.0; pos = 0; 
                foreach (double a in A.Iterator(1)) {
                    Res[pos++] = a; 
                }
                Res = Res.Reshape(new ILNumerics.Misc.ILDimension(3,2,4)).S(2); 
                if (!Res.Equals(A))
                    throw new Exception ("Enumerator: invalid values detected!"); 
                errorCode = 3; 
                Res[":;:;:"] = 0.0; pos = 0; 
                foreach (double a in A.Iterator(2)) {
                    Res[pos++] = a; 
                }
                Res = Res.Reshape(new ILNumerics.Misc.ILDimension(2,4,3)).S(1); 
                if (!Res.Equals(A))
                    throw new Exception ("Enumerator: invalid values detected!"); 
                Success(); 
            } catch (Exception e) {
                Error(errorCode,e.Message); 
            }
        }
Exemple #10
0
		public void Test_AddDouble() {
			int errorCode = 0;
			// success? 
			try {
				ILPerformer p = new ILPerformer();
				double[] data1 = new double[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
				double[] data2 = new double[10] { 11, 12, -13, 14, 15, 16, -17, 18, 19, 110 };
				double[] results = new double[18] { 12,-10,20,28,12,20,14,18,22,120,14,22,12,-10
													,20,28,12,20};
				ILArray<double> C = new ILArray<double>(data1, 2, 5);
				ILArray<double> B = new ILArray<double>(data2, 2, 5);
				ILArray<double> R = new ILArray<double>(results, 6, 3);
				ILArray<double> BR = (ILArray<double>)B[1,"0:1,0;0,1,2,4,0,2"];
				ILArray<double> CR = (ILArray<double>)C[1,"0:1,0;0,1,2,4,0,2"];
				C = CR.R;    // creates reference only 
				B = BR.R;
				C.Detach();
				B.Detach();
				ILArray<double> A = B+C;
				errorCode = 1;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = B+CR;
				errorCode = 2;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = BR+CR;
				errorCode = 3;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = BR+CR;
				errorCode = 4;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				Success("Test_AddDouble successful. (" + p.Toc() + "ms needed)");
			}
			catch (Exception e) {
				Error("Test_AddDouble failed at step: " + errorCode + " Msg: " + e.Message);
			}
		}
Exemple #11
0
        public void Test_Find() {
			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 = null; 
				ILArray<double> Res = A[ILMath.find(A > 10)];
                // test emtpy 
                Res = A[ILMath.find(A > 50)];
                if (!Res.IsEmpty) 
					Error("Test_Find: empty index array should throw an exception! "); 
                errorCode = 1; 
                ILArray<double> ResI = new ILArray<double>(new double[12] {0,2,4,6,8,10,12,14,16,18,20,22},1,12);
                ILArray<double> ResR = ILMath.zeros(1,12); 
                ILArray<double> ResC = new ILArray<double>(new double[12] {0,1,2,3,4,5,6,7,8,9,10,11},1,12);
                ILArray<byte> ResV = new ILArray<byte>(new byte[12] {1,1,1,1,1,1,1,1,1,1,1,1},1,12);

                // Test physical storage forward, no limit
                ILArray<double> Rows = ILMath.empty(); 
                ILArray<double> Cols = ILMath.empty(); 
                ILArray<byte> Vals = ILArray<byte>.empty(); 
                Rows = ILMath.find(A/2 == ILMath.round(A/2)); 
                if (!Rows.Equals(ResI)) 
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2)); A - physical");
                Rows = ILMath.find(A/2 == ILMath.round(A/2),2);
                if (!Rows.Equals(ResI["0;0,1"]))
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2),2); A - physical");
                Rows = ILMath.find(A/2 == ILMath.round(A/2),-2);
                if (!Rows.Equals(ResI["0;10:end"]))
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2),-2); A - physical");
                // Test physical, backward, no limit
                Rows = ILMath.find(A/2 == ILMath.round(A/2),-200);
                if (!Rows.Equals(ResI))
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2),-200); A - physical");
                Rows = ILMath.find(A/2 == ILMath.round(A/2),0,ref Cols, ref Vals); 
                if (!Rows.Equals(ResR) || !Cols.Equals(ResC) || ILMath.find(Vals != ResV.T).Length > 0)
                    throw new Exception ("Invalid values: [r,c,v] = Find(A/2 == ILMath.round(A/2),-200); A - physical");
                Rows = ILMath.find(A/2 == ILMath.round(A/2),-3,ref Cols, ref Vals); 
                if (!Rows.Equals(ResR["0;9,10,11"]) || !Cols.Equals(ResC["0;9,10,11"]) || !Vals.Equals(ResV["0;9,10,11"]))
                    throw new Exception ("Invalid values: [r,c,v] = Find(A/2 == ILMath.round(A/2),-3); A - physical");
                // Test reference storage, forward, no limit
                errorCode = 2; 

                ILLogicalArray A1 = (A/2 == ILMath.round(A/2));
                A1 = A1.GetShifted(3);
                Rows = ILMath.find(A1); 
                if (!Rows.Equals(ResI)) 
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2)); A - reference");
                Rows = ILMath.find(A1,2);
                if (!Rows.Equals(ResI["0;0,1"]))
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2),2); A - reference");
                Rows = ILMath.find(A1,-2);
                if (!Rows.Equals(ResI["0;10:end"]))
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2),-2); A - reference");
                // Test physical, backward, no limit
                Rows = ILMath.find(A1,-200);
                if (!Rows.Equals(ResI))
                    throw new Exception ("Invalid values: Find(A/2 == ILMath.round(A/2),-200); A - reference");
                Rows = ILMath.find(A1,0,ref Cols, ref Vals); 
                if (!Rows.Equals(ResR) || !Cols.Equals(ResC) || ILMath.find(Vals != ResV.T).Length > 0)
                    throw new Exception ("Invalid values: [r,c,v] = Find(A/2 == ILMath.round(A/2),-200); A - reference");
                Rows = ILMath.find(A1,-3,ref Cols, ref Vals); 
                if (!Rows.Equals(ResR["0;9,10,11"]) || !Cols.Equals(ResC["0;9,10,11"]) || !Vals.Equals(ResV["0;9,10,11"]))
                    throw new Exception ("Invalid values: [r,c,v] = Find(A/2 == ILMath.round(A/2),-3); A - reference");

                errorCode = 3;
                float[] data2 = new float[24];
                for (int i = 0; i < data2.Length; i++)
					data2[i] = (float)(i%2.0f);
                ResI = new ILArray<double>(new double[4]{18,20,22,24},4,1) - 1.0; 
                ILArray<float> A2 = new ILArray<float>(data2,2,3,4);
                Rows = ILMath.find(A2,-4);
                if (!Rows.Equals(ResI))
                    throw new Exception ("Invalid values: Find(A2,-4); A - phys., float");

                errorCode = 4; 
                // test large 
                A = ILMath.ones(500, 500, 10);
                A["200:300;200:300;0:end"] = (ILArray<double>)0.0;
                A = A["0:end;0:end;0:end"];
                ILLogicalArray L = A != 0; 
                ILPerformer p = new ILPerformer();
                // Matlab Code: 
                // a = ones(1000,1000,10); a(200:300,200:300,:) = 0; tic; b = a(find(a~=0)); toc; 
                Info("Test_Find (testing performance please wait...) ");
                int cycles = 20;
                long duration = 0;
                for (int i = 0; i < cycles; i++) {
                    p.Tic();
                    B = ILMath.find(L); 
                    p.Toc();
                    duration += p.Duration;
                    //System.GC.Collect();
                }
                duration /= cycles;
                Info("Test_Find [500,500,10] " + (L.IsReference ? "Ref: " : "Phy: ") + "'B = Find(A != 0)' avg. needed: " + p.ToString() + " ms");

                errorCode = 5; 
                cycles = 4;
                duration = 0;
                L = L["0:end;0:end;0:end"]; 
                for (int i = 0; i < cycles; i++) {
                    p.Tic();
                    B = ILMath.find(L);
                    p.Toc();
                    duration += p.Duration;
                    System.GC.Collect(); 
                }
                duration /= cycles;
                Info("Test_Find [500,500,10] " + (L.IsReference ? "Ref: " : "Phy: ") + "'B = Find(L)' avg. needed: " + p.ToString() + " ms");

                errorCode = 6; 
                // value ok? 
                if (ILMath.sum(ILMath.sum(B)) != 2997460747500)
                    throw new Exception("TEst_Find: wrong value of result!"); 

				Success();
			} catch (Exception e) {
				Error(errorCode, e.Message);
			}
		}
Exemple #12
0
        public void Test_MMult() {
            int errorCode = 0;
            try {
                double[] data = new double[20];
				for (int i = 0; i < data.Length; i++)
					data[i] = i+1;
                ILArray<double> origA = new ILArray<double>(data,5,4); 
				ILArray<double> A = new ILArray<double>(origA);
                ILArray<double> B = new ILArray<double>(origA.T).Detach();

                ILArray<double> Res = new ILArray<double>(new double[] {414,448,482,516,550,448,486,524,562,600,482,524,566,608,650,516,562,608,654,700,550,600,650,700,750} ,5,5); 
                // test phy * phy
                if (!ILMath.Equals (ILMath.multiply(A,B),Res) )
                    throw new Exception ("Test MathBasic: MMult failed at A*B (phys * phys) due: invalid values"); 
                B = new ILArray<double> (origA.T);
                // test phy * ref 
                if (!ILMath.Equals (ILMath.multiply(A,B),Res) )
                    throw new Exception ("Test MathBasic: MMult failed at A*B (phys * ref) due: invalid values"); 
                // test ref * ref 
                A = origA.T.Detach().T; 
                if (!ILMath.Equals (ILMath.multiply(A,B),Res) )
                    throw new Exception ("Test MathBasic: MMult failed at A*B (ref * phys) due: invalid values"); 
                // test ref * phy 
                A = A.Detach(); 
                B = B.Detach(); 
                if (!ILMath.Equals (ILMath.multiply(A,B),Res) )
                    throw new Exception ("Test MathBasic: MMult failed at A*B (ref * ref) due: invalid values"); 
                ILPerformer p = new ILPerformer(); 
                data = new double[1000000];
                A = ILMath.ones(1000,1000); 
                p.Tic(); 
                    B = ILMath.multiply (A,A.T); 
                p.Toc(); 
                Info("MMult 1000x1000 procceeded in " + p.ToString() + "msec.");
                Success("MMult finished successfully"); 
            } catch (Exception e) {
				Error("Test_MMult failed at errorCode: " + errorCode + " Reason: " + e.Message);
            }
        }
Exemple #13
0
        public void Test_Sum() {
            int errorCode = 0;
            try {
                double[] data = new double[120];
				for (int i = 0; i < data.Length; i++)
					data[i] = i+1;
				ILArray<double> A = new ILArray<double>(data, 6, 5, 4);
				ILArray<double> Res = new ILArray<double>(new double[20] {
					21,57,93,129,165,201,237,273,309,345,381,417,453,489,525,561,597,633,669,705}, 1, 5, 4);
				ILArray<double> S = ILMath.sum(A);
                ILPerformer p = new ILPerformer();
                if (S.Dimensions.NonSingletonDimensions != 2)
					throw new Exception("Wrong size of Sum result! ");
				if (S.Dimensions.NumberOfDimensions != 3)
					throw new Exception("Wrong size of Sum result! ");
				if (S.Dimensions[0] != 1)
					throw new Exception("Wrong size of leading Dimension of Sum result! ");
				if (S.Dimensions[1] != 5)
					throw new Exception("Wrong size of 2. Dimension of Sum result! ");
				if (S.Dimensions[2] != 4)
					throw new Exception("Wrong size of 3. Dimension of Sum result! ");
				if (S.Dimensions.NumberOfElements != 20)
					throw new Exception("Wrong number of elements of Sum result! ");
				if (! Res.Equals(S))
					throw new Exception("Wrong values of Sum result! ");

				ILArray<double> B = (ILArray<double>)A[1,"1:end;1:end;2"];
				double [] data2 = new double[4] { 350,380,410,440 };
				Res = new ILArray<double>(data2, 4, 1); 
				if (!Res.Equals(ILMath.sum(B,1)))
					throw new Exception("Wrong values of Sum result! ");
				
				errorCode = 1;
                // test non-matrix, reference case 
                A = (ILArray<double>)ILMath.counter(4,3,2).CreateReference();
                if (!A.IsReference) 
                    throw new Exception("sum: test data creation failed: A should be reference array!"); 
                Res = new double[,]{{15,18,21,24},{51,54,57,60}};  
                Res = ILMath.reshape(Res ,4,1,2);
                B = ILMath.sum(A,1); 
                if (!Res.Equals(B)) 
                    throw new Exception("sum: invalid result (n-d, reference)"); 

				
                ILArray<double> C = new ILArray<double>(data, 1, 1, 4, 5, 6);
				Res = new ILArray<double>(new double[30] {
					10,26,42,58,74,90,106,122,138,154,170,186,202,218,234,250,266
					,282,298,314,330,346,362,378,394,410,426,442,458,474},1,1,1,5,6);
                p.Tic(); 
                S = ILMath.sum(C,2);
                p.Toc();
                if (!Res.Equals(S)) 
					throw new Exception("Wrong values of Sum result! ");
                Info("Sum(1x1x4x5x6)[phy] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(C);
                p.Toc();
                Info("Sum(1x1x4x5x6)[phy ohne Zuweisung] needed: " + p.ToString());
				
                errorCode = 2;
                C = (ILArray<double>)A.T;
                p.Tic();
                B = ILMath.sum(C);
                p.Toc();
                Info("Sum(5x4x6)[Ref] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(C);
                p.Toc();
                Info("Sum(5x4x6)[Ref ohne Zuweisung] needed: " + p.ToString());
				
				data = new double[8]{15,51,18,54,21,57,24,60};
				Res = new ILArray<double>(data,1,2,4);
				if (!Res.Equals(B))
					throw new Exception("Wrong values of Sum result! ");
				
				errorCode = 3; 
				// big array: 
				data = new double[1000 * 1000 * 10]; 
				A = new ILArray<double>(data,1000,1000,10);
                p.Tic();
                C = ILMath.sum(A);
                p.Toc();
                Info("Sum(1000x1000x10) [phy] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(A);
                p.Toc();
                Info("Sum(1000x1000x10) [phy ohne Zuweisung] needed: " + p.ToString());

				errorCode = 4;
				data = new double[1000 * 1000 * 10];
				A = new ILArray<double>(data, 1000000, 10);
                p.Tic();
                C = ILMath.sum(A);
                p.Toc();
                Info("Sum(1000000x10) [phy] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(A);
                p.Toc();
                Info("Sum(1000000x10) [phy ohne Zuweisung] needed: " + p.ToString());

				errorCode = 5;
				data = new double[10 * 1000000];
				A = new ILArray<double>(data, 10, 1000000);
                p.Tic();
                C = ILMath.sum(A);
                p.Toc();
                Info("Sum(10 x 1000000) [Phy] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(A);
                p.Toc();
                Info("Sum(10 x 1000000) [Phy ohne Zuweisung] needed: " + p.ToString());

                errorCode = 6;
				data = new double[1000 * 1000 * 10];
				data[1] = 1.0;
                A = (ILArray<double>)A.T;
                p.Tic();
                C = ILMath.sum(A);
                p.Toc();
                Info("Sum(1000000 x 10) [Ref] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(A);
                p.Toc();
                Info("Sum(1000000 x 10) [Ref ohne Zuweisung] needed: " + p.ToString());


                errorCode = 7;
                data = new double[120];
                for (int i = 0; i < data.Length; i++)
                    data[i] = i + 1;
                A = new ILArray<double>(data, 6, 5, 4); 
                data = new double[24]{65,70,75,80,85,90,215,220,225,230,235,240,365
                                        ,370,375,380,385,390,515,520,525,530,535,540};
                Res = new ILArray<double>(data, 6, 1, 4);
                p.Tic();
                C = ILMath.sum(A,1);
                p.Toc();
                Info("Sum(6, 5, 4) [phy, dim 2] needed: " + p.ToString());
                p.Tic();
                ILMath.sum(A,1);
                p.Toc();
                Info("Sum(6, 5, 4) [phy ohne Zuweisung] needed: " + p.ToString());
                if (!Res.Equals(C))
					throw new Exception("Wrong values of Sum result! ");

				errorCode = 8;
                //data = new double[20000000];
                //for (int i = 0; i < data.Length; i++)
                //    data[i] = 2;
				A = ILMath.zeros(1,20000000) + 2.0; 
				Res = 4.0e+07;
				p.Tic();
				C = ILMath.sum(A);
				p.Toc();
				Info("Sum(20000000,1) [phy] needed: " + p.ToString());
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Sum result! ");
				p.Tic();
				ILMath.sum(A);
				p.Toc();
				Info("Sum(20000000,1) [phy ohne Zuw.] needed: " + p.ToString());

				errorCode = 9;
                A.MinimumRefDimensions = 2;
				A.Dispose();
				A = new ILArray<double>(ILMemoryPool.Pool.New<double>(20000000),1,20000000).R; 
				p.Tic();
				C = ILMath.sum(A);
				p.Toc();
				Info("Sum(2,10000000) [ref 'vector'] needed: " + p.ToString());
				p.Tic();
				ILMath.sum(A);
				p.Toc();
				Info("Sum(1,20000000) [ref vector ohne Zuw.] needed: " + p.ToString());
				A = null;
				B = null;
				C = null;
				Res = null; 
                errorCode = 10; 
				Success("Test_Sum successfull");
            } catch (SerializationException e) {
				Error("Test_Sum failed at errorCode: "+errorCode +" Reason: " + e.Message);
            } catch (Exception e) {
				Error("Test_Sum failed at errorCode: " + errorCode + " Reason: " + e.Message);
            }
        }
Exemple #14
0
		public void Test_Relop() {
            int errorCode = 0;
            try {
                
				byte[] data = new byte[120];
				for (int i = 0; i < data.Length; i++)
					data[i] = (i % 2 == 1) ? (byte)1 : (byte)0;
 				ILLogicalArray A = new ILLogicalArray(data, 6, 5, 4);
				double[] data2 = new double[120];
				for (int i = 0; i < data.Length; i++)
					data2[i] = (i % 2) ;
				ILArray<double> B = new ILArray<double>(data2,6,5,4);
				ILArray<double> C = ILMath.ones(6,5,4); 
				ILLogicalArray Res = ILMath.eq(B,C);
				if (!A.Equals(Res))
					throw new Exception("Invalid result values!");
				errorCode = 1;
				B = ILMath.ones(1000, 1000, 10);
				C = ILMath.zeros(1000, 1000, 10);
				ILPerformer pEq = new ILPerformer();
				ILPerformer pAll = new ILPerformer();
				long durationGC = 0, durationEq = 0;
				int cycles = 20; 
				pAll.Tic(); 
				for (int i = 0; i < cycles; i++) {
					pEq.Tic(); 
					Res = B == C;
					pEq.Toc();
					durationEq += pEq.Duration;

					pEq.Tic();
					//System.GC.Collect();
					pEq.Toc();
					durationGC += pEq.Duration; 
				}
				pAll.Toc(); 
				durationEq /= cycles;
				durationGC /= cycles;
				Info("Test Eq[ual] phys. Arrays: [1000 x 1000 x 10] needed :" + durationEq + " /GC: "
							+ durationGC + " /All: " + pAll.Duration);

				errorCode = 3;
				B = (ILArray<double>)B[1,"0:end;0:end;0:end"];
				C = (ILArray<double>)C.T;
				durationGC = 0; durationEq = 0;
				cycles = 3;
				pAll.Tic();
				for (int i = 0; i < cycles; i++) {
					pEq.Tic();
					Res = B == C;
					pEq.Toc();
					durationEq += pEq.Duration;

					pEq.Tic();
					//System.GC.Collect();
					pEq.Toc();
					durationGC += pEq.Duration;
				}
				pAll.Toc();
				durationEq /= cycles;
				durationGC /= cycles;
				Info("Test Eq[ual] Ref. Arrays: [1000 x 1000 x 10] needed :" + durationEq + " /GC: "
							+ durationGC + " /All: " + pAll.Duration); 

				/*if (S.Dimensions.NonSingletonDimensions != 2)
					throw new Exception("Wrong size of Sum result! ");
				if (S.Dimensions.NumberOfDimensions != 3)
					throw new Exception("Wrong size of Sum result! ");
				if (S.Dimensions[0] != 1)
					throw new Exception("Wrong size of leading Dimension of Sum result! ");
				if (S.Dimensions[1] != 5)
					throw new Exception("Wrong size of 2. Dimension of Sum result! ");
				if (S.Dimensions[2] != 4)
					throw new Exception("Wrong size of 3. Dimension of Sum result! ");
				if (S.Dimensions.NumberOfElements != 20)
					throw new Exception("Wrong number of elements of Sum result! ");
				if (! Res.Equals(S))
					throw new Exception("Wrong values of Sum result! ");

				ILArray<double> B = (ILArray<double>)A["1:end;1:end;2", 1];
				double [] data2 = new double[4] { 350,380,410,440 };
				Res = new ILArray<double>(data2, 4, 1); 
				if (!Res.Equals(ILMath.Sum(B,1)))
					throw new Exception("Wrong values of Sum result! ");
				
				errorCode = 1;
				ILArray<double> C = new ILArray<double>(data, 1, 1, 4, 5, 6);
				Res = new ILArray<double>(new double[30] {
					10,26,42,58,74,90,106,122,138,154,170,186,202,218,234,250,266
					,282,298,314,330,346,362,378,394,410,426,442,458,474},1,1,1,5,6);
                p.Tic(); 
                S = ILMath.Sum(C,2);
                p.Toc();
                if (!Res.Equals(S)) 
					throw new Exception("Wrong values of Sum result! ");
                Info("Sum(1x1x4x5x6)[phy] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(C);
                p.Toc();
                Info("Sum(1x1x4x5x6)[phy ohne Zuweisung] needed: " + p.ToString());
				
                errorCode = 2;
                C = (ILArray<double>)A.T;
                p.Tic();
                B = ILMath.Sum(C);
                p.Toc();
                Info("Sum(5x4x6)[Ref] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(C);
                p.Toc();
                Info("Sum(5x4x6)[Ref ohne Zuweisung] needed: " + p.ToString());
				
				data = new double[24]{65,215,365,515,70,220,370,520,75,225
					,375,525,80,230,380,530,85,235,385,535,90,240,390,540};
				Res = new ILArray<double>(data,1,4,6);
				if (!Res.Equals(B))
					throw new Exception("Wrong values of Sum result! ");
				
				errorCode = 3; 
				// big array: 
				data = new double[1000 * 1000 * 10]; 
				A = new ILArray<double>(data,1000,1000,10);
                p.Tic();
                C = ILMath.Sum(A);
                p.Toc();
                Info("Sum(1000x1000x10) [phy] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(A);
                p.Toc();
                Info("Sum(1000x1000x10) [phy ohne Zuweisung] needed: " + p.ToString());

				errorCode = 4;
				data = new double[1000 * 1000 * 10];
				A = new ILArray<double>(data, 1000000, 10);
                p.Tic();
                C = ILMath.Sum(A);
                p.Toc();
                Info("Sum(1000000x10) [phy] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(A);
                p.Toc();
                Info("Sum(1000000x10) [phy ohne Zuweisung] needed: " + p.ToString());

				errorCode = 5;
				data = new double[10 * 1000000];
				A = new ILArray<double>(data, 10, 1000000);
                p.Tic();
                C = ILMath.Sum(A);
                p.Toc();
                Info("Sum(10 x 1000000) [Phy] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(A);
                p.Toc();
                Info("Sum(10 x 1000000) [Phy ohne Zuweisung] needed: " + p.ToString());

                errorCode = 6;
				data = new double[1000 * 1000 * 10];
				data[1] = 1.0;
                A = (ILArray<double>)A.T;
                p.Tic();
                C = ILMath.Sum(A);
                p.Toc();
                Info("Sum(1000000 x 10) [Ref] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(A);
                p.Toc();
                Info("Sum(1000000 x 10) [Ref ohne Zuweisung] needed: " + p.ToString());


                errorCode = 7;
                data = new double[120];
                for (int i = 0; i < data.Length; i++)
                    data[i] = i + 1;
                A = new ILArray<double>(data, 6, 5, 4); 
                data = new double[24]{65,70,75,80,85,90,215,220,225,230,235,240,365
                                        ,370,375,380,385,390,515,520,525,530,535,540};
                Res = new ILArray<double>(data, 6, 1, 4);
                p.Tic();
                C = ILMath.Sum(A,1);
                p.Toc();
                Info("Sum(6, 5, 4) [phy, dim 2] needed: " + p.ToString());
                p.Tic();
                ILMath.Sum(A,1);
                p.Toc();
                Info("Sum(6, 5, 4) [phy ohne Zuweisung] needed: " + p.ToString());
                if (!Res.Equals(C))
					throw new Exception("Wrong values of Sum result! ");

				errorCode = 8;
				data = new double[20000000];
				for (int i = 0; i < data.Length; i++)
					data[i] = 2;
				A = new ILArray<double>(data, 20000000);
				Res = new ILArray<double>(new double[1] { 4.0e+07 }, 1);
				p.Tic();
				C = ILMath.Sum(A);
				p.Toc();
				Info("Sum(20000000,1) [phy] needed: " + p.ToString());
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Sum result! ");
				p.Tic();
				ILMath.Sum(A);
				p.Toc();
				Info("Sum(20000000,1) [phy ohne Zuw.] needed: " + p.ToString());

				errorCode = 9;
				ILArray<double>.MinimumRefDimensions = 1;
				A = (ILArray<double>)A.T;
				p.Tic();
				C = ILMath.Sum(A);
				p.Toc();
				Info("Sum(1,20000000) [ref vector] needed: " + p.ToString());
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Sum result! ");
				p.Tic();
				ILMath.Sum(A);
				p.Toc();
				Info("Sum(1,20000000) [ref vector ohne Zuw.] needed: " + p.ToString());
				A = null;
				B = null;
				C = null;
				Res = null; 
*/				System.GC.Collect();
				Success("Test_Relop successfull");
            } catch (SerializationException e) {
				Error("Test_Relop failed at errorCode: " + errorCode + " Reason: " + e.Message);
            } catch (Exception e) {
				Error("Test_Relop failed at errorCode: " + errorCode + " Reason: " + e.Message);
            }
        }
Exemple #15
0
		public void Test_Apply() {
			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 = (ILArray<double>)A[1,"1,1;2,1,0;2:end"]; 
				ILArray<double> Res = new ILArray<double>(new double[24] {
				0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
				}, 2, 3, 4);
				// apply on physical storage
				ILArray<double> C = ILMath.ceil(ILMath.tanh(A) - 0.5); 
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Apply result! ");

				// apply on reference arbitrary storage
				errorCode = 1; 
				Res = new ILArray<double>(new double[12] {
				 -1,0,0,-1,0,0,-1,0,0,-1,0,0
				}, 3, 2, 2);
				C = ILMath.floor(ILMath.sin(B));
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Apply result! ");

				// apply on row reference vector 
				errorCode = 2;
				B.MinimumRefDimensions = 2; 
				C = (ILArray<double>) B["1,1;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"+
				"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0"];
				C = ILMath.pow(C, 2.3); 
				Res = ILMath.ones(2, 36) * 507.00226068959716;
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Apply result! ");

				// apply on column reference vector 
				errorCode = 3; 
				C = (ILArray<double>)B[1,"1,1;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"+
				"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0"];
				C = ILMath.sqrt(C) + 2.4432112354;       
				Res = ILMath.ones(36, 2) * 6.3161945816074176;
				if (!Res.Equals(C))
					throw new Exception("Wrong values of Apply result! ");

				// apply large array -> performance test
				errorCode = 4; 
				ILPerformer p = new ILPerformer();
				A = ILMath.ones(1000, 1000, 10);
				long durationsMath = 0;
				ILPerformer p2 = new ILPerformer(); 
				long durationsGC = 0;
				int cycles = 20; p2.Tic();
				for (int i = 0; i < cycles; i++) {
					durationsGC += p.Duration;
                    p.Tic();
						A = A + 3.4;
					p.Toc();
					durationsMath += p.Duration;

					p.Tic();
						System.GC.Collect();
					p.Toc(); 
				}
				p2.Toc(); 
				durationsMath /= cycles;
				durationsGC /= cycles;
				Info("Apply(1000x1000x10)[Phy] needed: " + durationsMath.ToString() +"/GC: "+ durationsGC.ToString() + "/All: " +p2.Duration.ToString());

				errorCode = 5;
				durationsMath = 0;
				durationsGC = 0;
				cycles = 20;
				A = (ILArray<double>)A.T;
				p2.Tic();
				for (int i = 0; i < cycles; i++) {
					p.Tic();
					B = A + 3.4;
					p.Toc();
					durationsMath += p.Duration;

					p.Tic();
					System.GC.Collect();
					p.Toc();
					durationsGC += p.Duration;
				}
				p2.Toc();
				durationsMath /= cycles;
				durationsGC /= cycles;
				Info("Apply(1000x1000x10)[Ref] needed: " + durationsMath.ToString() + "/GC: " + durationsGC.ToString() + "/All: " +p2.Duration.ToString());
				 
				Success();
            } catch (Exception e) {
				Error(errorCode, e.Message);
            }
		}
Exemple #16
0
 public void Test_EnumeratorPerf(ILArray<double> A) {
     int errorCode = 1; 
     try  {
         ILPerformer p = new ILPerformer();
         Info("Enumerator test A => " + A.Dimensions); 
         p.Tic();
         foreach (ILArray<double> a in A) { }
         p.Toc();
         Info(" foreach (ILArray<double> a in A){ ... => " + p.ToString() + " ms");
         errorCode = 2; 
         p.Tic(); 
         foreach (double a in A) { }
         p.Toc(); 
         Info(" foreach (double a in A){ }  => " + p.ToString() + " ms");
         errorCode = 3; 
         p.Tic(); 
         foreach (double a in A.Values) { }
         p.Toc();
         Info(" foreach (double a in A.Values){ } [solid] => " + p.ToString() + " ms");
         A = A.R;
         p.Tic(); 
         foreach (double a in A.Values) { }
         p.Toc();
         Info(" foreach (double a in A.Values){ } [Ref] => " + p.ToString() + " ms");
         int l = A.Dimensions.NumberOfElements; 
         double b;
         p.Tic(); 
         for (int i = 0; i < l; i++) { b = A.GetValue(i); }
         p.Toc();
         Info(" for (int i = 0; i < l; i++) { a = A.GetValue(i); } => " + p.ToString() + " ms");
         if (A.IsReference) 
             A.Detach(); 
         p.Tic(); 
         for (int i = 0; i < l; i++) { b = A.m_data[i]; }
         p.Toc();
         Info(" for (int i = 0; i < l; i++) { a = A.m_data[i]; } => " + p.ToString() + " ms");
         Success(); 
     } catch (Exception e) {
         Error(errorCode,e.Message); 
     }
 }
Exemple #17
0
		public void Test_MultiplyElementsDouble() {
			int errorCode = 0;
			// success? 
			try {
				ILPerformer p = new ILPerformer();
				double[] data1 = new double[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
				double[] data2 = new double[10] { 11, 12, -13, 14, 15, 16, -17, 18, 19, 110 };
				double[] results = new double[18] { 11, -39, 75, 171, 11, 75, 24, 56, 96, 1100
												   ,24, 96, 11, -39, 75, 171, 11, 75 };
				ILArray<double> C = new ILArray<double>(data1, 2, 5);
				ILArray<double> B = new ILArray<double>(data2, 2, 5);
				ILArray<double> R = new ILArray<double>(results, 6, 3);
				ILArray<double> BR = (ILArray<double>)B[1,"0:1,0;0,1,2,4,0,2"];
				ILArray<double> CR = (ILArray<double>)C[1,"0:1,0;0,1,2,4,0,2"];
				C = (ILArray<double>)CR.T.T;
				B = (ILArray<double>)BR.T.T;
				C.Detach();
				B.Detach();
				ILArray<double> A = B*C;
				errorCode = 1;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = B*CR;
				errorCode = 2;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = BR*CR;
				errorCode = 3;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				A = BR*CR;
				errorCode = 4;
				if (!A.Equals(R))
					throw new Exception("Values did not match!");
				Success("Test_MultiplyElementsDouble successful. (" + p.Toc() + "ms needed)");
			}
			catch (Exception e) {
				Error("Test_MultiplyElementsDouble failed at step: " + errorCode + " Msg: " + e.Message);
			}
		}
Exemple #18
0
 public void Test_Enumerator() {
     int errorCode = 1; 
     try  {
         ILArray<double> A = ILMath.counter(10,30,20); 
         ILArray<double> Res = ILMath.zeros(10,30,20); 
         int pos = 0; 
         ILPerformer p = new ILPerformer();
         foreach (ILArray<double> a in A) {
             Res[pos++] = a; 
         }
         if (!Res.Equals(A))
             throw new Exception ("Enumerator: invalid values detected!"); 
         errorCode = 2; 
         Res[":;:;:"] = 0.0; pos = 0; 
         foreach (double a in A) {
             Res[pos++] = a; 
         }
         if (!Res.Equals(A))
             throw new Exception ("Enumerator: invalid values detected!"); 
         errorCode = 3; 
         Res[":;:;:"] = 0.0; pos = 0; 
         foreach (double a in A.Values) {
             Res[pos++] = a; 
         }
         if (!Res.Equals(A))
             throw new Exception ("Enumerator: invalid values detected!"); 
         Res[":;:"] = 0.0;  
         int l = A.Dimensions.NumberOfElements; 
         for (int i = 0; i < l; i++) {
             Res.SetValue(A.GetValue(i),i); 
         }
         Success(); 
     } catch (Exception e) {
         Error(errorCode,e.Message); 
     }
 }