MCPcopy Index your code
hub / github.com/apache/tvm / copyFrom

Method copyFrom

web/src/runtime.ts:607–644  ·  view source on GitHub ↗

* Copy data from another Tensor or javascript array. * The number of elements must match. * * @param data The source data array. * @returns this

(
    data: Tensor | Array<number> | Float32Array | Float64Array |
      Int32Array | Int8Array | Uint8Array | Uint8ClampedArray
  )

Source from the content-addressed store, hash-verified

605 * @returns this
606 */
607 copyFrom(
608 data: Tensor | Array<number> | Float32Array | Float64Array |
609 Int32Array | Int8Array | Uint8Array | Uint8ClampedArray
610 ): this {
611 if (data instanceof Tensor) {
612 this.ctx.tensorCopyFromTo(data, this);
613 return this;
614 } else {
615 const size = this.shape.reduce((a, b) => {
616 return a * b;
617 }, 1);
618 if (data.length != size) {
619 throw new Error(
620 "data size and shape mismatch data.length" +
621 data.length +
622 " vs " +
623 size
624 );
625 }
626 let buffer: ArrayBuffer;
627 if (this.dtype === "float32") {
628 buffer = Float32Array.from(data).buffer;
629 } else if (this.dtype === "float64") {
630 buffer = Float64Array.from(data).buffer;
631 } else if (this.dtype === "int32") {
632 buffer = Int32Array.from(data).buffer;
633 } else if (this.dtype === "int8") {
634 buffer = Int8Array.from(data).buffer;
635 } else if (this.dtype === "uint8") {
636 buffer = Uint8Array.from(data).buffer;
637 } else if (this.dtype === "uint32") {
638 buffer = Uint32Array.from(data).buffer;
639 } else {
640 throw new Error("Unsupported data type " + this.dtype);
641 }
642 return this.copyFromRawBytes(new Uint8Array(buffer));
643 }
644 }
645 /**
646 * Copy data from raw bytes.
647 * @param data Uint8Array of bytes.

Callers 7

uniformMethod · 0.45
test_vm.jsFile · 0.45
testArrayCopyFunction · 0.45
test_object.jsFile · 0.45

Calls 2

copyFromRawBytesMethod · 0.95
reduceMethod · 0.80

Tested by

no test coverage detected