diff --git a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/benchmark/benchmark.js index f171ca433ffc..44e317150986 100644 --- a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/benchmark/benchmark.js @@ -80,6 +80,30 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { b.end(); }); +bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) { + var x; + var o; + var i; + + x = empty( [ 2, 2 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = broadcastScalarLike( x, i, { + 'dtype': 'float16' + }); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( o ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) { var x; var o; diff --git a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/index.d.ts index e9ef788d9785..bc0c7645533e 100644 --- a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/index.d.ts @@ -21,7 +21,7 @@ /// import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, genericndarray, boolndarray, Shape, DataType, Order, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType, BooleanDataType, Int32DataType, Int16DataType, Int8DataType, Uint32DataType, Uint16DataType, Uint8DataType, Uint8cDataType, GenericDataType } from '@stdlib/types/ndarray'; +import { ndarray, float64ndarray, float32ndarray, float16ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, genericndarray, boolndarray, Shape, DataType, Order, Float64DataType, Float32DataType, Float16DataType, Complex128DataType, Complex64DataType, BooleanDataType, Int32DataType, Int16DataType, Int8DataType, Uint32DataType, Uint16DataType, Uint8DataType, Uint8cDataType, GenericDataType } from '@stdlib/types/ndarray'; /** * Interface defining function options. @@ -73,6 +73,16 @@ interface Float32Options extends BaseOptions { dtype: Float32DataType; } +/** +* Interface defining function options. +*/ +interface Float16Options extends BaseOptions { + /** + * Output array data type. + */ + dtype: Float16DataType; +} + /** * Interface defining function options. */ @@ -271,6 +281,48 @@ declare function broadcastScalarLike( x: float32ndarray, value: number, options? */ declare function broadcastScalarLike( x: ndarray, value: number, options: Float32Options ): float32ndarray; +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* @param x - input ndarray +* @param value - scalar value +* @param options - function options +* @returns ndarray +* +* @example +* var empty = require( '@stdlib/ndarray/empty' ); +* +* var x = empty( [ 2, 2 ], { +* 'dtype': 'float16' +* }); +* // returns +* +* var out = broadcastScalarLike( x, 1.0 ); +* // returns +*/ +declare function broadcastScalarLike( x: float16ndarray, value: number, options?: BaseOptions ): float16ndarray; + +/** +* Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. +* +* @param x - input ndarray +* @param value - scalar value +* @param options - function options +* @returns ndarray +* +* @example +* var empty = require( '@stdlib/ndarray/empty' ); +* +* var x = empty( [ 2, 2 ] ); +* // returns +* +* var out = broadcastScalarLike( x, 1.0, { +* 'dtype': 'float16' +* }); +* // returns +*/ +declare function broadcastScalarLike( x: ndarray, value: number, options: Float16Options ): float16ndarray; + /** * Broadcasts a scalar value to an ndarray having the same shape and data type as a provided input ndarray. * diff --git a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/test.ts index f0c20e2ff153..d657f40cfca6 100644 --- a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/docs/types/test.ts @@ -34,6 +34,7 @@ import broadcastScalarLike = require( './index' ); broadcastScalarLike( x, 1.0, { 'dtype': 'float64' } ); // $ExpectType float64ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'float32' } ); // $ExpectType float32ndarray + broadcastScalarLike( x, 1.0, { 'dtype': 'float16' } ); // $ExpectType float16ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray broadcastScalarLike( x, 1.0, { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray broadcastScalarLike( x, true, { 'dtype': 'bool' } ); // $ExpectType boolndarray diff --git a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/test/test.js b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/test/test.js index a58871a5f335..18c079eaca6f 100644 --- a/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/broadcast-scalar-like/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); +var Float16Array = require( '@stdlib/array/float16' ); var Int32Array = require( '@stdlib/array/int32' ); var Uint32Array = require( '@stdlib/array/uint32' ); var Int16Array = require( '@stdlib/array/int16' ); @@ -319,6 +320,29 @@ tape( 'the function returns an ndarray having the same shape and data type as a t.end(); }); +tape( 'the function returns an ndarray having the same shape and data type as a provided ndarray (default, float16)', function test( t ) { + var expected; + var arr; + var x; + + x = empty( [ 2, 2 ], { + 'dtype': 'float16' + }); + arr = broadcastScalarLike( x, 1.0 ); + expected = new Float16Array( [ 1.0 ] ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( arr ), 4, 'returns expected value' ); + t.deepEqual( ndarray2array( arr ), [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ], 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns an ndarray having the same shape and data type as a provided ndarray (default, complex128)', function test( t ) { var expected; var arr; @@ -472,6 +496,29 @@ tape( 'the function returns an ndarray having the specified data type (dtype=flo t.end(); }); +tape( 'the function returns an ndarray having the specified data type (dtype=float16)', function test( t ) { + var expected; + var arr; + var x; + + x = empty( [ 2, 2 ] ); + + arr = broadcastScalarLike( x, 1.0, { + 'dtype': 'float16' + }); + expected = new Float16Array( [ 1.0 ] ); + + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + t.strictEqual( numel( arr ), 4, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns an ndarray having the specified data type (dtype=int32)', function test( t ) { var expected; var arr;