diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..536449d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +## 1.1.1 (2026-08-25) + +Note: published as 1.1.1 because the version number 1.1.0 was published and unpublished in 2014, and npm permanently reserves it. + +- Added `Float16Array` support: it now gets a `"float16"` dtype instead of falling back to `"generic"`, which previously caused `.get()` to throw with `this.data.get is not a function` ([#49](https://github.com/scijs/ndarray/pull/49), thanks [@NAThompson](https://github.com/NAThompson)) diff --git a/README.md b/README.md index a7989ef..4b219dd 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,9 @@ Data type | String `Uint8Array` | "uint8" `Uint16Array` | "uint16" `Uint32Array` | "uint32" +`BigInt64Array` | "bigint64" +`BigUint64Array` | "biguint64" +`Float16Array` | "float16" `Float32Array` | "float32" `Float64Array` | "float64" `Array` | "array" diff --git a/ndarray.js b/ndarray.js index f50d99e..0c93775 100644 --- a/ndarray.js +++ b/ndarray.js @@ -262,6 +262,8 @@ function arrayDType(data) { return "float64" case "[object Float32Array]": return "float32" + case "[object Float16Array]": + return "float16" case "[object Int8Array]": return "int8" case "[object Int16Array]": @@ -276,6 +278,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)) { @@ -287,6 +293,7 @@ function arrayDType(data) { var CACHED_CONSTRUCTORS = { "float32":[], "float64":[], + "float16":[], "int8":[], "int16":[], "int32":[], @@ -295,6 +302,8 @@ var CACHED_CONSTRUCTORS = { "uint32":[], "array":[], "uint8_clamped":[], + "bigint64": [], + "biguint64": [], "buffer":[], "generic":[] } diff --git a/package.json b/package.json index e570f4a..6ad3c9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ndarray", - "version": "1.0.18", + "version": "1.1.1", "description": "Multidimensional Arrays", "main": "ndarray.js", "directories": { diff --git a/test/test.js b/test/test.js index 92ed2de..330c2b0 100644 --- a/test/test.js +++ b/test/test.js @@ -63,6 +63,33 @@ 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() +}) + +if((typeof Float16Array) !== "undefined") +test("float16", function(t) { + var p = ndarray(new Float16Array([1,2,3,4]), [4]) + t.equals(p.dtype, "float16") + t.equals(p.get(0), 1) + t.equals(p.get(1), 2) + t.equals(p.get(2), 3) + t.equals(p.get(3), 4) + p.set(0, 0.5) + t.equals(p.get(0), 0.5) + //values are rounded to the nearest half, as the array itself does + p.set(1, 0.1) + t.equals(p.get(1), new Float16Array([0.1])[0]) + t.end() +}) + test("buffer", function(t) { var p = ndarray(new Buffer(5)) t.equals(p.dtype, "buffer")