quantnn/generic/__init__.py
def _trapz(module, y, x, dimension):
    """
    Numeric integration using  trapezoidal rule.

    Arguments:
        module: The backend array corresponding to the given array.
        y: Rank k-tensor to integrate over the given dimension.
        x: The domain values to integrate over.
        dimension: The dimension to integrate over.

    Return:
       The rank k-1 tensor containing the numerical integrals corresponding
       to y.
    """
    n = len(y.shape)
    x_shape = [1] * n
    x_shape[dimension] = -1
    x = reshape(module, x, x_shape)

    selection = [slice(0, None)] * n
    selection_l = selection[:]
    selection_l[dimension] = slice(0, -1)
    selection_r = selection[:]
    selection_r[dimension] = slice(1, None)

    dx = x[selection_r] - x[selection_l]
    return module.math.reduce_sum(
        0.5 * (dx * y[selection_l] + dx * y[selection_r]), axis=dimension
    )

    Numeric integration using  trapezoidal rule.

    Arguments:
        module: The backend array corresponding to the given array.
        y: Rank k-tensor to integrate over the given dimension.
        x: The domain values to integrate over.
        dimension: The dimension to integrate over.

    Return:
       The rank k-1 tensor containing the numerical integrals corresponding
       to y.
    
Numeric integration using  trapezoidal rule.
Numeric integration using trapezoidal rule .
def _trapz(module, y, x, dimension):
    n = len(y.shape)
    x_shape = [1] * n
    x_shape[dimension] = -1
    x = reshape(module, x, x_shape)
    selection = [slice(0, None)] * n
    selection_l = selection[:]
    selection_l[dimension] = slice(0, -1)
    selection_r = selection[:]
    selection_r[dimension] = slice(1, None)
    dx = x[selection_r] - x[selection_l]
    return module.math.reduce_sum(
        0.5 * (dx * y[selection_l] + dx * y[selection_r]), axis=dimension
    )
def _trapz ( module , y , x , dimension ) : n = len ( y . shape ) x_shape = [ 1 ] * n x_shape [ dimension ] = - 1 x = reshape ( module , x , x_shape ) selection = [ slice ( 0 , None ) ] * n selection_l = selection [ : ] selection_l [ dimension ] = slice ( 0 , - 1 ) selection_r = selection [ : ] selection_r [ dimension ] = slice ( 1 , None ) dx = x [ selection_r ] - x [ selection_l ] return module . math . reduce_sum ( 0.5 * ( dx * y [ selection_l ] + dx * y [ selection_r ] ) , axis = dimension )
Numeric integration using  trapezoidal rule.
Numeric integration using trapezoidal rule .
"""
    Numeric integration using  trapezoidal rule.

    Arguments:
        module: The backend array corresponding to the given array.
        y: Rank k-tensor to integrate over the given dimension.
        x: The domain values to integrate over.
        dimension: The dimension to integrate over.

    Return:
       The rank k-1 tensor containing the numerical integrals corresponding
       to y.
    """
module
The backend array corresponding to the given array.
The backend array corresponding to the given array .
y
Rank k-tensor to integrate over the given dimension.
Rank k - tensor to integrate over the given dimension .
x
The domain values to integrate over.
The domain values to integrate over .
dimension
The dimension to integrate over.
The dimension to integrate over .