예제 #1
0
            protected override bool InvEigImpl(Matrix mat, double?thresEigval, int?numZeroEigval, out Matrix inv, InfoPack extra)
            {
                NamedLock.FuncO <Matrix, bool> func = delegate(out Matrix linv)
                {
                    Matlab.Clear("HTLib2_Matlab_InvEigImpl");
                    Matlab.PutMatrix("HTLib2_Matlab_InvEigImpl.A", mat.ToArray());
                    Matlab.PutValue("HTLib2_Matlab_InvEigImpl.ze", numZeroEigval.GetValueOrDefault(0));
                    Matlab.PutValue("HTLib2_Matlab_InvEigImpl.th", Math.Abs(thresEigval.GetValueOrDefault(0)));
                    Matlab.Execute("[HTLib2_Matlab_InvEigImpl.V, HTLib2_Matlab_InvEigImpl.D] = eig(HTLib2_Matlab_InvEigImpl.A);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.D = diag(HTLib2_Matlab_InvEigImpl.D);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.sortAbsD = sort(abs(HTLib2_Matlab_InvEigImpl.D));");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.sortAbsD0 = [0; HTLib2_Matlab_InvEigImpl.sortAbsD];"); // add zero to the first list, for the case ze=0 (null)
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.ze  = HTLib2_Matlab_InvEigImpl.sortAbsD0(HTLib2_Matlab_InvEigImpl.ze+1);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.th  = max(HTLib2_Matlab_InvEigImpl.th, HTLib2_Matlab_InvEigImpl.ze);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.idx = abs(HTLib2_Matlab_InvEigImpl.D) <= HTLib2_Matlab_InvEigImpl.th;");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invD = ones(size(HTLib2_Matlab_InvEigImpl.D)) ./ HTLib2_Matlab_InvEigImpl.D;");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invD(HTLib2_Matlab_InvEigImpl.idx) = 0;");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invD = diag(HTLib2_Matlab_InvEigImpl.invD);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invA = HTLib2_Matlab_InvEigImpl.V * HTLib2_Matlab_InvEigImpl.invD * inv(HTLib2_Matlab_InvEigImpl.V);");
                    linv = Matlab.GetMatrix("HTLib2_Matlab_InvEigImpl.invA");
                    if (extra != null)
                    {
                        int num_zero_eigvals = Matlab.GetValueInt("sum(HTLib2_Matlab_InvEigImpl.idx)");
                        HDebug.AssertIf(numZeroEigval != null, numZeroEigval.GetValueOrDefault() <= num_zero_eigvals);
                        extra["num_zero_eigvals"] = num_zero_eigvals;
                        extra["eigenvalues"]      = Matlab.GetVector("HTLib2_Matlab_InvEigImpl.D");
                    }
                    Matlab.Clear("HTLib2_Matlab_InvEigImpl");

                    return(true);
                };
                //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.InvEigImpl(Matrix, double?, int?, out Matrix, InfoPack)", func, out inv);
                return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_InvEigImpl"), func, out inv));
            }
예제 #2
0
 protected override bool RankImpl(Matrix mat, out int rank)
 {
     NamedLock.FuncO <int, bool> func = delegate(out int lrank)
     {
         string varname = "HTLib2_Matlab_RankImpl";
         Matlab.Clear(varname);
         Matlab.PutMatrix(varname, mat.ToArray());
         lrank = Matlab.GetValueInt("rank(" + varname + ")");
         Matlab.Clear(varname);
         return(true);
     };
     //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.RankImpl(Matrix, out int)", func, out rank);
     return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_RankImpl"), func, out rank));
 }
예제 #3
0
 protected override bool CorrImpl(Vector vec1, Vector vec2, out double corr)
 {
     NamedLock.FuncO <double, bool> func = delegate(out double lcorr)
     {
         Matlab.Clear("HTLib2_Matlab_CorrImpl");
         Matlab.PutVector("HTLib2_Matlab_CorrImpl.vec1", vec1.ToArray());
         Matlab.PutVector("HTLib2_Matlab_CorrImpl.vec2", vec2.ToArray());
         Matlab.Execute("HTLib2_Matlab_CorrImpl.corr = corr(HTLib2_Matlab_CorrImpl.vec1, HTLib2_Matlab_CorrImpl.vec2);");
         lcorr = Matlab.GetValue("HTLib2_Matlab_CorrImpl.corr");
         Matlab.Clear("HTLib2_Matlab_CorrImpl");
         return(true);
     };
     //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.CorrImpl(Vector, Vector, out double)", func, out corr);
     return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_CorrImpl"), func, out corr));
 }
