#NEWLINE# def _comp_sums_meg( beta , ctheta , lut_fun , n_fact , volume_integral ) : #NEWLINE# #INDENT# 'Lead field dot products using Legendre polynomial (P_n) series.\n\n    Parameters\n    ----------\n    beta : array, shape (n_points * n_points, 1)\n        Coefficients of the integration.\n    ctheta : array, shape (n_points * n_points, 1)\n        Cosine of the angle between the sensor integration points.\n    lut_fun : callable\n        Look-up table for evaluating Legendre polynomials.\n    n_fact : array\n        Coefficients in the integration sum.\n    volume_integral : bool\n        If True, compute volume integral.\n\n    Returns\n    -------\n    sums : array, shape (4, n_points * n_points)\n        The results.\n    ' #NEWLINE# sums = np . empty ( ( n_fact . shape [ 1 ] , len ( beta ) ) ) #NEWLINE# n_chunk = ( 50000000 // ( ( 8 * max ( n_fact . shape ) ) * 2 ) ) #NEWLINE# lims = np . concatenate ( [ np . arange ( 0 , beta . size , n_chunk ) , [ beta . size ] ] ) #NEWLINE# for ( start , stop ) in zip ( lims [ : ( - 1 ) ] , lims [ 1 : ] ) : #NEWLINE# #INDENT# bbeta = np . tile ( beta [ start : stop ] [ np . newaxis ] , ( n_fact . shape [ 0 ] , 1 ) ) #NEWLINE# bbeta [ 0 ] *= beta [ start : stop ] #NEWLINE# np . cumprod ( bbeta , axis = 0 , out = bbeta ) #NEWLINE# np . einsum ( 'ji,jk,ijk->ki' , bbeta , n_fact , lut_fun ( ctheta [ start : stop ] ) , out = sums [ : , start : stop ] ) #NEWLINE# #UNINDENT# return sums