Skip to content

Commit d202a06

Browse files
committed
Auto-generated commit
1 parent 9a4fe58 commit d202a06

File tree

13 files changed

+1907
-3
lines changed

13 files changed

+1907
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`42656f4`](https://github.com/stdlib-js/stdlib/commit/42656f425904ee6bb2608459bc6be406cd8e827f) - add `ndarray/to-locale-string` [(#10898)](https://github.com/stdlib-js/stdlib/pull/10898)
1314
- [`d597c1d`](https://github.com/stdlib-js/stdlib/commit/d597c1d7b7dcb6b9a8d30e93b0042b61b0b2f130) - update `ndarray` TypeScript declarations [(#11048)](https://github.com/stdlib-js/stdlib/pull/11048)
1415
- [`02c34bc`](https://github.com/stdlib-js/stdlib/commit/02c34bcc0cdd0ebba2f0fc8c311534aebf1ede2a) - add `everyBy` to namespace
1516
- [`37969ad`](https://github.com/stdlib-js/stdlib/commit/37969adc28a67964a680c4205775d12383d02938) - add `ndarray/every-by` [(#11012)](https://github.com/stdlib-js/stdlib/pull/11012)
@@ -791,6 +792,8 @@ A total of 44 issues were closed in this release:
791792

792793
<details>
793794

795+
- [`42656f4`](https://github.com/stdlib-js/stdlib/commit/42656f425904ee6bb2608459bc6be406cd8e827f) - **feat:** add `ndarray/to-locale-string` [(#10898)](https://github.com/stdlib-js/stdlib/pull/10898) _(by Muhammad Haris, Athan Reines)_
796+
- [`25e5ccb`](https://github.com/stdlib-js/stdlib/commit/25e5ccb8759c3f7b409e58454fafb52cc8c89394) - **bench:** refactor to use string interpolation in `ndarray/base/ndarraylike2ndarray` [(#11060)](https://github.com/stdlib-js/stdlib/pull/11060) _(by Partha Das)_
794797
- [`f5c5dfa`](https://github.com/stdlib-js/stdlib/commit/f5c5dfaf00b470450be52e27649c745019b61aa3) - **bench:** refactor to use string interpolation in `ndarray/base/pop` [(#11061)](https://github.com/stdlib-js/stdlib/pull/11061) _(by Partha Das)_
795798
- [`16f3ebe`](https://github.com/stdlib-js/stdlib/commit/16f3ebefefdfedb0a98d276312d35a8e6de2d195) - **bench:** refactor to use string interpolation in `ndarray/base/reverse` [(#11062)](https://github.com/stdlib-js/stdlib/pull/11062) _(by Partha Das)_
796799
- [`a0084e4`](https://github.com/stdlib-js/stdlib/commit/a0084e42e84516d1b9031ce2994e8694a294b92f) - **bench:** refactor to use string interpolation in `ndarray/base/buffer-ctors` [(#11038)](https://github.com/stdlib-js/stdlib/pull/11038) _(by Partha Das)_

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ For more information on the project, filing bug reports and feature requests, an
256256

257257
---
258258

259+
## License
260+
261+
See [LICENSE][stdlib-license].
262+
263+
259264
## Copyright
260265

261266
Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
@@ -302,6 +307,8 @@ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
302307
[esm-readme]: https://github.com/stdlib-js/ndarray/blob/esm/README.md
303308
[branches-url]: https://github.com/stdlib-js/ndarray/blob/main/branches.md
304309

310+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray/main/LICENSE
311+
305312
<!-- <toc-links> -->
306313

307314
[@stdlib/ndarray/any-by]: https://github.com/stdlib-js/ndarray/tree/main/any-by

base/ndarraylike2ndarray/benchmark/benchmark.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ var Float64Array = require( '@stdlib/array/float64' );
2525
var ndarrayBase = require( './../../../base/ctor' );
2626
var ndarray = require( './../../../ctor' );
2727
var isCollection = require( '@stdlib/assert/is-collection' );
28+
var format = require( '@stdlib/string/format' );
2829
var pkg = require( './../package.json' ).name;
2930
var ndarraylike2ndarray = require( './../lib' );
3031

3132

3233
// MAIN //
3334

34-
bench( pkg+'::base_ndarray', function benchmark( b ) {
35+
bench( format( '%s::base_ndarray', pkg ), function benchmark( b ) {
3536
var strides;
3637
var values;
3738
var buffer;
@@ -72,7 +73,7 @@ bench( pkg+'::base_ndarray', function benchmark( b ) {
7273
b.end();
7374
});
7475

75-
bench( pkg+'::ndarray', function benchmark( b ) {
76+
bench( format( '%s::ndarray', pkg ), function benchmark( b ) {
7677
var strides;
7778
var values;
7879
var buffer;
@@ -113,7 +114,7 @@ bench( pkg+'::ndarray', function benchmark( b ) {
113114
b.end();
114115
});
115116

116-
bench( pkg+'::ndarray_like', function benchmark( b ) {
117+
bench( format( '%s::ndarray_like', pkg ), function benchmark( b ) {
117118
var strides;
118119
var values;
119120
var buffer;

to-locale-string/README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
# ndarray2localeString
22+
23+
> Serialize an [ndarray][@stdlib/ndarray/ctor] as a locale-aware 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 ndarray2localeString = require( '@stdlib/ndarray/to-locale-string' );
41+
```
42+
43+
#### ndarray2localeString( x\[, locales\[, options]] )
44+
45+
Serializes an [ndarray][@stdlib/ndarray/ctor] as a locale-aware 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 = ndarray2localeString( x );
56+
// returns <string>
57+
```
58+
59+
The function supports the following parameters:
60+
61+
- **x**: input ndarray.
62+
- **locales**: a [BCP 47][bcp-47] language tag or an array of such strings (_optional_).
63+
- **options**: configuration options (_optional_).
64+
65+
</section>
66+
67+
<!-- /.usage -->
68+
69+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
70+
71+
<section class="notes">
72+
73+
## Notes
74+
75+
- The function does **not** serialize data outside of the buffer region defined by the [ndarray][@stdlib/ndarray/ctor] view.
76+
- For ndarrays with more than `100` elements, the function abbreviates the data, showing only the first three and last three values.
77+
78+
</section>
79+
80+
<!-- /.notes -->
81+
82+
<!-- Package usage examples. -->
83+
84+
<section class="examples">
85+
86+
## Examples
87+
88+
<!-- eslint no-undef: "error" -->
89+
90+
```javascript
91+
var array = require( '@stdlib/ndarray/array' );
92+
var ndarray2localeString = require( '@stdlib/ndarray/to-locale-string' );
93+
94+
// Create a 2x3 ndarray:
95+
var x = array( [ 1234.567, 9876.543, 1111.222, 3333.444, 5555.666, 7777.888 ], {
96+
'shape': [ 2, 3 ],
97+
'dtype': 'generic'
98+
});
99+
100+
// Serialize using the default locale:
101+
var str = ndarray2localeString( x );
102+
// e.g., returns 'ndarray( \'generic\', [ 1,234.567, 9,876.543, 1,111.222, 3,333.444, 5,555.666, 7,777.888 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
103+
104+
// Serialize using the English (US) locale:
105+
str = ndarray2localeString( x, 'en-US' );
106+
// returns 'ndarray( \'generic\', [ 1,234.567, 9,876.543, 1,111.222, 3,333.444, 5,555.666, 7,777.888 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
107+
108+
// Serialize using the German locale:
109+
str = ndarray2localeString( x, 'de-DE' );
110+
// returns 'ndarray( \'generic\', [ 1.234,567, 9.876,543, 1.111,222, 3.333,444, 5.555,666, 7.777,888 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
111+
112+
// Serialize with a maximum number of fraction digits:
113+
str = ndarray2localeString( x, 'en-US', {
114+
'maximumFractionDigits': 0
115+
});
116+
// returns 'ndarray( \'generic\', [ 1,235, 9,877, 1,111, 3,333, 5,556, 7,778 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
117+
```
118+
119+
</section>
120+
121+
<!-- /.examples -->
122+
123+
<!-- 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. -->
124+
125+
<section class="references">
126+
127+
</section>
128+
129+
<!-- /.references -->
130+
131+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
132+
133+
<section class="related">
134+
135+
</section>
136+
137+
<!-- /.related -->
138+
139+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
140+
141+
<section class="links">
142+
143+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
144+
145+
[bcp-47]: https://tools.ietf.org/html/rfc5646
146+
147+
<!-- <related-links> -->
148+
149+
<!-- </related-links> -->
150+
151+
</section>
152+
153+
<!-- /.links -->
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 ndarray2localeString = 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 = ndarray2localeString( 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 = ndarray2localeString( 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-locale-string/docs/repl.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{alias}}( x[, locales[, options]] )
3+
Serializes an ndarray as a locale-aware 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+
locales: string|Array<string> (optional)
14+
A BCP 47 language tag or an array of such strings.
15+
16+
options: Object (optional)
17+
Configuration options.
18+
19+
Returns
20+
-------
21+
out: string
22+
String representation.
23+
24+
Examples
25+
--------
26+
> var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );
27+
> var out = {{alias}}( arr )
28+
<string>
29+
30+
See Also
31+
--------
32+

0 commit comments

Comments
 (0)