UNPKG

@thi.ng/tensors

Version:

0D/1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage

31 lines (30 loc) 618 B
import { typedArrayType } from "@thi.ng/api/typedarray"; import { tensor } from "./tensor.js"; const asTensor = (src, opts) => tensor(src.type, src.shape, { copy: false, data: src.data, stride: src.stride, offset: src.offset, ...opts }); const fromFloatBuffer = ({ size: [sx, sy], stride: [tx, ty], data, format: { size } }) => { const type = typedArrayType(data); return size > 1 ? tensor(type, [sy, sx, size], { stride: [ty, tx, 1], copy: false, data }) : tensor(type, [sy, sx], { stride: [ty, tx], copy: false, data }); }; export { asTensor, fromFloatBuffer };