From 374a023239673476bd4829282a17df1eb91be184 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Sat, 19 Sep 2026 02:18:44 +0530 Subject: [PATCH 1/2] feat: add float16 dtype support to ndarray/base/data-buffer --- .../ndarray/base/data-buffer/README.md | 10 ++++++++++ .../base/data-buffer/docs/types/index.d.ts | 20 ++++++++++++++++++- .../base/data-buffer/docs/types/test.ts | 1 + .../base/data-buffer/examples/index.js | 12 +++++++++++ .../ndarray/base/data-buffer/test/test.js | 12 +++++++++-- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/data-buffer/README.md b/lib/node_modules/@stdlib/ndarray/base/data-buffer/README.md index 51caeabd1bda..11d8e7c580f3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/data-buffer/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/data-buffer/README.md @@ -100,6 +100,16 @@ x = zeros( [ 2, 2 ], opts ); buf = data( x ); // returns +// Create a 'float16' array... +opts = { + 'dtype': 'float16' +}; +x = zeros( [ 2, 2 ], opts ); +// returns + +buf = data( x ); +// returns + // Create a 'complex128' array... opts = { 'dtype': 'complex128' diff --git a/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/index.d.ts index 33a824d8546d..19b079986640 100644 --- a/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; +import { typedndarray, genericndarray, float64ndarray, float32ndarray, float16ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; /** * Returns the underlying data buffer of a provided ndarray. @@ -58,6 +58,24 @@ declare function data( x: float64ndarray ): float64ndarray[ 'data' ]; */ declare function data( x: float32ndarray ): float32ndarray[ 'data' ]; +/** +* Returns the underlying data buffer of a provided ndarray. +* +* @param x - input ndarray +* @returns underlying data buffer +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = zeros( [ 3, 3, 3 ], { +* 'dtype': 'float16' +* }); +* +* var out = data( x ); +* // returns +*/ +declare function data( x: float16ndarray ): float16ndarray[ 'data' ]; + /** * Returns the underlying data buffer of a provided ndarray. * diff --git a/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts index 7ba3b035ddcb..8c0180dcb09e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts @@ -26,6 +26,7 @@ import data = require( './index' ); { data( zeros( [ 3, 2, 1 ], { 'dtype': 'float64' } ) ); // $ExpectType Float64Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'float32' } ) ); // $ExpectType Float32Array + data( zeros( [ 3, 2, 1 ], { 'dtype': 'float16' } ) ); // $ExpectType Float16Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'int32' } ) ); // $ExpectType Int32Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'int16' } ) ); // $ExpectType Int16Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'int8' } ) ); // $ExpectType Int8Array diff --git a/lib/node_modules/@stdlib/ndarray/base/data-buffer/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/data-buffer/examples/index.js index 84f49b7ad701..3be83acc28c4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/data-buffer/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/data-buffer/examples/index.js @@ -45,6 +45,18 @@ buf = data( x ); console.log( buf ); +// Create a 'float16' array... +opts = { + 'dtype': 'float16' +}; +x = zeros( [ 2, 2 ], opts ); +// returns + +buf = data( x ); +// returns + +console.log( buf ); + // Create a 'complex128' array... opts = { 'dtype': 'complex128' diff --git a/lib/node_modules/@stdlib/ndarray/base/data-buffer/test/test.js b/lib/node_modules/@stdlib/ndarray/base/data-buffer/test/test.js index db7f4119fa0b..206485c34971 100644 --- a/lib/node_modules/@stdlib/ndarray/base/data-buffer/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/data-buffer/test/test.js @@ -47,6 +47,9 @@ tape( 'the function returns the underlying data buffer of a provided ndarray', f zeros( [ 3, 3, 3 ], { 'dtype': 'float32' }), + zeros( [ 3, 3, 3 ], { + 'dtype': 'float16' + }), zeros( [ 1, 1 ], { 'dtype': 'int32' }), @@ -67,7 +70,8 @@ tape( 'the function returns the underlying data buffer of a provided ndarray', f values[ 2 ].data, values[ 3 ].data, values[ 4 ].data, - values[ 5 ].data + values[ 5 ].data, + values[ 6 ].data ]; for ( i = 0; i < values.length; i++ ) { @@ -90,6 +94,9 @@ tape( 'the function accepts minimal ndarray-like objects (data)', function test( { 'data': buffer( 'float32', 10 ) }, + { + 'data': buffer( 'float16', 10 ) + }, { 'data': buffer( 'int32', 10 ) }, @@ -110,7 +117,8 @@ tape( 'the function accepts minimal ndarray-like objects (data)', function test( values[ 2 ].data, values[ 3 ].data, values[ 4 ].data, - values[ 5 ].data + values[ 5 ].data, + values[ 6 ].data ]; for ( i = 0; i < values.length; i++ ) { From 9eb6166ca8896ea807bcfd6afb95bcc4d558f2a8 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Sat, 19 Sep 2026 03:11:07 +0530 Subject: [PATCH 2/2] fix: update expected float16 return type in test.ts --- .../@stdlib/ndarray/base/data-buffer/docs/types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts index 8c0180dcb09e..25a1b4dd969d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/data-buffer/docs/types/test.ts @@ -26,7 +26,7 @@ import data = require( './index' ); { data( zeros( [ 3, 2, 1 ], { 'dtype': 'float64' } ) ); // $ExpectType Float64Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'float32' } ) ); // $ExpectType Float32Array - data( zeros( [ 3, 2, 1 ], { 'dtype': 'float16' } ) ); // $ExpectType Float16Array + data( zeros( [ 3, 2, 1 ], { 'dtype': 'float16' } ) ); // $ExpectType Float16ArrayFallback data( zeros( [ 3, 2, 1 ], { 'dtype': 'int32' } ) ); // $ExpectType Int32Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'int16' } ) ); // $ExpectType Int16Array data( zeros( [ 3, 2, 1 ], { 'dtype': 'int8' } ) ); // $ExpectType Int8Array