astro-informatics / sopt

Sparse OPTimisation using state-of-the-art convex optimisation algorithms.
http://astro-informatics.github.io/sopt/
GNU General Public License v2.0
9 stars 11 forks source link

Code quality: Repeated branch in conditional chain #388

Open krishnakumarg1984 opened 1 year ago

krishnakumarg1984 commented 1 year ago

In sopt/cpp/chained_operators.h, we have

    if (funcs.size() == 1)
      (*first)(output, input);
    else if (funcs.size() % 2 == 1)
      (*first)(output, input);
    else {
      (*first)(*buffer, input);
      first++;
      (*first)(output, *buffer);
    }

As we can see, the if statement and the elseif has the same statement in their bodies. This can be cleaned up to get rid of the redundancy.

SJaffa commented 1 year ago

Doesn't 1%2 ==1 so the first two conditions are both true if funcs.size ==1? So you could just remove the first condition entirely.

krishnakumarg1984 commented 1 year ago

@SJaffa Agreed. Shall I do that then?