Skip to content

Commit 4e90719

Browse files
committed
refactor: apply suggestions from code review
1 parent 965ad96 commit 4e90719

File tree

9 files changed

+164
-445
lines changed

9 files changed

+164
-445
lines changed

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

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ limitations under the License.
3232
var nullaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' );
3333
```
3434

35-
#### nullaryStrided1dDispatchFactory( table, odtypes, policies\[, options] )
35+
#### nullaryStrided1dDispatchFactory( table, idtypes, odtypes\[, options] )
3636

3737
Returns a function for applying a strided function to an output ndarray.
3838

@@ -46,11 +46,8 @@ var table = {
4646
};
4747

4848
var dtypes = [ 'float64', 'float32', 'generic' ];
49-
var policies = {
50-
'output': 'same'
51-
};
5249

53-
var nullary = nullaryStrided1dDispatchFactory( table, [ dtypes ], policies );
50+
var nullary = nullaryStrided1dDispatchFactory( table, [ dtypes ], dtypes );
5451
```
5552

5653
The function has the following parameters:
@@ -64,11 +61,9 @@ The function has the following parameters:
6461
- **types**: one-dimensional list of ndarray data types describing specialized output ndarray argument signatures. Only the output ndarray argument data types should be specified. Additional ndarray argument data types should be omitted and are not considered during dispatch. The length of `types` must equal the number of strided functions specified by `fcns`.
6562
- **fcns**: list of strided functions which are specific to specialized output ndarray argument signatures.
6663

67-
- **odtypes**: list containing lists of supported output data types for each input ndarray argument.
68-
69-
- **policies**: dispatch policies. Must have the following properties:
64+
- **idtypes**: list containing lists of supported input data types for each input ndarray argument.
7065

71-
- **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies].
66+
- **odtypes**: list of supported output data types.
7267

7368
- **options**: function options (_optional_).
7469

@@ -89,15 +84,13 @@ var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
8984
var ndarray2array = require( '@stdlib/ndarray/to-array' );
9085
var ndarray = require( '@stdlib/ndarray/base/ctor' );
9186

92-
var odt = dtypes( 'real_and_generic' );
93-
var policies = {
94-
'output': 'same'
95-
};
87+
var idt = dtypes( 'real_and_generic' );
88+
var odt = dtypes( 'all' );
9689

9790
var table = {
9891
'default': base
9992
};
100-
var nullary = nullaryStrided1dDispatchFactory( table, [ odt ], policies );
93+
var nullary = nullaryStrided1dDispatchFactory( table, [ idt ], odt );
10194

