diff --git a/lib/node_modules/@stdlib/ndarray/to-string/README.md b/lib/node_modules/@stdlib/ndarray/to-string/README.md
new file mode 100644
index 000000000000..d332603c73db
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/README.md
@@ -0,0 +1,132 @@
+
+
+# ndarray2string
+
+> Serialize an [ndarray][@stdlib/ndarray/ctor] as a string.
+
+
+
+
+
+
+
+
+
+
+
+## Usage
+
+```javascript
+var ndarray2string = require( '@stdlib/ndarray/to-string' );
+```
+
+#### ndarray2string( x )
+
+Serializes an [ndarray][@stdlib/ndarray/ctor] as a string.
+
+```javascript
+var array = require( '@stdlib/ndarray/array' );
+
+var x = array( [ 1, 2, 3, 4 ], {
+ 'shape': [ 2, 2 ]
+});
+// returns
+
+var str = ndarray2string( x );
+// returns "ndarray( 'float64', new Float64Array( [ 1, 2, 3, 4 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' )"
+```
+
+
+
+
+
+
+
+
+
+## Notes
+
+- The function does **not** serialize data outside of the buffer defined by the [ndarray][@stdlib/ndarray/ctor] view.
+- For ndarrays with more than `100` elements, the function abbreviates the data, showing only the first and last three values.
+
+
+
+
+
+
+
+
+
+## Examples
+
+
+
+```javascript
+var array = require( '@stdlib/ndarray/array' );
+var ndarray2string = require( '@stdlib/ndarray/to-string' );
+
+// Create a 2x3 ndarray:
+var x = array( [ 1, 2, 3, 4, 5, 6 ], {
+ 'shape': [ 2, 3 ],
+ 'dtype': 'generic'
+});
+
+// Serialize the ndarray as a string:
+var str = ndarray2string( x );
+console.log( str );
+// => 'ndarray( \'generic\', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor
+
+
+
+
+
+
+
+
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js
new file mode 100644
index 000000000000..202a4bb2e91e
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/benchmark/benchmark.js
@@ -0,0 +1,99 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var bench = require( '@stdlib/bench' );
+var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
+var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
+var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
+var numel = require( '@stdlib/ndarray/base/numel' );
+var zeroTo = require( '@stdlib/array/base/zero-to' );
+var format = require( '@stdlib/string/format' );
+var ndarray = require( '@stdlib/ndarray/ctor' );
+var pkg = require( './../package.json' ).name;
+var ndarray2string = require( './../lib' );
+
+
+// MAIN //
+
+bench( format( '%s:order=row-major', pkg ), function benchmark( b ) {
+ var strides;
+ var buffer;
+ var offset;
+ var order;
+ var shape;
+ var arr;
+ var out;
+ var i;
+
+ shape = [ 10, 10, 10 ];
+ order = 'row-major';
+ buffer = zeroTo( numel( shape ) );
+ strides = shape2strides( shape, order );
+ offset = strides2offset( shape, strides );
+ arr = ndarray( 'generic', buffer, shape, strides, offset, order );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = ndarray2string( arr );
+ if ( typeof out !== 'string' ) {
+ b.fail( 'should return a string' );
+ }
+ }
+ b.toc();
+ if ( !isString( out ) ) {
+ b.fail( 'should return a string' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
+
+bench( format( '%s:order=column-major', pkg ), function benchmark( b ) {
+ var strides;
+ var buffer;
+ var offset;
+ var order;
+ var shape;
+ var arr;
+ var out;
+ var i;
+
+ shape = [ 10, 10, 10 ];
+ order = 'column-major';
+ buffer = zeroTo( numel( shape ) );
+ strides = shape2strides( shape, order );
+ offset = strides2offset( shape, strides );
+ arr = ndarray( 'generic', buffer, shape, strides, offset, order );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = ndarray2string( arr );
+ if ( typeof out !== 'string' ) {
+ b.fail( 'should return a string' );
+ }
+ }
+ b.toc();
+ if ( !isString( out ) ) {
+ b.fail( 'should return a string' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/to-string/docs/repl.txt
new file mode 100644
index 000000000000..33502d6fbaa9
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/docs/repl.txt
@@ -0,0 +1,26 @@
+
+{{alias}}( x )
+ Serializes an ndarray as a string.
+
+ This function does *not* serialize data outside of the buffer region
+ defined by the ndarray view.
+
+ Parameters
+ ----------
+ x: ndarray
+ Input ndarray.
+
+ Returns
+ -------
+ out: string
+ String representation.
+
+ Examples
+ --------
+ > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );
+ > var out = {{alias}}( arr )
+
+
+ See Also
+ --------
+
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts
new file mode 100644
index 000000000000..34843ec46261
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts
@@ -0,0 +1,49 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+// TypeScript Version: 4.1
+
+///
+
+import { ndarray } from '@stdlib/types/ndarray';
+
+/**
+* Serializes an ndarray as a string.
+*
+* ## Notes
+*
+* - The function does **not** serialize data outside of the buffer region defined by the ndarray view.
+*
+* @param x - input ndarray
+* @returns string representation
+*
+* @example
+* var array = require( `@stdlib/ndarray/array` );
+*
+* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
+* // returns
+*
+* var str = ndarray2string( x );
+* // returns
+*/
+declare function ndarray2string( x: ndarray ): string;
+
+
+// EXPORTS //
+
+export = ndarray2string;
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/to-string/docs/types/test.ts
new file mode 100644
index 000000000000..cfae97466960
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/docs/types/test.ts
@@ -0,0 +1,49 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import array = require( '@stdlib/ndarray/array' );
+import ndarray2string = require( './index' );
+
+
+// TESTS //
+
+// The function returns a string...
+{
+ ndarray2string( array( [ [ 1, 2 ], [ 3, 4 ] ] ) ); // $ExpectType string
+}
+
+// The compiler throws an error if the function is provided a first argument which is not an ndarray...
+{
+ ndarray2string( 10 ); // $ExpectError
+ ndarray2string( '10' ); // $ExpectError
+ ndarray2string( true ); // $ExpectError
+ ndarray2string( false ); // $ExpectError
+ ndarray2string( null ); // $ExpectError
+ ndarray2string( undefined ); // $ExpectError
+ ndarray2string( [ 1, 2 ] ); // $ExpectError
+ ndarray2string( {} ); // $ExpectError
+ ndarray2string( ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an unsupported number of arguments...
+{
+ const arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+
+ ndarray2string(); // $ExpectError
+ ndarray2string( arr, {} ); // $ExpectError
+}
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/examples/index.js b/lib/node_modules/@stdlib/ndarray/to-string/examples/index.js
new file mode 100644
index 000000000000..1ae65db92518
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/examples/index.js
@@ -0,0 +1,33 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var array = require( '@stdlib/ndarray/array' );
+var ndarray2string = require( './../lib' );
+
+// Create a 2x3 ndarray:
+var x = array( [ 1, 2, 3, 4, 5, 6 ], {
+ 'shape': [ 2, 3 ],
+ 'dtype': 'generic'
+});
+
+// Serialize the ndarray as a string:
+var str = ndarray2string( x );
+console.log( str );
+// => 'ndarray( \'generic\', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js b/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js
new file mode 100644
index 000000000000..8c8954c9dbf2
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/lib/index.js
@@ -0,0 +1,44 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+/**
+* Serialize an ndarray as a string.
+*
+* @module @stdlib/ndarray/to-string
+*
+* @example
+* var array = require( '@stdlib/ndarray/array' );
+* var ndarray2string = require( '@stdlib/ndarray/to-string' );
+*
+* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
+* // returns
+*
+* var str = ndarray2string( x );
+* // returns
+*/
+
+// MODULES //
+
+var main = require( './main.js' );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js b/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js
new file mode 100644
index 000000000000..64b378a47a01
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/lib/main.js
@@ -0,0 +1,243 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' );
+var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
+var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
+var getDType = require( '@stdlib/ndarray/dtype' );
+var getShape = require( '@stdlib/ndarray/shape' );
+var getStrides = require( '@stdlib/ndarray/strides' );
+var getOrder = require( '@stdlib/ndarray/order' );
+var numel = require( '@stdlib/ndarray/base/numel' );
+var ind2sub = require( '@stdlib/ndarray/base/ind2sub' );
+var replace = require( '@stdlib/string/replace' );
+var format = require( '@stdlib/string/format' );
+var join = require( '@stdlib/array/base/join' );
+var real = require( '@stdlib/complex/float64/real' );
+var imag = require( '@stdlib/complex/float64/imag' );
+
+
+// VARIABLES //
+
+var CTORS = {
+ 'int8': 'new Int8Array( [ {{data}} ] )',
+ 'uint8': 'new Uint8Array( [ {{data}} ] )',
+ 'uint8c': 'new Uint8ClampedArray( [ {{data}} ] )',
+ 'int16': 'new Int16Array( [ {{data}} ] )',
+ 'uint16': 'new Uint16Array( [ {{data}} ] )',
+ 'int32': 'new Int32Array( [ {{data}} ] )',
+ 'uint32': 'new Uint32Array( [ {{data}} ] )',
+ 'float32': 'new Float32Array( [ {{data}} ] )',
+ 'float64': 'new Float64Array( [ {{data}} ] )',
+ 'generic': '[ {{data}} ]',
+ 'binary': 'new Buffer( [ {{data}} ] )',
+ 'complex64': 'new Complex64Array( [ {{data}} ] )',
+ 'complex128': 'new Complex128Array( [ {{data}} ] )',
+ 'bool': 'new BooleanArray( [ {{data}} ] )'
+};
+
+
+// FUNCTIONS //
+
+/**
+* Tests whether an object has a specified method.
+*
+* @private
+* @param {Object} obj - input object
+* @param {string} method - method name
+* @returns {boolean} boolean indicating whether an object has a specified method
+*
+* @example
+* var bool = hasMethod( [], 'toString' );
+* // returns true
+*/
+function hasMethod( obj, method ) {
+ return ( typeof obj[ method ] === 'function' && obj[ method ] !== Object.prototype[ method ] );
+}
+
+/**
+* Serializes an ndarray element to a string.
+*
+* @private
+* @param {ndarrayLike} x - input ndarray
+* @param {NonNegativeIntegerArray} sub - subscripts
+* @returns {string} serialized element
+*/
+function serializeElement( x, sub ) {
+ var v = x.get.apply( x, sub );
+ return String( v );
+}
+
+/**
+* Serializes a complex ndarray element to a string.
+*
+* @private
+* @param {ndarrayLike} x - input ndarray
+* @param {NonNegativeIntegerArray} sub - subscripts
+* @returns {string} serialized element
+*/
+function serializeComplexElement( x, sub ) {
+ var v = x.get.apply( x, sub );
+ return String( real( v ) ) + ', ' + String( imag( v ) );
+}
+
+
+// MAIN //
+
+/**
+* Serializes an ndarray as a string.
+*
+* ## Notes
+*
+* - The function does **not** serialize data outside of the buffer region defined by the ndarray view.
+*
+* @param {ndarrayLike} x - input ndarray
+* @throws {TypeError} must provide an ndarray-like object
+* @returns {string} string representation
+*
+* @example
+* var array = require( '@stdlib/ndarray/array' );
+*
+* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
+* // returns
+*
+* var str = ndarray2string( x );
+* // returns
+*/
+function ndarray2string( x ) {
+ var serialize;
+ var isCmplx;
+ var buffer;
+ var ndims;
+ var ctor;
+ var len;
+ var str;
+ var ord;
+ var ust;
+ var sh;
+ var st;
+ var dt;
+ var i;
+
+ if ( !isndarrayLike( x ) ) {
+ throw new TypeError( format( 'invalid argument. Must provide an ndarray. Value: `%s`.', x ) );
+ }
+ // Defer to input argument's custom implementation, if already defined...
+ if ( hasMethod( x, 'toString' ) ) {
+ return x.toString();
+ }
+ // Resolve array meta data:
+ dt = getDType( x );
+ sh = getShape( x );
+ st = getStrides( x );
+ ord = getOrder( x );
+ ndims = sh.length;
+ isCmplx = isComplexDataType( dt );
+ len = numel( sh );
+
+ // Compute unit strides for iteration (as `x.get` handles stride/offset mapping):
+ ust = shape2strides( sh, ord );
+
+ // Resolve element serialization function:
+ if ( isCmplx ) {
+ serialize = serializeComplexElement;
+ } else {
+ serialize = serializeElement;
+ }
+
+ // Function to invoke to create an ndarray:
+ str = format( 'ndarray( \'%s\', ', String( dt ) );
+
+ // Data buffer parameter...
+ buffer = '';
+ if ( len <= 100 ) {
+ for ( i = 0; i < len; i++ ) {
+ buffer += serialize( x, ind2sub( sh, ust, 0, ord, i, 'throw' ) );
+ if ( i < len-1 ) {
+ buffer += ', ';
+ }
+ }
+ } else {
+ // First three values...
+ for ( i = 0; i < 3; i++ ) {
+ buffer += serialize( x, ind2sub( sh, ust, 0, ord, i, 'throw' ) );
+ if ( i < 2 ) {
+ buffer += ', ';
+ }
+ }
+ buffer += ', ..., ';
+
+ // Last three values...
+ for ( i = 2; i >= 0; i-- ) {
+ buffer += serialize( x, ind2sub( sh, ust, 0, ord, len-1-i, 'throw' ) );
+ if ( i > 0 ) {
+ buffer += ', ';
+ }
+ }
+ }
+ ctor = CTORS[ dt ] || CTORS[ 'generic' ];
+ str += replace( ctor, '{{data}}', buffer );
+ str += ', ';
+
+ // Array shape...
+ if ( ndims === 0 ) {
+ str += '[]';
+ } else {
+ str += format( '[ %s ]', join( sh, ', ' ) );
+ }
+ str += ', ';
+
+ // Stride array...
+ str += '[ ';
+ if ( ndims === 0 ) {
+ str += '0';
+ } else {
+ for ( i = 0; i < ndims; i++ ) {
+ if ( st[ i ] < 0 ) {
+ str += -st[ i ];
+ } else {
+ str += st[ i ];
+ }
+ if ( i < ndims-1 ) {
+ str += ', ';
+ }
+ }
+ }
+ str += ' ]';
+ str += ', ';
+
+ // Buffer offset:
+ str += '0';
+ str += ', ';
+
+ // Order:
+ str += format( '\'%s\'', ord );
+
+ // Close the function call:
+ str += ' )';
+ return str;
+}
+
+
+// EXPORTS //
+
+module.exports = ndarray2string;
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/package.json b/lib/node_modules/@stdlib/ndarray/to-string/package.json
new file mode 100644
index 000000000000..050b579e5ed5
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/package.json
@@ -0,0 +1,70 @@
+{
+ "name": "@stdlib/ndarray/to-string",
+ "version": "0.0.0",
+ "description": "Serialize an ndarray as a string.",
+ "license": "Apache-2.0",
+ "author": {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ },
+ "contributors": [
+ {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ }
+ ],
+ "main": "./lib",
+ "directories": {
+ "benchmark": "./benchmark",
+ "doc": "./docs",
+ "example": "./examples",
+ "lib": "./lib",
+ "test": "./test"
+ },
+ "types": "./docs/types",
+ "scripts": {},
+ "homepage": "https://github.com/stdlib-js/stdlib",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/stdlib-js/stdlib.git"
+ },
+ "bugs": {
+ "url": "https://github.com/stdlib-js/stdlib/issues"
+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "engines": {
+ "node": ">=0.10.0",
+ "npm": ">2.7.0"
+ },
+ "os": [
+ "aix",
+ "darwin",
+ "freebsd",
+ "linux",
+ "macos",
+ "openbsd",
+ "sunos",
+ "win32",
+ "windows"
+ ],
+ "keywords": [
+ "stdlib",
+ "stdtypes",
+ "types",
+ "ndarray",
+ "multidimensional",
+ "array",
+ "utilities",
+ "utility",
+ "utils",
+ "util",
+ "view",
+ "convert",
+ "tostring",
+ "transform",
+ "string",
+ "serialize"
+ ],
+ "__stdlib__": {}
+}
diff --git a/lib/node_modules/@stdlib/ndarray/to-string/test/test.js b/lib/node_modules/@stdlib/ndarray/to-string/test/test.js
new file mode 100644
index 000000000000..1f730c1f4c3f
--- /dev/null
+++ b/lib/node_modules/@stdlib/ndarray/to-string/test/test.js
@@ -0,0 +1,538 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var tape = require( 'tape' );
+var Float64Array = require( '@stdlib/array/float64' );
+var Complex64Array = require( '@stdlib/array/complex64' );
+var Complex128Array = require( '@stdlib/array/complex128' );
+var BooleanArray = require( '@stdlib/array/bool' );
+var Complex64 = require( '@stdlib/complex/float32/ctor' );
+var ndarray = require( '@stdlib/ndarray/ctor' );
+var noop = require( '@stdlib/utils/noop' );
+var ndarray2string = require( './../lib' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof ndarray2string, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function throws an error if not provided an ndarray-like object', function test( t ) {
+ var values;
+ var i;
+
+ values = [
+ '5',
+ 5,
+ NaN,
+ true,
+ false,
+ null,
+ void 0,
+ [],
+ {},
+ function noop() {}
+ ];
+ for ( i = 0; i < values.length; i++ ) {
+ t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
+ }
+ t.end();
+
+ function badValue( value ) {
+ return function badValue() {
+ ndarray2string( value );
+ };
+ }
+});
+
+tape( 'the function serializes an ndarray as a string (row-major)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ 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, 7.0, 8.0 ] );
+ shape = [ 2, 2 ];
+ order = 'row-major';
+ strides = [ 2, 1 ];
+ offset = 2;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'float64\', new Float64Array( [ 3, 4, 5, 6 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (row-major, negative strides)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ 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, 7.0, 8.0 ] );
+ shape = [ 2, 2 ];
+ order = 'row-major';
+ strides = [ -2, -1 ];
+ offset = 5;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'float64\', new Float64Array( [ 6, 5, 4, 3 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (column-major)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var dtype;
+ var order;
+ var shape;
+ var arr;
+
+ dtype = 'generic';
+ buffer = [ 1, 2, 3, 4 ];
+ shape = [ 2, 2 ];
+ order = 'column-major';
+ strides = [ 1, 2 ];
+ offset = 0;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'generic\', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, \'column-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (column-major, negative strides)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ 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, 7.0, 8.0 ] );
+ shape = [ 2, 2 ];
+ order = 'column-major';
+ strides = [ -1, -2 ];
+ offset = 5;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'float64\', new Float64Array( [ 6, 5, 4, 3 ] ), [ 2, 2 ], [ 1, 2 ], 0, \'column-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (0d)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var dtype;
+ var order;
+ var shape;
+ var arr;
+
+ dtype = 'generic';
+ buffer = [ 1, 2, 3, 4 ];
+ shape = [];
+ order = 'column-major';
+ strides = [ 0 ];
+ offset = 2;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'generic\', [ 3 ], [], [ 0 ], 0, \'column-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (dtype=complex64)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ 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 );
+
+ expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (dtype=complex128)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var dtype;
+ var order;
+ var shape;
+ var arr;
+
+ dtype = 'complex128';
+ buffer = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
+ shape = [ 2, 2 ];
+ order = 'row-major';
+ strides = [ 2, 1 ];
+ offset = 0;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'complex128\', new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray as a string (dtype=bool)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var dtype;
+ var order;
+ var shape;
+ var arr;
+
+ dtype = 'bool';
+ buffer = new BooleanArray( [ true, false, true, false ] );
+ shape = [ 2, 2 ];
+ order = 'row-major';
+ strides = [ 2, 1 ];
+ offset = 0;
+
+ arr = ndarray( dtype, buffer, shape, strides, offset, order );
+
+ expected = 'ndarray( \'bool\', new BooleanArray( [ true, false, true, false ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function serializes an ndarray-like object as a string', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var arr;
+
+ strides = [ 2, 1 ];
+ offset = 2;
+ buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
+
+ arr = {
+ 'dtype': 'float64',
+ 'data': buffer,
+ 'shape': [ 2, 2 ],
+ 'strides': strides,
+ 'offset': offset,
+ 'order': 'row-major',
+ 'ndims': 2,
+ 'length': 4,
+ 'flags': {
+ 'READONLY': true
+ },
+ 'get': getter,
+ 'set': noop
+ };
+
+ expected = 'ndarray( \'float64\', new Float64Array( [ 3, 4, 5, 6 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+
+ function getter( i, j ) {
+ return buffer[ offset + ( strides[0]*i ) + ( strides[1]*j ) ];
+ }
+});
+
+tape( 'the function serializes an ndarray-like object as a string (column-major)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var arr;
+
+ strides = [ -1, -2 ];
+ offset = 3;
+ buffer = [ 1.0, 2.0, 3.0, 4.0 ];
+
+ arr = {
+ 'dtype': 'generic',
+ 'data': buffer,
+ 'shape': [ 2, 2 ],
+ 'strides': strides,
+ 'offset': offset,
+ 'order': 'column-major',
+ 'ndims': 2,
+ 'length': 4,
+ 'flags': {
+ 'READONLY': true
+ },
+ 'get': getter,
+ 'set': noop
+ };
+
+ expected = 'ndarray( \'generic\', [ 4, 3, 2, 1 ], [ 2, 2 ], [ 1, 2 ], 0, \'column-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+
+ function getter( i, j ) {
+ return buffer[ offset + ( strides[0]*i ) + ( strides[1]*j ) ];
+ }
+});
+
+tape( 'the function serializes an ndarray-like object as a string (dtype=complex)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var arr;
+
+ strides = [ 2, 1 ];
+ offset = 0;
+ buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
+
+ arr = {
+ 'dtype': 'complex64',
+ 'data': buffer,
+ 'shape': [ 2, 2 ],
+ 'strides': strides,
+ 'offset': offset,
+ 'order': 'row-major',
+ 'ndims': 2,
+ 'length': 4,
+ 'flags': {
+ 'READONLY': true
+ },
+ 'get': getter,
+ 'set': noop
+ };
+
+ expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+
+ function getter( i, j ) {
+ return buffer.get( offset + ( strides[0]*i ) + ( strides[1]*j ) );
+ }
+});
+
+tape( 'the function serializes an ndarray-like object as a string (large array)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var arr;
+ var i;
+
+ strides = [ 1 ];
+ offset = 0;
+
+ buffer = new Float64Array( 10000 );
+ for ( i = 0; i < 10000; i++ ) {
+ if ( i < 3 ) {
+ buffer[ i ] = i + 1;
+ } else if ( i >= 9997 ) {
+ buffer[ i ] = i - 9993;
+ } else {
+ buffer[ i ] = 0;
+ }
+ }
+ arr = {
+ 'dtype': 'float64',
+ 'data': buffer,
+ 'shape': [ 10000 ],
+ 'strides': strides,
+ 'offset': offset,
+ 'order': 'row-major',
+ 'ndims': 1,
+ 'length': 10000,
+ 'flags': {
+ 'READONLY': false
+ },
+ 'get': getter,
+ 'set': noop
+ };
+
+ expected = 'ndarray( \'float64\', new Float64Array( [ 1, 2, 3, ..., 4, 5, 6 ] ), [ 10000 ], [ 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+
+ function getter( i ) {
+ return buffer[ offset + ( strides[0]*i ) ];
+ }
+});
+
+tape( 'the function serializes an ndarray-like object as a string (large array, complex)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var arr;
+ var i;
+
+ strides = [ 1 ];
+ offset = 0;
+
+ buffer = new Complex64Array( 10000 );
+ for ( i = 0; i < 10000; i++ ) {
+ if ( i < 3 ) {
+ buffer.set( new Complex64( i+1, i+1 ), i );
+ } else if ( i >= 9997 ) {
+ buffer.set( new Complex64( i-9993, i-9993 ), i );
+ } else {
+ buffer.set( new Complex64( 0, 0 ), i );
+ }
+ }
+ arr = {
+ 'dtype': 'complex64',
+ 'data': buffer,
+ 'shape': [ 10000 ],
+ 'strides': strides,
+ 'offset': offset,
+ 'order': 'row-major',
+ 'ndims': 1,
+ 'length': 10000,
+ 'flags': {
+ 'READONLY': false
+ },
+ 'get': getter,
+ 'set': noop
+ };
+
+ expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 1, 2, 2, 3, 3, ..., 4, 4, 5, 5, 6, 6 ] ), [ 10000 ], [ 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+
+ function getter( i ) {
+ return buffer.get( offset + ( strides[0]*i ) );
+ }
+});
+
+tape( 'the function serializes an ndarray-like object as a string (null/undefined values)', function test( t ) {
+ var expected;
+ var strides;
+ var actual;
+ var buffer;
+ var offset;
+ var arr;
+
+ strides = [ 2, 1 ];
+ offset = 0;
+ buffer = [ null, void 0, null, void 0 ];
+
+ arr = {
+ 'dtype': 'generic',
+ 'data': buffer,
+ 'shape': [ 2, 2 ],
+ 'strides': strides,
+ 'offset': offset,
+ 'order': 'row-major',
+ 'ndims': 2,
+ 'length': 4,
+ 'flags': {
+ 'READONLY': false
+ },
+ 'get': getter,
+ 'set': noop
+ };
+
+ expected = 'ndarray( \'generic\', [ null, undefined, null, undefined ], [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
+ actual = ndarray2string( arr );
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ t.end();
+
+ function getter( i, j ) {
+ return buffer[ offset + ( strides[0]*i ) + ( strides[1]*j ) ];
+ }
+});