Skip to content

Commit d5280f3

Browse files
committed
fix: apply suggestions from code review
--- 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 status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_license_headers status: passed ---
1 parent 01538fb commit d5280f3

File tree

14 files changed

+1504
-554
lines changed

14 files changed

+1504
-554
lines changed

lib/node_modules/@stdlib/blas/ext/join-between/README.md

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,56 @@ limitations under the License.
3030
var joinBetween = require( '@stdlib/blas/ext/join-between' );
3131
```
3232

33-
#### joinBetween( x\[, options] )
33+
#### joinBetween( x, separators\[, options] )
3434

3535
Returns an [ndarray][@stdlib/ndarray/ctor] created by joining elements using specified separators for each pair of consecutive elements along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
3636

3737
```javascript
3838
var array = require( '@stdlib/ndarray/array' );
39+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
3940

4041
// Create an input ndarray:
4142
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4243
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
4344

45+
// Create a separators ndarray:
46+
var sep = scalar2ndarray( ',', {
47+
'dtype': 'generic'
48+
});
49+
4450
// Perform operation:
45-
var out = joinBetween( x );
51+
var out = joinBetween( x, sep );
4652
// returns <ndarray>[ '1,2,3,4,5,6' ]
4753
```
4854

4955
The function has the following parameters:
5056

5157
- **x**: input [ndarray][@stdlib/ndarray/ctor].
58+
- **separators**: separators [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape consisting of the complement of the shape defined by `options.dims` followed by `N-1` where `N` is the number of elements along the reduced dimensions.
5259
- **options**: function options (_optional_).
5360

5461
The function accepts the following options:
5562

56-
- **prefix**: prefix to prepend to each joined string. Default: `''`.
57-
- **suffix**: suffix to append to each joined string. Default: `''`.
58-
- **separators**: separators. Must be an array-like object. When provided an array containing a single element, the same separator is used between all consecutive pairs of elements. When containing multiple elements, each element specifies the separator to use between consecutive pairs, and the number of elements must equal one less than the number of elements along the reduced dimensions. Default: `[ ',' ]`.
63+
- **prefix**: prefix to prepend to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. Default: `''`.
64+
- **suffix**: suffix to append to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. Default: `''`.
5965
- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
6066
- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`.
6167

62-
By default, the function joins [ndarray][@stdlib/ndarray/ctor] elements by using `,` as a separator between all consecutive pairs of elements. To perform the operation with a different separator, provide a `separators` option.
68+
To specify a prefix and suffix to prepend and append to each joined string, provide `prefix` and `suffix` options.
6369

6470
```javascript
6571
var array = require( '@stdlib/ndarray/array' );
72+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
6673

6774
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
6875

69-
var out = joinBetween( x, {
70-
'separators': [ '|' ]
76+
var sep = scalar2ndarray( ', ', {
77+
'dtype': 'generic'
7178
});
72-
// returns <ndarray>[ '1|2|3|4|5|6' ]
73-
```
7479

75-
To specify a prefix and suffix to prepend and append to each joined string, provide `prefix` and `suffix` options.
76-
77-
```javascript
78-
var array = require( '@stdlib/ndarray/array' );
79-
80-
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
81-
// returns <ndarray>[ 1, 2, 3, 4, 5, 6 ]
82-
83-
var out = joinBetween( x, {
80+
var out = joinBetween( x, sep, {
8481
'prefix': '[ ',
85-
'suffix': ' ]',
86-
'separators': [ ', ' ]
82+
'suffix': ' ]'
8783
});
8884
// returns <ndarray>[ '[ 1, 2, 3, 4, 5, 6 ]' ]
8985
```
@@ -92,32 +88,45 @@ By default, the function performs the operation over all elements in a provided
9288

9389
```javascript
9490
var array = require( '@stdlib/ndarray/array' );
91+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
9592

9693
var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
97-
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
9894

99-
var out = joinBetween( x, {
95+
var sep = scalar2ndarray( ',', {
96+
'dtype': 'generic'
97+
});
98+
99+
var out = joinBetween( x, sep, {
100100
'dims': [ 0 ]
101101
});
102102
// returns <ndarray>[ '1,3', '2,4' ]
103+
104+
out = joinBetween( x, sep, {
105+
'dims': [ 1 ]
106+
});
107+
// returns <ndarray>[ '1,2', '3,4' ]
103108
```
104109

105110
By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`.
106111

107112
```javascript
108113
var array = require( '@stdlib/ndarray/array' );
114+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
109115

110116
var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
111-
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
112117

