From 86be8a1639a402aa1a6f185a74871cef6b49512f Mon Sep 17 00:00:00 2001 From: Andrew Champion Date: Fri, 8 Feb 2019 12:14:44 -0500 Subject: [PATCH 1/2] Support BigInt64Array/BigUint64Array Add support for typed arrays of 64-bit integers (BigInt) now available in many browsers. Without this patch these typed arrays were given the "generic" dtype, which then attempted to use getters and setters rather than indexing, causing an error since typed arrays do not provide these. These changes are compatible with browsers that do not have these 64-bit typed arrays. --- README.md | 2 ++ ndarray.js | 6 ++++++ test/test.js | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index a7989ef..259fa0d 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,8 @@ Data type | String `Uint8Array` | "uint8" `Uint16Array` | "uint16" `Uint32Array` | "uint32" +`BigInt64Array` | "bigint64" +`BigUint64Array` | "biguint64" `Float32Array` | "float32" `Float64Array` | "float64" `Array` | "array" diff --git a/ndarray.js b/ndarray.js index f50d99e..43c9b5a 100644 --- a/ndarray.js +++ b/ndarray.js @@ -276,6 +276,10 @@ function arrayDType(data) { return "uint32" case "[object Uint8ClampedArray]": return "uint8_clamped" + case "[object BigInt64Array]": + return "bigint64" + case "[object BigUint64Array]": + return "biguint64" } } if(Array.isArray(data)) { @@ -295,6 +299,8 @@ var CACHED_CONSTRUCTORS = { "uint32":[], "array":[], "uint8_clamped":[], + "bigint64": [], + "biguint64": [], "buffer":[], "generic":[] } diff --git a/test/test.js b/test/test.js index 92ed2de..7c79eb9 100644 --- a/test/test.js +++ b/test/test.js @@ -63,6 +63,17 @@ test("uint8clamped", function(t) { t.end() }) +if((typeof BigInt64Array) !== "undefined") +test("bigint64", function(t) { + var p = ndarray(new BigInt64Array([1,2,3,4].map(BigInt)), [4]) + t.equals(p.dtype, "bigint64") + t.equals(p.get(0), BigInt(1)) + t.equals(p.get(1), BigInt(2)) + t.equals(p.get(2), BigInt(3)) + t.equals(p.get(3), BigInt(4)) + t.end() +}) + test("buffer", function(t) { var p = ndarray(new Buffer(5)) t.equals(p.dtype, "buffer") From 58f5d8ca9cd37fa708c3996b0e8bbad0937678fc Mon Sep 17 00:00:00 2001 From: mikola Date: Sun, 5 Jan 2020 11:55:06 +0800 Subject: [PATCH 2/2] 1.0.19 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e570f4a..bbfb670 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ndarray", - "version": "1.0.18", + "version": "1.0.19", "description": "Multidimensional Arrays", "main": "ndarray.js", "directories": {