Skip to content

Commit 6d4630b

Browse files
committed
docs: update to support data type objects and be opaque regarding return value
--- 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: 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 4f2cdaa commit 6d4630b

7 files changed

Lines changed: 81 additions & 73 deletions

File tree

lib/node_modules/@stdlib/ndarray/base/unary-output-dtype/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,22 @@ Resolves the output ndarray [data type][@stdlib/ndarray/dtypes] for a unary func
4646

4747
```javascript
4848
var dt = unaryOutputDataType( 'int32', 'floating_point' );
49+
50+
var s = String( dt );
4951
// returns 'float64'
5052
```
5153

5254
If `policy` is a [data type][@stdlib/ndarray/dtypes], the function always returns the `policy` value (i.e., the second argument).
5355

5456
```javascript
5557
var dt = unaryOutputDataType( 'float32', 'float64' );
58+
59+
var s = String( dt );
5660
// returns 'float64'
5761

5862
dt = unaryOutputDataType( 'int32', 'float64' );
63+
64+
s = String( dt );
5965
// returns 'float64'
6066

6167
// ...

lib/node_modules/@stdlib/ndarray/base/unary-output-dtype/benchmark/benchmark.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var bench = require( '@stdlib/bench' );
2424
var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
2525
var dtypes = require( '@stdlib/ndarray/dtypes' );
26+
var format = require( '@stdlib/string/format' );
2627
var pkg = require( './../package.json' ).name;
2728
var resolve = require( './../lib' );
2829

@@ -34,15 +35,15 @@ var DTYPES = dtypes( 'numeric' );
3435

3536
// MAIN //
3637

37-
bench( pkg+':policy=default', function benchmark( b ) {
38+
bench( format( '%s:policy=default', pkg ), function benchmark( b ) {
3839
var out;
3940
var i;
4041

4142
b.tic();
4243
for ( i = 0; i < b.iterations; i++ ) {
4344
out = resolve( DTYPES[ i%DTYPES.length ], 'default' );
44-
if ( typeof out !== 'string' ) {
45-
b.fail( 'should return a string' );
45+
if ( typeof out === 'boolean' ) {
46+
b.fail( 'should return a data type' );
4647
}
4748
}
4849
b.toc();
@@ -53,15 +54,15 @@ bench( pkg+':policy=default', function benchmark( b ) {
5354
b.end();
5455
});
5556

56-
bench( pkg+':policy=same', function benchmark( b ) {
57+
bench( format( '%s:policy=same', pkg ), function benchmark( b ) {
5758
var out;
5859
var i;
5960

6061
b.tic();
6162
for ( i = 0; i < b.iterations; i++ ) {
6263
out = resolve( DTYPES[ i%DTYPES.length ], 'same' );
63-
if ( typeof out !== 'string' ) {
64-
b.fail( 'should return a string' );
64+
if ( typeof out === 'boolean' ) {
65+
b.fail( 'should return a data type' );
6566
}
6667
}
6768
b.toc();
@@ -72,15 +73,15 @@ bench( pkg+':policy=same', function benchmark( b ) {
7273
b.end();
7374
});
7475

75-
bench( pkg+':policy=promoted', function benchmark( b ) {
76+
bench( format( '%s:policy=promoted', pkg ), function benchmark( b ) {
7677
var out;
7778
var i;
7879

7980
b.tic();
8081
for ( i = 0; i < b.iterations; i++ ) {
8182
out = resolve( DTYPES[ i%DTYPES.length ], 'promoted' );
82-
if ( typeof out !== 'string' ) {
83-
b.fail( 'should return a string' );
83+
if ( typeof out === 'boolean' ) {
84+
b.fail( 'should return a data type' );
8485
}
8586
}
8687
b.toc();
@@ -91,15 +92,15 @@ bench( pkg+':policy=promoted', function benchmark( b ) {
9192
b.end();
9293
});
9394

94-
bench( pkg+':policy=real', function benchmark( b ) {
95+
bench( format( '%s:policy=real', pkg ), function benchmark( b ) {
9596
var out;
9697
var i;
9798

9899
b.tic();
99100
for ( i = 0; i < b.iterations; i++ ) {
100101
out = resolve( DTYPES[ i%DTYPES.length ], 'real' );
101-
if ( typeof out !== 'string' ) {
102-
b.fail( 'should return a string' );
102+
if ( typeof out === 'boolean' ) {
103+
b.fail( 'should return a data type' );
103104
}
104105
}
105106
b.toc();
@@ -110,15 +111,15 @@ bench( pkg+':policy=real', function benchmark( b ) {
110111
b.end();
111112
});
112113

113-
bench( pkg+':policy=floating_point', function benchmark( b ) {
114+
bench( format( '%s:policy=floating_point', pkg ), function benchmark( b ) {
114115
var out;
115116
var i;
116117

117118
b.tic();
118119
for ( i = 0; i < b.iterations; i++ ) {
119120
out = resolve( DTYPES[ i%DTYPES.length ], 'floating_point' );
120-
if ( typeof out !== 'string' ) {
121-
b.fail( 'should return a string' );
121+
if ( typeof out === 'boolean' ) {
122+
b.fail( 'should return a data type' );
122123
}
123124
}
124125
b.toc();
@@ -129,15 +130,15 @@ bench( pkg+':policy=floating_point', function benchmark( b ) {
129130
b.end();
130131
});
131132

132-
bench( pkg+':policy=real_floating_point', function benchmark( b ) {
133+
bench( format( '%s:policy=real_floating_point', pkg ), function benchmark( b ) {
133134
var out;
134135
var i;
135136

136137
b.tic();
137138
for ( i = 0; i < b.iterations; i++ ) {
138139
out = resolve( DTYPES[ i%DTYPES.length ], 'real_floating_point' );
139-
if ( typeof out !== 'string' ) {
140-
b.fail( 'should return a string' );
140+
if ( typeof out === 'boolean' ) {
141+
b.fail( 'should return a data type' );
141142
}
142143
}
143144
b.toc();
@@ -148,15 +149,15 @@ bench( pkg+':policy=real_floating_point', function benchmark( b ) {
148149
b.end();
149150
});
150151

151-
bench( pkg+':policy=complex_floating_point', function benchmark( b ) {
152+
bench( format( '%s:policy=complex_floating_point', pkg ), function benchmark( b ) {
152153
var out;
153154
var i;
154155

155156
b.tic();
156157
for ( i = 0; i < b.iterations; i++ ) {
157158
out = resolve( DTYPES[ i%DTYPES.length ], 'complex_floating_point' );
158-
if ( typeof out !== 'string' ) {
159-
b.fail( 'should return a string' );
159+
if ( typeof out === 'boolean' ) {
160+
b.fail( 'should return a data type' );
160161
}
161162
}
162163
b.toc();
@@ -167,15 +168,15 @@ bench( pkg+':policy=complex_floating_point', function benchmark( b ) {
167168
b.end();
168169
});
169170

170-
bench( pkg+':policy=integer', function benchmark( b ) {
171+
bench( format( '%s:policy=integer', pkg ), function benchmark( b ) {
171172
var out;
172173
var i;
173174

174175
b.tic();
175176
for ( i = 0; i < b.iterations; i++ ) {
176177
out = resolve( DTYPES[ i%DTYPES.length ], 'integer' );
177-
if ( typeof out !== 'string' ) {
178-
b.fail( 'should return a string' );
178+
if ( typeof out === 'boolean' ) {
179+
b.fail( 'should return a data type' );
179180
}
180181
}
181182
b.toc();
@@ -186,15 +187,15 @@ bench( pkg+':policy=integer', function benchmark( b ) {
186187
b.end();
187188
});
188189

189-
bench( pkg+':policy=signed_integer', function benchmark( b ) {
190+
bench( format( '%s:policy=signed_integer', pkg ), function benchmark( b ) {
190191
var out;
191192
var i;
192193

193194
b.tic();
194195
for ( i = 0; i < b.iterations; i++ ) {
195196
out = resolve( DTYPES[ i%DTYPES.length ], 'signed_integer' );
196-
if ( typeof out !== 'string' ) {
197-
b.fail( 'should return a string' );
197+
if ( typeof out === 'boolean' ) {
198+
b.fail( 'should return a data type' );
198199
}
199200
}
200201
b.toc();
@@ -205,15 +206,15 @@ bench( pkg+':policy=signed_integer', function benchmark( b ) {
205206
b.end();
206207
});
207208

208-
bench( pkg+':policy=unsigned_integer', function benchmark( b ) {
209+
bench( format( '%s:policy=unsigned_integer', pkg ), function benchmark( b ) {
209210
var out;
210211
var i;
211212

212213
b.tic();
213214
for ( i = 0; i < b.iterations; i++ ) {
214215
out = resolve( DTYPES[ i%DTYPES.length ], 'unsigned_integer' );
215-
if ( typeof out !== 'string' ) {
216-
b.fail( 'should return a string' );
216+
if ( typeof out === 'boolean' ) {
217+
b.fail( 'should return a data type' );
217218
}
218219
}
219220
b.toc();
@@ -224,15 +225,15 @@ bench( pkg+':policy=unsigned_integer', function benchmark( b ) {
224225
b.end();
225226
});
226227

227-
bench( pkg+':policy=numeric', function benchmark( b ) {
228+
bench( format( '%s:policy=numeric', pkg ), function benchmark( b ) {
228229
var out;
229230
var i;
230231

231232
b.tic();
232233
for ( i = 0; i < b.iterations; i++ ) {
233234
out = resolve( DTYPES[ i%DTYPES.length ], 'numeric' );
234-
if ( typeof out !== 'string' ) {
235-
b.fail( 'should return a string' );
235+
if ( typeof out === 'boolean' ) {
236+
b.fail( 'should return a data type' );
236237
}
237238
}
238239
b.toc();
@@ -243,15 +244,15 @@ bench( pkg+':policy=numeric', function benchmark( b ) {
243244
b.end();
244245
});
245246

246-
bench( pkg+':policy=<dtype>', function benchmark( b ) {
247+
bench( format( '%s:policy=<dtype>', pkg ), function benchmark( b ) {
247248
var out;
248249
var i;
249250

250251
b.tic();
251252
for ( i = 0; i < b.iterations; i++ ) {
252253
out = resolve( DTYPES[ i%DTYPES.length ], 'int32' );
253-
if ( typeof out !== 'string' ) {
254-
b.fail( 'should return a string' );
254+
if ( typeof out === 'boolean' ) {
255+
b.fail( 'should return a data type' );
255256
}
256257
}
257258
b.toc();

lib/node_modules/@stdlib/ndarray/base/unary-output-dtype/docs/repl.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55
Parameters
66
----------
7-
dtype: string
7+
dtype: string|DataType
88
Input ndarray data type.
99

10-
policy: string
10+
policy: string|DataType
1111
Output ndarray data type policy. If `policy` is a data type, the
1212
function returns the `policy` value.
1313

1414
Returns
1515
-------
16-
out: string
16+
out: DataType
1717
Output ndarray data type.
1818

1919
Examples
2020
--------
21-
> var out = {{alias}}( 'float64', 'real' )
21+
> var dt = {{alias}}( 'float64', 'real' );
22+
> String( dt )
2223
'float64'
2324

2425
See Also

lib/node_modules/@stdlib/ndarray/base/unary-output-dtype/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { DataType, OutputPolicy } from '@stdlib/types/ndarray';
3131
*
3232
* @example
3333
* var dt = outputDataType( 'float64', 'complex_floating_point' );
34-
* // returns <string>
34+
* // returns <DataType>
3535
*/
3636
declare function outputDataType( dtype: DataType, policy: OutputPolicy | DataType ): DataType;
3737

lib/node_modules/@stdlib/ndarray/base/unary-output-dtype/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* var resolve = require( '@stdlib/ndarray/base/unary-output-dtype' );
2828
*
2929
* var dt = resolve( 'float64', 'complex_floating_point' );
30-
* // returns <string>
30+
* // returns <DataType>
3131
*/
3232

3333
// MODULES //

lib/node_modules/@stdlib/ndarray/base/unary-output-dtype/lib/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ var outputDataType = require( '@stdlib/ndarray/base/output-dtype' );
2828
/**
2929
* Resolves the output ndarray data type for a unary function.
3030
*
31-
* @param {string} dtype - input ndarray data type
32-
* @param {string} policy - output ndarray data type policy
31+
* @param {*} dtype - input ndarray data type
32+
* @param {(string|*)} policy - output ndarray data type policy
3333
* @throws {TypeError} second argument must be a recognized data type policy
34-
* @returns {string} output ndarray data type
34+
* @returns {DataType} output ndarray data type
3535
*
3636
* @example
3737
* var dt = resolve( 'float64', 'complex_floating_point' );
38-
* // returns <string>
38+
* // returns <DataType>
3939
*/
4040
function resolve( dtype, policy ) {
4141
return outputDataType( [ dtype ], policy );

0 commit comments

Comments
 (0)