license import { ENGINE } from '../engine' ; import { LRN , LRNAttrs , LRNInputs } from '../kernel_names' ; import { NamedAttrMap } from '../kernel_registry' ; import { Tensor3D , Tensor4D } from '../tensor' ; import { NamedTensorMap } from '../tensor_types' ; import { convertToTensor } from '../tensor_util_env' ; import { TensorLike } from '../types' ; import * as util from '../util' ; import { op } from './operation' ; import { reshape } from './reshape' ; param x param depthRadius param bias param alpha param beta doc function localResponseNormalization_ < T extends Tensor3D | Tensor4D > ( x , depthRadius = 5 , bias = 1 , alpha = 1 , beta = 0.5 ) { const $x = convertToTensor ( x , 'x' , 'localResponseNormalization' ) ; util . assert ( $x . rank === 4 || $x . rank === 3 , ( ) => `Error in localResponseNormalization: x must be rank 3 or 4 but got
               rank ${ $x . rank }.` ) ; util . assert ( util . isInt ( depthRadius ) , ( ) => `Error in localResponseNormalization: depthRadius must be an ` + `integer but got depthRadius ${ depthRadius }.` ) ; let x4D = $x as Tensor4D ; let reshapedTo4D = false ; if ( $x . rank === 3 ) { reshapedTo4D = true ; x4D = reshape ( $x , [ 1 , $x . shape [ 0 ] , $x . shape [ 1 ] , $x . shape [ 2 ] ] ) ; } const inputs = { x : x4D } ; const attrs = { depthRadius , bias , alpha , beta } ; const res = ENGINE . runKernel ( LRN , inputs as { } as NamedTensorMap , attrs as { } as NamedAttrMap ) as T ; if ( reshapedTo4D ) { return reshape ( res , [ res . shape [ 1 ] , res . shape [ 2 ] , res . shape [ 3 ] ] ) as T ; } else { return res ; } } export const localResponseNormalization = op ( { localResponseNormalization_ } ) ;