/** * Returns an array of a given size with each element filled with a single value */ export function values(size: number, value: number): Float32Array { return new Float32Array(size).fill(value); }
/** * Cleans ie sets all elements to 0 of a Texture or a js array * @param texture The texture or js array to be cleared */ export function clear( texture: Texture | Float32Array | Float32Array[] | Float32Array[][] ): void { if ('clear' in texture) { texture.clear(); return; } if (texture instanceof Float32Array) { texture.fill(0); } else if (texture[0] instanceof Float32Array) { for (let x = 0; x < texture.length; x++) { (texture[x] as Float32Array).fill(0); } } else if (texture[0][0] instanceof Float32Array) { for (let y = 0; y < texture.length; y++) { const row = texture[y]; for (let x = 0; x < row.length; x++) { (row[x] as Float32Array).fill(0); } } } }
it('PreProcessInfo.setPreProcessChannel should set the stdScale and the meanValue', () => { const preprocessInfo = network.getInputsInfo()[0].getPreProcess(); let width = 32; let height = 32; let typedArray1 = new Float32Array(width * height); typedArray1.fill(32.0); let tensorDesc = { precision: 'fp32', dims: [width, height], layout: 'hw' }; let meanData = {desc: tensorDesc, data: typedArray1.buffer}; preprocessInfo.setPreProcessChannel( 0, {'stdScale': 127.5, 'meanValue': 127.5, 'meanData': meanData}); const perProcessChannel = preprocessInfo.getPreProcessChannel(0); expect(perProcessChannel.meanValue).to.be.a('number').equal(127.5); expect(perProcessChannel.stdScale).to.be.a('number').equal(127.5); expect(new Float32Array(perProcessChannel.meanData)[0]).equal(32.0); });