MCPcopy Create free account
hub / github.com/tensorflow/tfjs / toArrayBuffer

Function toArrayBuffer

tfjs-inference/src/file_handler.ts:132–142  ·  view source on GitHub ↗

* Convert a Buffer or an Array of Buffers to an ArrayBuffer. * * If the input is an Array of Buffers, they will be concatenated in the * specified order to form the output ArrayBuffer. * * @param buf A Buffer or an Array of Buffers. * @return An ArrayBuffer.

(buf: Buffer|Buffer[])

Source from the content-addressed store, hash-verified

130 * @return An ArrayBuffer.
131 */
132function toArrayBuffer(buf: Buffer|Buffer[]): ArrayBuffer {
133 if (Array.isArray(buf)) {
134 const newBuf = Buffer.concat(buf);
135
136 return newBuf.buffer.slice(
137 newBuf.byteOffset, newBuf.byteOffset + newBuf.byteLength);
138 } else {
139 // A single Buffer. Return a copy of the underlying ArrayBuffer slice.
140 return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
141 }
142}

Callers 1

loadWeightsMethod · 0.70

Calls 2

concatMethod · 0.65
sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…