当前位置: 首页>>代码示例>>C#>>正文


C# ILArray.Detach方法代码示例

本文整理汇总了C#中ILArray.Detach方法的典型用法代码示例。如果您正苦于以下问题:C# ILArray.Detach方法的具体用法?C# ILArray.Detach怎么用?C# ILArray.Detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILArray的用法示例。


在下文中一共展示了ILArray.Detach方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: svd

        /// <summary>
        /// singular value decomposition 
        /// </summary>
        /// <param name="X">matrix X. The elements of X will not be altered.</param>
        /// <param name="U">(return value) left singular vectors of X as columns of matrix U. 
        /// If this parameter is set, it must be not null. It might be an empty array. On return
        /// it will be set to a physical array accordingly.</param>
        /// <param name="V">right singular vectors of X as rows of matrix V.
        /// If this parameter is set, it must be not null. It might be an empty array. On return
        /// it will be set to a physical array accordingly.</param>
        /// <param name="small">if true: return only first min(M,N) columns of U and S will be 
        /// of size [min(M,N),min(M,N)]</param>
        /// <param name="discardFiniteTest">if true: the matrix given will not be checked for infinte or NaN values. If such elements 
        /// are contained nevertheless, this may result in failing convergence or error. In worst case 
        /// the function may hang inside the Lapack lib. Use with care! </param>
        /// <returns>singluar values as diagonal matrix of same size as X</returns>
        /// <remarks>the right singular vectors V will be returned as reference array.</remarks>
        public static  ILArray<double> svd( ILArray<complex> X, ref  ILArray<complex> U, ref  ILArray<complex> V, bool small, bool discardFiniteTest) {
            if (!X.IsMatrix)
                throw new ILArgumentSizeException("svd is defined for matrices only!");
            // early exit for small matrices
            if (X.Dimensions[1] < 4 && X.Dimensions[0] == X.Dimensions[1]) { 
                switch (X.Dimensions[0]) {
                    case 1: 
                        if (!Object.Equals(U,null))
                            U = ( complex ) 1.0; 
                        if (!Object.Equals(V,null))
                            V = ( complex ) 1.0; 
                        return new  ILArray<double> ( ILMath.abs(X)); 
                    //case 2:
                    //    return -1; 
                    //case 3: 
                    //    return -1; 
                }
            }
            if (!discardFiniteTest && !all(all(isfinite( X )))) 
                throw new ILArgumentException("svd: input must have only finite elements!");
            if (Lapack == null)
                throw new ILMathException("No Lapack package available.");
            // parameter evaluation
            int M = X.Dimensions[0]; int N = X.Dimensions[1];
            int minMN = (M < N) ? M : N;
            int LDU = M; int LDVT = N;
            int LDA = M;
            double [] dS = new  double [minMN];
            char jobz = (small) ? 'S' : 'A';
            complex [] dU = null;
            complex [] dVT = null;
            int info = 0;
            if (!Object.Equals(U, null) || !Object.Equals(V, null)) {
                // need to return U and VT 
                if (small) {
                    dU = new  complex  [M * minMN];
                    dVT = new  complex [N * minMN];
                } else {
                    dU = new  complex [M * M];
                    dVT = new  complex [N * N];
                }
            } else {
                jobz = 'N';
            }

            if (X.IsReference) {
                X.Detach();
            }
            // must create copy of input ! 
            complex [] dInput = new  complex [X.m_data.Length]; 
            System.Array.Copy(X.m_data, dInput, X.m_data.Length);
            Lapack.zgesdd(jobz, M, N, dInput, LDA, dS, dU, LDU, dVT, LDVT, ref info);
            if (info < 0) 
                throw new ILArgumentException ("ILMath.svd: the " + (-info).ToString() +"th argument was invalid.");
            if (info > 0)
                throw new ILArgumentException("svd was not converging!");
            ILArray<double> ret = null; 
            if (info == 0) {
                // success
                if (!Object.Equals(U, null) || !Object.Equals(V, null)) {
                    if (small) {
                        ret =  ILArray<double> .zeros(minMN,minMN);
                    } else {
                        ret =  ILArray<double> .zeros(M, N);
                    }
                    for (int i = 0; i < minMN; i++) {
                        ret.SetValue(dS[i],i,i); 
                    }
                    if (!Object.Equals(U, null))
                        U = new  ILArray<complex> (dU,M,dU.Length / M);
                    if (!Object.Equals(V, null)) {
                        V = conj(new  ILArray<complex> (dVT,N,dVT.Length / N).T);
                    }
                } else {
                    ret = new  ILArray<double> (dS,minMN,1); 
                }
            }
            return ret;
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:96,代码来源:Svd.cs

示例2: Test_DivideDouble

		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);
			}
		}
