function makeTensor(values, shape, inferredShape, dtype) {
    if (dtype == null) dtype = (0, _util.inferDtype)(values);
    else if (dtype === "complex64") throw new Error(`Cannot construct a complex64 tensor directly. ` + `Please use tf.complex(real, imag).`);
    if ((0, _types.isWebGPUData)(values) || (0, _types.isWebGLData)(values)) {
        if (dtype !== "float32" && dtype !== "int32") throw new Error(`Creating tensor from GPU data only supports ` + `'float32'|'int32' dtype, while the dtype is ${dtype}.`);
        return (0, _engine.ENGINE).backend.createTensorFromGPUData(values, shape || inferredShape, dtype);
    }
    if (!(0, _util.isTypedArray)(values) && !Array.isArray(values) && typeof values !== "number" && typeof values !== "boolean" && typeof values !== "string") throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
    // Verify that the shape matches the inferred shape.
    if (shape != null) {
        (0, _util.assertNonNegativeIntegerDimensions)(shape);
        const providedSize = (0, _util.sizeFromShape)(shape);
        const inferredSize = (0, _util.sizeFromShape)(inferredShape);
        (0, _util.assert)(providedSize === inferredSize, ()=>`Based on the provided shape, [${shape}], the tensor should have ` + `${providedSize} values but has ${inferredSize}`);
        for(let i = 0; i < inferredShape.length; ++i){
            const inferred = inferredShape[i];
            const flatDimsDontMatch = i === inferredShape.length - 1 ? inferred !== (0, _util.sizeFromShape)(shape.slice(i)) : true;
            (0, _util.assert)(inferredShape[i] === shape[i] || !flatDimsDontMatch, ()=>`Error creating a new Tensor. Inferred shape ` + `(${inferredShape}) does not match the provided ` + `shape (${shape}). `);
        }
    }
    if (!(0, _util.isTypedArray)(values) && !Array.isArray(values)) values = [
        values
    ];
    shape = shape || inferredShape;
    values = dtype !== "string" ? (0, _util.toTypedArray)(values, dtype) : (0, _util.flatten)(values, [], true);
    return (0, _engine.ENGINE).makeTensor(values, shape, dtype);
}
This is shared code across all tensor creation methods.