license import { Abs , AbsInputs , KernelConfig , KernelFunc , TypedArray , util } from '@tensorflow/tfjs-core' ; import { MathBackendCPU } from '../backend_cpu' ; import { assertNotComplex } from '../cpu_util' ; export function simpleAbsImpl ( vals ) { const resultValues = new Float32Array ( vals . length ) ; for ( let i = 0 ; i < vals . length ; ++ i ) { resultValues [ i ] = Math . abs ( vals [ i ] ) ; } return resultValues ; } export const abs = ( args ) => { const { x } = args . inputs ; const cpuBackend = args . backend ; assertNotComplex ( x , 'abs' ) ; let resultValues = new Float32Array ( util . sizeFromShape ( x . shape ) ) ; const values = cpuBackend . data . get ( x . dataId ) . values as TypedArray ; resultValues = simpleAbsImpl ( values ) ; return cpuBackend . makeOutput ( resultValues , x . shape , x . dtype ) ; } ; export const absConfig = { kernelName : Abs , backendName : 'cpu' , kernelFunc : abs as { } as KernelFunc , } ;