[ 
https://issues.apache.org/jira/browse/MATH-1293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15010820#comment-15010820
 ] 

Gilles commented on MATH-1293:
------------------------------

bq. create a package-local class

Yes (although actually I'd think it should be a "private" inner class).
Thus IMHO to be hopefully quite clear there could be
{code}
public class CombinatoricsUtils {
    final FastFactorialLog FAST_FACTORIAL_LOG = new FastFactorialLog();
    // ...
    public static double factorialLog(final int n) {
         return FAST_FACTORIAL_LOG.value(n);
    }
    // ...
    private static class FastFactorialLog {
        // Constants...  No hard-coded numbers. ;-)
        // ... Initialization
        /** ... */
        public double value(int n) {
            // ...
        }
    }
}
{code}

But then, it will possible to consider parameterization of the utility class 
(e.g. size of the precomputed table).
Also to be clarified is whether to always initialize this class, or use lazy 
initialization.  This has to be agreed on on the "dev" ML.


> Tabulating the logarithmic factorial
> ------------------------------------
>
>                 Key: MATH-1293
>                 URL: https://issues.apache.org/jira/browse/MATH-1293
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.5
>            Reporter: Aleksei Dievskii
>            Priority: Minor
>              Labels: feature, patch
>         Attachments: factlog.patch
>
>
> Presently, CombinatoricsUtils#factorialLog is calculated via a tabulated 
> value for the first 21 entries, and for the rest it employs linear-complexity 
> direct summing. For the factorial-heavy computations this can be rather 
> painful. I propose a patch which allocates additional 16KB of tabulated 
> log-factorial values, allowing very fast (constant complexity) computation 
> for arguments up to 17000, and delegating to the log-gamma for the rest. 
> Benchmarks show a speed-up of up to 200x.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to