<commit_before>## Automatically adapted for scipy Oct 05, 2005 by convertcode.py

#
# Author:  <NAME>, 2002
#

from numpy import *
from _cephes import *
import types
import specfun

def sinc(x):
    """Returns sin(pi*x)/(pi*x) at all points of array x.
    """
    w = asarray(asarray(x)*pi)
    return where(x==0, 1.0, sin(w)/w)

def diric(x,n):
    """Returns the periodic sinc function also called the dirichlet function:

    diric(x) = sin(x *n / 2) / (n sin(x / 2))

    where n is a positive integer.
    """
    x,n = asarray(x), asarray(n)
    n = asarray(n + (x-x))
    x = asarray(x + (n-n))
    if x.dtype.char in ['fFdD']:
        ytype = x.dtype.char
    else:
        ytype = 'd'
    y = zeros(x.shape,ytype)

    mask1 = (n <= 0) | (n <> floor(n))
    insert(y,mask1,nan)

    z = asarray(x / 2.0 / pi)
    mask2 = (1-mask1) & (z == floor(z))
    zsub = extract(mask2,z)
    nsub = extract(mask2,n)
    insert(y,mask2,pow(-1,zsub*(nsub-1)))

    mask = (1-mask1) & (1-mask2)
    xsub = extract(mask,x)
    nsub = extract(mask,n)
    insert(y,mask,sin(nsub*xsub/2.0)/(nsub*sin(xsub/2.0)))
    return y



def jnjnp_zeros(nt):
    """Compute nt (<=1400) zeros of the bessel functions Jn and Jn'
    and arange them in order of their magnitudes.

    Outputs (all are arrays of length nt):

       zo[l-1] -- Value of the lth zero of of Jn(x) and Jn'(x)
       n[l-1]  -- Order of the Jn(x) or Jn'(x) associated with lth zero
       m[l-1]  -- Serial number of the zeros of Jn(x) or Jn'(x) associated
                    with lth zero.
       t[l-1]  -- 0 if lth zero in zo is zero of Jn(x), 1 if it is a zero
                    of Jn'(x)

    See jn_zeros, jnp_zeros to get separated arrays of zeros.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt>1200):
        raise ValueError, "Number must be integer <= 1200."
    nt = int(nt)
    n,m,t,zo = specfun.jdzo(nt)
    return zo[:nt],n[:nt],m[:nt],t[:nt]

def jnyn_zeros(n,nt):
    """Compute nt zeros of the Bessel functions Jn(x), Jn'(x), Yn(x), and
    Yn'(x), respectively. Returns 4 arrays of length nt.

    See jn_zeros, jnp_zeros, yn_zeros, ynp_zeros to get separate arrays.
    """
    if not (isscalar(nt) and isscalar(n)):
        raise ValueError, "Arguments must be scalars."
    if (floor(n)!=n) or (floor(nt)!=nt):
        raise ValueError, "Arguments must be integers."
    if (nt <=0):
        raise ValueError, "nt > 0"
    return specfun.jyzo(n,nt)

def jn_zeros(n,nt):
    """Compute nt zeros of the Bessel function Jn(x).
    """
    return jnyn_zeros(n,nt)[0]
def jnp_zeros(n,nt):
    """Compute nt zeros of the Bessel function Jn'(x).
    """
    return jnyn_zeros(n,nt)[1]
def yn_zeros(n,nt):
    """Compute nt zeros of the Bessel function Yn(x).
    """
    return jnyn_zeros(n,nt)[2]
def ynp_zeros(n,nt):
    """Compute nt zeros of the Bessel function Yn'(x).
    """
    return jnyn_zeros(n,nt)[3]

def y0_zeros(nt,complex=0):
    """Returns nt (complex or real) zeros of Y0(z), z0, and the value
    of Y0'(z0) = -Y1(z0) at each zero.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt <=0):
        raise ValueError, "Arguments must be scalar positive integer."
    kf = 0
    kc = (complex != 1)
    return specfun.cyzo(nt,kf,kc)

