Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12262


Ignore:
Timestamp:
03/27/15 16:06:31 (10 years ago)
Author:
gkronber
Message:

#2363: implemented a fix for the performance problem without a call to .ToArray() (overwrites changes of r12227)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r12227 r12262  
    299299        // simplify expressions x0..xn
    300300        // make multiplication (x0 * 1/(x1 * x1 * .. * xn))
    301         var simplifiedTrees = original.Subtrees.Select(GetSimplifiedTree).ToArray();
     301        var first = original.Subtrees.First();
     302        var remaining = original.Subtrees.Skip(1);
    302303        return
    303           MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate(MakeProduct)));
     304          MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate((a, b) => MakeProduct(a, GetSimplifiedTree(b)))));
    304305      }
    305306    }
     
    310311      } else {
    311312        return original.Subtrees
    312           .Select(GetSimplifiedTree).ToArray()
     313          .Select(GetSimplifiedTree)
    313314          .Aggregate(MakeProduct);
    314315      }
     
    321322        // simplify expressions x0..xn
    322323        // make addition (x0,-x1..-xn)
    323         var simplifiedTrees = original.Subtrees.Select(GetSimplifiedTree).ToArray();
    324         return simplifiedTrees.Take(1)
    325           .Concat(simplifiedTrees.Skip(1).Select(Negate))
    326           .Aggregate(MakeSum);
     324        var first = original.Subtrees.First();
     325        var remaining = original.Subtrees.Skip(1);
     326        return remaining.Aggregate(GetSimplifiedTree(first), (a, b) => MakeSum(a, Negate(GetSimplifiedTree(b))));
    327327      }
    328328    }
     
    335335        // make addition (x0..xn)
    336336        return original.Subtrees
    337           .Select(GetSimplifiedTree).ToArray()
     337          .Select(GetSimplifiedTree)
    338338          .Aggregate(MakeSum);
    339339      }
     
    345345    private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) {
    346346      return original.Subtrees
    347         .Select(x => GetSimplifiedTree(x))
    348         .Aggregate((a, b) => MakeOr(a, b));
     347        .Select(GetSimplifiedTree)
     348        .Aggregate(MakeOr);
    349349    }
    350350    private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) {
    351351      return original.Subtrees
    352         .Select(x => GetSimplifiedTree(x))
    353         .Aggregate((a, b) => MakeAnd(a, b));
     352        .Select(GetSimplifiedTree)
     353        .Aggregate(MakeAnd);
    354354    }
    355355    private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) {
Note: See TracChangeset for help on using the changeset viewer.