(N, dtype, even='avg')
Generate multiplication array for composite Simpson's rule.

    Generates an array whose dot product with some array of equal
    length is equivalent to the definite integral of the latter
    computed using composite Simpson's rule.

    If there are an even number of samples, N, then there are an odd 
    number of intervals (N-1), but Simpson's rule requires an even number 
    of intervals. The parameter 'even' controls how this is handled.

    Parameters
    ----------
    N : int
        Length of array.
    dtype : float type
        Floating point type to use when generating the array.
    even : str {'avg', 'first', 'last'}, optional
        'avg' : Average two results:1) use the first N-2 intervals with
                  a trapezoidal rule on the last interval and 2) use the last
                  N-2 intervals with a trapezoidal rule on the first interval.
        'first' : Use Simpson's rule for the first N-2 intervals with
                a trapezoidal rule on the last interval.
        'last' : Use Simpson's rule for the last N-2 intervals with a
               trapezoidal rule on the first interval.

    Returns
    -------
    result : pycuda.gpuarray.GPUArray
        Generated array.
Generate multiplication array for composite Simpson's rule.
Generate multiplication array for composite Simpson s rule .
def gen_simps_mult(N, dtype, even='avg'):
    """
    Generate multiplication array for composite Simpson's rule.

    Generates an array whose dot product with some array of equal
    length is equivalent to the definite integral of the latter
    computed using composite Simpson's rule.

    If there are an even number of samples, N, then there are an odd 
    number of intervals (N-1), but Simpson's rule requires an even number 
    of intervals. The parameter 'even' controls how this is handled.

    Parameters
    ----------
    N : int
        Length of array.
    dtype : float type
        Floating point type to use when generating the array.
    even : str {'avg', 'first', 'last'}, optional
        'avg' : Average two results:1) use the first N-2 intervals with
                  a trapezoidal rule on the last interval and 2) use the last
                  N-2 intervals with a trapezoidal rule on the first interval.
        'first' : Use Simpson's rule for the first N-2 intervals with
                a trapezoidal rule on the last interval.
        'last' : Use Simpson's rule for the last N-2 intervals with a
               trapezoidal rule on the first interval.

    Returns
    -------
    result : pycuda.gpuarray.GPUArray
        Generated array.
    """

    if dtype not in [np.float32, np.float64, np.complex64,
                     np.complex128]:
        raise ValueError('unrecognized type')

    ctype = tools.dtype_to_ctype(dtype)
    x_gpu = gpuarray.zeros(N, dtype)

    if N % 2:
        func = elementwise.ElementwiseKernel("{ctype} *x".format(ctype=ctype),
                                             "x[i] = (i%2 == 0) ? ((i != 0 && i != {M}) ? 2. : 1.) : 4.".format(M=N-1))
        x_gpu.fill(1.)
        func(x_gpu)
        return x_gpu/3.
    else:
        if even not in ['avg', 'last', 'first']:
            raise ValueError("Parameter 'even' must be "
                             "'avg', 'last', or 'first'.")
        basic_simps = gen_simps_mult(N-1, dtype)
        
        if even in ['avg', 'first']:
            x_gpu[:-1] += basic_simps
            x_gpu[-2:] += 0.5 # trapz on last interval
        if even in ['avg', 'last']:
            x_gpu[1:] += basic_simps
            x_gpu[:2] += 0.5 # trapz on first interval
        if even == 'avg':
            x_gpu /= 2.
        return x_gpu
def gen_simps_mult ( N , dtype , even = 'avg' ) : if dtype not in [ np . float32 , np . float64 , np . complex64 , np . complex128 ] : raise ValueError ( 'unrecognized type' ) ctype = tools . dtype_to_ctype ( dtype ) x_gpu = gpuarray . zeros ( N , dtype ) if N % 2 : func = elementwise . ElementwiseKernel ( "{ctype} *x" . format ( ctype = ctype ) , "x[i] = (i%2 == 0) ? ((i != 0 && i != {M}) ? 2. : 1.) : 4." . format ( M = N - 1 ) ) x_gpu . fill ( 1. ) func ( x_gpu ) return x_gpu / 3. else : if even not in [ 'avg' , 'last' , 'first' ] : raise ValueError ( "Parameter 'even' must be " "'avg', 'last', or 'first'." ) basic_simps = gen_simps_mult ( N - 1 , dtype ) if even in [ 'avg' , 'first' ] : x_gpu [ : - 1 ] += basic_simps x_gpu [ - 2 : ] += 0.5 # trapz on last interval if even in [ 'avg' , 'last' ] : x_gpu [ 1 : ] += basic_simps x_gpu [ : 2 ] += 0.5 # trapz on first interval if even == 'avg' : x_gpu /= 2. return x_gpu