Skip to content

Commit fc4fbba

Browse files
committed
Auto-generated commit
1 parent d4104ac commit fc4fbba

5 files changed

Lines changed: 119 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`40e6a9e`](https://github.com/stdlib-js/stdlib/commit/40e6a9e4cc2d941aa2c62c6365c1351ff139850e) - add float16 dtype support to `ndarray/from-scalar-like` [(#15244)](https://github.com/stdlib-js/stdlib/pull/15244)
1314
- [`81645db`](https://github.com/stdlib-js/stdlib/commit/81645db64e0d7a9d27a59850ae50001534edb809) - update `ndarray/base` TypeScript declarations [(#15838)](https://github.com/stdlib-js/stdlib/pull/15838)
1415
- [`85f3d87`](https://github.com/stdlib-js/stdlib/commit/85f3d878b126107b24ba09fd08bea53307422087) - add float16 dtype support to `ndarray/base/empty-like` [(#15739)](https://github.com/stdlib-js/stdlib/pull/15739)
1516
- [`ce01d62`](https://github.com/stdlib-js/stdlib/commit/ce01d62f42a0f04f16f413f93dea56794a601211) - add float16 dtype support to `ndarray/base/from-array` [(#15742)](https://github.com/stdlib-js/stdlib/pull/15742)
@@ -144,6 +145,7 @@ A total of 4 issues were closed in this release:
144145

145146
<details>
146147

148+
- [`40e6a9e`](https://github.com/stdlib-js/stdlib/commit/40e6a9e4cc2d941aa2c62c6365c1351ff139850e) - **feat:** add float16 dtype support to `ndarray/from-scalar-like` [(#15244)](https://github.com/stdlib-js/stdlib/pull/15244) _(by Samarth Kolarkar)_
147149
- [`81645db`](https://github.com/stdlib-js/stdlib/commit/81645db64e0d7a9d27a59850ae50001534edb809) - **feat:** update `ndarray/base` TypeScript declarations [(#15838)](https://github.com/stdlib-js/stdlib/pull/15838) _(by stdlib-bot)_
148150
- [`ba2b826`](https://github.com/stdlib-js/stdlib/commit/ba2b8265baf1b23a75e26fc890488691501edb67) - **docs:** update example [(#16075)](https://github.com/stdlib-js/stdlib/pull/16075) _(by stdlib-bot)_
149151
- [`76fd996`](https://github.com/stdlib-js/stdlib/commit/76fd996a6129ea7c663b0ac89fc65480698241c2) - **docs:** update namespace table of contents [(#16076)](https://github.com/stdlib-js/stdlib/pull/16076) _(by stdlib-bot)_

‎from-scalar-like/benchmark/benchmark.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
8080
b.end();
8181
});
8282

83+
bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) {
84+
var x;
85+
var o;
86+
var i;
87+
88+
x = empty( [ 2 ] );
89+
90+
b.tic();
91+
for ( i = 0; i < b.iterations; i++ ) {
92+
o = scalar2ndarrayLike( x, i, {
93+
'dtype': 'float16'
94+
});
95+
if ( o.length !== 1 ) {
96+
b.fail( 'should have length 1' );
97+
}
98+
}
99+
b.toc();
100+
if ( !isndarrayLike( o ) ) {
101+
b.fail( 'should return an ndarray' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
});
106+
83107
bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
84108
var x;
85109
var o;

‎from-scalar-like/docs/types/index.d.ts‎

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// <reference types="@stdlib/types"/>
2222

2323
import { ComplexLike } from '@stdlib/types/complex';
24-
import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, genericndarray, boolndarray, DataType, Order, Float64DataType, Float32DataType, Complex128DataType, Complex64DataType, BooleanDataType, Int32DataType, Int16DataType, Int8DataType, Uint32DataType, Uint16DataType, Uint8DataType, Uint8cDataType, GenericDataType } from '@stdlib/types/ndarray';
24+
import { ndarray, float64ndarray, float32ndarray, float16ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, genericndarray, boolndarray, Order, Float64DataType, Float32DataType, Float16DataType, Complex128DataType, Complex64DataType, BooleanDataType, Int32DataType, Int16DataType, Int8DataType, Uint32DataType, Uint16DataType, Uint8DataType, Uint8cDataType, GenericDataType } from '@stdlib/types/ndarray';
2525

2626
/**
2727
* Interface defining common options.
@@ -39,33 +39,33 @@ interface BaseOptions {
3939
}
4040

4141
/**
42-
* Interface defining options.
42+
* Interface defining options when `dtype` is `'float64'`.
4343
*/
44-
interface Options extends BaseOptions {
44+
interface Float64Options extends BaseOptions {
4545
/**
4646
* Output array data type.
4747
*/
48-
dtype?: DataType;
48+
dtype: Float64DataType;
4949
}
5050

5151
/**
52-
* Interface defining options when `dtype` is `'float64'`.
52+
* Interface defining options when `dtype` is `'float32'`.
5353
*/
54-
interface Float64Options extends BaseOptions {
54+
interface Float32Options extends BaseOptions {
5555
/**
5656
* Output array data type.
5757
*/
58-
dtype: Float64DataType;
58+
dtype: Float32DataType;
5959
}
6060

6161
/**
62-
* Interface defining options when `dtype` is `'float32'`.
62+
* Interface defining options when `dtype` is `'float16'`.
6363
*/
64-
interface Float32Options extends BaseOptions {
64+
interface Float16Options extends BaseOptions {
6565
/**
6666
* Output array data type.
6767
*/
68-
dtype: Float32DataType;
68+
dtype: Float16DataType;
6969
}
7070

7171
/**
@@ -292,6 +292,64 @@ declare function scalar2ndarrayLike( x: float32ndarray, value: number, options?:
292292
*/
293293
declare function scalar2ndarrayLike( x: ndarray, value: number, options: Float32Options ): float32ndarray;
294294

295+
/**
296+
* Converts a scalar value to a zero-dimensional ndarray having the same data type as a provided ndarray.
297+
*
298+
* @param x - input ndarray
299+
* @param value - scalar value
300+
* @param options - function options
301+
* @returns zero-dimensional ndarray
302+
*
303+
* @example
304+
* var getShape = require( '@stdlib/ndarray/shape' );
305+
* var getDType = require( '@stdlib/ndarray/dtype' );
306+
* var empty = require( '@stdlib/ndarray/empty' );
307+
*
308+
* var x = empty( [ 2 ], {
309+
* 'dtype': 'float16'
310+
* });
311+
* // returns <ndarray>
312+
*
313+
* var out = scalar2ndarrayLike( x, 1.0 );
314+
* // returns <ndarray>[ 1.0 ]
315+
*
316+
* var sh = getShape( out );
317+
* // returns []
318+
*
319+
* var dt = String( getDType( out ) );
320+
* // returns 'float16'
321+
*/
322+
declare function scalar2ndarrayLike( x: float16ndarray, value: number, options?: BaseOptions ): float16ndarray;
323+
324+
/**
325+
* Converts a scalar value to a zero-dimensional ndarray having the same data type as a provided ndarray.
326+
*
327+
* @param x - input ndarray
328+
* @param value - scalar value
329+
* @param options - function options
330+
* @returns zero-dimensional ndarray
331+
*
332+
* @example
333+
* var getShape = require( '@stdlib/ndarray/shape' );
334+
* var getDType = require( '@stdlib/ndarray/dtype' );
335+
* var empty = require( '@stdlib/ndarray/empty' );
336+
*
337+
* var x = empty( [ 2 ] );
338+
* // returns <ndarray>
339+
*
340+
* var out = scalar2ndarrayLike( x, 1.0, {
341+
* 'dtype': 'float16'
342+
* });
343+
* // returns <ndarray>[ 1.0 ]
344+
*
345+
* var sh = getShape( out );
346+
* // returns []
347+
*
348+
* var dt = String( getDType( out ) );
349+
* // returns 'float16'
350+
*/
351+
declare function scalar2ndarrayLike( x: ndarray, value: number, options: Float16Options ): float16ndarray;
352+
295353
/**
296354
* Converts a scalar value to a zero-dimensional ndarray having the same data type as a provided ndarray.
297355
*

‎from-scalar-like/docs/types/test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import scalar2ndarrayLike = require( './index' );
3434

3535
scalar2ndarrayLike( x, 1.0, { 'dtype': 'float64' } ); // $ExpectType float64ndarray
3636
scalar2ndarrayLike( x, 1.0, { 'dtype': 'float32' } ); // $ExpectType float32ndarray
37+
scalar2ndarrayLike( x, 1.0, { 'dtype': 'float16' } ); // $ExpectType float16ndarray
3738
scalar2ndarrayLike( x, 1.0, { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray
3839
scalar2ndarrayLike( x, 1.0, { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray
3940
scalar2ndarrayLike( x, true, { 'dtype': 'bool' } ); // $ExpectType boolndarray

‎from-scalar-like/test/test.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var tape = require( 'tape' );
2424
var Float64Array = require( '@stdlib/array/float64' );
2525
var Float32Array = require( '@stdlib/array/float32' );
26+
var Float16Array = require( '@stdlib/array/float16' );
2627
var Int32Array = require( '@stdlib/array/int32' );
2728
var Uint32Array = require( '@stdlib/array/uint32' );
2829
var Int16Array = require( '@stdlib/array/int16' );
@@ -414,6 +415,29 @@ tape( 'the function returns a zero-dimensional ndarray (dtype=float32)', functio
414415
t.end();
415416
});
416417

418+
tape( 'the function returns a zero-dimensional ndarray (dtype=float16)', function test( t ) {
419+
var expected;
420+
var arr;
421+
var x;
422+
423+
x = empty( [ 2 ] );
424+
425+
arr = scalar2ndarrayLike( x, 1.0, {
426+
'dtype': 'float16'
427+
});
428+
expected = new Float16Array( [ 1.0 ] );
429+
430+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
431+
t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' );
432+
t.deepEqual( getShape( arr ), [], 'returns expected value' );
433+
t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' );
434+
t.deepEqual( getData( arr ), expected, 'returns expected value' );
435+
t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' );
436+
t.strictEqual( numel( arr ), 1, 'returns expected value' );
437+
438+
t.end();
439+
});
440+
417441
tape( 'the function returns a zero-dimensional ndarray (dtype=int32)', function test( t ) {
418442
var expected;
419443
var arr;

0 commit comments

Comments
 (0)