Skip to content

Commit

Permalink
added more datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
martineho committed Aug 14, 2024
1 parent a174775 commit d00d266
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msgpack-numpy-js",
"version": "0.0.2",
"version": "0.0.3",
"description": "",
"main": "src/index.js",
"type": "module",
Expand Down
17 changes: 13 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import msgpack from "msgpack-lite";
import _ from "underscore";

if (typeof BigInt64Array === 'undefined') {
if (typeof BigInt64Array === "undefined") {
const BigInt64Array = window.BigInt64Array;
}
if (typeof BigUint64Array === 'undefined') {
if (typeof BigUint64Array === "undefined") {
const BigUint64Array = window.BigUint64Array;
}

Expand Down Expand Up @@ -74,20 +74,25 @@ export function unpackNumpy(v) {
if (isnd !== undefined && typeof t === "string") {
d = byteswap(t[0], d);
t = t.slice(1);

// documentation is here https://numpy.org/doc/stable/reference/arrays.dtypes.html
constr = {
U8: Uint8Array,
U8: Uint8Array, // this is a unicode string

b: Int8Array,
B: Int8Array,

i1: Int8Array,
i2: Int16Array,
i4: Int32Array,
i8: BigInt64Array,

I1: Uint8Array,
I2: Uint16Array,
I4: Uint32Array,
I8: BigUint64Array,

u1: Uint8Array,
u2: Uint16Array,
u4: Uint32Array,
u8: BigUint64Array,
Expand All @@ -99,7 +104,11 @@ export function unpackNumpy(v) {
if (constr !== undefined) {
if (d.byteOffset !== undefined) {
// NodeJS
v = new constr(d.buffer, d.byteOffset, d.length / constr.BYTES_PER_ELEMENT);
v = new constr(
d.buffer,
d.byteOffset,
d.length / constr.BYTES_PER_ELEMENT
);
} else {
v = new constr(d.buffer);
}
Expand Down

0 comments on commit d00d266

Please sign in to comment.