From 14c0a7e86278738051aa359e75f2064837c58655 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Fri, 25 Sep 2026 10:27:16 +0530 Subject: [PATCH 1/2] feat: add float16 dtype support to ndarray/base/slice-from --- .../base/slice-from/benchmark/benchmark.js | 22 ++++++++++ .../base/slice-from/docs/types/index.d.ts | 42 ++++++++++++++++++- .../base/slice-from/docs/types/test.ts | 2 + .../ndarray/base/slice-from/test/test.js | 4 ++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-from/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/slice-from/benchmark/benchmark.js index 32fdbfaafeb7..81b1bb6f4572 100644 --- a/lib/node_modules/@stdlib/ndarray/base/slice-from/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/slice-from/benchmark/benchmark.js @@ -40,6 +40,7 @@ bench( format( '%s::0d,base', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [], 'row-major' ), baseEmpty( 'float32', [], 'row-major' ), + baseEmpty( 'float16', [], 'row-major' ), baseEmpty( 'int32', [], 'row-major' ), baseEmpty( 'complex128', [], 'row-major' ), baseEmpty( 'generic', [], 'row-major' ) @@ -72,6 +73,7 @@ bench( format( '%s::0d,non-base', pkg ), function benchmark( b ) { values = [ empty( [], { 'dtype': 'float64' } ), empty( [], { 'dtype': 'float32' } ), + empty( [], { 'dtype': 'float16' } ), empty( [], { 'dtype': 'int32' } ), empty( [], { 'dtype': 'complex128' } ), empty( [], { 'dtype': 'generic' } ) @@ -105,6 +107,7 @@ bench( format( '%s::1d,base', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2 ], 'row-major' ), baseEmpty( 'float32', [ 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2 ], 'row-major' ), baseEmpty( 'int32', [ 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2 ], 'row-major' ), baseEmpty( 'generic', [ 2 ], 'row-major' ) @@ -137,6 +140,7 @@ bench( format( '%s::1d,non-base', pkg ), function benchmark( b ) { values = [ empty( [ 2 ], { 'dtype': 'float64' } ), empty( [ 2 ], { 'dtype': 'float32' } ), + empty( [ 2 ], { 'dtype': 'float16' } ), empty( [ 2 ], { 'dtype': 'int32' } ), empty( [ 2 ], { 'dtype': 'complex128' } ), empty( [ 2 ], { 'dtype': 'generic' } ) @@ -170,6 +174,7 @@ bench( format( '%s::1d,base,out-of-bounds', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2 ], 'row-major' ), baseEmpty( 'float32', [ 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2 ], 'row-major' ), baseEmpty( 'int32', [ 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2 ], 'row-major' ), baseEmpty( 'generic', [ 2 ], 'row-major' ) @@ -202,6 +207,7 @@ bench( format( '%s::1d,non-base,out-of-bounds', pkg ), function benchmark( b ) { values = [ empty( [ 2 ], { 'dtype': 'float64' } ), empty( [ 2 ], { 'dtype': 'float32' } ), + empty( [ 2 ], { 'dtype': 'float16' } ), empty( [ 2 ], { 'dtype': 'int32' } ), empty( [ 2 ], { 'dtype': 'complex128' } ), empty( [ 2 ], { 'dtype': 'generic' } ) @@ -235,6 +241,7 @@ bench( format( '%s::2d,base', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) @@ -267,6 +274,7 @@ bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2 ], { 'dtype': 'generic' } ) @@ -300,6 +308,7 @@ bench( format( '%s::2d,base,out-of-bounds', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) @@ -332,6 +341,7 @@ bench( format( '%s::2d,non-base,out-of-bounds', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2 ], { 'dtype': 'generic' } ) @@ -365,6 +375,7 @@ bench( format( '%s::3d,base', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) @@ -397,6 +408,7 @@ bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) @@ -430,6 +442,7 @@ bench( format( '%s::3d,base,out-of-bounds', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) @@ -462,6 +475,7 @@ bench( format( '%s::3d,non-base,out-of-bounds', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) @@ -495,6 +509,7 @@ bench( format( '%s::4d,base', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) @@ -527,6 +542,7 @@ bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) @@ -560,6 +576,7 @@ bench( format( '%s::4d,base,out-of-bounds', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) @@ -592,6 +609,7 @@ bench( format( '%s::4d,non-base,out-of-bounds', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) @@ -625,6 +643,7 @@ bench( format( '%s::5d,base', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) @@ -657,6 +676,7 @@ bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) @@ -690,6 +710,7 @@ bench( format( '%s::5d,base,out-of-bounds', pkg ), function benchmark( b ) { values = [ baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float16', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) @@ -722,6 +743,7 @@ bench( format( '%s::5d,non-base,out-of-bounds', pkg ), function benchmark( b ) { values = [ empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float16' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/index.d.ts index c51e6ab884b2..a961544068b6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/slice-from/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'; import { ArrayLike } from '@stdlib/types/array'; /** @@ -113,6 +113,46 @@ declare function sliceFrom( x: float64ndarray, start: ArrayLike, */ declare function sliceFrom( x: float32ndarray, start: ArrayLike, strict: boolean, writable: boolean ): float32ndarray; +/** +* Returns a shifted view of an input ndarray. +* +* @param x - input array +* @param start - starting indices (inclusive) +* @param strict - boolean indicating whether to enforce strict bounds checking +* @param writable - boolean indicating whether a returned array should be writable +* @returns output array +* +* @example +* var typedarray = require( '@stdlib/array/typed' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float16' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 2 ] +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var s = [ 1, null ]; +* var y = sliceFrom( x, s, false, false ); +* // returns +* +* sh = y.shape; +* // returns [ 2, 2 ] +* +* arr = ndarray2array( y ); +* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +*/ +declare function sliceFrom( x: float16ndarray, start: ArrayLike, strict: boolean, writable: boolean ): float16ndarray; + /** * Returns a shifted view of an input ndarray. * diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/test.ts index 4a05d0fbd427..1f998d589351 100644 --- a/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/slice-from/docs/types/test.ts @@ -30,6 +30,7 @@ import sliceFrom = require( './index' ); sliceFrom( empty( 'float64', sh, order ), s, false, false ); // $ExpectType float64ndarray sliceFrom( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray + sliceFrom( empty( 'float16', sh, order ), s, false, false ); // $ExpectType float16ndarray sliceFrom( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray sliceFrom( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray sliceFrom( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray @@ -42,6 +43,7 @@ import sliceFrom = require( './index' ); sliceFrom( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray sliceFrom( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray + sliceFrom( empty( 'float16', sh, order ), s, true, true ); // $ExpectType float16ndarray sliceFrom( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray sliceFrom( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray sliceFrom( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js b/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js index 42e202b41e33..ac1df11ac9d6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js @@ -145,6 +145,7 @@ tape( 'in non-strict mode, the function returns an empty array when a starting i values = [ zeros( [ 1 ], { 'dtype': 'float64' } ), zeros( [ 1, 1 ], { 'dtype': 'float32' } ), + zeros( [ 1, 1 ], { 'dtype': 'float16' } ), zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) @@ -153,6 +154,7 @@ tape( 'in non-strict mode, the function returns an empty array when a starting i start = [ [ 10 ], [ null, 20 ], + [ null, 20 ], [ 20, null, null ], [ 20, 20, null, null ], [ null, null, null, null, 10 ] @@ -175,6 +177,7 @@ tape( 'the function returns an empty array when a starting index is one more tha values = [ zeros( [ 1 ], { 'dtype': 'float64' } ), zeros( [ 1, 1 ], { 'dtype': 'float32' } ), + zeros( [ 1, 1 ], { 'dtype': 'float16' } ), zeros( [ 1, 1, 1 ], { 'dtype': 'int32' } ), zeros( [ 1, 1, 1, 1 ], { 'dtype': 'uint32' } ), zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) @@ -183,6 +186,7 @@ tape( 'the function returns an empty array when a starting index is one more tha start = [ [ 1 ], [ null, 1 ], + [ null, 1 ], [ 1, null, null ], [ 1, 1, null, null ], [ null, null, null, null, 1 ] From 73886bdc8f6a5841f56866168815d2c9fed21c1f Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Fri, 25 Sep 2026 10:50:58 +0530 Subject: [PATCH 2/2] chore: fix JavaScript lint errors in test.js --- .../@stdlib/ndarray/base/slice-from/test/test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js b/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js index ac1df11ac9d6..fe40b1306b5c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/slice-from/test/test.js @@ -142,6 +142,8 @@ tape( 'in non-strict mode, the function returns an empty array when a starting i var start; var i; + /* eslint-disable stdlib/line-closing-bracket-spacing */ + values = [ zeros( [ 1 ], { 'dtype': 'float64' } ), zeros( [ 1, 1 ], { 'dtype': 'float32' } ), @@ -151,6 +153,8 @@ tape( 'in non-strict mode, the function returns an empty array when a starting i zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) ]; + /* eslint-enable stdlib/line-closing-bracket-spacing */ + start = [ [ 10 ], [ null, 20 ], @@ -174,6 +178,8 @@ tape( 'the function returns an empty array when a starting index is one more tha var start; var i; + /* eslint-disable stdlib/line-closing-bracket-spacing */ + values = [ zeros( [ 1 ], { 'dtype': 'float64' } ), zeros( [ 1, 1 ], { 'dtype': 'float32' } ), @@ -183,6 +189,8 @@ tape( 'the function returns an empty array when a starting index is one more tha zeros( [ 1, 1, 1, 1, 1 ], { 'dtype': 'complex128' } ) ]; + /* eslint-enable stdlib/line-closing-bracket-spacing */ + start = [ [ 1 ], [ null, 1 ],