开发者ID:wdxa,项目名称:ILNumerics,代码行数:42,代码来源:TESTILNumericArray.cs

示例3: Test_setrange_of_reference

		public void Test_setrange_of_reference() {
			int errorCode = 0;
			// success? 
			try {
				object[] data = new object[120];
				for (int i = 120; i-- > 0; )
					data[i] = (double)i;
                ILArray<object> B = new ILArray<object>(data, 5, 4, 1, 3, 2, 1);
				int oldRefDim = ILSettings.MinimumRefDimensions; 
                ILSettings.MinimumRefDimensions = 2; 
                ILArray<object> A = B[3,"0:2,4;1,3;0;2,1,0,1"];
				// make A writable
				ILArray<object>.DetachReferences = ILDetachingBehavior.DetachNever; 
				B.Detach();
				errorCode = 1;
				// new values
				double[] vals = new double[12] { 101, 102, 103, 104, 105, 106, 107, 
												 108, 109, 110, 111, 112 };
				object[] valso = new object[vals.Length];
				for (int i = 0; i < vals.Length; i++)
					valso[i] = vals[i];
				ILArray<object> C = new ILArray<object>(valso, 3, 2, 2);
				// should replace missing trailing dimension by 0
				// inner singleton dimensions should be ok! 
				ILArray<object>.DetachReferences = ILDetachingBehavior.DetachSave;
				A["0,2,3;0,3;0,1"] = C;
				errorCode = 2;

				double[] results = new double[32] {101,103,102,103,46,26, 6,26,47
						,27, 7,27,104,106,105,106,107,109,108,109,56,36,16,36,57,37,17
						,37,110,112,111,112};
				ILIterator<object> I = A.CreateIterator(ILIteratorPositions.ILStart, 0);
				int count = 0;
				do {
					if (((Double)I.Value).CompareTo(results[count++]) != 0)
						throw new Exception("Values did not match!");
					I.Increment();
				} while (!I.IsAtStart());
				errorCode = 3; 
				// test detaching before altering 
				ILArray<object>.DetachReferences = ILDetachingBehavior.DetachOnWrite;
				A = B[3,"0:2,4;1,3;0;2,1,0,1"];
				B.Detach();
				A.SetRange(new ILRange(A.Dimensions,RangeSide.Left,"0,2,3;0,3;0,1"), C);
				errorCode = 4;

				results = new double[32] {101,25,102,103,46,26, 6,26,47
						,27, 7,27,104,29,105,106,107,35,108,109,56,36,16,36,57,37,17
						,37,110,39,111,112};
				I = A.CreateIterator(ILIteratorPositions.ILStart, 0);
				count = 0;
				do {
					if (((Double)I.Value).CompareTo(results[count++]) != 0)
						throw new Exception("The values did not match!");
					I.Increment();
				} while (!I.IsAtStart());
				// complain if dimensions do not match
				errorCode = 5;
				ILArray<object> D = new ILArray<object>(new object[4] { 1, 1, 1, 1 }, 1, 2, 2);
				try {
					A["0,1,0,0:2"] = D;
				} catch (ILArgumentSizeException) {
					Info("setrange: dimension mismatch signaled correctly"); 
				}
				errorCode = 4;
                ILSettings.MinimumRefDimensions = oldRefDim; 
				Success();
			} catch (Exception e) {
				Error(errorCode, e.Message);
			}
		}
开发者ID:wdxa,项目名称:ILNumerics,代码行数:71,代码来源:TESTILStorage.cs

示例4: Test_MultiplyElementsDouble

		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);
			}
		}
开发者ID:wdxa,项目名称:ILNumerics,代码行数:40,代码来源:TESTILNumericArray.cs

示例5: Test_AddDouble

		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);
			}
		}
开发者ID:wdxa,项目名称:ILNumerics,代码行数:40,代码来源:TESTILNumericArray.cs

示例6: Test_MMult

        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);
            }
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:39,代码来源:TESTILMath.cs

