#NEWLINE# def _fast_sphere_dot_r0( r , rr1_orig , rr2s , lr1 , lr2s , cosmags1 , cosmags2s , w1 , w2s , volume_integral , lut , n_fact , ch_type ) : #NEWLINE# #INDENT# "Lead field dot product computation for M/EEG in the sphere model.\n\n    Parameters\n    ----------\n    r : float\n        The integration radius. It is used to calculate beta as:\n        beta = (r * r) / (lr1 * lr2).\n    rr1 : array, shape (n_points x 3)\n        Normalized position vectors of integrations points in first sensor.\n    rr2s : list\n        Normalized position vector of integration points in second sensor.\n    lr1 : array, shape (n_points x 1)\n        Magnitude of position vector of integration points in first sensor.\n    lr2s : list\n        Magnitude of position vector of integration points in second sensor.\n    cosmags1 : array, shape (n_points x 1)\n        Direction of integration points in first sensor.\n    cosmags2s : list\n        Direction of integration points in second sensor.\n    w1 : array, shape (n_points x 1) | None\n        Weights of integration points in the first sensor.\n    w2s : list\n        Weights of integration points in the second sensor.\n    volume_integral : bool\n        If True, compute volume integral.\n    lut : callable\n        Look-up table for evaluating Legendre polynomials.\n    n_fact : array\n        Coefficients in the integration sum.\n    ch_type : str\n        The channel type. It can be 'meg' or 'eeg'.\n\n    Returns\n    -------\n    result : float\n        The integration sum.\n    " #NEWLINE# if ( w1 is None ) : #NEWLINE# #INDENT# out_shape = ( len ( rr2s ) , len ( rr1_orig ) ) #NEWLINE# sum_axis = 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# out_shape = ( len ( rr2s ) , ) #NEWLINE# sum_axis = None #NEWLINE# #UNINDENT# out = np . empty ( out_shape ) #NEWLINE# rr2 = np . concatenate ( rr2s ) #NEWLINE# lr2 = np . concatenate ( lr2s ) #NEWLINE# cosmags2 = np . concatenate ( cosmags2s ) #NEWLINE# ct = np . einsum ( 'ik,jk->ij' , rr1_orig , rr2 ) #NEWLINE# rr1 = rr1_orig [ : , np . newaxis , : ] #NEWLINE# rr2 = rr2 [ np . newaxis , : , : ] #NEWLINE# lr1lr2 = ( lr1 [ : , np . newaxis ] * lr2 [ np . newaxis , : ] ) #NEWLINE# beta = ( ( r * r ) / lr1lr2 ) #NEWLINE# if ( ch_type == 'meg' ) : #NEWLINE# #INDENT# sums = _comp_sums_meg ( beta . flatten ( ) , ct . flatten ( ) , lut , n_fact , volume_integral ) #NEWLINE# sums . shape = ( ( 4 , ) + beta . shape ) #NEWLINE# n1c1 = np . einsum ( 'ik,ijk->ij' , cosmags1 , rr1 ) #NEWLINE# n1c2 = np . einsum ( 'ik,ijk->ij' , cosmags1 , rr2 ) #NEWLINE# n2c1 = np . einsum ( 'jk,ijk->ij' , cosmags2 , rr1 ) #NEWLINE# n2c2 = np . einsum ( 'jk,ijk->ij' , cosmags2 , rr2 ) #NEWLINE# n1n2 = np . einsum ( 'ik,jk->ij' , cosmags1 , cosmags2 ) #NEWLINE# part1 = ( ( ct * n1c1 ) * n2c2 ) #NEWLINE# part2 = ( ( n1c1 * out ) + ( n1c2 * n2c2 ) ) #NEWLINE# result = ( ( ( ( ( n1c1 * n2c2 ) * sums [ 0 ] ) + ( ( ( 2.0 * part1 ) - part2 ) * sums [ 1 ] ) ) + ( ( ( n1n2 + part1 ) - part2 ) * sums [ 2 ] ) ) + ( ( ( n1c2 - ( ct * n1c1 ) ) * ( n2c1 - ( ct * n2c2 ) ) ) * sums [ 3 ] ) ) #NEWLINE# result *= ( _meg_const / lr1lr2 ) #NEWLINE# if volume_integral : #NEWLINE# #INDENT# result *= r #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# result = _comp_sum_eeg ( beta . flatten ( ) , ct . flatten ( ) , lut , n_fact ) #NEWLINE# result . shape = beta . shape #NEWLINE# result *= _eeg_const #NEWLINE# result /= lr1lr2 #NEWLINE# #UNINDENT# offset = 0 #NEWLINE# result *= np . concatenate ( w2s ) #NEWLINE# if ( w1 is not None ) : #NEWLINE# #INDENT# result *= w1 [ : , np . newaxis ] #NEWLINE# #UNINDENT# for ( ii , w2 ) in enumerate ( w2s ) : #NEWLINE# #INDENT# out [ ii ] = np . sum ( result [ : , offset : ( offset + len ( w2 ) ) ] , axis = sum_axis ) #NEWLINE# offset += len ( w2 ) #NEWLINE# #UNINDENT# return out