Skip to content

Commit 6173534

Browse files
committed
refactor: 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: na - task: lint_javascript_tests status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent bc93f68 commit 6173534

File tree

6 files changed

+116
-65
lines changed

6 files changed

+116
-65
lines changed

lib/node_modules/@stdlib/array/base/map/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The callback function is provided the following arguments:
8989
- **index**: current element index.
9090
- **arr**: input array.
9191

92-
#### map.assign( x, y, strideX, offsetX, fcn\[, thisArg] )
92+
#### map.assign( x, y, stride, offset, fcn\[, thisArg] )
9393

9494
Applies a callback function to elements in an input array and assigns results to elements in an output array.
9595

@@ -113,8 +113,8 @@ The function accepts the following arguments:
113113

114114
- **x**: input array.
115115
- **y**: output array.
116-
- **strideX**: stride length for x.
117-
- **offsetX**: starting index for x.
116+
- **stride**: stride length for output array.
117+
- **offset**: starting index for output array.
118118
- **fcn**: callback function.
119119
- **thisArg**: callback execution context (_optional_).
120120

lib/node_modules/@stdlib/array/base/map/benchmark/benchmark.assign.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function createBenchmark( len ) {
6262

6363
b.tic();
6464
for ( i = 0; i < b.iterations; i++ ) {
65-
out = map( x, y, identity );
65+
out = map( x, y, 1, 0, identity );
6666
if ( isnan( out[ i%len ] ) ) {
6767
b.fail( 'should not return NaN' );
6868
}

lib/node_modules/@stdlib/array/base/map/docs/repl.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
Returns
3030
-------
31-
out: Array
31+
out: Array|TypedArray|Object
3232
Output array.
3333

3434
Examples
@@ -38,7 +38,7 @@
3838
[ 1, 2, 3, 4 ]
3939

4040

41-
{{alias}}.assign( x, y, strideX, offsetX, fcn[, thisArg] )
41+
{{alias}}.assign( x, y, stride, offset, fcn[, thisArg] )
4242
Applies a callback function to elements in an input array and assigns
4343
results to elements in an output array.
4444

@@ -50,11 +50,11 @@
5050
y: Array|TypedArray|Object
5151
Output array.
5252

53-
strideX: integer
54-
Stride length for x.
53+
stride: integer
54+
Stride length for output array.
5555

56-
offsetX: integer
57-
Starting index for x.
56+
offset: integer
57+
Starting index for output array.
5858

5959
fcn: Function
6060
Callback function.

lib/node_modules/@stdlib/array/base/map/docs/types/index.d.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ interface Routine {
118118
*
119119
* @param x - input array object
120120
* @param y - output array object
121+
* @param stride - stride length for output array
122+
* @param offset - starting index for output array
121123
* @param fcn - callback function
122124
* @param thisArg - callback execution context
123125
* @returns output array object
@@ -133,16 +135,18 @@ interface Routine {
133135
* var x = ones( 4 );
134136
* var y = zeros( x.length );
135137
*
136-
* var out = map.assign( toAccessorArray( x ), toAccessorArray( y ), scale );
138+
* var out = map.assign( toAccessorArray( x ), toAccessorArray( y ), 1, 0 scale );
137139
* // y => [ 10, 10, 10, 10 ]
138140
*/
139-
assign<T = unknown, U = unknown, V = unknown>( x: AccessorArrayLike<T>, y: AccessorArrayLike<U>, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): AccessorArrayLike<U>;
141+
assign<T = unknown, U = unknown, V = unknown>( x: AccessorArrayLike<T>, y: AccessorArrayLike<U>, stride: number, offset: number, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): AccessorArrayLike<U>;
140142

141143
/**
142144
* Applies a callback function to elements in an input array and assigns results to elements in an output array.
143145
*
144146
* @param x - input array
145147
* @param y - output array
148+
* @param stride - stride length for output array
149+
* @param offset - starting index for output array
146150
* @param fcn - callback function
147151
* @param thisArg - callback execution context
148152
* @returns output array
@@ -157,13 +161,13 @@ interface Routine {
157161
* var x = ones( 4 );
158162
* var y = zeros( x.length );
159163
*
160-
* var out = map.assign( x, y, scale );
164+
* var out = map.assign( x, y, 1, 0, scale );
161165
* // returns [ 10, 10, 10, 10 ]
162166
*
163167
* var bool = ( out === y );
164168
* // returns true
165169
*/
166-
assign<T = unknown, U = unknown, V = unknown>( x: Collection<T>, y: Collection<U>, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): Collection<U>;
170+
assign<T = unknown, U = unknown, V = unknown>( x: Collection<T>, y: Collection<U>, stride: number, offset: number, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): Collection<U>;
167171
}
168172

169173
/**
@@ -186,7 +190,6 @@ interface Routine {
186190
* // returns [ 10, 10, 10, 10 ]
187191
*
188192
* @example
189-
* var toAccessorArray = require( '@stdlib/array/to-accessor-array' );
190193
* var ones = require( '@stdlib/array/base/ones' );
191194
* var zeros = require( '@stdlib/array/base/zeros' );
192195
*
@@ -197,8 +200,11 @@ interface Routine {
197200
* var x = ones( 4 );
198201
* var y = zeros( x.length );
199202
*
200-
* var out = map.assign( toAccessorArray( x ), toAccessorArray( y ), scale );
203+
* var out = map.assign( x, y, 1, 0, scale );
201204
* // y => [ 10, 10, 10, 10 ]
205+
*
206+
* var bool = ( out === y );
207+
* // returns true
202208
*/
203209
declare var map: Routine;
204210

lib/node_modules/@stdlib/array/base/map/docs/types/test.ts

Lines changed: 86 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -113,59 +113,103 @@ function fcn( v: number ): number {
113113
const x = [ 1, 2, 3 ];
114114
const y = [ 0, 0, 0 ];
115115

116-
map.assign( x, y, fcn ); // $ExpectType Collection<number>
117-
map.assign( new Float64Array( x ), new Float64Array( y ), fcn ); // $ExpectType Collection<number>
118-
map.assign( new Float32Array( x ), new Float32Array( y ), fcn ); // $ExpectType Collection<number>
119-
map.assign( new Int32Array( x ), new Int32Array( y ), fcn ); // $ExpectType Collection<number>
120-
map.assign( new Int16Array( x ), new Int16Array( y ), fcn ); // $ExpectType Collection<number>
121-
map.assign( new Int8Array( x ), new Int8Array( y ), fcn ); // $ExpectType Collection<number>
122-
map.assign( new Uint32Array( x ), new Uint32Array( y ), fcn ); // $ExpectType Collection<number>
123-
map.assign( new Uint16Array( x ), new Uint16Array( y ), fcn ); // $ExpectType Collection<number>
124-
map.assign( new Uint8Array( x ), new Uint8Array( y ), fcn ); // $ExpectType Collection<number>
125-
map.assign( new Uint8ClampedArray( x ), new Uint8ClampedArray( y ), fcn ); // $ExpectType Collection<number>
126-
map.assign( toAccessorArray( x ), toAccessorArray( y ), fcn ); // $ExpectType AccessorArrayLike<number>
127-
128-
map.assign( x, y, fcn, {} ); // $ExpectType Collection<number>
129-
map.assign( new Float64Array( x ), new Float64Array( y ), fcn, {} ); // $ExpectType Collection<number>
130-
map.assign( new Float32Array( x ), new Float32Array( y ), fcn, {} ); // $ExpectType Collection<number>
131-
map.assign( new Int32Array( x ), new Int32Array( y ), fcn, {} ); // $ExpectType Collection<number>
132-
map.assign( new Int16Array( x ), new Int16Array( y ), fcn, {} ); // $ExpectType Collection<number>
133-
map.assign( new Int8Array( x ), new Int8Array( y ), fcn, {} ); // $ExpectType Collection<number>
134-
map.assign( new Uint32Array( x ), new Uint32Array( y ), fcn, {} ); // $ExpectType Collection<number>
135-
map.assign( new Uint16Array( x ), new Uint16Array( y ), fcn, {} ); // $ExpectType Collection<number>
136-
map.assign( new Uint8Array( x ), new Uint8Array( y ), fcn, {} ); // $ExpectType Collection<number>
137-
map.assign( new Uint8ClampedArray( x ), new Uint8ClampedArray( y ), fcn, {} ); // $ExpectType Collection<number>
138-
map.assign( toAccessorArray( x ), toAccessorArray( y ), fcn, {} ); // $ExpectType AccessorArrayLike<number>
116+
map.assign( x, y, 1, 0, fcn ); // $ExpectType Collection<number>
117+
map.assign( new Float64Array( x ), new Float64Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
118+
map.assign( new Float32Array( x ), new Float32Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
119+
map.assign( new Int32Array( x ), new Int32Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
120+
map.assign( new Int16Array( x ), new Int16Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
121+
map.assign( new Int8Array( x ), new Int8Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
122+
map.assign( new Uint32Array( x ), new Uint32Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
123+
map.assign( new Uint16Array( x ), new Uint16Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
124+
map.assign( new Uint8Array( x ), new Uint8Array( y ), 1, 0, fcn ); // $ExpectType Collection<number>
125+
map.assign( new Uint8ClampedArray( x ), new Uint8ClampedArray( y ), 1, 0, fcn ); // $ExpectType Collection<number>
126+
map.assign( toAccessorArray( x ), toAccessorArray( y ), 1, 0, fcn ); // $ExpectType AccessorArrayLike<number>
127+
128+
map.assign( x, y, 1, 0, fcn, {} ); // $ExpectType Collection<number>
129+
map.assign( new Float64Array( x ), new Float64Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
130+
map.assign( new Float32Array( x ), new Float32Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
131+
map.assign( new Int32Array( x ), new Int32Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
132+
map.assign( new Int16Array( x ), new Int16Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
133+
map.assign( new Int8Array( x ), new Int8Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
134+
map.assign( new Uint32Array( x ), new Uint32Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
135+
map.assign( new Uint16Array( x ), new Uint16Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
136+
map.assign( new Uint8Array( x ), new Uint8Array( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
137+
map.assign( new Uint8ClampedArray( x ), new Uint8ClampedArray( y ), 1, 0, fcn, {} ); // $ExpectType Collection<number>
138+
map.assign( toAccessorArray( x ), toAccessorArray( y ), 1, 0, fcn, {} ); // $ExpectType AccessorArrayLike<number>
139139
}
140140

141141
// The compiler throws an error if the `assign` method is provided a first argument which is not a collection...
142142
{
143143
const y = [ 0, 0, 0 ];
144144

145-
map.assign( 2, y, fcn ); // $ExpectError
146-
map.assign( false, y, fcn ); // $ExpectError
147-
map.assign( true, y, fcn ); // $ExpectError
148-
map.assign( {}, y, fcn ); // $ExpectError
145+
map.assign( 2, y, 1, 0, fcn ); // $ExpectError
146+
map.assign( false, y, 1, 0, fcn ); // $ExpectError
147+
map.assign( true, y, 1, 0, fcn ); // $ExpectError
148+
map.assign( {}, y, 1, 0, fcn ); // $ExpectError
149149

150-
map.assign( 2, y, fcn, {} ); // $ExpectError
151-
map.assign( false, y, fcn, {} ); // $ExpectError
152-
map.assign( true, y, fcn, {} ); // $ExpectError
153-
map.assign( {}, y, fcn, {} ); // $ExpectError
150+
map.assign( 2, y, 1, 0, fcn, {} ); // $ExpectError
151+
map.assign( false, y, 1, 0, fcn, {} ); // $ExpectError
152+
map.assign( true, y, 1, 0, fcn, {} ); // $ExpectError
153+
map.assign( {}, y, 1, 0, fcn, {} ); // $ExpectError
154154
}
155155

156-
// The compiler throws an error if the `assign` method is provided a second argument which is not a function...
156+
// The compiler throws an error if the `assign` method is provided a second argument which is not a collection...
157157
{
158158
const x = [ 1, 2, 3 ];
159159

160-
map.assign( x, 2 ); // $ExpectError
161-
map.assign( x, false ); // $ExpectError
162-
map.assign( x, true ); // $ExpectError
163-
map.assign( x, {} ); // $ExpectError
160+
map.assign( x, 2, 1, 0, fcn ); // $ExpectError
161+
map.assign( x, false, 1, 0, fcn ); // $ExpectError
162+
map.assign( x, true, 1, 0, fcn ); // $ExpectError
163+
map.assign( x, {}, 1, 0, fcn ); // $ExpectError
164164

165-
map.assign( x, 2, {} ); // $ExpectError
166-
map.assign( x, false, {} ); // $ExpectError
167-
map.assign( x, true, {} ); // $ExpectError
168-
map.assign( x, {}, {} ); // $ExpectError
165+
map.assign( x, 2, 1, 0, fcn, {} ); // $ExpectError
166+
map.assign( x, false, 1, 0, fcn, {} ); // $ExpectError
167+
map.assign( x, true, 1, 0, fcn, {} ); // $ExpectError
168+
map.assign( x, {}, 1, 0, fcn, {} ); // $ExpectError
169+
}
170+
171+
// The compiler throws an error if the `assign` method is provided a third argument which is not a number...
172+
{
173+
const x = [ 1, 2, 3 ];
174+
const y = [ 0, 0, 0 ];
175+
176+
map.assign( x, y, false, 0, fcn ); // $ExpectError
177+
map.assign( x, y, true, 0, fcn ); // $ExpectError
178+
map.assign( x, y, {}, 0, fcn ); // $ExpectError
179+
180+
map.assign( x, y, false, 0, fcn, {} ); // $ExpectError
181+
map.assign( x, y, true, 0, fcn, {} ); // $ExpectError
182+
map.assign( x, y, {}, 0, fcn, {} ); // $ExpectError
183+
}
184+
185+
// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number...
186+
{
187+
const x = [ 1, 2, 3 ];
188+
const y = [ 0, 0, 0 ];
189+
190+
map.assign( x, y, 1, false, fcn ); // $ExpectError
191+
map.assign( x, y, 1, true, fcn ); // $ExpectError
192+
map.assign( x, y, 1, {}, fcn ); // $ExpectError
193+
194+
map.assign( x, y, 1, false, fcn, {} ); // $ExpectError
195+
map.assign( x, y, 1, true, fcn, {} ); // $ExpectError
196+
map.assign( x, y, 1, {}, fcn, {} ); // $ExpectError
197+
}
198+
199+
// The compiler throws an error if the `assign` method is provided a fifth argument which is not a function...
200+
{
201+
const x = [ 1, 2, 3 ];
202+
const y = [ 0, 0, 0 ];
203+
204+
map.assign( x, y, 1, 0, 2 ); // $ExpectError
205+
map.assign( x, y, 1, 0, false ); // $ExpectError
206+
map.assign( x, y, 1, 0, true ); // $ExpectError
207+
map.assign( x, y, 1, 0, {} ); // $ExpectError
208+
209+
map.assign( x, y, 1, 0, 2, {} ); // $ExpectError
210+
map.assign( x, y, 1, 0, false, {} ); // $ExpectError
211+
map.assign( x, y, 1, 0, true, {} ); // $ExpectError
212+
map.assign( x, y, 1, 0, {}, {} ); // $ExpectError
169213
}
170214

171215
// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
@@ -176,5 +220,6 @@ function fcn( v: number ): number {
176220
map.assign(); // $ExpectError
177221
map.assign( x ); // $ExpectError
178222
map.assign( x, y ); // $ExpectError
179-
map.assign( x, y, fcn, {}, {} ); // $ExpectError
223+
map.assign( x, y, 1, 0 ); // $ExpectError
224+
map.assign( x, y, 1, 0, fcn, {}, {} ); // $ExpectError
180225
}

lib/node_modules/@stdlib/array/base/map/lib/assign.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
5454
* // returns true
5555
*/
5656
function internal( x, y, strideX, offsetX, fcn, thisArg ) {
57-
var ix;
57+
var io;
5858
var i;
5959

60-
ix = offsetX;
60+
io = offsetX;
6161
for ( i = 0; i < y.length; i++ ) {
62-
y[ i ] = fcn.call( thisArg, x[ ix ], ix, x );
63-
ix += strideX;
62+
y[ io ] = fcn.call( thisArg, x[ i ], i, x );
63+
io += strideX;
6464
}
6565
return y;
6666
}
@@ -98,18 +98,18 @@ function accessors( x, y, strideX, offsetX, fcn, thisArg ) {
9898
var ydata;
9999
var xget;
100100
var yset;
101-
var ix;
101+
var io;
102102
var i;
103103

104104
xdata = x.data;
105105
ydata = y.data;
106106
xget = x.accessors[ 0 ];
107107
yset = y.accessors[ 1 ];
108108

109-
ix = offsetX;
109+
io = offsetX;
110110
for ( i = 0; i < ydata.length; i++ ) {
111-
yset( ydata, i, fcn.call( thisArg, xget( xdata, ix ), ix, xdata ) );
112-
ix += strideX;
111+
yset( ydata, io, fcn.call( thisArg, xget( xdata, i ), i, xdata ) );
112+
io += strideX;
113113
}
114114
return y;
115115
}

0 commit comments

Comments
 (0)