Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCMapWithProgressBar #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion FeynCalc/Shared/SharedTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ will generate a warning (when running with the frontend) or quit kernel (when \
FeynArts or QGAF into the FeynCalc notation. It uses memoization to improve the \
performance."

FCMapWithProgressBar::usage =
"FCMapWithProgressBar[f, expr] is like Map[f,@expr] but with a graphical
progress bar to show the progress of the evaluation.";

FCPatternFreeQ::usage =
"FCPatternFreeQ[{exp}] yields True if {exp} does not contain any \
pattern objects, e.g. Pattern, Blank, BlankSequence and BlankNullSequence. \n
Expand Down Expand Up @@ -247,7 +251,10 @@ an integer (even if it is symbolic). Furthermore \
appends the subset of remaining unmatched elements.";

XYT::usage=
"XYT[exp, x,y] transforms (x y)^m away ..."
"XYT[exp, x,y] transforms (x y)^m away ...";

FCMapWithProgressBar::failmsg = "Error! FCMapWithProgressBar has encountered a fatal problem and must abort the computation. \n
The problem reads: `1`";

FCProductSplit::failmsg = "Error! FCProductSplit has encountered a fatal problem and must abort the computation. \n
The problem reads: `1`";
Expand Down Expand Up @@ -512,6 +519,31 @@ an integer (even if it is symbolic). Furthermore \
head[ToExpression[x <> "Minus" <> ToString[-y]]]
]/; y < 0;


FCMapWithProgressBar[x_, y_, OptionsPattern[]] :=
Block[{iter = 0, len= Length[y], xNew, res},

If[ Head[x] =!= Function,
Message[FCMapWithProgressBar::failmsg,"The head of the first argument must be a Function"];
Abort[]
];

If[ $FrontEnd===Null,
(*No FrontEnd*)
FCPrint[0, "Unfortunately, the progress bar requires the graphical Front End."];
(*TODO: Command line implementation, cf. https://mathematica.stackexchange.com/questions/183632/any-ergonomic-tools-for-the-command-line-kernel *)
res = Map[x,y],
(*FrontEnd is available*)
xNew = x /. Function[z_] :> Function[CompoundExpression[iter++, z]];
Monitor[
res = Map[xNew, y],
Grid[{{ProgressIndicator[iter, {1, len}]}, {Row[{iter, "/", len}]}}]
]
];

res
];

FCFactorOut[expr_,pref_,OptionsPattern[]]:=
pref OptionValue[Head][OptionValue[Factoring][expr/pref]];

Expand Down