Skip to content

Commit d19823e

Browse files
committed
refactor: avoid mutating the list of views
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - 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: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d923b6e commit d19823e

40 files changed

+287
-87
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/10d.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
// MODULES //
2424

25+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2526
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
2627
var incrementOffsets = require( './increment_offsets.js' );
2728
var setViewOffsets = require( './set_view_offsets.js' );
@@ -158,6 +159,7 @@ function unary10d( fcn, arrays, views, strides, strategy, opts ) { // eslint-dis
158159
var i8;
159160
var i9;
160161
var y;
162+
var v;
161163
var i;
162164

163165
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
@@ -241,6 +243,9 @@ function unary10d( fcn, arrays, views, strides, strategy, opts ) { // eslint-dis
241243
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
242244
iv = offsets( arrays );
243245

246+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
247+
v = copyIndexed( views );
248+
244249
// Cache a reference to the output ndarray buffer:
245250
ybuf = y.data;
246251

@@ -256,8 +261,8 @@ function unary10d( fcn, arrays, views, strides, strategy, opts ) { // eslint-dis
256261
for ( i1 = 0; i1 < S1; i1++ ) {
257262
for ( i0 = 0; i0 < S0; i0++ ) {
258263
setViewOffsets( views, iv );
259-
views[ 0 ] = strategy( views[ 0 ] );
260-
ybuf[ iv[1] ] = fcn( views, opts );
264+
v[ 0 ] = strategy( views[ 0 ] );
265+
ybuf[ iv[1] ] = fcn( v, opts );
261266
incrementOffsets( iv, dv0 );
262267
}
263268
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/10d_accessors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
// MODULES //
2424

25+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2526
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
2627
var incrementOffsets = require( './increment_offsets.js' );
2728
var setViewOffsets = require( './set_view_offsets.js' );
@@ -163,6 +164,7 @@ function unary10d( fcn, arrays, views, strides, strategy, opts ) { // eslint-dis
163164
var i8;
164165
var i9;
165166
var y;
167+
var v;
166168
var i;
167169

168170
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
@@ -246,6 +248,9 @@ function unary10d( fcn, arrays, views, strides, strategy, opts ) { // eslint-dis
246248
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
247249
iv = offsets( arrays );
248250

251+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
252+
v = copyIndexed( views );
253+
249254
// Cache a reference to the output ndarray buffer:
250255
ybuf = y.data;
251256

@@ -264,8 +269,8 @@ function unary10d( fcn, arrays, views, strides, strategy, opts ) { // eslint-dis
264269
for ( i1 = 0; i1 < S1; i1++ ) {
265270
for ( i0 = 0; i0 < S0; i0++ ) {
266271
setViewOffsets( views, iv );
267-
views[ 0 ] = strategy( views[ 0 ] );
268-
set( ybuf, iv[ 1 ], fcn( views, opts ) );
272+
v[ 0 ] = strategy( views[ 0 ] );
273+
set( ybuf, iv[ 1 ], fcn( v, opts ) );
269274
incrementOffsets( iv, dv0 );
270275
}
271276
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/10d_blocked.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' );
2626
var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' );
2727
var takeIndexed = require( '@stdlib/array/base/take-indexed' );
28+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2829
var zeros = require( '@stdlib/array/base/zeros' );
2930
var incrementOffsets = require( './increment_offsets.js' );
3031
var setViewOffsets = require( './set_view_offsets.js' );
@@ -184,6 +185,7 @@ function blockedunary10d( fcn, arrays, views, strides, strategy, opts ) { // esl
184185
var N;
185186
var x;
186187
var y;
188+
var v;
187189
var o;
188190
var k;
189191

@@ -235,6 +237,9 @@ function blockedunary10d( fcn, arrays, views, strides, strategy, opts ) { // esl
235237
dv9 = zeros( N );
236238
iv = zeros( N );
237239

240+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
241+
v = copyIndexed( views );
242+
238243
// Iterate over blocks...
239244
for ( j9 = sh[9]; j9 > 0; ) {
240245
if ( j9 < bsize ) {
@@ -368,8 +373,8 @@ function blockedunary10d( fcn, arrays, views, strides, strategy, opts ) { // esl
368373
for ( i1 = 0; i1 < s1; i1++ ) {
369374
for ( i0 = 0; i0 < s0; i0++ ) {
370375
setViewOffsets( views, iv );
371-
views[ 0 ] = strategy( views[ 0 ] );
372-
ybuf[ iv[1] ] = fcn( views, opts );
376+
v[ 0 ] = strategy( views[ 0 ] );
377+
ybuf[ iv[1] ] = fcn( v, opts );
373378
incrementOffsets( iv, dv0 );
374379
}
375380
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/10d_blocked_accessors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' );
2626
var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' );
2727
var takeIndexed = require( '@stdlib/array/base/take-indexed' );
28+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2829
var zeros = require( '@stdlib/array/base/zeros' );
2930
var incrementOffsets = require( './increment_offsets.js' );
3031
var setViewOffsets = require( './set_view_offsets.js' );
@@ -189,6 +190,7 @@ function blockedunary10d( fcn, arrays, views, strides, strategy, opts ) { // esl
189190
var N;
190191
var x;
191192
var y;
193+
var v;
192194
var o;
193195
var k;
194196

@@ -243,6 +245,9 @@ function blockedunary10d( fcn, arrays, views, strides, strategy, opts ) { // esl
243245
dv9 = zeros( N );
244246
iv = zeros( N );
245247

248+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
249+
v = copyIndexed( views );
250+
246251
// Iterate over blocks...
247252
for ( j9 = sh[9]; j9 > 0; ) {
248253
if ( j9 < bsize ) {
@@ -376,8 +381,8 @@ function blockedunary10d( fcn, arrays, views, strides, strategy, opts ) { // esl
376381
for ( i1 = 0; i1 < s1; i1++ ) {
377382
for ( i0 = 0; i0 < s0; i0++ ) {
378383
setViewOffsets( views, iv );
379-
views[ 0 ] = strategy( views[ 0 ] );
380-
set( ybuf, iv[ 1 ], fcn( views, opts ) );
384+
v[ 0 ] = strategy( views[ 0 ] );
385+
set( ybuf, iv[ 1 ], fcn( v, opts ) );
381386
incrementOffsets( iv, dv0 );
382387
}
383388
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/1d.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2324
var incrementOffsets = require( './increment_offsets.js' );
2425
var setViewOffsets = require( './set_view_offsets.js' );
2526
var offsets = require( './offsets.js' );
@@ -127,6 +128,7 @@ function unary1d( fcn, arrays, views, strides, strategy, opts ) {
127128
var iv;
128129
var i0;
129130
var y;
131+
var v;
130132
var i;
131133

132134
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
@@ -144,14 +146,17 @@ function unary1d( fcn, arrays, views, strides, strategy, opts ) {
144146
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
145147
iv = offsets( arrays );
146148

149+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
150+
v = copyIndexed( views );
151+
147152
// Cache a reference to the output ndarray buffer:
148153
ybuf = y.data;
149154

150155
// Iterate over the non-reduced ndarray dimensions...
151156
for ( i0 = 0; i0 < S0; i0++ ) {
152157
setViewOffsets( views, iv );
153-
views[ 0 ] = strategy( views[ 0 ] );
154-
ybuf[ iv[1] ] = fcn( views, opts );
158+
v[ 0 ] = strategy( views[ 0 ] );
159+
ybuf[ iv[1] ] = fcn( v, opts );
155160
incrementOffsets( iv, dv0 );
156161
}
157162
}

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/1d_accessors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2324
var incrementOffsets = require( './increment_offsets.js' );
2425
var setViewOffsets = require( './set_view_offsets.js' );
2526
var offsets = require( './offsets.js' );
@@ -132,6 +133,7 @@ function unary1d( fcn, arrays, views, strides, strategy, opts ) {
132133
var iv;
133134
var i0;
134135
var y;
136+
var v;
135137
var i;
136138

137139
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
@@ -149,6 +151,9 @@ function unary1d( fcn, arrays, views, strides, strategy, opts ) {
149151
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
150152
iv = offsets( arrays );
151153

154+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
155+
v = copyIndexed( views );
156+
152157
// Cache a reference to the output ndarray buffer:
153158
ybuf = y.data;
154159

@@ -158,8 +163,8 @@ function unary1d( fcn, arrays, views, strides, strategy, opts ) {
158163
// Iterate over the non-reduced ndarray dimensions...
159164
for ( i0 = 0; i0 < S0; i0++ ) {
160165
setViewOffsets( views, iv );
161-
views[ 0 ] = strategy( views[ 0 ] );
162-
set( ybuf, iv[1], fcn( views, opts ) );
166+
v[ 0 ] = strategy( views[ 0 ] );
167+
set( ybuf, iv[1], fcn( v, opts ) );
163168
incrementOffsets( iv, dv0 );
164169
}
165170
}

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/2d.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2324
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
2425
var incrementOffsets = require( './increment_offsets.js' );
2526
var setViewOffsets = require( './set_view_offsets.js' );
@@ -132,6 +133,7 @@ function unary2d( fcn, arrays, views, strides, strategy, opts ) {
132133
var i0;
133134
var i1;
134135
var y;
136+
var v;
135137
var i;
136138

137139
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
@@ -167,15 +169,18 @@ function unary2d( fcn, arrays, views, strides, strategy, opts ) {
167169
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
168170
iv = offsets( arrays );
169171

172+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
173+
v = copyIndexed( views );
174+
170175
// Cache a reference to the output ndarray buffer:
171176
ybuf = y.data;
172177

173178
// Iterate over the non-reduced ndarray dimensions...
174179
for ( i1 = 0; i1 < S1; i1++ ) {
175180
for ( i0 = 0; i0 < S0; i0++ ) {
176181
setViewOffsets( views, iv );
177-
views[ 0 ] = strategy( views[ 0 ] );
178-
ybuf[ iv[1] ] = fcn( views, opts );
182+
v[ 0 ] = strategy( views[ 0 ] );
183+
ybuf[ iv[1] ] = fcn( v, opts );
179184
incrementOffsets( iv, dv0 );
180185
}
181186
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/2d_accessors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2324
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
2425
var incrementOffsets = require( './increment_offsets.js' );
2526
var setViewOffsets = require( './set_view_offsets.js' );
@@ -137,6 +138,7 @@ function unary2d( fcn, arrays, views, strides, strategy, opts ) {
137138
var i0;
138139
var i1;
139140
var y;
141+
var v;
140142
var i;
141143

142144
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
@@ -172,6 +174,9 @@ function unary2d( fcn, arrays, views, strides, strategy, opts ) {
172174
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
173175
iv = offsets( arrays );
174176

177+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
178+
v = copyIndexed( views );
179+
175180
// Cache a reference to the output ndarray buffer:
176181
ybuf = y.data;
177182

@@ -182,8 +187,8 @@ function unary2d( fcn, arrays, views, strides, strategy, opts ) {
182187
for ( i1 = 0; i1 < S1; i1++ ) {
183188
for ( i0 = 0; i0 < S0; i0++ ) {
184189
setViewOffsets( views, iv );
185-
views[ 0 ] = strategy( views[ 0 ] );
186-
set( ybuf, iv[1], fcn( views, opts ) );
190+
v[ 0 ] = strategy( views[ 0 ] );
191+
set( ybuf, iv[ 1 ], fcn( v, opts ) );
187192
incrementOffsets( iv, dv0 );
188193
}
189194
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/2d_blocked.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' );
2424
var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' );
2525
var takeIndexed = require( '@stdlib/array/base/take-indexed' );
26+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2627
var zeros = require( '@stdlib/array/base/zeros' );
2728
var incrementOffsets = require( './increment_offsets.js' );
2829
var setViewOffsets = require( './set_view_offsets.js' );
@@ -142,6 +143,7 @@ function blockedunary2d( fcn, arrays, views, strides, strategy, opts ) {
142143
var N;
143144
var x;
144145
var y;
146+
var v;
145147
var o;
146148
var k;
147149

@@ -177,6 +179,9 @@ function blockedunary2d( fcn, arrays, views, strides, strategy, opts ) {
177179
dv1 = zeros( N );
178180
iv = zeros( N );
179181

182+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
183+
v = copyIndexed( views );
184+
180185
// Iterate over blocks...
181186
for ( j1 = sh[1]; j1 > 0; ) {
182187
if ( j1 < bsize ) {
@@ -206,8 +211,8 @@ function blockedunary2d( fcn, arrays, views, strides, strategy, opts ) {
206211
for ( i1 = 0; i1 < s1; i1++ ) {
207212
for ( i0 = 0; i0 < s0; i0++ ) {
208213
setViewOffsets( views, iv );
209-
views[ 0 ] = strategy( views[ 0 ] );
210-
ybuf[ iv[1] ] = fcn( views, opts );
214+
v[ 0 ] = strategy( views[ 0 ] );
215+
ybuf[ iv[1] ] = fcn( v, opts );
211216
incrementOffsets( iv, dv0 );
212217
}
213218
incrementOffsets( iv, dv1 );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d/lib/2d_blocked_accessors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var loopOrder = require( '@stdlib/ndarray/base/unary-loop-interchange-order' );
2424
var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' );
2525
var takeIndexed = require( '@stdlib/array/base/take-indexed' );
26+
var copyIndexed = require( '@stdlib/array/base/copy-indexed' );
2627
var zeros = require( '@stdlib/array/base/zeros' );
2728
var incrementOffsets = require( './increment_offsets.js' );
2829
var setViewOffsets = require( './set_view_offsets.js' );
@@ -147,6 +148,7 @@ function blockedunary2d( fcn, arrays, views, strides, strategy, opts ) {
147148
var N;
148149
var x;
149150
var y;
151+
var v;
150152
var o;
151153
var k;
152154

@@ -185,6 +187,9 @@ function blockedunary2d( fcn, arrays, views, strides, strategy, opts ) {
185187
dv1 = zeros( N );
186188
iv = zeros( N );
187189

190+
// Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views:
191+
v = copyIndexed( views );
192+
188193
// Iterate over blocks...
189194
for ( j1 = sh[1]; j1 > 0; ) {
190195
if ( j1 < bsize ) {
@@ -214,8 +219,8 @@ function blockedunary2d( fcn, arrays, views, strides, strategy, opts ) {
214219
for ( i1 = 0; i1 < s1; i1++ ) {
215220
for ( i0 = 0; i0 < s0; i0++ ) {
216221
setViewOffsets( views, iv );
217-
views[ 0 ] = strategy( views[ 0 ] );
218-
set( ybuf, iv[1], fcn( views, opts ) );
222+
v[ 0 ] = strategy( views[ 0 ] );
223+
set( ybuf, iv[ 1 ], fcn( v, opts ) );
219224
incrementOffsets( iv, dv0 );
220225
}
221226
incrementOffsets( iv, dv1 );

0 commit comments

Comments
 (0)