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)); }
public static Matrix Pinv(Matrix mat, InfoPack extra = null) { Matrix pinv; HDebug.Verify(solver.PinvImpl(mat, out pinv, extra)); return(pinv); }
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)); }
public static bool Pinv(Matrix mat, out Matrix pinv, InfoPack extra = null) { bool succ = solver.PinvImpl(mat, out pinv, extra); HDebug.Assert(succ); return(succ); }
protected abstract bool PinvImpl(Matrix mat, out Matrix pinv, InfoPack extra = null);
public static Matrix InvEig(Matrix mat, double?thresEigval, int?numZeroEigval, InfoPack extra = null) { Matrix inv; HDebug.Verify(solver.InvEigImpl(mat, thresEigval, numZeroEigval, out inv, extra)); return(inv); }
public static bool InvEig(Matrix mat, double?thresEigval, int?numZeroEigval, out Matrix inv, InfoPack extra = null) { bool succ = solver.InvEigImpl(mat, thresEigval, numZeroEigval, out inv, extra); HDebug.Assert(succ); return(succ); }
// inverse matrix using eigen-decomposition protected abstract bool InvEigImpl(Matrix mat, double?thresEigval, int?numZeroEigval, out Matrix inv, InfoPack extra = null);