Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/node_modules/@stdlib/array/typed-real/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The function recognizes the following data types:

- `float64`: double-precision floating-point numbers (IEEE 754)
- `float32`: single-precision floating-point numbers (IEEE 754)
- `float16`: half-precision floating-point numbers (IEEE 754)
- `int32`: 32-bit two's complement signed integers
- `uint32`: 32-bit unsigned integers
- `int16`: 16-bit two's complement signed integers
Expand Down
18 changes: 18 additions & 0 deletions lib/node_modules/@stdlib/array/typed-real/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ bench( format( '%s:dtype=%s', pkg, 'float32' ), function benchmark( b ) {
b.end();
});

bench( format( '%s:dtype=%s', pkg, 'float16' ), function benchmark( b ) {
var arr;
var i;
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = realarray( 0, 'float16' );
if ( arr.length !== 0 ) {
b.fail( 'should have length 0' );
}
}
b.toc();
if ( !isTypedArray( arr ) ) {
b.fail( 'should return a typed array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:dtype=%s', pkg, 'int32' ), function benchmark( b ) {
var arr;
var i;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var isTypedArray = require( '@stdlib/assert/is-typed-array' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var realarray = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var arr;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = realarray( len, 'float16' );
if ( arr.length !== len ) {
b.fail( 'unexpected length' );
}
}
b.toc();
if ( !isTypedArray( arr ) ) {
b.fail( 'should return a typed array' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:dtype=%s,len=%d', pkg, 'float16', len ), f );
}
}

main();
1 change: 1 addition & 0 deletions lib/node_modules/@stdlib/array/typed-real/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- float64: double-precision floating-point numbers (IEEE 754).
- float32: single-precision floating-point numbers (IEEE 754).
- float16: half-precision floating-point numbers (IEEE 754).
- int32: 32-bit two's complement signed integers.
- uint32: 32-bit unsigned integers.
- int16: 16-bit two's complement signed integers.
Expand Down
4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/array/typed-real/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"matrix",
"float64array",
"float32array",
"float16array",
"int32array",
"uint32array",
"int16array",
Expand All @@ -78,6 +79,9 @@
"float",
"single-precision",
"float32",
"half",
"half-precision",
"float16",
"ieee754",
"integer",
"int32",
Expand Down
68 changes: 68 additions & 0 deletions lib/node_modules/@stdlib/array/typed-real/test/test.js
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 @@ -302,6 +303,13 @@ tape( 'the function returns a typed array (dtype=float32)', function test( t ) {
t.end();
});

tape( 'the function returns a typed array (dtype=float16)', function test( t ) {
var arr = realarray( 'float16' );
t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
t.strictEqual( arr.length, 0, 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32)', function test( t ) {
var arr = realarray( 'int32' );
t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' );
Expand Down Expand Up @@ -372,6 +380,13 @@ tape( 'the function returns a typed array (dtype=float32, length)', function tes
t.end();
});

tape( 'the function returns a typed array (dtype=float16, length)', function test( t ) {
var arr = realarray( 10, 'float16' );
t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' );
t.strictEqual( arr.length, 10, 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) {
var arr = realarray( 10, 'int32' );
t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' );
Expand Down Expand Up @@ -454,6 +469,17 @@ tape( 'the function returns a typed array (dtype=float32, array)', function test
t.end();
});

tape( 'the function returns a typed array (dtype=float16, array)', function test( t ) {
var arr = [ 1.0, 2.0, 3.0 ];
var out = realarray( arr, 'float16' );
t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, 3, 'returns expected value' );
t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' );
t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' );
t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) {
var arr = [ 1.0, 2.0, 3.0 ];
var out = realarray( arr, 'int32' );
Expand Down Expand Up @@ -564,6 +590,17 @@ tape( 'the function returns a typed array (dtype=float32, typed array)', functio
t.end();
});

tape( 'the function returns a typed array (dtype=float16, typed array)', function test( t ) {
var arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] );
var out = realarray( arr, 'float16' );
t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, 3, 'returns expected value' );
t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' );
t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' );
t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) {
var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] );
var out = realarray( arr, 'int32' );
Expand Down Expand Up @@ -669,6 +706,16 @@ tape( 'the function returns a typed array (dtype=float32, arraybuffer)', functio
t.end();
});

tape( 'the function returns a typed array (dtype=float16, arraybuffer)', function test( t ) {
var buf = new ArrayBuffer( 8 );
var out = realarray( buf, 'float16' );
t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, 4, 'returns expected value' );
t.strictEqual( out[ 0 ], 0.0, 'returns expected value' );
t.strictEqual( out[ 1 ], 0.0, 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32, arraybuffer)', function test( t ) {
var buf = new ArrayBuffer( 8 );
var out = realarray( buf, 'int32' );
Expand Down Expand Up @@ -794,6 +841,17 @@ tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffse
t.end();
});

tape( 'the function returns a typed array (dtype=float16, arraybuffer, byteoffset)', function test( t ) {
var buf = new ArrayBuffer( 16 );
var out = realarray( buf, 4, 'float16' );
t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, 6, 'returns expected value' );
t.strictEqual( out[ 0 ], 0.0, 'returns expected value' );
t.strictEqual( out[ 1 ], 0.0, 'returns expected value' );
t.strictEqual( out[ 2 ], 0.0, 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset)', function test( t ) {
var buf = new ArrayBuffer( 16 );
var out = realarray( buf, 4, 'int32' );
Expand Down Expand Up @@ -934,6 +992,16 @@ tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffse
t.end();
});

tape( 'the function returns a typed array (dtype=float16, arraybuffer, byteoffset, length)', function test( t ) {
var buf = new ArrayBuffer( 16 );
var out = realarray( buf, 4, 2, 'float16' );
t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' );
t.strictEqual( out.length, 2, 'returns expected value' );
t.strictEqual( out[ 0 ], 0.0, 'returns expected value' );
t.strictEqual( out[ 1 ], 0.0, 'returns expected value' );
t.end();
});

tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset, length)', function test( t ) {
var buf = new ArrayBuffer( 16 );
var out = realarray( buf, 4, 2, 'int32' );
Expand Down
Loading