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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
b.end();
});

bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) {
var x;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = broadcastScalar( i, 'float16', [ 2, 2 ], 'row-major' );
if ( x.length !== 4 ) {
b.fail( 'should have length 4' );
}
}
b.toc();
if ( !isndarrayLike( x ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
var x;
var v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// <reference types="@stdlib/types"/>

import { ComplexLike } from '@stdlib/types/complex';
import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray';
import { ndarray, float64ndarray, float32ndarray, float16ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray';

/**
* Broadcasts a scalar value to an ndarray having a specified shape.
Expand Down Expand Up @@ -77,6 +77,33 @@
*/
declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray;

/**
* Broadcasts a scalar value to an ndarray having a specified shape.
*
* @param value - scalar value
* @param dtype - array data type
* @param shape - array shape
* @param order - array order
* @returns ndarray
*
* @example
* var getShape = require( '@stdlib/ndarray/shape' );
* var getDType = require( '@stdlib/ndarray/dtype' );
*
* var x = broadcastScalar( 1.0, 'float16', [ 2, 2 ], 'row-major' );
* // returns <ndarray>
*
* var sh = getShape( x );
* // returns [ 2, 2 ]
*
* var dt = String( getDType( x ) );
* // returns 'float16'
*
* var v = x.get( 0, 1 );
* // returns 1.0
*/
declare function broadcastScalar( value: number, dtype: 'float16', shape: Shape, order: Order ): float16ndarray;

/**
* Broadcasts a scalar value to an ndarray having a specified shape.
*
Expand Down Expand Up @@ -361,7 +388,7 @@
* var v = x.get( 0, 1 );
* // returns 1.0
*/
declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray;

Check warning on line 391 in lib/node_modules/@stdlib/ndarray/base/broadcast-scalar/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import broadcastScalar = require( './index' );
{
broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray
broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray
broadcastScalar( 1.0, 'float16', [ 2, 2 ], 'row-major' ); // $ExpectType float16ndarray
broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray
broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray
broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -121,6 +122,24 @@ tape( 'the function returns a broadcasted ndarray (dtype=float32)', function tes
t.end();
});

tape( 'the function returns a broadcasted ndarray (dtype=float16)', function test( t ) {
var expected;
var arr;

expected = new Float16Array( [ 1.0 ] );
arr = broadcastScalar( 1.0, 'float16', [ 3, 3 ], 'column-major' );

t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' );
t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' );
t.deepEqual( getShape( arr ), [ 3, 3 ], '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 ), 'column-major', 'returns expected value' );
t.strictEqual( numel( arr ), 9, 'returns expected value' );

t.end();
});

tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) {
var expected;
var arr;
Expand Down
Loading