@thi.ng/tensors
Version:
0D/1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage
32 lines (31 loc) • 717 B
JavaScript
import { always } from "@thi.ng/api/fn";
import { typedArray, TYPEDARRAY_CTORS } from "@thi.ng/api/typedarray";
const __impl = (type) => ({
alloc: (size) => typedArray(type, size),
from: (iter) => TYPEDARRAY_CTORS[type].from(iter),
release: always
});
const STORAGE = {
u8: __impl("u8"),
u8c: __impl("u8c"),
i8: __impl("i8"),
u16: __impl("u16"),
i16: __impl("i16"),
u32: __impl("u32"),
i32: __impl("i32"),
f32: __impl("f32"),
f64: __impl("f64"),
num: {
alloc: (size) => new Array(size).fill(0),
from: (iter) => [...iter],
release: always
},
str: {
alloc: (size) => new Array(size).fill(""),
from: (iter) => [...iter],
release: always
}
};
export {
STORAGE
};