Scipy factorial

Issue #40 resolved
andrew_peterson repo owner created an issue

From our conversation with CPC, apparently from scipy.special import factorial is giving problems, presumably as it has moved locations. However, both the math and the numpy module also have factorial functions; is there any reason to choose scipy's over these?

If we need scipy's, can we catch both versions with a try loop?

Comments (4)

  1. Alireza Khorshidi

    Other than factorial, we have also:

    from scipy.special import sph_harm

    which is available in scipy v0.14.0 and after. It seems that numpy and math do not have this function. Therefore, I would say that we need an upgraded enough version of scipy anyhow. What do you think?

  2. andrew_peterson reporter

    I think this dependency on 0.15.1 (as you have it in the documentation) will create some problems, as that version is so recent it has not made it to the major repositories yet. I am running the latest ubuntu (15.10) and it has 0.14.0. Presumably people running the LTS version of ubuntu (14.04) might have an older version. However, both these functions are in 0.14.0.

    I see spherical harmonics as far back as 0.7, which is the oldest version they still have documentation online for:

    http://docs.scipy.org/doc/scipy-0.7.x/reference/generated/scipy.special.sph_harm.html

    I also see factorial in 0.7, but it is just in misc instead of special:

    http://docs.scipy.org/doc/scipy-0.7.x/reference/misc.html?highlight=factorial#scipy.misc.factorial

    So it looks like it used to live in misc but is now (also) in special. Note that in my version these are the exact same thing:

    >>> from scipy import misc
    >>> from scipy import special
    >>> misc.factorial is special.factorial
    True
    

    So it seems it would be safe to just import factorial from misc and call it good, right? Or in new versions of scipy will it only be in special? Then all we need is a try loop.

    try:
        from scipy.special import factorial
    except ImportError:
        from scipy.misc import factorial
    

    In either case, we can drop the dependency and the software should work on CSS's machines without us having to get them to update their scipy.

  3. Alireza Khorshidi

    Fixed in the commit def4ef9 by the try loop:

    try:  # for scipy v <= 0.90
        from scipy import factorial as fac
    except ImportError:
        try:  # for scipy v >= 0.10
            from scipy.misc import factorial as fac
        except ImportError:  # for newer version of scipy
            from scipy.special import factorial as fac
    

    P.S. math has only factorial for integer numbers and not half-integers, so it does not work for us.

  4. Log in to comment