Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 = typedarray( 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, 'complex128' ), 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 typedarray = 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 = typedarray( 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, 'float32', len ), f );
}
}

main();
4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/array/typed/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var ctors = require( '@stdlib/array/typed-ctors' );
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
var reinterpretFloat16 = require( '@stdlib/strided/base/reinterpret-float16' );
Comment thread
kgryte marked this conversation as resolved.
Outdated
var defaults = require( '@stdlib/array/defaults' );
var format = require( '@stdlib/string/format' );

Expand All @@ -35,6 +36,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.default' );
var Complex64Array = ctors( 'complex64' );
var Complex128Array = ctors( 'complex128' );
var BooleanArray = ctors( 'bool' );
var Float16Array = ctors( 'float16' );
Comment thread
kgryte marked this conversation as resolved.
Outdated


// MAIN //
Expand Down Expand Up @@ -151,6 +153,8 @@ function typedarray() {
arg = reinterpret128( arg, 0 );
} else if ( arg instanceof BooleanArray ) {
arg = reinterpretBoolean( arg, 0 );
} else if ( arg instanceof Float16Array ) {
arg = reinterpretFloat16( arg, 0 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works the way you want it to. We reinterpret the other ones because the respect constructors know how to deal with, e.g., interleaved real and imaginary components. In contrast, Float16Array doesn't know how to deal with 16-bit integer words.

Comment thread
kgryte marked this conversation as resolved.
Outdated
}
return new ctor( arg );
}
Expand Down
8 changes: 8 additions & 0 deletions lib/node_modules/@stdlib/array/typed/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 @@ -308,6 +309,13 @@
t.end();
});

tape( 'the function returns a typed array (dtype=float16)', function test( t ) {
Comment thread
kgryte marked this conversation as resolved.
var arr = typedarray( '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=complex128)', function test( t ) {
var arr = typedarray( 'complex128' );
t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' );
Expand Down Expand Up @@ -1203,7 +1211,7 @@
t.strictEqual( out[ 1 ], 0, 'returns expected value' );
t.strictEqual( out[ 2 ], 0, 'returns expected value' );
t.strictEqual( out[ 3 ], 0, 'returns expected value' );
t.strictEqual( out[ 4 ], 0, 'returns expected value' );

Check warning on line 1214 in lib/node_modules/@stdlib/array/typed/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

File has too many lines (1325). Maximum allowed is 1000
t.strictEqual( out[ 5 ], 0, 'returns expected value' );
t.strictEqual( out[ 6 ], 0, 'returns expected value' );
t.strictEqual( out[ 7 ], 0, 'returns expected value' );
Expand Down