diff --git a/lib/node_modules/@stdlib/ndarray/base/ctor/README.md b/lib/node_modules/@stdlib/ndarray/base/ctor/README.md index 9940b8d06872..d6ba74ea1637 100644 --- a/lib/node_modules/@stdlib/ndarray/base/ctor/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/ctor/README.md @@ -163,6 +163,26 @@ var nbytes = arr.BYTES_PER_ELEMENT; // returns 4 ``` +For half-precision floating-point numbers: + +```javascript +var Float16Array = require( '@stdlib/array/float16' ); + +// Specify the array configuration: +var buffer = new Float16Array( [ 1, 2, 3, 4 ] ); +var shape = [ 2, 2 ]; +var order = 'row-major'; +var strides = [ 2, 1 ]; +var offset = 0; + +// Create a new ndarray: +var arr = ndarray( 'float16', buffer, shape, strides, offset, order ); + +// Get the number of bytes per element: +var nbytes = arr.BYTES_PER_ELEMENT; +// returns 2 +``` + If size of each array element is unknown, the property value is `null`. ```javascript diff --git a/lib/node_modules/@stdlib/ndarray/base/ctor/lib/serialize2string.js b/lib/node_modules/@stdlib/ndarray/base/ctor/lib/serialize2string.js index 44d8cf9d3bac..0f48655fcaf6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/ctor/lib/serialize2string.js +++ b/lib/node_modules/@stdlib/ndarray/base/ctor/lib/serialize2string.js @@ -41,6 +41,7 @@ var CTORS = { 'uint16': 'new Uint16Array( [ {{data}} ] )', 'int32': 'new Int32Array( [ {{data}} ] )', 'uint32': 'new Uint32Array( [ {{data}} ] )', + 'float16': 'new Float16Array( [ {{data}} ] )', 'float32': 'new Float32Array( [ {{data}} ] )', 'float64': 'new Float64Array( [ {{data}} ] )', 'generic': '[ {{data}} ]', diff --git a/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js index 202a4bb2e91e..1f91800d8d42 100644 --- a/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js @@ -26,6 +26,7 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); var numel = require( '@stdlib/ndarray/base/numel' ); var zeroTo = require( '@stdlib/array/base/zero-to' ); +var zeros = require( '@stdlib/ndarray/zeros' ); var format = require( '@stdlib/string/format' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var pkg = require( './../package.json' ).name; @@ -97,3 +98,27 @@ bench( format( '%s:order=column-major', pkg ), function benchmark( b ) { b.pass( 'benchmark finished' ); b.end(); }); + +bench( format( '%s:dtype=float16', pkg ), function benchmark( b ) { + var arr; + var out; + var i; + + arr = zeros( [ 10, 10, 10 ], { + 'dtype': 'float16' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = ndarray2string( arr ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts index e6a14d5449ab..44f1f06cac9c 100644 --- a/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts @@ -40,6 +40,17 @@ import { ndarray } from '@stdlib/types/ndarray'; * * var str = ndarray2string( x ); * // returns +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = zeros( [ 2, 2 ], { +* 'dtype': 'float16' +* }); +* // returns +* +* var str = ndarray2string( x ); +* // returns */ declare function ndarray2string( x: ndarray ): string; diff --git a/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js b/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js index 8c8954c9dbf2..27147c47f52a 100644 --- a/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js @@ -32,6 +32,18 @@ * * var str = ndarray2string( x ); * // returns +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var ndarray2string = require( '@stdlib/ndarray/to-string' ); +* +* var x = zeros( [ 2, 2 ], { +* 'dtype': 'float16' +* }); +* // returns +* +* var str = ndarray2string( x ); +* // returns */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js b/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js index 64b378a47a01..c29473eb6d29 100644 --- a/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js @@ -46,6 +46,7 @@ var CTORS = { 'uint16': 'new Uint16Array( [ {{data}} ] )', 'int32': 'new Int32Array( [ {{data}} ] )', 'uint32': 'new Uint32Array( [ {{data}} ] )', + 'float16': 'new Float16Array( [ {{data}} ] )', 'float32': 'new Float32Array( [ {{data}} ] )', 'float64': 'new Float64Array( [ {{data}} ] )', 'generic': '[ {{data}} ]', @@ -122,6 +123,17 @@ function serializeComplexElement( x, sub ) { * * var str = ndarray2string( x ); * // returns +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = zeros( [ 2, 2 ], { +* 'dtype': 'float16' +* }); +* // returns +* +* var str = ndarray2string( x ); +* // returns */ function ndarray2string( x ) { var serialize; diff --git a/lib/node_modules/@stdlib/ndarray/to-string/test/test.js b/lib/node_modules/@stdlib/ndarray/to-string/test/test.js index 1f730c1f4c3f..fd6bcd13d9c5 100644 --- a/lib/node_modules/@stdlib/ndarray/to-string/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/to-string/test/test.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); +var Float16Array = require( '@stdlib/array/float16' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex128Array = require( '@stdlib/array/complex128' ); var BooleanArray = require( '@stdlib/array/bool' ); @@ -94,6 +95,60 @@ tape( 'the function serializes an ndarray as a string (row-major)', function tes t.end(); }); +tape( 'the function serializes an ndarray as a string (dtype=float16, row-major)', function test( t ) { + var expected; + var strides; + var actual; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + expected = 'ndarray( \'float16\', new Float16Array( [ 1, 2, 3, 4 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )'; + actual = ndarray2string( arr ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function serializes an ndarray as a string (dtype=float16, column-major)', function test( t ) { + var expected; + var strides; + var actual; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; + order = 'column-major'; + strides = [ 1, 2 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + expected = 'ndarray( \'float16\', new Float16Array( [ 1, 2, 3, 4 ] ), [ 2, 2 ], [ 1, 2 ], 0, \'column-major\' )'; + actual = ndarray2string( arr ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function serializes an ndarray as a string (row-major, negative strides)', function test( t ) { var expected; var strides;