[GiNaC-devel] infinite loop in simplify_indexed()
PG CLARK
P.G.Clark at Bradford.ac.uk
Tue May 17 20:07:45 CEST 2011
I can confirm that I was able to successfully compile and run my test
code with this patch applied. took about 10 seconds to execute.
Thanks for the help guys
peter
Quoting Alexei Sheplyakov <alexei.sheplyakov at gmail.com>:
> The patch below (drastically) improves the run time at the expense of using
> more RAM in some situations. Please note: it doesn't improve the actual
> algorithm (iteration over all permutations).
>
> diff --git a/ginac/symmetry.cpp b/ginac/symmetry.cpp
> index 7d1ff97..d93e34c 100644
> --- a/ginac/symmetry.cpp
> +++ b/ginac/symmetry.cpp
> @@ -22,6 +22,7 @@
>
> #include "symmetry.h"
> #include "lst.h"
> +#include "add.h"
> #include "numeric.h" // for factorial()
> #include "operators.h"
> #include "archive.h"
> @@ -495,7 +496,8 @@ static ex symm(const ex & e,
> exvector::const_iterator first, exvector::const_ite
>
> // Loop over all permutations (the first permutation, which is the
> // identity, is unrolled)
> - ex sum = e;
> + exvector sum_v;
> + sum_v.push_back(e);
> while (std::next_permutation(iv, iv + num)) {
> lst new_lst;
> for (unsigned i=0; i<num; i++)
> @@ -505,8 +507,9 @@ static ex symm(const ex & e,
> exvector::const_iterator first, exvector::const_ite
> memcpy(iv2, iv, num * sizeof(unsigned));
> term *= permutation_sign(iv2, iv2 + num);
> }
> - sum += term;
> + sum_v.push_back(term);
> }
> + ex sum = (new add(sum_v))->setflag(status_flags::dynallocated);
>
> delete[] iv;
> delete[] iv2;
>
>
> Best regards,
> Alexei
>
> P.S. The bug has nothing to do with infinite loops.
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the GiNaC-devel
mailing list