From e38d0475efff71ec534d0dccdbd42dd0195b9bc5 Mon Sep 17 00:00:00 2001 From: DivyanshuVortex Date: Sun, 20 Sep 2026 01:05:35 +0530 Subject: [PATCH] feat: add float16 dtype support to --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/ctor/README.md | 20 + .../ndarray/base/ctor/lib/serialize2string.js | 1 + .../@stdlib/ndarray/base/ctor/test/test.js | 2176 ++++++++++++++--- 3 files changed, 1898 insertions(+), 299 deletions(-) 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/base/ctor/test/test.js b/lib/node_modules/@stdlib/ndarray/base/ctor/test/test.js index c2a8c631438c..2ff4b825ae00 100644 --- a/lib/node_modules/@stdlib/ndarray/base/ctor/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/ctor/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var proxyquire = require( 'proxyquire' ); var Float64Array = require( '@stdlib/array/float64' ); +var Float16Array = require( '@stdlib/array/float16' ); var Uint8Array = require( '@stdlib/array/uint8' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex128Array = require( '@stdlib/array/complex128' ); @@ -153,6 +154,31 @@ tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of t.end(); }); +tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (typed)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.byteLength ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.byteLength, 2*buffer.length, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (complex typed)', function test( t ) { var strides; var buffer; @@ -203,6 +229,31 @@ tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of t.end(); }); +tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (typed; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.byteLength ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.byteLength, 2*buffer.length, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (complex typed; 0d)', function test( t ) { var strides; var buffer; @@ -301,6 +352,31 @@ tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in byt t.end(); }); +tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (typed)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( isPositiveInteger( arr.BYTES_PER_ELEMENT ), true, 'is a positive integer' ); + t.strictEqual( arr.BYTES_PER_ELEMENT, 2, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (complex typed)', function test( t ) { var strides; var buffer; @@ -351,6 +427,31 @@ tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in byt t.end(); }); +tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (typed; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( isPositiveInteger( arr.BYTES_PER_ELEMENT ), true, 'is a positive integer' ); + t.strictEqual( arr.BYTES_PER_ELEMENT, 2, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (complex typed; 0d)', function test( t ) { var strides; var buffer; @@ -448,6 +549,30 @@ tape( 'an ndarray has a `data` property pointing to the underlying data buffer', t.end(); }); +tape( 'an ndarray has a `data` property pointing to the underlying data buffer', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'data' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'data' ), true, 'has property' ); + t.strictEqual( arr.data, buffer, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `data` property pointing to the underlying data buffer (complex typed)', function test( t ) { var strides; var buffer; @@ -496,6 +621,30 @@ tape( 'an ndarray has a `data` property pointing to the underlying data buffer ( t.end(); }); +tape( 'an ndarray has a `data` property pointing to the underlying data buffer (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'data' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'data' ), true, 'has property' ); + t.strictEqual( arr.data, buffer, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `dtype` property specifying the underlying data type', function test( t ) { var strides; var buffer; @@ -520,6 +669,30 @@ tape( 'an ndarray has a `dtype` property specifying the underlying data type', f t.end(); }); +tape( 'an ndarray has a `dtype` property specifying the underlying data type', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'dtype' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'dtype' ), true, 'has property' ); + t.strictEqual( arr.dtype, dtype, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `dtype` property specifying the underlying data type (complex typed)', function test( t ) { var strides; var buffer; @@ -568,6 +741,30 @@ tape( 'an ndarray has a `dtype` property specifying the underlying data type (0d t.end(); }); +tape( 'an ndarray has a `dtype` property specifying the underlying data type (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'dtype' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'dtype' ), true, 'has property' ); + t.strictEqual( arr.dtype, dtype, 'has expected value' ); + t.end(); +}); + tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major contiguous)', function test( t ) { var strides; var buffer; @@ -599,7 +796,7 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.end(); }); -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (column-major contiguous)', function test( t ) { +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major contiguous)', function test( t ) { var strides; var buffer; var offset; @@ -608,11 +805,11 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -622,15 +819,15 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, false, 'has expected value' ); t.end(); }); -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous)', function test( t ) { +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (column-major contiguous)', function test( t ) { var strides; var buffer; var offset; @@ -641,9 +838,9 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf dtype = 'float64'; buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; + shape = [ 2, 2 ]; + order = 'column-major'; + strides = [ 1, 2 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -653,7 +850,7 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); @@ -661,7 +858,7 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.end(); }); -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous; 0d)', function test( t ) { +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (column-major contiguous)', function test( t ) { var strides; var buffer; var offset; @@ -670,11 +867,11 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; + 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 ); @@ -684,7 +881,7 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); @@ -692,7 +889,7 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.end(); }); -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout the array (neither row-major nor column-major contiguous)', function test( t ) { +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous)', function test( t ) { var strides; var buffer; var offset; @@ -702,10 +899,10 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - shape = [ 2, 2, 2 ]; - order = 'column-major'; - strides = [ 4, 1, 2 ]; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 4 ]; + order = 'row-major'; + strides = [ 1 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -715,15 +912,15 @@ tape( 'an ndarray has a `flags` property providing meta information, such as inf t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, false, 'has expected value' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); t.end(); }); -tape( 'an ndarray has a `length` property specifying the number of array elements', function test( t ) { +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous)', function test( t ) { var strides; var buffer; var offset; @@ -732,23 +929,29 @@ tape( 'an ndarray has a `length` property specifying the number of array element var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 4 ]; order = 'row-major'; - strides = [ 2, 1 ]; + strides = [ 1 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.length, buffer.length, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); + t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); + + t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); + + t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); + t.end(); }); -tape( 'an ndarray has a `length` property specifying the number of array elements (complex typed)', function test( t ) { +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous; 0d)', function test( t ) { var strides; var buffer; var offset; @@ -757,11 +960,235 @@ tape( 'an ndarray has a `length` property specifying the number of array element var shape; var arr; - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; order = 'row-major'; - strides = [ 2, 1 ]; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); + t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); + + t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); + + t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); + + t.end(); +}); + +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); + t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); + + t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); + + t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); + + t.end(); +}); + +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout the array (neither row-major nor column-major contiguous)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); + shape = [ 2, 2, 2 ]; + order = 'column-major'; + strides = [ 4, 1, 2 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); + t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); + + t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); + + t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, false, 'has expected value' ); + + t.end(); +}); + +tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout the array (neither row-major nor column-major contiguous)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); + shape = [ 2, 2, 2 ]; + order = 'column-major'; + strides = [ 4, 1, 2 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); + t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); + + t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); + + t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); + t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, false, 'has expected value' ); + + t.end(); +}); + +tape( 'an ndarray has a `length` property specifying the number of array elements', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 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 ); + + t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.length, buffer.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `length` property specifying the number of array elements', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.length, buffer.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `length` property specifying the number of array elements (complex typed)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'complex64'; + buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.length, buffer.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `length` property specifying the number of array elements (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.length, buffer.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `length` property specifying the number of array elements (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -773,7 +1200,597 @@ tape( 'an ndarray has a `length` property specifying the number of array element t.end(); }); -tape( 'an ndarray has a `length` property specifying the number of array elements (0d)', function test( t ) { +tape( 'an ndarray has an `ndims` property specifying the number of array dimensions', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 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 ); + + t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); + t.strictEqual( isPositiveInteger( arr.ndims ), true, 'is a positive integer' ); + t.strictEqual( arr.ndims, shape.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `ndims` property specifying the number of array dimensions', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); + t.strictEqual( isPositiveInteger( arr.ndims ), true, 'is a positive integer' ); + t.strictEqual( arr.ndims, shape.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `ndims` property specifying the number of array dimensions (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); + t.strictEqual( arr.ndims, shape.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `ndims` property specifying the number of array dimensions (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); + t.strictEqual( arr.ndims, shape.length, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `offset` property specifying the location of the first indexed element', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.offset, offset, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `offset` property specifying the location of the first indexed element', function test( t ) { + var strides; + 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, 5.0, 6.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.offset, offset, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (complex typed)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'complex64'; + buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.offset, offset, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.offset, offset, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); + t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); + t.strictEqual( arr.offset, offset, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (row-major)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 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 ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (row-major)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (row-major; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (row-major; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (column-major)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 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 ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (column-major)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (column-major; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; + order = 'column-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has an `order` property specifying the array order (column-major; 0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'column-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); + t.strictEqual( arr.order, order, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `shape` property specifying the array shape (dimensions)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 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 ); + + t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); + t.notEqual( arr.shape, shape, 'returns a copy' ); + t.deepEqual( arr.shape, shape, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `shape` property specifying the array shape (dimensions)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); + t.notEqual( arr.shape, shape, 'returns a copy' ); + t.deepEqual( arr.shape, shape, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `shape` property specifying the array shape (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; + order = 'column-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); + t.notEqual( arr.shape, shape, 'returns a copy' ); + t.deepEqual( arr.shape, shape, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `shape` property specifying the array shape (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); + shape = []; + order = 'column-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); + t.notEqual( arr.shape, shape, 'returns a copy' ); + t.deepEqual( arr.shape, shape, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 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 ); + + t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); + t.notEqual( arr.strides, strides, 'returns a copy' ); + t.deepEqual( arr.strides, strides, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); + t.notEqual( arr.strides, strides, 'returns a copy' ); + t.deepEqual( arr.strides, strides, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions (0d)', function test( t ) { + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + + dtype = 'float64'; + buffer = new Float64Array( [ 1.0 ] ); + shape = []; + order = 'column-major'; + strides = [ 0 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); + t.notEqual( arr.strides, strides, 'returns a copy' ); + t.deepEqual( arr.strides, strides, 'has expected value' ); + t.end(); +}); + +tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions (0d)', function test( t ) { var strides; var buffer; var offset; @@ -782,23 +1799,23 @@ tape( 'an ndarray has a `length` property specifying the number of array element var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0 ] ); shape = []; - order = 'row-major'; + order = 'column-major'; strides = [ 0 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.length, buffer.length, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); + t.notEqual( arr.strides, strides, 'returns a copy' ); + t.deepEqual( arr.strides, strides, 'has expected value' ); t.end(); }); -tape( 'an ndarray has an `ndims` property specifying the number of array dimensions', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -816,14 +1833,19 @@ tape( 'an ndarray has an `ndims` property specifying the number of array dimensi arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); - t.strictEqual( isPositiveInteger( arr.ndims ), true, 'is a positive integer' ); - t.strictEqual( arr.ndims, shape.length, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `ndims` property specifying the number of array dimensions (0d)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -832,22 +1854,28 @@ tape( 'an ndarray has an `ndims` property specifying the number of array dimensi var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 0 ]; + strides = [ 2, 1 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); - t.strictEqual( arr.ndims, shape.length, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `offset` property specifying the location of the first indexed element', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -857,22 +1885,27 @@ tape( 'an ndarray has an `offset` property specifying the location of the first var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; + strides = [ 2, -1 ]; + offset = 1; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.offset, offset, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (complex typed)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -881,23 +1914,28 @@ tape( 'an ndarray has an `offset` property specifying the location of the first var shape; var arr; - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; + strides = [ 2, -1 ]; + offset = 1; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.offset, offset, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (0d)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -907,22 +1945,27 @@ tape( 'an ndarray has an `offset` property specifying the location of the first var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = []; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 0 ]; + strides = [ -2, 1 ]; offset = 2; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.offset, offset, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `order` property specifying the array order (row-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -931,22 +1974,28 @@ tape( 'an ndarray has an `order` property specifying the array order (row-major) var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; + strides = [ -2, 1 ]; + offset = 2; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `order` property specifying the array order (row-major; 0d)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -956,21 +2005,27 @@ tape( 'an ndarray has an `order` property specifying the array order (row-major; var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 0 ]; - offset = 0; + strides = [ -2, -1 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `order` property specifying the array order (column-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -979,22 +2034,28 @@ tape( 'an ndarray has an `order` property specifying the array order (column-maj var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; + order = 'row-major'; + strides = [ -2, -1 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has an `order` property specifying the array order (column-major; 0d)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major; complex dtype)', function test( t ) { var strides; var buffer; var offset; @@ -1002,23 +2063,38 @@ tape( 'an ndarray has an `order` property specifying the array order (column-maj var order; var shape; var arr; + var v; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'column-major'; - strides = [ 0 ]; + dtype = 'complex64'; + buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + v = arr.get( 0, 0 ); + t.strictEqual( real( v ), 1.0, 'returns expected value' ); + t.strictEqual( imag( v ), 2.0, 'returns expected value' ); + v = arr.get( 0, 1 ); + t.strictEqual( real( v ), 3.0, 'returns expected value' ); + t.strictEqual( imag( v ), 4.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( real( v ), 5.0, 'returns expected value' ); + t.strictEqual( imag( v ), 6.0, 'returns expected value' ); + v = arr.get( 1, 1 ); + t.strictEqual( real( v ), 7.0, 'returns expected value' ); + t.strictEqual( imag( v ), 8.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has a `shape` property specifying the array shape (dimensions)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1036,14 +2112,19 @@ tape( 'an ndarray has a `shape` property specifying the array shape (dimensions) arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); - t.notEqual( arr.shape, shape, 'returns a copy' ); - t.deepEqual( arr.shape, shape, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has a `shape` property specifying the array shape (0d)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1052,23 +2133,28 @@ tape( 'an ndarray has a `shape` property specifying the array shape (0d)', funct var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; order = 'column-major'; - strides = [ 0 ]; + strides = [ 1, 2 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); - t.notEqual( arr.shape, shape, 'returns a copy' ); - t.deepEqual( arr.shape, shape, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1081,19 +2167,24 @@ tape( 'an ndarray has a `strides` property specifying how to access array elemen buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; + strides = [ -1, 2 ]; + offset = 1; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); - arr = ndarray( dtype, buffer, shape, strides, offset, order ); + t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); - t.notEqual( arr.strides, strides, 'returns a copy' ); - t.deepEqual( arr.strides, strides, 'has expected value' ); t.end(); }); -tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions (0d)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1102,23 +2193,28 @@ tape( 'an ndarray has a `strides` property specifying how to access array elemen var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; order = 'column-major'; - strides = [ 0 ]; - offset = 0; + strides = [ -1, 2 ]; + offset = 1; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); - t.notEqual( arr.strides, strides, 'returns a copy' ); - t.deepEqual( arr.strides, strides, 'has expected value' ); + t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); + t.strictEqual( isFunction( arr.get ), true, 'has method' ); + + t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); + t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1130,9 +2226,9 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc dtype = 'float64'; buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; + order = 'column-major'; + strides = [ 1, -2 ]; + offset = 2; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1140,15 +2236,15 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); t.strictEqual( isFunction( arr.get ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1157,12 +2253,12 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; + order = 'column-major'; + strides = [ 1, -2 ]; + offset = 2; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1170,15 +2266,15 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); t.strictEqual( isFunction( arr.get ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1190,9 +2286,9 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc dtype = 'float64'; buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; + order = 'column-major'; + strides = [ -1, -2 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1200,15 +2296,15 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); t.strictEqual( isFunction( arr.get ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { var strides; var buffer; var offset; @@ -1217,11 +2313,11 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; + order = 'column-major'; + strides = [ -1, -2 ]; offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1231,14 +2327,14 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( isFunction( arr.get ), true, 'has method' ); t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major; complex dtype)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major; complex dtype)', function test( t ) { var strides; var buffer; var offset; @@ -1251,8 +2347,8 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc dtype = 'complex64'; buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; + order = 'column-major'; + strides = [ 1, 2 ]; offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1265,11 +2361,11 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( real( v ), 1.0, 'returns expected value' ); t.strictEqual( imag( v ), 2.0, 'returns expected value' ); v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.get( 1, 0 ); t.strictEqual( real( v ), 5.0, 'returns expected value' ); t.strictEqual( imag( v ), 6.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( real( v ), 3.0, 'returns expected value' ); + t.strictEqual( imag( v ), 4.0, 'returns expected value' ); v = arr.get( 1, 1 ); t.strictEqual( real( v ), 7.0, 'returns expected value' ); t.strictEqual( imag( v ), 8.0, 'returns expected value' ); @@ -1277,7 +2373,7 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (0d)', function test( t ) { var strides; var buffer; var offset; @@ -1287,11 +2383,11 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1299,15 +2395,12 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); t.strictEqual( isFunction( arr.get ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.get(), 4.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { +tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (0d)', function test( t ) { var strides; var buffer; var offset; @@ -1316,12 +2409,12 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1329,15 +2422,12 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); t.strictEqual( isFunction( arr.get ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.get(), 4.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -1349,25 +2439,55 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc dtype = 'float64'; buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -1379,25 +2499,25 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc dtype = 'float64'; buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; + order = 'row-major'; + strides = [ 2, -1 ]; + offset = 1; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 3.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major; complex dtype)', function test( t ) { +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -1405,38 +2525,29 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc var order; var shape; var arr; - var v; - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; + order = 'row-major'; + strides = [ 2, -1 ]; + offset = 1; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - v = arr.get( 0, 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.get( 1, 0 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.get( 1, 1 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 3.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (0d)', function test( t ) { +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { var strides; var buffer; var offset; @@ -1446,19 +2557,22 @@ tape( 'an ndarray has a `get` method for retrieving an array element using subsc var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - shape = []; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 0 ]; - offset = 3; + strides = [ -2, 1 ]; + offset = 2; arr = ndarray( dtype, buffer, shape, strides, offset, order ); - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.get(), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 2.0, 'returns expected value' ); t.end(); }); @@ -1472,12 +2586,12 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; + strides = [ -2, 1 ]; + offset = 2; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1485,10 +2599,10 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 2.0, 'returns expected value' ); t.end(); }); @@ -1506,8 +2620,8 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; + strides = [ -2, -1 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1515,10 +2629,10 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.iget( 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 1.0, 'returns expected value' ); t.end(); }); @@ -1532,12 +2646,12 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; + strides = [ -2, -1 ]; + offset = 3; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1545,15 +2659,15 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.iget( 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 1.0, 'returns expected value' ); t.end(); }); -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major; noncontiguous)', function test( t ) { var strides; var buffer; var offset; @@ -1563,11 +2677,11 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l var arr; dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2, 1 ]; order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; + strides = [ 4, 1, 1 ]; + offset = 0; arr = ndarray( dtype, buffer, shape, strides, offset, order ); @@ -1575,10 +2689,10 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - t.strictEqual( arr.iget( 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 5.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 6.0, 'returns expected value' ); t.end(); }); @@ -1592,8 +2706,8 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); shape = [ 2, 2, 1 ]; order = 'row-major'; strides = [ 4, 1, 1 ]; @@ -1799,6 +2913,36 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.end(); }); +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { + var strides; + 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 ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); + + t.end(); +}); + tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { var strides; var buffer; @@ -1829,6 +2973,36 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.end(); }); +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { + var strides; + 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 = 1; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget( 0 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 3.0, 'returns expected value' ); + + t.end(); +}); + tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { var strides; var buffer; @@ -1859,6 +3033,36 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.end(); }); +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { + var strides; + 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 = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget( 0 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 2.0, 'returns expected value' ); + + t.end(); +}); + tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { var strides; var buffer; @@ -1889,6 +3093,36 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.end(); }); +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { + var strides; + 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 = 3; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget( 0 ), 4.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 3.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 1.0, 'returns expected value' ); + + t.end(); +}); + tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; noncontiguous)', function test( t ) { var strides; var buffer; @@ -1919,6 +3153,36 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.end(); }); +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; noncontiguous)', function test( t ) { + var strides; + 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, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2, 1 ]; + order = 'column-major'; + strides = [ 1, 4, 8 ]; + offset = 0; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); + t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); + t.strictEqual( arr.iget( 2 ), 5.0, 'returns expected value' ); + t.strictEqual( arr.iget( 3 ), 6.0, 'returns expected value' ); + + t.end(); +}); + tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; complex type)', function test( t ) { var strides; var buffer; @@ -2102,6 +3366,33 @@ tape( 'an ndarray has an `iget` method for retrieving an array element using a l t.end(); }); +tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (0d)', function test( t ) { + var strides; + 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, 5.0 ] ); + shape = []; + order = 'row-major'; + strides = [ 0 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); + t.strictEqual( isFunction( arr.iget ), true, 'has method' ); + + t.strictEqual( arr.iget(), 3.0, 'returns expected value' ); + + t.end(); +}); + tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (0d; complex type)', function test( t ) { var strides; var buffer; @@ -4112,8 +5403,49 @@ tape( 'an ndarray has a custom `toJSON()` method (row-major)', function test( t var shape; var arr; - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + dtype = 'float64'; + buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, 'toJSON' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, 'toJSON' ), true, 'has property' ); + t.strictEqual( isFunction( arr.toJSON ), true, 'has method' ); + + expected = { + 'type': 'ndarray', + 'dtype': 'float64', + 'data': [ 3.0, 4.0, 5.0, 6.0 ], + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'order': 'row-major', + 'flags': { + 'READONLY': false + } + }; + actual = arr.toJSON(); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'an ndarray has a custom `toJSON()` method (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, 5.0, 6.0, 7.0, 8.0 ] ); shape = [ 2, 2 ]; order = 'row-major'; strides = [ 2, 1 ]; @@ -4127,7 +5459,7 @@ tape( 'an ndarray has a custom `toJSON()` method (row-major)', function test( t expected = { 'type': 'ndarray', - 'dtype': 'float64', + 'dtype': 'float16', 'data': [ 3.0, 4.0, 5.0, 6.0 ], 'shape': [ 2, 2 ], 'strides': [ 2, 1 ], @@ -4408,6 +5740,87 @@ tape( 'an ndarray has a protocol method for serializing meta data to a DataView' /* eslint-enable no-underscore-dangle */ }); +tape( 'an ndarray has a protocol method for serializing meta data to a DataView', function test( t ) { + /* eslint-disable no-underscore-dangle */ + var expected; + var strides; + var actual; + var buffer; + var offset; + var dtype; + var order; + var shape; + var bytes; + var arr; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, '__array_meta_dataview__' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, '__array_meta_dataview__' ), true, 'has property' ); + t.strictEqual( isFunction( arr.__array_meta_dataview__ ), true, 'has method' ); + + expected = { + 'dtype': DTYPES[ 'float16' ], + 'ndims': shape.length, + 'shape': shape, + 'strides': strides, + 'offset': offset, + 'order': ORDERS[ 'row-major' ], + 'mode': MODES[ 'throw' ], + 'nsubmodes': 1, + 'submodes': [ MODES[ 'throw' ] ], + 'flags': 0 + }; + + arr.__meta_dataview__ = null; + actual = arr.__array_meta_dataview__(); + arr.__meta_dataview__ = null; + + t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); + t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); + + bytes = new Uint8Array( actual.buffer ); + if ( IS_LITTLE_ENDIAN ) { + t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); + t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); + t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); + t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); + t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); + t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); + t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); + t.strictEqual( bytes[ 43 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); + t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); + t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); + t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); + t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); + t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); + } else { + t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); + t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); + t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); + t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); + t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); + t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); + t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); + t.strictEqual( bytes[ 50 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); + t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); + t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); + t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); + t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); + t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); + } + t.end(); + + /* eslint-enable no-underscore-dangle */ +}); + tape( 'an ndarray has a protocol method for serializing meta data to a DataView (no BigInt support)', function test( t ) { /* eslint-disable no-underscore-dangle */ var expected; @@ -4498,6 +5911,96 @@ tape( 'an ndarray has a protocol method for serializing meta data to a DataView /* eslint-enable no-underscore-dangle */ }); +tape( 'an ndarray has a protocol method for serializing meta data to a DataView (no BigInt support)', function test( t ) { + /* eslint-disable no-underscore-dangle */ + var expected; + var strides; + var ndarray; + var actual; + var buffer; + var offset; + var dtype; + var order; + var shape; + var bytes; + var arr; + + ndarray = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-bigint-support': hasSupport + }); + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + t.strictEqual( hasOwnProp( arr, '__array_meta_dataview__' ), false, 'does not have own property' ); + t.strictEqual( hasProp( arr, '__array_meta_dataview__' ), true, 'has property' ); + t.strictEqual( isFunction( arr.__array_meta_dataview__ ), true, 'has method' ); + + expected = { + 'dtype': DTYPES[ 'float16' ], + 'ndims': shape.length, + 'shape': shape, + 'strides': strides, + 'offset': offset, + 'order': ORDERS[ 'row-major' ], + 'mode': MODES[ 'throw' ], + 'nsubmodes': 1, + 'submodes': [ MODES[ 'throw' ] ], + 'flags': 0 + }; + + arr.__meta_dataview__ = null; + actual = arr.__array_meta_dataview__(); + arr.__meta_dataview__ = null; + + t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); + t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); + + bytes = new Uint8Array( actual.buffer ); + if ( IS_LITTLE_ENDIAN ) { + t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); + t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); + t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); + t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); + t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); + t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); + t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); + t.strictEqual( bytes[ 43 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); + t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); + t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); + t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); + t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); + t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); + } else { + t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); + t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); + t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); + t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); + t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); + t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); + t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); + t.strictEqual( bytes[ 50 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); + t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); + t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); + t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); + t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); + t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); + } + t.end(); + + function hasSupport() { + return false; + } + + /* eslint-enable no-underscore-dangle */ +}); + tape( 'an ndarray has a protocol method for serializing meta data to a DataView (cached)', function test( t ) { /* eslint-disable no-underscore-dangle */ var strides; @@ -4531,6 +6034,39 @@ tape( 'an ndarray has a protocol method for serializing meta data to a DataView /* eslint-enable no-underscore-dangle */ }); +tape( 'an ndarray has a protocol method for serializing meta data to a DataView (cached)', function test( t ) { + /* eslint-disable no-underscore-dangle */ + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + var dv1; + var dv2; + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + arr.__meta_dataview__ = null; + dv1 = arr.__array_meta_dataview__(); + dv2 = arr.__array_meta_dataview__(); + arr.__meta_dataview__ = null; + + t.strictEqual( dv1, dv2, 'returns cached meta data' ); + + t.end(); + + /* eslint-enable no-underscore-dangle */ +}); + tape( 'an ndarray has a protocol method for serializing meta data to a DataView (cached)', function test( t ) { /* eslint-disable no-underscore-dangle */ var ndarray; @@ -4572,3 +6108,45 @@ tape( 'an ndarray has a protocol method for serializing meta data to a DataView /* eslint-enable no-underscore-dangle */ }); + +tape( 'an ndarray has a protocol method for serializing meta data to a DataView (cached)', function test( t ) { + /* eslint-disable no-underscore-dangle */ + var ndarray; + var strides; + var buffer; + var offset; + var dtype; + var order; + var shape; + var arr; + var dv1; + var dv2; + + ndarray = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-bigint-support': hasSupport + }); + + dtype = 'float16'; + buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + shape = [ 2, 2 ]; + order = 'row-major'; + strides = [ 2, 1 ]; + offset = 2; + + arr = ndarray( dtype, buffer, shape, strides, offset, order ); + + arr.__meta_dataview__ = null; + dv1 = arr.__array_meta_dataview__(); + dv2 = arr.__array_meta_dataview__(); + arr.__meta_dataview__ = null; + + t.strictEqual( dv1, dv2, 'returns cached meta data' ); + + t.end(); + + function hasSupport() { + return false; + } + + /* eslint-enable no-underscore-dangle */ +});