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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
b.end();
});

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

buf = typedarray( 1, 'float16' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = array2ndarray( buf, 'row-major' );
if ( x.length !== 1 ) {
b.fail( 'should have length 1' );
}
}
b.toc();
if ( !isndarrayLike( x ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
var buf;
var x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

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

import { Collection, AccessorArrayLike, Complex128Array, Complex64Array, BooleanArray } from '@stdlib/types/array';
import { float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, boolndarray, genericndarray, Order } from '@stdlib/types/ndarray';
import { Collection, AccessorArrayLike, Complex128Array, Complex64Array, BooleanArray, Float16Array } from '@stdlib/types/array';
import { float64ndarray, float32ndarray, float16ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, boolndarray, genericndarray, Order } from '@stdlib/types/ndarray';

/**
* Converts an array to a one-dimensional ndarray.
Expand Down Expand Up @@ -65,6 +65,27 @@ declare function array2ndarray( buf: Float64Array, order: Order ): float64ndarra
*/
declare function array2ndarray( buf: Float32Array, order: Order ): float32ndarray;

/**
* Converts an array to a one-dimensional ndarray.
*
* @param buf - input array
* @param order - memory layout (row-major or column-major)
* @returns one-dimensional ndarray
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var Float16Array = require( '@stdlib/array/float16' );
*
* var arr = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] );
*
* var x = array2ndarray( arr, 'row-major' );
* // returns <ndarray>
*
* var dt = String( getDType( x ) );
* // returns 'float16'
*/
declare function array2ndarray( buf: Float16Array, order: Order ): float16ndarray;

/**
* Converts an array to a one-dimensional ndarray.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import array2ndarray = require( './index' );
{
array2ndarray( zeros( 1, 'float64' ), 'row-major' ); // $ExpectType float64ndarray
array2ndarray( zeros( 1, 'float32' ), 'row-major' ); // $ExpectType float32ndarray
array2ndarray( zeros( 1, 'float16' ), 'row-major' ); // $ExpectType float16ndarray
array2ndarray( zeros( 1, 'complex128' ), 'row-major' ); // $ExpectType complex128ndarray
array2ndarray( zeros( 1, 'complex64' ), 'row-major' ); // $ExpectType complex64ndarray
array2ndarray( zeros( 1, 'int32' ), 'row-major' ); // $ExpectType int32ndarray
Expand Down
18 changes: 18 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/from-array/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ tape( 'the function returns a one-dimensional ndarray (dtype=float32)', function
t.end();
});

tape( 'the function returns a one-dimensional ndarray (dtype=float16)', function test( t ) {
var buf;
var arr;

buf = typedarray( 4, 'float16' );
arr = array2ndarray( buf, 'column-major' );

t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' );
t.strictEqual( String( getDType( arr ) ), 'float16', 'returns expected value' );
t.strictEqual( getData( arr ), buf, 'returns expected value' );
t.deepEqual( getShape( arr ), [ buf.length ], 'returns expected value' );
t.deepEqual( getStrides( arr ), [ 1 ], 'returns expected value' );
t.strictEqual( getOffset( arr ), 0, 'returns expected value' );
t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' );

t.end();
});

tape( 'the function returns a one-dimensional ndarray (dtype=int32)', function test( t ) {
var buf;
var arr;
Expand Down
Loading