Skip to content

Commit 641fa20

Browse files
committed
refactor: implementation
1 parent 004f5b8 commit 641fa20

6 files changed

Lines changed: 2630 additions & 1151 deletions

File tree

lib/node_modules/@stdlib/array/float16/README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# Float16Array
2222

23-
> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of half-precision (16-bit) floating-point numbers in the platform byte order.
23+
> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of half-precision floating-point numbers in the platform byte order.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -38,7 +38,7 @@ limitations under the License.
3838

3939
```javascript
4040
var Float16Array = require( '@stdlib/array/float16' );
41-
41+
```
4242

4343
#### Float16Array()
4444

@@ -96,7 +96,7 @@ Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][@stdlib/arra
9696
```javascript
9797
var ArrayBuffer = require( '@stdlib/array/buffer' );
9898

99-
var buf = new ArrayBuffer( 16 );
99+
var buf = new ArrayBuffer( 8 );
100100
var arr = new Float16Array( buf, 0, 4 );
101101
// returns <Float16Array>[ 0.0, 0.0, 0.0, 0.0 ]
102102
```
@@ -211,17 +211,13 @@ var len = arr.length;
211211

212212
Creates a new typed array from an array-like `object` or an iterable.
213213

214-
<!-- eslint-disable stdlib/require-globals -->
215-
216214
```javascript
217215
var arr = Float16Array.from( [ 1.0, 2.0 ] );
218216
// returns <Float16Array>[ 1.0, 2.0 ]
219217
```
220218

221219
To invoke a function for each `src` value, provide a callback function.
222220

223-
<!-- eslint-disable stdlib/require-globals -->
224-
225221
```javascript
226222
function mapFcn( v ) {
227223
return v * 2.0;
@@ -238,8 +234,6 @@ A callback function is provided two arguments:
238234

239235
To set the callback execution context, provide a `thisArg`.
240236

241-
<!-- eslint-disable stdlib/require-globals -->
242-
243237
```javascript
244238
function mapFcn( v ) {
245239
this.count += 1;
@@ -263,8 +257,6 @@ var n = ctx.count;
263257

264258
Creates a new typed array from a variable number of arguments.
265259

266-
<!-- eslint-disable stdlib/require-globals -->
267-
268260
```javascript
269261
var arr = Float16Array.of( 1.0, 2.0 );
270262
// returns <Float16Array>[ 1.0, 2.0 ]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
// MAIN //
22+
23+
/**
24+
* Returns an array of iterated values.
25+
*
26+
* @private
27+
* @param {Object} it - iterator
28+
* @returns {Array} output array
29+
*/
30+
function fromIterator( it ) {
31+
var out;
32+
var v;
33+
34+
out = [];
35+
while ( true ) {
36+
v = it.next();
37+
if ( v.done ) {
38+
break;
39+
}
40+
out.push( v.value );
41+
}
42+
return out;
43+
}
44+
45+
46+
// EXPORTS //
47+
48+
module.exports = fromIterator;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
// MAIN //
22+
23+
/**
24+
* Returns an array of iterated values.
25+
*
26+
* @private
27+
* @param {Object} it - iterator
28+
* @param {Function} clbk - callback to invoke for each iterated value
29+
* @param {*} thisArg - invocation context
30+
* @returns {Array} output array
31+
*/
32+
function fromIteratorMap( it, clbk, thisArg ) {
33+
var out;
34+
var v;
35+
var i;
36+
37+
out = [];
38+
i = -1;
39+
while ( true ) {
40+
v = it.next();
41+
if ( v.done ) {
42+
break;
43+
}
44+
i += 1;
45+
out.push( clbk.call( thisArg, v.value, i ) );
46+
}
47+
return out;
48+
}
49+
50+
51+
// EXPORTS //
52+
53+
module.exports = fromIteratorMap;

lib/node_modules/@stdlib/array/float16/lib/index.js

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,76 @@
1919
'use strict';
2020

2121
/**
22-
* Typed array constructor which returns a typed array representing an array of half-precision floating-point numbers in the platform byte order.
22+
* 16-bit floating-point number array constructor.
2323
*
2424
* @module @stdlib/array/float16
2525
*
2626
* @example
27-
* var ctor = require( '@stdlib/array/float16' );
27+
* var Float16Array = require( '@stdlib/array/float16' );
2828
*
29-
* var arr = new ctor( 10 );
29+
* var arr = new Float16Array();
3030
* // returns <Float16Array>
31+
*
32+
* var len = arr.length;
33+
* // returns 0
34+
*
35+
* @example
36+
* var Float16Array = require( '@stdlib/array/float16' );
37+
*
38+
* var arr = new Float16Array( 2 );
39+
* // returns <Float16Array>
40+
*
41+
* var len = arr.length;
42+
* // returns 2
43+
*
44+
* @example
45+
* var Float16Array = require( '@stdlib/array/float16' );
46+
*
47+
* var arr = new Float16Array( [ true, false ] );
48+
* // returns <Float16Array>
49+
*
50+
* var len = arr.length;
51+
* // returns 2
52+
*
53+
* @example
54+
* var ArrayBuffer = require( '@stdlib/array/buffer' );
55+
* var Float16Array = require( '@stdlib/array/float16' );
56+
*
57+
* var buf = new ArrayBuffer( 16 );
58+
* var arr = new Float16Array( buf );
59+
* // returns <Float16Array>
60+
*
61+
* var len = arr.length;
62+
* // returns 8
63+
*
64+
* @example
65+
* var ArrayBuffer = require( '@stdlib/array/buffer' );
66+
* var Float16Array = require( '@stdlib/array/float16' );
67+
*
68+
* var buf = new ArrayBuffer( 16 );
69+
* var arr = new Float16Array( buf, 8 );
70+
* // returns <Float16Array>
71+
*
72+
* var len = arr.length;
73+
* // returns 4
74+
*
75+
* @example
76+
* var ArrayBuffer = require( '@stdlib/array/buffer' );
77+
* var Float16Array = require( '@stdlib/array/float16' );
78+
*
79+
* var buf = new ArrayBuffer( 32 );
80+
* var arr = new Float16Array( buf, 8, 2 );
81+
* // returns <Float16Array>
82+
*
83+
* var len = arr.length;
84+
* // returns 2
3185
*/
3286

3387
// MODULES //
3488

35-
var hasFloat16ArraySupport = require( '@stdlib/assert/has-float16array-support' );
36-
var builtin = require( './main.js' );
37-
var polyfill = require( './polyfill.js' );
38-
39-
40-
// MAIN //
41-
42-
var ctor;
43-
if ( hasFloat16ArraySupport() ) {
44-
ctor = builtin;
45-
} else {
46-
ctor = polyfill;
47-
}
89+
var main = require( './main.js' );
4890

4991

5092
// EXPORTS //
5193

52-
module.exports = ctor;
94+
module.exports = main;

0 commit comments

Comments
 (0)