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
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/array/convert-same/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var bench = require( '@stdlib/bench' );
var isCollection = require( '@stdlib/assert/is-collection' );
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 Int16Array = require( '@stdlib/array/int16' );
var Int8Array = require( '@stdlib/array/int8' );
Expand Down Expand Up @@ -122,6 +123,34 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
b.end();
});

bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) {
var arr;
var out;
var v;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( i );
}
v = new Float16Array( 0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr[ 0 ] += 1;
out = convertArraySame( arr, v );
if ( out.length !== arr.length ) {
b.fail( 'should have expected length' );
}
}
b.toc();
if ( !isCollection( out ) ) {
b.fail( 'should return an array-like object' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) {
var arr;
var out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var isCollection = require( '@stdlib/assert/is-collection' );
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 Int16Array = require( '@stdlib/array/int16' );
var Int8Array = require( '@stdlib/array/int8' );
Expand Down Expand Up @@ -116,6 +117,9 @@ function main() {
f = createBenchmark( len, new Float32Array( 0 ) );
bench( format( '%s:len=%d,dtype=float32', pkg, len ), f );

f = createBenchmark( len, new Float16Array( 0 ) );
bench( format( '%s:len=%d,dtype=float16', pkg, len ), f );

f = createBenchmark( len, new Int32Array( 0 ) );
bench( format( '%s:len=%d,dtype=int32', pkg, len ), f );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function main()
dtypes = [
Float64,
Float32,
Float16,
Int32,
Int16,
Int8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def main():
dtypes = [
"float64",
"float32",
"float16",
"int32",
"int16",
"int8",
Expand All @@ -120,8 +121,7 @@ def main():
n = 1
while n < 1e7:
n *= 10
for i in range(0, len(dtypes)):
dtype = dtypes[i]
for dtype in dtypes:
name = ":len="+str(n)+",dtype="+dtype
setup = "import numpy as np;"
setup += "A = np.ones([1,"+str(n)+"], dtype='float64');"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/// <reference types="@stdlib/types"/>

import { AnyArray, Collection, Complex128Array, Complex64Array, BooleanArray } from '@stdlib/types/array';
import { AnyArray, Collection, Float16Array, Complex128Array, Complex64Array, BooleanArray } from '@stdlib/types/array';

/**
* Converts an array to a `Float64Array`.
Expand Down Expand Up @@ -58,6 +58,24 @@
*/
declare function convertSame( x: Collection, y: Float32Array ): Float32Array;

/**
* Converts an array to a `Float16Array`.
*
* @param x - array to convert
* @param y - array having the desired output data type
* @returns output array
*
* @example
* var Float16Array = require( '@stdlib/array/float16' );
*
* var x = [ 1.0, 2.0, 3.0, 4.0 ];
* var y = new Float16Array( 0 );
*
* var out = convertSame( x, y );
* // returns <Float16Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
declare function convertSame( x: Collection, y: Float16Array ): Float16Array;

/**
* Converts an array to an `Int32Array`.
*
Expand Down Expand Up @@ -254,7 +272,7 @@
* var out = convertSame( x, y );
* // returns [ 1.0, 2.0, 3.0, 4.0 ]
*/
declare function convertSame( x: Collection, y: Array<any> ): Array<any>;

Check warning on line 275 in lib/node_modules/@stdlib/array/convert-same/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

Check warning on line 275 in lib/node_modules/@stdlib/array/convert-same/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* Converts an array to the same data type as a second input array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import Float16Array = require( '@stdlib/array/float16' );
import Complex128Array = require( '@stdlib/array/complex128' );
import Complex64Array = require( '@stdlib/array/complex64' );
import BooleanArray = require( '@stdlib/array/bool' );
Expand All @@ -28,6 +29,7 @@ import convertSame = require( './index' );
{
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Float64Array( 0 ) ); // $ExpectType Float64Array
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Float32Array( 0 ) ); // $ExpectType Float32Array
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Float16Array( 0 ) ); // $ExpectType Float16ArrayFallback
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Int32Array( 0 ) ); // $ExpectType Int32Array
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Int16Array( 0 ) ); // $ExpectType Int16Array
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Int8Array( 0 ) ); // $ExpectType Int8Array
Expand Down
14 changes: 14 additions & 0 deletions lib/node_modules/@stdlib/array/convert-same/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var tape = require( 'tape' );
var dtype = require( '@stdlib/array/dtype' );
var Float64Array = require( '@stdlib/array/float64' );
var Float32Array = require( '@stdlib/array/float32' );
var Float16Array = require( '@stdlib/array/float16' );
var Int16Array = require( '@stdlib/array/int16' );
var Int32Array = require( '@stdlib/array/int32' );
var Int8Array = require( '@stdlib/array/int8' );
Expand All @@ -39,6 +40,7 @@ var BooleanArray = require( '@stdlib/array/bool' );
var isArray = require( '@stdlib/assert/is-array' );
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
var isFloat32Array = require( '@stdlib/assert/is-float32array' );
var isFloat16Array = require( '@stdlib/assert/is-float16array' );
var isInt16Array = require( '@stdlib/assert/is-int16array' );
var isInt32Array = require( '@stdlib/assert/is-int32array' );
var isInt8Array = require( '@stdlib/assert/is-int8array' );
Expand Down Expand Up @@ -156,6 +158,7 @@ tape( 'the function converts an array to the same data type as a second input ar
y = [
new Float64Array( 0 ),
new Float32Array( 0 ),
new Float16Array( 0 ),
[],
new Int16Array( 0 ),
new Int32Array( 0 ),
Expand All @@ -169,6 +172,7 @@ tape( 'the function converts an array to the same data type as a second input ar
expected = [
[ new Float64Array( [ -1.0, 0.0, 1.0 ] ), isFloat64Array ],
[ new Float32Array( [ -1.0, 0.0, 1.0 ] ), isFloat32Array ],
[ new Float16Array( [ -1.0, 0.0, 1.0 ] ), isFloat16Array ],
[ x, isArray ],
[ new Int16Array( [ -1, 0, 1 ] ), isInt16Array ],
[ new Int32Array( [ -1, 0, 1 ] ), isInt32Array ],
Expand Down Expand Up @@ -201,6 +205,7 @@ tape( 'the function converts an array to the same data type as a second input ar
y = [
new Float64Array( 0 ),
new Float32Array( 0 ),
new Float16Array( 0 ),
[],
new Int16Array( 0 ),
new Int32Array( 0 ),
Expand All @@ -219,6 +224,7 @@ tape( 'the function converts an array to the same data type as a second input ar
expected = [
[ new Float64Array( [ -1.0, 0.0, 1.0 ] ), isFloat64Array ],
[ new Float32Array( [ -1.0, 0.0, 1.0 ] ), isFloat32Array ],
[ new Float16Array( [ -1.0, 0.0, 1.0 ] ), isFloat16Array ],
[ [ -1, 0, 1 ], isArray ],
[ new Int16Array( [ -1, 0, 1 ] ), isInt16Array ],
[ new Int32Array( [ -1, 0, 1 ] ), isInt32Array ],
Expand Down Expand Up @@ -354,6 +360,7 @@ tape( 'the function converts an array to the same data type as a second input ar
y = [
new Float64Array( 0 ),
new Float32Array( 0 ),
new Float16Array( 0 ),
new Int16Array( 0 ),
new Int32Array( 0 ),
new Int8Array( 0 ),
Expand All @@ -366,6 +373,7 @@ tape( 'the function converts an array to the same data type as a second input ar
expected = [
[ new Float64Array( [ 1.0, 0.0, 1.0 ] ), isFloat64Array ],
[ new Float32Array( [ 1.0, 0.0, 1.0 ] ), isFloat32Array ],
[ new Float16Array( [ 1.0, 0.0, 1.0 ] ), isFloat16Array ],
[ new Int16Array( [ 1, 0, 1 ] ), isInt16Array ],
[ new Int32Array( [ 1, 0, 1 ] ), isInt32Array ],
[ new Int8Array( [ 1, 0, 1 ] ), isInt8Array ],
Expand Down Expand Up @@ -505,6 +513,7 @@ tape( 'the function converts an array to the same data type as a second input ar
y = [
new Float64Array( 0 ),
new Float32Array( 0 ),
new Float16Array( 0 ),
new Int16Array( 0 ),
new Int32Array( 0 ),
new Int8Array( 0 ),
Expand All @@ -517,6 +526,7 @@ tape( 'the function converts an array to the same data type as a second input ar
expected = [
[ new Float64Array( [ -1.0, 0.0, 1.0, 2.0 ] ), isFloat64Array ],
[ new Float32Array( [ -1.0, 0.0, 1.0, 2.0 ] ), isFloat32Array ],
[ new Float16Array( [ -1.0, 0.0, 1.0, 2.0 ] ), isFloat16Array ],
[ new Int16Array( [ -1, 0, 1, 2 ] ), isInt16Array ],
[ new Int32Array( [ -1, 0, 1, 2 ] ), isInt32Array ],
[ new Int8Array( [ -1, 0, 1, 2 ] ), isInt8Array ],
Expand Down Expand Up @@ -548,6 +558,7 @@ tape( 'the function converts an array to the same data type as a second input ar
y = [
new Float64Array( 0 ),
new Float32Array( 0 ),
new Float16Array( 0 ),
new Int16Array( 0 ),
new Int32Array( 0 ),
new Int8Array( 0 ),
Expand All @@ -560,6 +571,7 @@ tape( 'the function converts an array to the same data type as a second input ar
expected = [
[ new Float64Array( [ -1.0, 0.0, 1.0, 2.0 ] ), isFloat64Array ],
[ new Float32Array( [ -1.0, 0.0, 1.0, 2.0 ] ), isFloat32Array ],
[ new Float16Array( [ -1.0, 0.0, 1.0, 2.0 ] ), isFloat16Array ],
[ new Int16Array( [ -1, 0, 1, 2 ] ), isInt16Array ],
[ new Int32Array( [ -1, 0, 1, 2 ] ), isInt32Array ],
[ new Int8Array( [ -1, 0, 1, 2 ] ), isInt8Array ],
Expand Down Expand Up @@ -712,6 +724,7 @@ tape( 'the function converts an array to the same data type as a second input ar
y = [
new Float64Array( 0 ),
new Float32Array( 0 ),
new Float16Array( 0 ),
[],
new Int16Array( 0 ),
new Int32Array( 0 ),
Expand All @@ -731,6 +744,7 @@ tape( 'the function converts an array to the same data type as a second input ar
expected = [
isFloat64Array,
isFloat32Array,
isFloat16Array,
isArray,
isInt16Array,
isInt32Array,
Expand Down