예제 #4
0
 protected override bool EigImpl(Matrix A, Matrix B, out Matrix eigvec, out Vector eigval)
 {
     NamedLock.FuncOO <Matrix, Vector, bool> func = delegate(out Matrix leigvec, out Vector leigval)
     {
         Matlab.Clear("HTLib2_Matlab_EigImpl");
         Matlab.PutMatrix("HTLib2_Matlab_EigImpl.A", A.ToArray());
         Matlab.PutMatrix("HTLib2_Matlab_EigImpl.B", B.ToArray());
         Matlab.Execute("[HTLib2_Matlab_EigImpl.V, HTLib2_Matlab_EigImpl.D] = eig(HTLib2_Matlab_EigImpl.A, HTLib2_Matlab_EigImpl.B);");
         Matlab.Execute("HTLib2_Matlab_EigImpl.D = diag(HTLib2_Matlab_EigImpl.D);");
         leigvec = Matlab.GetMatrix("HTLib2_Matlab_EigImpl.V");
         leigval = Matlab.GetVector("HTLib2_Matlab_EigImpl.D");
         Matlab.Clear("HTLib2_Matlab_EigImpl");
         return(true);
     };
     //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.EigImpl(Matrix, Matrix, out Matrix, out Vector)", func, out eigvec, out eigval);
     return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_EigImpl"), func, out eigvec, out eigval));
 }
예제 #5
0
 protected override bool EigImpl(Matrix mat, out Matrix eigvec, out Vector eigval)
 {
     NamedLock.FuncOO <Matrix, Vector, bool> func = delegate(out Matrix leigvec, out Vector leigval)
     {
         bool bUseFile = (mat.ColSize * mat.ColSize > 1000 * 1000);
         Matlab.Clear("HTLib2_Matlab_EigImpl");
         Matlab.PutMatrix("HTLib2_Matlab_EigImpl.A", mat.ToArray(), bUseFile);
         Matlab.Execute("[HTLib2_Matlab_EigImpl.V, HTLib2_Matlab_EigImpl.D] = eig(HTLib2_Matlab_EigImpl.A);");
         Matlab.Execute("HTLib2_Matlab_EigImpl.D = diag(HTLib2_Matlab_EigImpl.D);");
         leigvec = Matlab.GetMatrix("HTLib2_Matlab_EigImpl.V", bUseFile);
         leigval = Matlab.GetVector("HTLib2_Matlab_EigImpl.D");
         Matlab.Clear("HTLib2_Matlab_EigImpl");
         return(true);
     };
     //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.EigImpl(Matrix, out Matrix, out Vector)", func, out eigvec, out eigval);
     return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_EigImpl"), func, out eigvec, out eigval));
 }
예제 #6
0
 protected override bool PinvImpl(Matrix mat, out Matrix pinv, InfoPack extra)
 {
     NamedLock.FuncO <Matrix, bool> func = delegate(out Matrix lpinv)
     {
         Matlab.Clear("HTLib2_Matlab_PinvImpl");
         Matlab.PutMatrix("HTLib2_Matlab_PinvImpl", mat.ToArray());
         if (extra != null)
         {
             extra.SetValue("rank", Matlab.GetValueInt("rank(HTLib2_Matlab_PinvImpl)"));
         }
         Matlab.Execute("HTLib2_Matlab_PinvImpl = pinv(HTLib2_Matlab_PinvImpl);");
         lpinv = Matlab.GetMatrix("HTLib2_Matlab_PinvImpl");
         Matlab.Clear("HTLib2_Matlab_PinvImpl");
         return(true);
     };
     //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.PinvImpl(Matrix, out Matrix, InfoPack)", func, out pinv);
     return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_PinvImpl"), func, out pinv));
 }
예제 #7
0
 public static void Feval(string bstrName, int nargout, out object pvarArgOut, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, object arg11, object arg12, object arg13, object arg14, object arg15, object arg16, object arg17, object arg18, object arg19, object arg20, object arg21, object arg22, object arg23, object arg24, object arg25, object arg26, object arg27, object arg28, object arg29, object arg30, object arg31, object arg32)
 {
     object lpvarArgOut = null; NamedLock.Func func = delegate() { _matlab.Feval(bstrName, nargout, out lpvarArgOut, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, arg31, arg32); }; NamedLock.LockedCall(lockname, func); pvarArgOut = lpvarArgOut;
 }
예제 #8
0
 public static void Feval(string bstrName, int nargout, out object pvarArgOut, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, object arg11)
 {
     object lpvarArgOut = null; NamedLock.Func func = delegate() { _matlab.Feval(bstrName, nargout, out lpvarArgOut, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); }; NamedLock.LockedCall(lockname, func); pvarArgOut = lpvarArgOut;
 }
예제 #9
0
 public static void Feval(string bstrName, int nargout, out object pvarArgOut, object arg1, object arg2)
 {
     object lpvarArgOut = null; NamedLock.Func func = delegate() { _matlab.Feval(bstrName, nargout, out lpvarArgOut, arg1, arg2); }; NamedLock.LockedCall(lockname, func); pvarArgOut = lpvarArgOut;
 }