Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Data type | String
`Uint32Array` | "uint32"
`BigInt64Array` | "bigint64"
`BigUint64Array` | "biguint64"
`Float16Array` | "float16"
`Float32Array` | "float32"
`Float64Array` | "float64"
`Array` | "array"
Expand Down
3 changes: 3 additions & 0 deletions ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]":
Expand Down Expand Up @@ -291,6 +293,7 @@ function arrayDType(data) {
var CACHED_CONSTRUCTORS = {
"float32":[],
"float64":[],
"float16":[],
"int8":[],
"int16":[],
"int32":[],
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ test("bigint64", function(t) {
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")
Expand Down