10295
var xbuf = [ -1.0, 2.0, -3.0 ];
10396
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -169,14 +162,10 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' );
169162
var ndarray = require( '@stdlib/ndarray/ctor' );
170163
var nullaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' );
171164
172-
// Define the supported output data types:
165+
// Define the supported input and output data types:
166+
var idt = dtypes( 'real_and_generic' );
173167
var odt = dtypes( 'all' );
174168
175-
// Define dispatch policies:
176-
var policies = {
177-
'output': 'same'
178-
};
179-
180169
// Define a dispatch table:
181170
var table = {
182171
'types': [
@@ -191,7 +180,7 @@ var table = {
191180
};
192181
193182
// Create an interface for performing an operation:
194-
var sorthp = nullaryStrided1dDispatchFactory( table, [ odt ], policies );
183+
var sorthp = nullaryStrided1dDispatchFactory( table, [ idt ], odt );
195184
196185
// Generate an array of random numbers:
197186
var xbuf = discreteUniform( 25, -10, 10, {
@@ -207,9 +196,7 @@ var o = scalar2ndarray( 1.0, {
207196
});
208197
209198
// Perform operation:
210-
sorthp.assign( x, o, {
211-
'dims': [ 0 ]
212-
});
199+
sorthp.assign( x, o );
213200
214201
// Print the results:
215202
console.log( ndarray2array( x ) );
@@ -231,8 +218,6 @@ console.log( ndarray2array( x ) );
231218

232219
<section class="links">
233220

234-
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies
235-
236221
</section>
237222

238223
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,19 @@ var factory = require( './../lib' );
4242
* @returns {Function} benchmark function
4343
*/
4444
function createBenchmark( len ) {
45-
var policies;
4645
var nullary;
4746
var table;
48-
var dt;
47+
var idt;
48+
var odt;
4949
var x;
5050
var o;
5151

5252
table = {
5353
'default': gsorthp
5454
};
55-
dt = dtypes( 'all' );
56-
policies = {
57-
'output': 'same'
58-
};
59-
nullary = factory( table, [ dt ], policies );
55+
idt = dtypes( 'real_and_generic' );
56+
odt = dtypes( 'all' );
57+
nullary = factory( table, [ idt ], odt );
6058

6159
x = uniform( len, -50.0, 50.0, {
6260
'dtype': 'float64'

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,27 @@ var factory = require( './../lib' );
2929
// MAIN //
3030

3131
bench( pkg+'::factory', function benchmark( b ) {
32-
var policies;
33-
var dtypes;
32+
var idtypes;
33+
var odtypes;
3434
var table;
3535
var v;
3636
var i;
3737

3838
table = {
3939
'default': gsorthp
4040
};
41-
dtypes = [
41+
idtypes = [
42+
'float64',
43+
'float32'
44+
];
45+
odtypes = [
4246
'float64',
4347
'float32'
4448
];
45-
policies = {
46-
'output': 'same'
47-
};
4849

4950
b.tic();
5051
for ( i = 0; i < b.iterations; i++ ) {
51-
v = factory( table, [ dtypes ], policies );
52+
v = factory( table, [ idtypes ], odtypes );
5253
if ( typeof v !== 'function' ) {
5354
b.fail( 'should return a function' );
5455
}

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
{{alias}}( table, odtypes, policies[, options] )
2+
{{alias}}( table, idtypes, odtypes[, options] )
33
Returns function for applying a strided function to an output ndarray.
44

55
Parameters
@@ -28,14 +28,12 @@
2828
- arrays: array containing an output ndarray, followed by any additional
2929
ndarray arguments.
3030

31-
odtypes: Array<Array<string>>
32-
List containing lists of supported output array data types for each
33-
output ndarray argument.
31+
idtypes: Array<Array<string>>
32+
List containing lists of supported input data types for each input
33+
ndarray argument.
3434

35-
policies: Object
36-
Dispatch policies. Must have the following properties:
37-
38-
- output: output data type policy.
35+
odtypes: Array<string>
36+
List of supported output data types.
3937

4038
options: Object (optional)
4139
Function options.
@@ -51,10 +49,10 @@
5149

5250
Examples
5351
--------
54-
> var dt = [ 'float64', 'float32', 'generic' ];
55-
> var p = { 'output': 'same' };
52+
> var idt = [ 'float64', 'float32', 'generic' ];
53+
> var odt = [ 'float64', 'float32', 'generic' ];
5654
> var t = { 'default': {{alias:@stdlib/blas/ext/base/ndarray/gsorthp}} };
57-
> var f = {{alias}}( t, [ dt ], p );
55+
> var f = {{alias}}( t, [ idt ], odt );
5856

5957
fcn.assign( x[, ...args][, options] )
6058
Applies a strided function and assign results to a provided output ndarray.
@@ -82,10 +80,10 @@ fcn.assign( x[, ...args][, options] )
8280

8381
Examples
8482
--------
85-
> var dts = [ 'float64', 'float32', 'generic' ];
86-
> var p = { 'output': 'same' };
83+
> var idt = [ 'float64', 'float32', 'generic' ];
84+
> var odt = [ 'float64', 'float32', 'generic' ];
8785
> var t = { 'default': {{alias:@stdlib/blas/ext/base/ndarray/gsorthp}} };
88-
> var f = {{alias}}( t, [ dts ], p );
86+
> var f = {{alias}}( t, [ idt ], odt );
8987
> var buf = [ -1.0, 2.0, -3.0, -4.0 ];
9088
> var dt = 'generic';
9189
> var sh = [ buf.length ];

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// <reference types="@stdlib/types"/>
2222

2323
import { ArrayLike } from '@stdlib/types/array';
24-
import { OutputPolicy, DataType, typedndarray } from '@stdlib/types/ndarray';
24+
import { DataType, typedndarray } from '@stdlib/types/ndarray';
2525

2626
/**
2727
* Input array.
@@ -96,15 +96,6 @@ interface DispatchTable<T> extends BaseDispatchTable<T> {
9696
fcns: ArrayLike<Nullary<T> | NullaryWithAdditionalArrays<T>>;
9797
}
9898

99-
/**
100-
* Dispatch policies.
101-
*/
102-
interface Policies {
103-
/**
104-
* Output data type policy.
105-
*/
106-
output: OutputPolicy;
107-
}
10899

109100
/**
110101
* Interface for applying an operation to an ndarray.
@@ -124,20 +115,22 @@ interface NullaryFunction<T> {
124115
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
125116
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
126117
*
118+
* var idt = dtypes( 'real_and_generic' );
127119
* var odt = dtypes( 'all' );
128-
* var policies = {
129-
* 'output': 'same'
130-
* };
131120
*
132121
* var table = {
133122
* 'default': base
134123
* };
135-
* var sorthp = factory( table, [ odt ], policy );
124+
* var sorthp = factory( table, [ idt ], odt );
136125
*
137126
* var xbuf = [ -1.0, 2.0, -3.0 ];
138127
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
139128
*
140-
* var out = sorthp.assign( x );
129+
* var o = scalar2ndarray( 1.0, {
130+
* 'dtype': 'generic'
131+
* });
132+
*
133+
* var out = sorthp.assign( x, o );
141134
* // returns <ndarray>
142135
*
143136
* var arr = ndarray2array( out );
@@ -163,15 +156,13 @@ interface NullaryFunction<T> {
163156
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
164157
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
165158
*
159+
* var idt = dtypes( 'real_and_generic' );
166160
* var odt = dtypes( 'all' );
167-
* var policies = {
168-
* 'output': 'same'
169-
* };
170161
*
171162
* var table = {
172163
* 'default': base
173164
* };
174-
* var sorthp = factory( table, [ odt ], policy );
165+
* var sorthp = factory( table, [ idt ], odt );
175166
*
176167
* var xbuf = [ -1.0, 2.0, -3.0 ];
177168
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -196,10 +187,10 @@ interface NullaryFunction<T> {
196187
* Creates a function for applying a strided function to an output ndarray.
197188
*
198189
* @param table - dispatch table
199-
* @param odtypes - list containing lists of supported output data types for each ndarray argument
200-
* @param policies - dispatch policies
190+
* @param idtypes - list containing lists of supported input data types for each ndarray argument
191+
* @param odtypes - list of supported output data types
201192
* @param options - function options
202-
* @returns function for applying a unary function
193+
* @returns function for applying a nullary function
203194
*
204195
* @example
205196
* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' );
@@ -208,15 +199,13 @@ interface NullaryFunction<T> {
208199
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
209200
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
210201
*
202+
* var idt = dtypes( 'real_and_generic' );
211203
* var odt = dtypes( 'all' );
212-
* var policies = {
213-
* 'output': 'same'
214-
* };
215204
*
216205
* var table = {
217206
* 'default': base
218207
* };
219-
* var sorthp = factory( table, [ odt ], policy );
208+
* var sorthp = factory( table, [ idt ], odt );
220209
*
221210
* var xbuf = [ -1.0, 2.0, -3.0 ];
222211
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
@@ -234,7 +223,7 @@ interface NullaryFunction<T> {
234223
* var bool = ( out === x );
235224
* // returns true
236225
*/
237-
declare function factory<T = unknown>( table: DispatchTable<T> | BaseDispatchTable<T>, odtypes: ArrayLike<ArrayLike<DataType>>, policies: Policies, options?: FactoryOptions ): NullaryFunction<T>;
226+
declare function factory<T = unknown>( table: DispatchTable<T> | BaseDispatchTable<T>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction<T>;
238227

239228

240229
// EXPORTS //

0 commit comments

Comments
 (0)