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

Function convertBackendValuesAndArrayBuffer

tfjs-core/src/util_base.ts:620–635  ·  view source on GitHub ↗
(
    data: BackendValues|ArrayBuffer, dtype: DataType)

Source from the content-addressed store, hash-verified

618}
619
620export function convertBackendValuesAndArrayBuffer(
621 data: BackendValues|ArrayBuffer, dtype: DataType) {
622 // If is type Uint8Array[], return it directly.
623 if (Array.isArray(data)) {
624 return data;
625 }
626 if (dtype === 'float32') {
627 return data instanceof Float32Array ? data : new Float32Array(data);
628 } else if (dtype === 'int32') {
629 return data instanceof Int32Array ? data : new Int32Array(data);
630 } else if (dtype === 'bool' || dtype === 'string') {
631 return Uint8Array.from(new Int32Array(data));
632 } else {
633 throw new Error(`Unknown dtype ${dtype}`);
634 }
635}
636
637export function makeOnesTypedArray<D extends DataType>(
638 size: number, dtype: D): DataTypeMap[D] {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…