diff --git a/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.js index f32c10f2080a..62989c8d7256 100644 --- a/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.js @@ -86,6 +86,24 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { b.end(); }); +bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = filledarray( 0.0, 0, 'float16' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) { var arr; var i; diff --git a/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.length.float16.js b/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.length.float16.js new file mode 100644 index 000000000000..cc696bd3788a --- /dev/null +++ b/lib/node_modules/@stdlib/array/filled/benchmark/benchmark.length.float16.js @@ -0,0 +1,95 @@ +/** +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 filledarray = 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 = filledarray( 1.0, 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=float32,len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/filled/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/filled/docs/types/index.d.ts index 4c16024e5faa..0d794a452af8 100644 --- a/lib/node_modules/@stdlib/array/filled/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/filled/docs/types/index.d.ts @@ -38,6 +38,10 @@ import { IterableIterator } from '@stdlib/types/iter'; * @example * var arr = filledarray( 'float32' ); * // returns +* +* @example +* var arr = filledarray( 'float16' ); +* // returns */ declare function filledarray = 'float64'>( dtype?: U ): DataTypeMap[U]; @@ -56,6 +60,10 @@ declare function filledarray = 'float64' * @example * var arr = filledarray( 1.0, 5, 'float32' ); * // returns [ 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var arr = filledarray( 1.0, 5, 'float16' ); +* // returns [ 1.0, 1.0, 1.0, 1.0, 1.0 ] */ declare function filledarray = 'float64'>( value: T, length: number, dtype?: U ): DataTypeMap[U]; @@ -74,6 +82,10 @@ declare function filledarray = 'float64'>( val * @example * var arr = filledarray( 1.0, [ 5.0, -3.0, 2.0 ], 'float32' ); * // returns [ 1.0, 1.0, 1.0 ] +* +* @example +* var arr = filledarray( 1.0, [ 5.0, -3.0, 2.0 ], 'float16' ); +* // returns [ 1.0, 1.0, 1.0 ] */ declare function filledarray = 'float64'>( value: T, array: Collection, dtype?: U ): DataTypeMap[U]; @@ -102,6 +114,15 @@ declare function filledarray = 'float64'>( val * }); * var arr = filledarray( 1.0, it, 'float32' ); * // returns [ 1.0, 1.0, 1.0 ] +* +* @example +* var iterConstant = require( '@stdlib/iter/constant' ); +* +* var it = iterConstant( 3.0, { +* 'iter': 3 +* }); +* var arr = filledarray( 1.0, it, 'float16' ); +* // returns [ 1.0, 1.0, 1.0 ] */ declare function filledarray = 'float64'>( value: T, iterable: IterableIterator, dtype?: U ): DataTypeMap[U]; @@ -132,6 +153,13 @@ declare function filledarray = 'float64'>( val * var buf = new ArrayBuffer( 32 ); * var arr = filledarray( 1.0, buf, 8, 2, 'float32' ); * // returns [ 1.0, 1.0 ] +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = filledarray( 1.0, buf, 8, 2, 'float16' ); +* // returns [ 1.0, 1.0 ] */ declare function filledarray = 'float64'>( value: T, buffer: ArrayBuffer, byteOffset: number, length: number, dtype?: U ): DataTypeMap[U]; @@ -161,6 +189,13 @@ declare function filledarray = 'float64'>( val * var buf = new ArrayBuffer( 32 ); * var arr = filledarray( 1.0, buf, 8, 'float32' ); * // returns [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 32 ); +* var arr = filledarray( 1.0, buf, 8, 'float16' ); +* // returns [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] */ declare function filledarray = 'float64'>( value: T, buffer: ArrayBuffer, byteOffset: number, dtype?: U ): DataTypeMap[U]; @@ -189,6 +224,13 @@ declare function filledarray = 'float64'>( val * var buf = new ArrayBuffer( 32 ); * var arr = filledarray( 1.0, buf, 'float32' ); * // returns [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] +* +* @example +* var ArrayBuffer = require( '@stdlib/array/buffer' ); +* +* var buf = new ArrayBuffer( 16 ); +* var arr = filledarray( 1.0, buf, 'float16' ); +* // returns [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] */ declare function filledarray = 'float64'>( value: T, buffer: ArrayBuffer, dtype?: U ): DataTypeMap[U]; diff --git a/lib/node_modules/@stdlib/array/filled/lib/index.js b/lib/node_modules/@stdlib/array/filled/lib/index.js index 9fc0dcc0d891..4725af77206f 100644 --- a/lib/node_modules/@stdlib/array/filled/lib/index.js +++ b/lib/node_modules/@stdlib/array/filled/lib/index.js @@ -44,6 +44,12 @@ * @example * var filledarray = require( '@stdlib/array/filled' ); * +* var arr = filledarray( 1.0, 2, 'float16' ); +* // returns [ 1.0, 1.0 ] +* +* @example +* var filledarray = require( '@stdlib/array/filled' ); +* * var arr = filledarray( 1.0, 2, 'generic' ); * // returns [ 1.0, 1.0 ] * diff --git a/lib/node_modules/@stdlib/array/filled/lib/main.js b/lib/node_modules/@stdlib/array/filled/lib/main.js index bd5474cc325c..b1ece8881608 100644 --- a/lib/node_modules/@stdlib/array/filled/lib/main.js +++ b/lib/node_modules/@stdlib/array/filled/lib/main.js @@ -115,6 +115,10 @@ function filledAccessors( arr, value ) { * // returns [ 1.0, 1.0 ] * * @example +* var arr = filledarray( 1.0, 2, 'float16' ); +* // returns [ 1.0, 1.0 ] +* +* @example * var arr = filledarray( 1.0, 2, 'generic' ); * // returns [ 1.0, 1.0 ] * diff --git a/lib/node_modules/@stdlib/array/filled/test/test.js b/lib/node_modules/@stdlib/array/filled/test/test.js index f903eb06133b..6109e40cdc16 100644 --- a/lib/node_modules/@stdlib/array/filled/test/test.js +++ b/lib/node_modules/@stdlib/array/filled/test/test.js @@ -18,12 +18,15 @@ 'use strict'; +/* eslint-disable max-lines */ + // MODULES // var tape = require( 'tape' ); var proxyquire = require( 'proxyquire' ); 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' ); @@ -79,8 +82,10 @@ tape( 'the function throws an error if provided an unrecognized data type (one a 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -114,8 +119,10 @@ tape( 'the function throws an error if provided an unrecognized data type (lengt 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -149,8 +156,10 @@ tape( 'the function throws an error if provided an unrecognized data type (typed 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -184,8 +193,10 @@ tape( 'the function throws an error if provided an unrecognized data type (array 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -219,8 +230,10 @@ tape( 'the function throws an error if provided an unrecognized data type (Array 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -254,8 +267,10 @@ tape( 'the function throws an error if provided an unrecognized data type (Array 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -289,8 +304,10 @@ tape( 'the function throws an error if provided an unrecognized data type (Array 'uint8_clamped', 'Float64', 'Float32', + 'Float16', 'FLOAT64', 'FLOAT32', + 'FLOAT16', 'GENERIC' ]; @@ -742,6 +759,20 @@ tape( 'the function returns a filled array (dtype=float32)', function test( t ) t.end(); }); +tape( 'the function returns a filled array (dtype=float16)', function test( t ) { + var expected; + var arr; + + expected = new Float16Array( 0 ); + + arr = filledarray( 'float16' ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (dtype=bool)', function test( t ) { var expected; var arr; @@ -980,6 +1011,34 @@ tape( 'the function returns a filled array (value=0, dtype=float32, length)', fu t.end(); }); +tape( 'the function returns a filled array (dtype=float16, length)', function test( t ) { + var expected; + var arr; + + expected = new Float16Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + arr = filledarray( 1.0, 5, 'float16' ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a filled array (value=0, dtype=float16, length)', function test( t ) { + var expected; + var arr; + + expected = new Float16Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + arr = filledarray( 0.0, 5, 'float16' ); + t.strictEqual( instanceOf( arr, Float16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (value=false, dtype=bool, length)', function test( t ) { var expected; var arr; @@ -1308,6 +1367,22 @@ tape( 'the function returns a filled array (dtype=float32, array)', function tes t.end(); }); +tape( 'the function returns a filled array (dtype=float16, array)', function test( t ) { + var expected; + var arr; + var out; + + expected = new Float16Array( [ 1.0, 1.0, 1.0 ] ); + + arr = [ 1.0, 2.0, 3.0 ]; + out = filledarray( 1.0, arr, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (dtype=bool, array)', function test( t ) { var expected; var arr; @@ -1540,6 +1615,22 @@ tape( 'the function returns a filled array (dtype=float32, typed array)', functi t.end(); }); +tape( 'the function returns a filled array (dtype=float16, typed array)', function test( t ) { + var expected; + var arr; + var out; + + expected = new Float16Array( [ 1.0, 1.0, 1.0 ] ); + + arr = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + out = filledarray( 1.0, arr, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (dtype=bool, typed array)', function test( t ) { var expected; var arr; @@ -1772,6 +1863,22 @@ tape( 'the function returns a filled typed array (dtype=float32, arraybuffer)', t.end(); }); +tape( 'the function returns a filled typed array (dtype=float16, arraybuffer)', function test( t ) { + var expected; + var buf; + var out; + + expected = new Float16Array( [ 1.0, 1.0 ] ); + + buf = new ArrayBuffer( 8 ); + out = filledarray( 1.0, buf, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled typed array (dtype=bool, arraybuffer)', function test( t ) { var expected; var buf; @@ -1998,6 +2105,22 @@ tape( 'the function returns a filled typed array (dtype=float32, arraybuffer, by t.end(); }); +tape( 'the function returns a filled typed array (dtype=float16, arraybuffer, byteoffset)', function test( t ) { + var expected; + var buf; + var out; + + expected = new Float16Array( [ 1.0, 1.0, 1.0 ] ); + + buf = new ArrayBuffer( 16 ); + out = filledarray( 1.0, buf, 4, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled typed array (dtype=bool, arraybuffer, byteoffset)', function test( t ) { var expected; var buf; @@ -2224,6 +2347,22 @@ tape( 'the function returns a filled typed array (dtype=float32, arraybuffer, by t.end(); }); +tape( 'the function returns a filled typed array (dtype=float16, arraybuffer, byteoffset, length)', function test( t ) { + var expected; + var buf; + var out; + + expected = new Float16Array( [ 1.0, 1.0 ] ); + + buf = new ArrayBuffer( 16 ); + out = filledarray( 1.0, buf, 4, 2, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled typed array (dtype=bool, arraybuffer, byteoffset, length)', function test( t ) { var expected; var buf; @@ -2456,6 +2595,24 @@ tape( 'the function returns a filled array (dtype=float32, iterator)', opts, fun t.end(); }); +tape( 'the function returns a filled array (dtype=float16, iterator)', opts, function test( t ) { + var expected; + var arr; + var out; + + expected = new Float16Array( [ 1.0, 1.0, 1.0 ] ); + + arr = iterConstant( 3.0, { + 'iter': 3 + }); + out = filledarray( 1.0, arr, 'float16' ); + t.strictEqual( instanceOf( out, Float16Array ), true, 'returns expected value' ); + t.strictEqual( out.length, expected.length, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a filled array (dtype=bool, iterator)', opts, function test( t ) { var expected; var arr;