def y1_zeros(nt,complex=0):
    """Returns nt (complex or real) zeros of Y1(z), z1, and the value
    of Y1'(z1) = Y0(z1) at each zero.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt <=0):
        raise ValueError, "Arguments must be scalar positive integer."
    kf = 1
    kc = (complex != 1)
    return specfun.cyzo(nt,kf,kc)

def y1p_zeros(nt,complex=0):
    """Returns nt (complex or real) zeros of Y1'(z), z1', and the value
    of Y1(z1') at each zero.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt <=0):
        raise ValueError, "Arguments must be scalar positive integer."
    kf = 2
    kc = (complex != 1)
    return specfun.cyzo(nt,kf,kc)

def jvp(v,z,n=1):
    """Return the nth derivative of Jv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return jv(v,z)
    else:
        return (jvp(v-1,z,n-1) - jvp(v+1,z,n-1))/2.0

def yvp(v,z,n=1):
    """Return the nth derivative of Yv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return yv(v,z)
    else:
        return (yvp(v-1,z,n-1) - yvp(v+1,z,n-1))/2.0

def kvp(v,z,n=1):
    """Return the nth derivative of Kv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return kv(v,z)
    else:
        return (kvp(v-1,z,n-1) - kvp(v+1,z,n-1))/2.0

def ivp(v,z,n=1):
    """Return the nth derivative of Iv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return iv(v,z)
    else:
        return (ivp(v-1,z,n-1) - ivp(v+1,z,n-1))/2.0

def h1vp(v,z,n=1):
    """Return the nth derivative of H1v(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return hankel1(v,z)
    else:
        return (h1vp(v-1,z,n-1) - h1vp(v+1,z,n-1))/2.0

def h2vp(v,z,n=1):
    """Return the nth derivative of H2v(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return hankel2(v,z)
    else:
        return (h2vp(v-1,z,n-1) - h2vp(v+1,z,n-1))/2.0

def sph_jn(n,z):
    """Compute the spherical Bessel function jn(z) and its derivative for
    all orders up to and including n.
    """
    if not (isscalar(n) and isscalar(z)):
        raise ValueError, "arguments must be scalars."
    if (n!= floor(n)) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if (n < 1): n1 = 1
    else: n1 = n<commit_msg>Fix recurrence relations for modified Bessel functions.<commit_after>## Automatically adapted for scipy Oct 05, 2005 by convertcode.py

#
# Author:  <NAME>, 2002
#

from numpy import *
from _cephes import *
import types
import specfun

def sinc(x):
    """Returns sin(pi*x)/(pi*x) at all points of array x.
    """
    w = asarray(asarray(x)*pi)
    return where(x==0, 1.0, sin(w)/w)

def diric(x,n):
    """Returns the periodic sinc function also called the dirichlet function:

    diric(x) = sin(x *n / 2) / (n sin(x / 2))

    where n is a positive integer.
    """
    x,n = asarray(x), asarray(n)
    n = asarray(n + (x-x))
    x = asarray(x + (n-n))
    if x.dtype.char in ['fFdD']:
        ytype = x.dtype.char
    else:
        ytype = 'd'
    y = zeros(x.shape,ytype)

    mask1 = (n <= 0) | (n <> floor(n))
    insert(y,mask1,nan)

    z = asarray(x / 2.0 / pi)
    mask2 = (1-mask1) & (z == floor(z))
    zsub = extract(mask2,z)
    nsub = extract(mask2,n)
    insert(y,mask2,pow(-1,zsub*(nsub-1)))

    mask = (1-mask1) & (1-mask2)
    xsub = extract(mask,x)
    nsub = extract(mask,n)
    insert(y,mask,sin(nsub*xsub/2.0)/(nsub*sin(xsub/2.0)))
    return y



def jnjnp_zeros(nt):
    """Compute nt (<=1400) zeros of the bessel functions Jn and Jn'
    and arange them in order of their magnitudes.

    Outputs (all are arrays of length nt):

       zo[l-1] -- Value of the lth zero of of Jn(x) and Jn'(x)
       n[l-1]  -- Order of the Jn(x) or Jn'(x) associated with lth zero
       m[l-1]  -- Serial number of the zeros of Jn(x) or Jn'(x) associated
                    with lth zero.
       t[l-1]  -- 0 if lth zero in zo is zero of Jn(x), 1 if it is a zero
                    of Jn'(x)

    See jn_zeros, jnp_zeros to get separated arrays of zeros.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt>1200):
        raise ValueError, "Number must be integer <= 1200."
    nt = int(nt)
    n,m,t,zo = specfun.jdzo(nt)
    return zo[:nt],n[:nt],m[:nt],t[:nt]

def jnyn_zeros(n,nt):
    """Compute nt zeros of the Bessel functions Jn(x), Jn'(x), Yn(x), and
    Yn'(x), respectively. Returns 4 arrays of length nt.

    See jn_zeros, jnp_zeros, yn_zeros, ynp_zeros to get separate arrays.
    """
    if not (isscalar(nt) and isscalar(n)):
        raise ValueError, "Arguments must be scalars."
    if (floor(n)!=n) or (floor(nt)!=nt):
        raise ValueError, "Arguments must be integers."
    if (nt <=0):
        raise ValueError, "nt > 0"
    return specfun.jyzo(n,nt)

def jn_zeros(n,nt):
    """Compute nt zeros of the Bessel function Jn(x).
    """
    return jnyn_zeros(n,nt)[0]
def jnp_zeros(n,nt):
    """Compute nt zeros of the Bessel function Jn'(x).
    """
    return jnyn_zeros(n,nt)[1]
def yn_zeros(n,nt):
    """Compute nt zeros of the Bessel function Yn(x).
    """
    return jnyn_zeros(n,nt)[2]
def ynp_zeros(n,nt):
    """Compute nt zeros of the Bessel function Yn'(x).
    """
    return jnyn_zeros(n,nt)[3]

def y0_zeros(nt,complex=0):
    """Returns nt (complex or real) zeros of Y0(z), z0, and the value
    of Y0'(z0) = -Y1(z0) at each zero.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt <=0):
        raise ValueError, "Arguments must be scalar positive integer."
    kf = 0
    kc = (complex != 1)
    return specfun.cyzo(nt,kf,kc)

def y1_zeros(nt,complex=0):
    """Returns nt (complex or real) zeros of Y1(z), z1, and the value
    of Y1'(z1) = Y0(z1) at each zero.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt <=0):
        raise ValueError, "Arguments must be scalar positive integer."
    kf = 1
    kc = (complex != 1)
    return specfun.cyzo(nt,kf,kc)

def y1p_zeros(nt,complex=0):
    """Returns nt (complex or real) zeros of Y1'(z), z1', and the value
    of Y1(z1') at each zero.
    """
    if not isscalar(nt) or (floor(nt)!=nt) or (nt <=0):
        raise ValueError, "Arguments must be scalar positive integer."
    kf = 2
    kc = (complex != 1)
    return specfun.cyzo(nt,kf,kc)

def jvp(v,z,n=1):
    """Return the nth derivative of Jv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return jv(v,z)
    else:
        return (jvp(v-1,z,n-1) - jvp(v+1,z,n-1))/2.0

def yvp(v,z,n=1):
    """Return the nth derivative of Yv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return yv(v,z)
    else:
        return (yvp(v-1,z,n-1) - yvp(v+1,z,n-1))/2.0

def kvp(v,z,n=1):
    """Return the nth derivative of Kv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return kv(v,z)
    else:
        return (kvp(v-1,z,n-1) + kvp(v+1,z,n-1))/(-2.0)

def ivp(v,z,n=1):
    """Return the nth derivative of Iv(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return iv(v,z)
    else:
        return (ivp(v-1,z,n-1) + ivp(v+1,z,n-1))/2.0

def h1vp(v,z,n=1):
    """Return the nth derivative of H1v(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return hankel1(v,z)
    else:
        return (h1vp(v-1,z,n-1) - h1vp(v+1,z,n-1))/2.0

def h2vp(v,z,n=1):
    """Return the nth derivative of H2v(z) with respect to z.
    """
    if not isinstance(n,types.IntType) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if n == 0:
        return hankel2(v,z)
    else:
        return (h2vp(v-1,z,n-1) - h2vp(v+1,z,n-1))/2.0

def sph_jn(n,z):
    """Compute the spherical Bessel function jn(z) and its derivative for
    all orders up to and including n.
    """
    if not (isscalar(n) and isscalar(z)):
        raise ValueError, "arguments must be scalars."
    if (n!= floor(n)) or (n<0):
        raise ValueError, "n must be a non-negative integer."
    if (n < 1): n1 = 1
    else: n1 = n
{'fraction_non_alphanumeric': 0.15736743504113382, 'fraction_numerical': 0.02622790584018897, 'mean_word_length': 2.5723014256619146, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5790114', 'n_tokens_mistral': 5008, 'n_tokens_neox': 4846, 'n_words': 1437}