Skip to content

Commit 1fcc2fd

Browse files
committed
refactor: refactor reshape strategy for nullary
--- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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 4bc9fed commit 1fcc2fd

File tree

10 files changed

+29
-91
lines changed

10 files changed

+29
-91
lines changed

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ var x = {
179179
'offset': 0,
180180
'order': 'row-major'
181181
};
182+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
183+
182184
var sortOrder = {
183185
'dtype': 'generic',
184186
'data': [ 0.0 ],

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/examples/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ var x = {
4747
'offset': 0,
4848
'order': 'row-major'
4949
};
50+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
51+
5052
var sortOrder = {
5153
'dtype': 'generic',
52-
'data': [ 0.0 ],
53-
'shape': [ 1, 2 ],
54-
'strides': [ 0, 0 ],
54+
'data': [ 1.0 ],
55+
'shape': [ 2 ],
56+
'strides': [ 0 ],
5557
'offset': 0,
5658
'order': 'row-major'
5759
};
5860

59-
nullaryStrided1d( wrapper, [ x, sortOrder ], [ 0 ] );
61+
nullaryStrided1d( wrapper, [ x, sortOrder ], [ 0, 1 ] );
6062

6163
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/0d.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* };
7979
*
8080
* // Define an input strategy:
81-
* function inputStrategy( x ) {
81+
* function strategy( x ) {
8282
* return {
8383
* 'dtype': x.dtype,
8484
* 'data': x.data,
@@ -89,18 +89,14 @@
8989
* };
9090
* }
9191
*
92-
* var strategy = {
93-
* 'input': inputStrategy
94-
* };
95-
*
9692
* // Apply strided function:
9793
* nullary0d( wrapper, [ x, sortOrder ], strategy, {} );
9894
*
9995
* var v = x.data;
10096
* // returns [ 1.0, 2.0, 3.0, 4.0 ]
10197
*/
10298
function nullary0d( fcn, arrays, strategyX, opts ) {
103-
arrays[ 0 ] = strategyX.input( arrays[ 0 ] );
99+
arrays[ 0 ] = strategyX( arrays[ 0 ] );
104100
fcn( arrays, opts );
105101
}
106102

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var offsets = require( './offsets.js' );
109109
* ];
110110
*
111111
* // Define an input strategy:
112-
* function inputStrategy( x ) {
112+
* function strategy( x ) {
113113
* return {
114114
* 'dtype': x.dtype,
115115
* 'data': x.data,
@@ -120,10 +120,6 @@ var offsets = require( './offsets.js' );
120120
* };
121121
* }
122122
*
123-
* var strategy = {
124-
* 'input': inputStrategy
125-
* };
126-
*
127123
* // Apply strided function:
128124
* nullary1d( wrapper, [ x, sortOrder ], views, [ 3 ], [ 4 ], strategy, {} );
129125
*
@@ -157,7 +153,7 @@ function nullary1d( fcn, arrays, views, shape, stridesX, strategyX, opts ) {
157153
// Iterate over the loop dimensions...
158154
for ( i0 = 0; i0 < S0; i0++ ) {
159155
setViewOffsets( views, iv );
160-
v[ 0 ] = strategyX.input( views[ 0 ] );
156+
v[ 0 ] = strategyX( views[ 0 ] );
161157
fcn( v, opts );
162158
incrementOffsets( iv, dv0 );
163159
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var offsets = require( './offsets.js' );
110110
* ];
111111
*
112112
* // Define an input strategy:
113-
* function inputStrategy( x ) {
113+
* function strategy( x ) {
114114
* return {
115115
* 'dtype': x.dtype,
116116
* 'data': x.data,
@@ -121,10 +121,6 @@ var offsets = require( './offsets.js' );
121121
* };
122122
* }
123123
*
124-
* var strategy = {
125-
* 'input': inputStrategy
126-
* };
127-
*
128124
* // Apply strided function:
129125
* nullary2d( wrapper, [ x, sortOrder ], views, [ 1, 3 ], [ 12, 4 ], true, strategy, {} );
130126
*
@@ -187,7 +183,7 @@ function nullary2d( fcn, arrays, views, shape, stridesX, isRowMajor, strategyX,
187183
for ( i1 = 0; i1 < S1; i1++ ) {
188184
for ( i0 = 0; i0 < S0; i0++ ) {
189185
setViewOffsets( views, iv );
190-
v[ 0 ] = strategyX.input( views[ 0 ] );
186+
v[ 0 ] = strategyX( views[ 0 ] );
191187
fcn( v, opts );
192188
incrementOffsets( iv, dv0 );
193189
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var offsets = require( './offsets.js' );
113113
* ];
114114
*
115115
* // Define an input strategy:
116-
* function inputStrategy( x ) {
116+
* function strategy( x ) {
117117
* return {
118118
* 'dtype': x.dtype,
119119
* 'data': x.data,
@@ -124,10 +124,6 @@ var offsets = require( './offsets.js' );
124124
* };
125125
* }
126126
*
127-
* var strategy = {
128-
* 'input': inputStrategy
129-
* };
130-
*
131127
* // Apply strided function:
132128
* blockednullary2d( wrapper, [ x, sortOrder ], views, [ 1, 3 ], [ 12, 4 ], strategy, {} );
133129
*
@@ -215,7 +211,7 @@ function blockednullary2d( fcn, arrays, views, shape, stridesX, strategyX, opts
215211
for ( i1 = 0; i1 < s1; i1++ ) {
216212
for ( i0 = 0; i0 < s0; i0++ ) {
217213
setViewOffsets( views, iv );
218-
v[ 0 ] = strategyX.input( views[ 0 ] );
214+
v[ 0 ] = strategyX( views[ 0 ] );
219215
fcn( v, opts );
220216
incrementOffsets( iv, dv0 );
221217
}

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/3d.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var offsets = require( './offsets.js' );
110110
* ];
111111
*
112112
* // Define an input strategy:
113-
* function inputStrategy( x ) {
113+
* function strategy( x ) {
114114
* return {
115115
* 'dtype': x.dtype,
116116
* 'data': x.data,
@@ -121,10 +121,6 @@ var offsets = require( './offsets.js' );
121121
* };
122122
* }
123123
*
124-
* var strategy = {
125-
* 'input': inputStrategy
126-
* };
127-
*
128124
* // Apply strided function:
129125
* nullary3d( wrapper, [ x, sortOrder ], views, [ 1, 1, 3 ], [ 12, 12, 4 ], true, strategy, {} );
130126
*
@@ -201,7 +197,7 @@ function nullary3d( fcn, arrays, views, shape, stridesX, isRowMajor, strategyX,
201197
for ( i1 = 0; i1 < S1; i1++ ) {
202198
for ( i0 = 0; i0 < S0; i0++ ) {
203199
setViewOffsets( views, iv );
204-
v[ 0 ] = strategyX.input( views[ 0 ] );
200+
v[ 0 ] = strategyX( views[ 0 ] );
205201
fcn( v, opts );
206202
incrementOffsets( iv, dv0 );
207203
}

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/3d_blocked.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ var offsets = require( './offsets.js' );
115115
* ];
116116
*
117117
* // Define an input strategy:
118-
* function inputStrategy( x ) {
118+
* function strategy( x ) {
119119
* return {
120120
* 'dtype': x.dtype,
121121
* 'data': x.data,
@@ -126,10 +126,6 @@ var offsets = require( './offsets.js' );
126126
* };
127127
* }
128128
*
129-
* var strategy = {
130-
* 'input': inputStrategy
131-
* };
132-
*
133129
* // Apply strided function:
134130
* blockednullary3d( wrapper, [ x, sortOrder ], views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategy, {} );
135131
*
@@ -237,7 +233,7 @@ function blockednullary3d( fcn, arrays, views, shape, stridesX, strategyX, opts
237233
for ( i1 = 0; i1 < s1; i1++ ) {
238234
for ( i0 = 0; i0 < s0; i0++ ) {
239235
setViewOffsets( views, iv );
240-
v[ 0 ] = strategyX.input( views[ 0 ] );
236+
v[ 0 ] = strategyX( views[ 0 ] );
241237
fcn( v, opts );
242238
incrementOffsets( iv, dv0 );
243239
}

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/nd.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var MODE = 'throw';
116116
* ];
117117
*
118118
* // Define an input strategy:
119-
* function inputStrategy( x ) {
119+
* function strategy( x ) {
120120
* return {
121121
* 'dtype': x.dtype,
122122
* 'data': x.data,
@@ -127,10 +127,6 @@ var MODE = 'throw';
127127
* };
128128
* }
129129
*
130-
* var strategy = {
131-
* 'input': inputStrategy
132-
* };
133-
*
134130
* // Apply strided function:
135131
* nullarynd( wrapper, [ x, sortOrder ], views, [ 3 ], [ 4 ], strategy, {} );
136132
*
@@ -166,7 +162,7 @@ function nullarynd( fcn, arrays, views, shape, stridesX, strategyX, opts ) {
166162
io[ j ] = vind2bind( shape, arr.strides, iv[ j ], arr.order, i, MODE ); // eslint-disable-line max-len
167163
}
168164
setViewOffsets( views, io );
169-
v[ 0 ] = strategyX.input( views[ 0 ] );
165+
v[ 0 ] = strategyX( views[ 0 ] );
170166
fcn( v, opts );
171167
}
172168
}

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/strategy.js

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -178,34 +178,11 @@ function copyToWorkspace( len, workspace ) {
178178
}
179179
}
180180

181-
/**
182-
* Returns a function which copies from a contiguous ndarray workspace to an input ndarray.
183-
*
184-
* @private
185-
* @param {ndarrayLike} workspace - ndarray workspace
186-
* @returns {Function} function which copies from a contiguous ndarray workspace to an input ndarray
187-
*/
188-
function copyFromWorkspace( workspace ) {
189-
return copy;
190-
191-
/**
192-
* Copies from a contiguous ndarray workspace to an input ndarray.
193-
*
194-
* @private
195-
* @param {ndarrayLike} x - input ndarray
196-
* @returns {ndarrayLike} input ndarray
197-
*/
198-
function copy( x ) {
199-
assign( [ workspace, x ] );
200-
return x;
201-
}
202-
}
203-
204181

205182
// MAIN //
206183

207184
/**
208-
* Returns an object for reshaping input ndarrays which have the same data type, shape, and strides as a provided ndarray.
185+
* Returns a function for reshaping input ndarrays which have the same data type, shape, and strides as a provided ndarray.
209186
*
210187
* @private
211188
* @param {ndarrayLike} x - input ndarray
@@ -215,7 +192,7 @@ function copyFromWorkspace( workspace ) {
215192
* @param {IntegerArray} x.strides - input ndarray strides
216193
* @param {NonNegativeInteger} x.offset - input ndarray index offset
217194
* @param {string} x.order - input ndarray memory layout
218-
* @returns {Object} object containing methods implementing a reshape strategy
195+
* @returns {Function} function implementing a reshape strategy
219196
*/
220197
function strategy( x ) {
221198
var workspace;
@@ -233,17 +210,11 @@ function strategy( x ) {
233210

234211
// Check whether the ndarray is zero-dimensional...
235212
if ( ndims === 0 ) {
236-
return {
237-
'input': broadcast,
238-
'output': identity
239-
};
213+
return broadcast;
240214
}
241215
// Check whether the ndarray is already one-dimensional...
242216
if ( ndims === 1 ) {
243-
return {
244-
'input': identity,
245-
'output': identity
246-
};
217+
return identity;
247218
}
248219
// Determine the number of singleton dimensions...
249220
len = 1; // number of elements
@@ -263,10 +234,7 @@ function strategy( x ) {
263234
break;
264235
}
265236
}
266-
return {
267-
'input': squeeze( x, i ),
268-
'output': identity
269-
};
237+
return squeeze( x, i );
270238
}
271239
iox = iterationOrder( x.strides ); // +/-1
272240

@@ -277,21 +245,15 @@ function strategy( x ) {
277245

278246
// Determine whether we can ignore shape (and strides) and create a new one-dimensional ndarray view...
279247
if ( len === ( xmmv[1]-xmmv[0]+1 ) ) {
280-
return {
281-
'input': contiguous( len, iox ),
282-
'output': identity
283-
};
248+
return contiguous( len, iox );
284249
}
285250
// The ndarray is non-contiguous, so we cannot directly interpret as a one-dimensional ndarray...
286251

287252
// Fall-through to copying to a workspace ndarray...
288253
}
289254
// At this point, we're dealing with a non-contiguous multi-dimensional ndarray, so we need to copy to a contiguous workspace:
290255
workspace = ndarraylike2object( emptyLike( ndarraylike2ndarray( x ) ) );
291-
return {
292-
'input': copyToWorkspace( len, workspace ),
293-
'output': copyFromWorkspace( workspace )
294-
};
256+
return copyToWorkspace( len, workspace );
295257
}
296258

297259

0 commit comments

Comments
 (0)