skcuda.integrate.simps

skcuda.integrate.simps(x_gpu, dx=1.0, even='avg', handle=None)[source]

Implementation of composite Simpson’s rule similar to scipy.integrate.simps.

Integrate x_gpu with spacing dx 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:
  • x_gpu (pycuda.gpuarray.GPUArray) – Input array to integrate.
  • dx (scalar) – Spacing.
  • 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.
  • handle (int) – CUBLAS context. If no context is specified, the default handle from skcuda.misc._global_cublas_handle is used.
Returns:

result – Definite integral as approximated by the composite Simpson’s rule.

Return type:

float

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray
>>> import numpy as np
>>> import integrate
>>> integrate.init()
>>> x_gpu = gpuarray.arange(0,10,dtype=np.float64)
>>> integrate.simps(x_gpu)
40.5
>>> x_gpu**=3
>>> integrate.simps(x_gpu)
1642.5
>>> integrate.simps(x_gpu, even='first')
1644.5