Skip to content

Commit 675a80e

Browse files
committed
Auto-generated commit
1 parent 918d6c2 commit 675a80e

6 files changed

Lines changed: 231 additions & 1 deletion

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+
- [`51a1812`](https://github.com/stdlib-js/stdlib/commit/51a1812de06d6c40a104be53b92515c8e6fb9809) - add float16 dtype support to `ndarray/ones-like` [(#15277)](https://github.com/stdlib-js/stdlib/pull/15277)
1314
- [`f6e94bd`](https://github.com/stdlib-js/stdlib/commit/f6e94bdde9601a2e893feb6c30f6c07a0d97a220) - add float16 dtype support to `ndarray/reject` [(#15278)](https://github.com/stdlib-js/stdlib/pull/15278)
1415
- [`ae93ffd`](https://github.com/stdlib-js/stdlib/commit/ae93ffdb56d57bce3ebbe8564269cff5a461ef03) - add float16 dtype support to `ndarray/zeros-like` [(#15280)](https://github.com/stdlib-js/stdlib/pull/15280)
1516
- [`c278d13`](https://github.com/stdlib-js/stdlib/commit/c278d135f0b97e37321d9c7ff4e65421029670e5) - add float16 dtype support to `ndarray/base/empty` [(#15282)](https://github.com/stdlib-js/stdlib/pull/15282)
@@ -113,6 +114,7 @@ A total of 4 issues were closed in this release:
113114

114115
<details>
115116

117+
- [`51a1812`](https://github.com/stdlib-js/stdlib/commit/51a1812de06d6c40a104be53b92515c8e6fb9809) - **feat:** add float16 dtype support to `ndarray/ones-like` [(#15277)](https://github.com/stdlib-js/stdlib/pull/15277) _(by Samarth Kolarkar)_
116118
- [`f6e94bd`](https://github.com/stdlib-js/stdlib/commit/f6e94bdde9601a2e893feb6c30f6c07a0d97a220) - **feat:** add float16 dtype support to `ndarray/reject` [(#15278)](https://github.com/stdlib-js/stdlib/pull/15278) _(by Samarth Kolarkar)_
117119
- [`ae93ffd`](https://github.com/stdlib-js/stdlib/commit/ae93ffdb56d57bce3ebbe8564269cff5a461ef03) - **feat:** add float16 dtype support to `ndarray/zeros-like` [(#15280)](https://github.com/stdlib-js/stdlib/pull/15280) _(by Samarth Kolarkar)_
118120
- [`c278d13`](https://github.com/stdlib-js/stdlib/commit/c278d135f0b97e37321d9c7ff4e65421029670e5) - **feat:** add float16 dtype support to `ndarray/base/empty` [(#15282)](https://github.com/stdlib-js/stdlib/pull/15282) _(by Samarth Kolarkar)_

ones-like/benchmark/benchmark.js

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

81+
bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) {
82+
var x;
83+
var y;
84+
var i;
85+
86+
x = zeros( [ 0 ], {
87+
'dtype': 'float16'
88+
});
89+
90+
b.tic();
91+
for ( i = 0; i < b.iterations; i++ ) {
92+
y = onesLike( x );
93+
if ( y.length !== 0 ) {
94+
b.fail( 'should have length 0' );
95+
}
96+
}
97+
b.toc();
98+
if ( !isndarrayLike( y ) ) {
99+
b.fail( 'should return an ndarray' );
100+
}
101+
b.pass( 'benchmark finished' );
102+
b.end();
103+
});
104+
81105
bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
82106
var x;
83107
var y;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
26+
var zeros = require( './../../zeros' );
27+
var format = require( '@stdlib/string/format' );
28+
var pkg = require( './../package.json' ).name;
29+
var onesLike = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var x = zeros( [ len ], {
43+
'dtype': 'float16'
44+
});
45+
return benchmark;
46+
47+
/**
48+
* Benchmark function.
49+
*
50+
* @private
51+
* @param {Benchmark} b - benchmark instance
52+
*/
53+
function benchmark( b ) {
54+
var arr;
55+
var i;
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
arr = onesLike( x );
60+
if ( arr.length !== len ) {
61+
b.fail( 'unexpected length' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isndarrayLike( arr ) ) {
66+
b.fail( 'should return an ndarray' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
}
71+
}
72+
73+
74+
// MAIN //
75+
76+
/**
77+
* Main execution sequence.
78+
*
79+
* @private
80+
*/
81+
function main() {
82+
var len;
83+
var min;
84+
var max;
85+
var f;
86+
var i;
87+
88+
min = 1; // 10^min
89+
max = 6; // 10^max
90+
91+
for ( i = min; i <= max; i++ ) {
92+
len = pow( 10, i );
93+
f = createBenchmark( len );
94+
bench( format( '%s:dtype=float16,size=%d', pkg, len ), f );
95+
}
96+
}
97+
98+
main();

ones-like/docs/types/index.d.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/// <reference types="@stdlib/types"/>
2424

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

2828
/**
2929
* Interface describing function options.
@@ -91,6 +91,20 @@ interface Float32Options extends Options {
9191
dtype: Float32DataType;
9292
}
9393

94+
/**
95+
* Interface describing function options.
96+
*/
97+
interface Float16Options extends Options {
98+
/**
99+
* Underlying data type.
100+
*
101+
* ## Notes
102+
*
103+
* - This option overrides the input array's inferred data type.
104+
*/
105+
dtype: Float16DataType;
106+
}
107+
94108
/**
95109
* Interface describing function options.
96110
*/
@@ -407,6 +421,48 @@ declare function onesLike( x: ndarray, options: Float64Options ): float64ndarray
407421
*/
408422
declare function onesLike( x: ndarray, options: Float32Options ): float32ndarray;
409423

424+
/**
425+
* Creates a ones-filled single-precision floating-point array having the same shape as a provided input ndarray.
426+
*
427+
* @param x - input array
428+
* @param options - options
429+
* @param options.dtype - output array data type
430+
* @param options.order - specifies whether the output array is 'row-major' (C-style) or 'column-major' (Fortran-style)
431+
* @param options.shape - output array shape
432+
* @param options.mode - specifies how to handle a linear index which exceeds array dimensions
433+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
434+
* @param options.readonly - boolean indicating whether an array should be read-only
435+
* @returns ones-filled ndarray
436+
*
437+
* @example
438+
* var getShape = require( '@stdlib/ndarray/shape' );
439+
* var getDType = require( '@stdlib/ndarray/dtype' );
440+
* var zeros = require( '@stdlib/ndarray/zeros' );
441+
*
442+
* var x = zeros( [ 2, 2 ], {
443+
* 'dtype': 'float64'
444+
* });
445+
* // returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
446+
*
447+
* var sh = getShape( x );
448+
* // returns [ 2, 2 ]
449+
*
450+
* var dt = String( getDType( x ) );
451+
* // returns 'float64'
452+
*
453+
* var y = onesLike( x, {
454+
* 'dtype': 'float16'
455+
* });
456+
* // returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
457+
*
458+
* sh = getShape( y );
459+
* // returns [ 2, 2 ]
460+
*
461+
* dt = String( getDType( y ) );
462+
* // returns 'float16'
463+
*/
464+
declare function onesLike( x: ndarray, options: Float16Options ): float16ndarray;
465+
410466
/**
411467
* Creates a ones-filled double-precision complex floating-point array having the same shape as a provided input ndarray.
412468
*

ones-like/docs/types/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import onesLike = require( './index' );
2929

3030
onesLike( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray
3131
onesLike( zeros( 'float32', sh, ord ) ); // $ExpectType float32ndarray
32+
onesLike( zeros( 'float16', sh, ord ) ); // $ExpectType float16ndarray
3233
onesLike( zeros( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray
3334
onesLike( zeros( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray
3435
onesLike( zeros( 'int32', sh, ord ) ); // $ExpectType int32ndarray
@@ -43,6 +44,7 @@ import onesLike = require( './index' );
4344

4445
onesLike( zeros( 'float64', sh, ord ), {} ); // $ExpectType float64ndarray
4546
onesLike( zeros( 'float32', sh, ord ), {} ); // $ExpectType float32ndarray
47+
onesLike( zeros( 'float16', sh, ord ), {} ); // $ExpectType float16ndarray
4648
onesLike( zeros( 'complex128', sh, ord ), {} ); // $ExpectType complex128ndarray
4749
onesLike( zeros( 'complex64', sh, ord ), {} ); // $ExpectType complex64ndarray
4850
onesLike( zeros( 'int32', sh, ord ), {} ); // $ExpectType int32ndarray
@@ -57,6 +59,7 @@ import onesLike = require( './index' );
5759

5860
onesLike( zeros( 'float64', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float64ndarray
5961
onesLike( zeros( 'float32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float32ndarray
62+
onesLike( zeros( 'float16', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float16ndarray
6063
onesLike( zeros( 'complex128', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType complex128ndarray
6164
onesLike( zeros( 'complex64', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType complex64ndarray
6265
onesLike( zeros( 'int32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int32ndarray
@@ -71,6 +74,7 @@ import onesLike = require( './index' );
7174

7275
onesLike( zeros( 'float64', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float64ndarray
7376
onesLike( zeros( 'float32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float32ndarray
77+
onesLike( zeros( 'float16', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float16ndarray
7478
onesLike( zeros( 'complex128', sh, ord ), { 'order': 'column-major' } ); // $ExpectType complex128ndarray
7579
onesLike( zeros( 'complex64', sh, ord ), { 'order': 'column-major' } ); // $ExpectType complex64ndarray
7680
onesLike( zeros( 'int32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int32ndarray
@@ -85,6 +89,7 @@ import onesLike = require( './index' );
8589

8690
onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'float64' } ); // $ExpectType float64ndarray
8791
onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'float32' } ); // $ExpectType float32ndarray
92+
onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'float16' } ); // $ExpectType float16ndarray
8893
onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray
8994
onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray
9095
onesLike( zeros( 'generic', sh, ord ), { 'dtype': 'int32' } ); // $ExpectType int32ndarray

ones-like/test/test.js

Lines changed: 45 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' );
@@ -432,6 +433,50 @@ tape( 'the function returns a ones-filled array (dtype=float32, options)', funct
432433
t.end();
433434
});
434435

436+
tape( 'the function returns a ones-filled array (dtype=float16, inferred)', function test( t ) {
437+
var expected;
438+
var arr;
439+
var x;
440+
441+
expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0 ] );
442+
443+
x = zeros( 'float16', [ 2, 2 ], 'row-major' );
444+
arr = onesLike( x );
445+
446+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
447+
t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' );
448+
t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' );
449+
t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' );
450+
t.deepEqual( getData( arr ), expected, 'returns expected value' );
451+
t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' );
452+
453+
t.end();
454+
});
455+
456+
tape( 'the function returns a ones-filled array (dtype=float16, options)', function test( t ) {
457+
var expected;
458+
var arr;
459+
var x;
460+
461+
expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0 ] );
462+
463+
x = zeros( 'generic', [ 4 ], 'row-major' );
464+
arr = onesLike( x, {
465+
'shape': [ 2, 2 ],
466+
'dtype': 'float16',
467+
'order': 'column-major'
468+
});
469+
470+
t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' );
471+
t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' );
472+
t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' );
473+
t.strictEqual( instanceOf( getData( arr ), Float16Array ), true, 'returns expected value' );
474+
t.deepEqual( getData( arr ), expected, 'returns expected value' );
475+
t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' );
476+
477+
t.end();
478+
});
479+
435480
tape( 'the function returns a ones-filled array (dtype=int32, inferred)', function test( t ) {
436481
var expected;
437482
var arr;

0 commit comments

Comments
 (0)