Skip to content

Commit 786fe7f

Browse files
committed
Auto-generated commit
1 parent f6f824e commit 786fe7f

File tree

12 files changed

+1297
-1
lines changed

12 files changed

+1297
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-04-02)
7+
## Unreleased (2026-04-06)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`aac0a2b`](https://github.com/stdlib-js/stdlib/commit/aac0a2be45cc8c0d70542b91d4ac3a958ea4881d) - add `ndarray2string` to namespace
14+
- [`47e4985`](https://github.com/stdlib-js/stdlib/commit/47e4985d18efb25b0fc00c6818fccdf547c9113e) - add `ndarray/to-string` [(#10899)](https://github.com/stdlib-js/stdlib/pull/10899)
1315
- [`8dbfe60`](https://github.com/stdlib-js/stdlib/commit/8dbfe608b990c4e12c729daa01489de8f6b56ac3) - add support for dtype instances
1416
- [`28d3e7d`](https://github.com/stdlib-js/stdlib/commit/28d3e7d6b05b312ebf14896cb0d8593902e443cb) - update `ndarray/base` TypeScript declarations [(#11166)](https://github.com/stdlib-js/stdlib/pull/11166)
1517
- [`364e294`](https://github.com/stdlib-js/stdlib/commit/364e294fbd4ebd149d86b8f7996da4b00b6c6b3b) - add `nulls` to namespace
@@ -818,6 +820,8 @@ A total of 45 issues were closed in this release:
818820

819821
<details>
820822

823+
- [`aac0a2b`](https://github.com/stdlib-js/stdlib/commit/aac0a2be45cc8c0d70542b91d4ac3a958ea4881d) - **feat:** add `ndarray2string` to namespace _(by Athan Reines)_
824+
- [`47e4985`](https://github.com/stdlib-js/stdlib/commit/47e4985d18efb25b0fc00c6818fccdf547c9113e) - **feat:** add `ndarray/to-string` [(#10899)](https://github.com/stdlib-js/stdlib/pull/10899) _(by Muhammad Haris, Athan Reines, stdlib-bot)_
821825
- [`a467bf0`](https://github.com/stdlib-js/stdlib/commit/a467bf0083da8f346611e53a684a78212f76d426) - **chore:** fix typos and incorrect test values [(#11270)](https://github.com/stdlib-js/stdlib/pull/11270) _(by Philipp Burckhardt)_
822826
- [`2db5404`](https://github.com/stdlib-js/stdlib/commit/2db5404d6a12f2d0c20fb61a5ce047daea72ea3f) - **refactor:** improve type specificity and use accessors for resolving ndarray meta data _(by Athan Reines)_
823827
- [`8dbfe60`](https://github.com/stdlib-js/stdlib/commit/8dbfe608b990c4e12c729daa01489de8f6b56ac3) - **feat:** add support for dtype instances _(by Athan Reines)_

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ setReadOnly( ns, 'toReversed', require( './../to-reversed' ) );
918918
*/
919919
setReadOnly( ns, 'toReversedDimension', require( './../to-reversed-dimension' ) );
920920

921+
/**
922+
* @name ndarray2string
923+
* @memberof ns
924+
* @readonly
925+
* @type {Function}
926+
* @see {@link module:@stdlib/ndarray/to-string}
927+
*/
928+
setReadOnly( ns, 'ndarray2string', require( './../to-string' ) );
929+
921930
/**
922931
* @name unshift
923932
* @memberof ns

to-string/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# ndarray2string
22+
23+
> Serialize an [ndarray][@stdlib/ndarray/ctor] as a string.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var ndarray2string = require( '@stdlib/ndarray/to-string' );
41+
```
42+
43+
#### ndarray2string( x )
44+
45+
Serializes an [ndarray][@stdlib/ndarray/ctor] as a string.
46+
47+
```javascript
48+
var array = require( '@stdlib/ndarray/array' );
49+
50+
var x = array( [ 1, 2, 3, 4 ], {
51+
'shape': [ 2, 2 ]
52+
});
53+
// returns <ndarray>
54+
55+
var str = ndarray2string( x );
56+
// returns "ndarray( 'float64', new Float64Array( [ 1, 2, 3, 4 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' )"
57+
```
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
64+
65+
<section class="notes">
66+
67+
## Notes
68+
69+
- The function does **not** serialize data outside of the buffer defined by the [ndarray][@stdlib/ndarray/ctor] view.
70+
- For ndarrays with more than `100` elements, the function abbreviates the data, showing only the first and last three values.
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<!-- Package usage examples. -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var array = require( '@stdlib/ndarray/array' );
86+
var ndarray2string = require( '@stdlib/ndarray/to-string' );
87+
88+
// Create a 2x3 ndarray:
89+
var x = array( [ 1, 2, 3, 4, 5, 6 ], {
90+
'shape': [ 2, 3 ],
91+
'dtype': 'generic'
92+
});
93+
94+
// Serialize the ndarray as a string:
95+
var str = ndarray2string( x );
96+
console.log( str );
97+
// => 'ndarray( \'generic\', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
98+
```
99+
100+
</section>
101+
102+
<!-- /.examples -->
103+
104+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
105+
106+
<section class="references">
107+
108+
</section>
109+
110+
<!-- /.references -->
111+
112+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
113+
114+
<section class="related">
115+
116+
</section>
117+
118+
<!-- /.related -->
119+
120+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="links">
123+
124+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
125+
126+
<!-- <related-links> -->
127+
128+
<!-- </related-links> -->
129+
130+
</section>
131+
132+
<!-- /.links -->

to-string/benchmark/benchmark.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25+
var shape2strides = require( './../../base/shape2strides' );
26+
var strides2offset = require( './../../base/strides2offset' );
27+
var numel = require( './../../base/numel' );
28+
var zeroTo = require( '@stdlib/array/base/zero-to' );
29+
var format = require( '@stdlib/string/format' );
30+
var ndarray = require( './../../ctor' );
31+
var pkg = require( './../package.json' ).name;
32+
var ndarray2string = require( './../lib' );
33+
34+
35+
// MAIN //
36+
37+
bench( format( '%s:order=row-major', pkg ), function benchmark( b ) {
38+
var strides;
39+
var buffer;
40+
var offset;
41+
var order;
42+
var shape;
43+
var arr;
44+
var out;
45+
var i;
46+
47+
shape = [ 10, 10, 10 ];
48+
order = 'row-major';
49+
buffer = zeroTo( numel( shape ) );
50+
strides = shape2strides( shape, order );
51+
offset = strides2offset( shape, strides );
52+
arr = ndarray( 'generic', buffer, shape, strides, offset, order );
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
out = ndarray2string( arr );
57+
if ( typeof out !== 'string' ) {
58+
b.fail( 'should return a string' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isString( out ) ) {
63+
b.fail( 'should return a string' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
});
68+
69+
bench( format( '%s:order=column-major', pkg ), function benchmark( b ) {
70+
var strides;
71+
var buffer;
72+
var offset;
73+
var order;
74+
var shape;
75+
var arr;
76+
var out;
77+
var i;
78+
79+
shape = [ 10, 10, 10 ];
80+
order = 'column-major';
81+
buffer = zeroTo( numel( shape ) );
82+
strides = shape2strides( shape, order );
83+
offset = strides2offset( shape, strides );
84+
arr = ndarray( 'generic', buffer, shape, strides, offset, order );
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
out = ndarray2string( arr );
89+
if ( typeof out !== 'string' ) {
90+
b.fail( 'should return a string' );
91+
}
92+
}
93+
b.toc();
94+
if ( !isString( out ) ) {
95+
b.fail( 'should return a string' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
});

to-string/docs/repl.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
{{alias}}( x )
3+
Serializes an ndarray as a string.
4+
5+
This function does *not* serialize data outside of the buffer region
6+
defined by the ndarray view.
7+
8+
Parameters
9+
----------
10+
x: ndarray
11+
Input ndarray.
12+
13+
Returns
14+
-------
15+
out: string
16+
String representation.
17+
18+
Examples
19+
--------
20+
> var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );
21+
> var out = {{alias}}( arr )
22+
<string>
23+
24+
See Also
25+
--------
26+

to-string/docs/types/index.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Serializes an ndarray as a string.
27+
*
28+
* ## Notes
29+
*
30+
* - The function does **not** serialize data outside of the buffer region defined by the ndarray view.
31+
*
32+
* @param x - input ndarray
33+
* @returns string representation
34+
*
35+
* @example
36+
* var array = require( `@stdlib/ndarray/array` );
37+
*
38+
* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
39+
* // returns <ndarray>
40+
*
41+
* var str = ndarray2string( x );
42+
* // returns <string>
43+
*/
44+
declare function ndarray2string( x: ndarray ): string;
45+
46+
47+
// EXPORTS //
48+
49+
export = ndarray2string;

0 commit comments

Comments
 (0)