113-
var out = joinBetween( x, {
118+
var sep = scalar2ndarray( ',', {
119+
'dtype': 'generic'
120+
});
121+
122+
var out = joinBetween( x, sep, {
114123
'dims': [ 0 ],
115124
'keepdims': true
116125
});
117126
// returns <ndarray>[ [ '1,3', '2,4' ] ]
118127
```
119128

120-
#### joinBetween.assign( x, out\[, options] )
129+
#### joinBetween.assign( x, separators, out\[, options] )
121130

122131
Joins elements of an input [ndarray][@stdlib/ndarray/ctor] using specified separators for each pair of consecutive elements along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].
123132

@@ -126,11 +135,14 @@ var array = require( '@stdlib/ndarray/array' );
126135
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
127136

128137
var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );
138+
var sep = scalar2ndarray( ',', {
139+
'dtype': 'generic'
140+
});
129141
var y = scalar2ndarray( '', {
130142
'dtype': 'generic'
131143
});
132144

133-
var out = joinBetween.assign( x, y );
145+
var out = joinBetween.assign( x, sep, y );
134146
// returns <ndarray>[ '1,2,3,4' ]
135147

136148
var bool = ( out === y );
@@ -140,14 +152,14 @@ var bool = ( out === y );
140152
The method has the following parameters:
141153

142154
- **x**: input [ndarray][@stdlib/ndarray/ctor].
155+
- **separators**: separators [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape consisting of the complement of the shape defined by `options.dims` followed by `N-1` where `N` is the number of elements along the reduced dimensions.
143156
- **out**: output [ndarray][@stdlib/ndarray/ctor].
144157
- **options**: function options (_optional_).
145158

146159
The method accepts the following options:
147160

148-
- **prefix**: prefix to prepend to each joined string. Default: `''`.
149-
- **suffix**: suffix to append to each joined string. Default: `''`.
150-
- **separators**: separators. Must be an array-like object. When provided an array containing a single element, the same separator is used between all consecutive pairs of elements. When containing multiple elements, each element specifies the separator to use between consecutive pairs, and the number of elements must equal one less than the number of elements along the reduced dimensions. Default: `[ ',' ]`.
161+
- **prefix**: prefix to prepend to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. Default: `''`.
162+
- **suffix**: suffix to append to each joined string. May be a scalar value or an [ndarray][@stdlib/ndarray/ctor] which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. Default: `''`.
151163
- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
152164

153165
</section>
@@ -159,7 +171,6 @@ The method accepts the following options:
159171
## Notes
160172

161173
- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor].
162-
- When providing an array containing multiple separators, each element specifies the separator to use between consecutive pairs. The same separators are used for every complement position when reducing specific dimensions.
163174

164175
</section>
165176

@@ -172,18 +183,22 @@ The method accepts the following options:
172183
<!-- eslint no-undef: "error" -->
173184

174185
```javascript
186+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
175187
var uniform = require( '@stdlib/random/uniform' );
176188
var ndarray2array = require( '@stdlib/ndarray/to-array' );
177189
var joinBetween = require( '@stdlib/blas/ext/join-between' );
178190

179191
var x = uniform( [ 5, 2 ], 0.0, 20.0 );
180192
console.log( ndarray2array( x ) );
181193

182-
var out = joinBetween( x, {
194+
var sep = scalar2ndarray( ', ', {
195+
'dtype': 'generic'
196+
});
197+
198+
var out = joinBetween( x, sep, {
183199
'dims': [ -1 ],
184200
'prefix': '[ ',
185-
'suffix': ' ]',
186-
'separators': [ ', ' ]
201+
'suffix': ' ]'
187202
});
188203
console.log( ndarray2array( out ) );
189204
```

lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.assign.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
26-
var uniform = require( '@stdlib/random/array/uniform' );
26+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
27+
var uniform = require( '@stdlib/random/uniform' );
2728
var empty = require( '@stdlib/ndarray/empty' );
28-
var ndarray = require( '@stdlib/ndarray/base/ctor' );
2929
var format = require( '@stdlib/string/format' );
3030
var pkg = require( './../package.json' ).name;
3131
var joinBetween = require( './../lib' );
@@ -48,11 +48,15 @@ var options = {
4848
* @returns {Function} benchmark function
4949
*/
5050
function createBenchmark( len ) {
51+
var sep;
5152
var out;
5253
var x;
5354

54-
x = uniform( len, -50.0, 50.0, options );
55-
x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' );
55+
x = uniform( [ len ], -50.0, 50.0, options );
56+
57+
sep = scalar2ndarray( ',', {
58+
'dtype': 'generic'
59+
});
5660

5761
out = empty( [], {
5862
'dtype': 'generic'
@@ -72,14 +76,14 @@ function createBenchmark( len ) {
7276

7377
b.tic();
7478
for ( i = 0; i < b.iterations; i++ ) {
75-
o = joinBetween.assign( x, out );
79+
o = joinBetween.assign( x, sep, out );
7680
if ( typeof o !== 'object' ) {
7781
b.fail( 'should return an ndarray' );
7882
}
7983
}
8084
b.toc();
81-
if ( isnan( o.get() ) ) {
82-
b.fail( 'should not return NaN' );
85+
if ( !isString( o.get() ) ) {
86+
b.fail( 'should return a string' );
8387
}
8488
b.pass( 'benchmark finished' );
8589
b.end();

lib/node_modules/@stdlib/blas/ext/join-between/benchmark/benchmark.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
26-
var uniform = require( '@stdlib/random/array/uniform' );
27-
var ndarray = require( '@stdlib/ndarray/base/ctor' );
26+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
27+
var uniform = require( '@stdlib/random/uniform' );
2828
var format = require( '@stdlib/string/format' );
2929
var pkg = require( './../package.json' ).name;
3030
var joinBetween = require( './../lib' );
@@ -47,8 +47,14 @@ var options = {
4747
* @returns {Function} benchmark function
4848
*/
4949
function createBenchmark( len ) {
50-
var x = uniform( len, -50.0, 50.0, options );
51-
x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' );
50+
var sep;
51+
var x;
52+
53+
x = uniform( [ len ], -50.0, 50.0, options );
54+
55+
sep = scalar2ndarray( ',', {
56+
'dtype': 'generic'
57+
});
5258

5359
return benchmark;
5460

@@ -64,14 +70,14 @@ function createBenchmark( len ) {
6470

6571
b.tic();
6672
for ( i = 0; i < b.iterations; i++ ) {
67-
o = joinBetween( x );
73+
o = joinBetween( x, sep );
6874
if ( typeof o !== 'object' ) {
6975
b.fail( 'should return an ndarray' );
7076
}
7177
}
7278
b.toc();
73-
if ( isnan( o.get() ) ) {
74-
b.fail( 'should not return NaN' );
79+
if ( !isString( o.get() ) ) {
80+
b.fail( 'should return a string' );
7581
}
7682
b.pass( 'benchmark finished' );
7783
b.end();

0 commit comments

Comments
 (0)