示例7: FFTBackwSym1D

// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! 



        public ILArray< float > FFTBackwSym1D(ILArray< fcomplex > A, int dim) {
            if (A == null || dim < 0) 
                throw new ILArgumentException("invalid parameter!"); 
            if (A.IsEmpty) return ILArray< float >.empty(A.Dimensions); 
            if (A.IsScalar || A.Dimensions[dim] == 1) 
                return ILMath.real(A); 
            // prepare output array, if we query the memory directly from
            // memory pool, we prevent from clearing the elements since every 
            // single one will be overwritten by fft anyway
            int error = 0,inDim = A.Dimensions[dim];   
            float [] retArr = ILMemoryPool.Pool.New< float >(A.Dimensions.NumberOfElements); 
            ILArray< float > ret = new ILArray< float >(retArr,A.Dimensions); 
            if (A.IsReference) 
                A.Detach(); 
            string hash = hashPlan( MKLValues.SINGLE , MKLValues.REAL, 1, inDim); 
            IntPtr descriptor = IntPtr.Zero;
            // try to reuse existing descriptor
            lock (_lockobject) {
                if (!m_descriptors.TryGetValue(hash, out descriptor)) {
                    error = MKLImports.DftiCreateDescriptor(ref descriptor, MKLValues.SINGLE , MKLValues.REAL, 1, inDim);
                    if (isMKLError(error)) {
                        throw new ILInvalidOperationException ("error creating descriptor: " + MKLImports.DftiErrorMessage(error)); 
                    }
                    m_descriptors[hash] = descriptor; 
                }
            }
            // spacing between elements
            int tmp = A.Dimensions.SequentialIndexDistance(dim); 
            int[] stride = new int[]{0,tmp}; 
            MKLImports.DftiSetValue(descriptor,MKLParameter.INPUT_STRIDES, __arglist(stride)); 
            error = MKLImports.DftiSetValue(descriptor,MKLParameter.OUTPUT_STRIDES, __arglist(stride)); 
            if (isMKLError(error)) {
                throw new ILInvalidOperationException ("error: " + MKLImports.DftiErrorMessage(error)); 
            }
            // storage of subsequent transformations
            tmp = inDim * tmp; 
            MKLImports.DftiSetValue(descriptor,MKLParameter.INPUT_DISTANCE, __arglist(tmp)); 
            MKLImports.DftiSetValue(descriptor,MKLParameter.OUTPUT_DISTANCE, __arglist(tmp)); 
            // how many transformations ? 
            tmp = A.Dimensions.NumberOfElements / tmp; 
            MKLImports.DftiSetValue(descriptor,MKLParameter.NUMBER_OF_TRANSFORMS, __arglist(tmp)); 
            error = MKLImports.DftiSetValue(descriptor,MKLParameter.PLACEMENT,__arglist(MKLValues.NOT_INPLACE)); 
            error = MKLImports.DftiSetValue(descriptor,MKLParameter.REAL_STORAGE, __arglist(MKLValues.REAL_REAL)); 
            error = MKLImports.DftiSetValue(descriptor,MKLParameter.CONJUGATE_EVEN_STORAGE, __arglist(MKLValues.COMPLEX_COMPLEX)); 
            error = MKLImports.DftiSetValue(descriptor,MKLParameter.BACKWARD_SCALE, __arglist(1.0 / inDim)); 
            error = MKLImports.DftiCommitDescriptor(descriptor);
            if (isMKLError(error)) {
                throw new ILInvalidOperationException ("error: " + MKLImports.DftiErrorMessage(error)); 
            }
            // do the transform(s)
            tmp = A.Dimensions.SequentialIndexDistance(dim); 
            unsafe {
                fixed ( float * retArrP = ret.m_data) 
                fixed ( fcomplex * pA = A.m_data) {
                    for (int i = 0; i < tmp && error == 0; i++) 
                        error = MKLImports.DftiComputeBackward(descriptor, __arglist(pA + i,retArrP + i));
                }
            }
            if (isMKLError(error)) {
                throw new ILInvalidOperationException ("error: " + MKLImports.DftiErrorMessage(error)); 
            }
            return ret;
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:67,代码来源:ILMKLFFT.cs

示例8: Test_EnumeratorPerf

 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); 
     }
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:41,代码来源:TESTILArray.cs


注:本文中的ILArray.Detach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。