@stdlib/strided-base-unary-dtype-signatures 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2022 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+ # Unary Signatures
22
+
23
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
24
+
25
+ > Generate a list of unary interface signatures from strided array [data types][@stdlib/strided/dtypes].
26
+
27
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
28
+
29
+ <section class="intro">
30
+
31
+ </section>
32
+
33
+ <!-- /.intro -->
34
+
35
+ <!-- Package usage documentation. -->
36
+
37
+ <section class="installation">
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ npm install @stdlib/strided-base-unary-dtype-signatures
43
+ ```
44
+
45
+ </section>
46
+
47
+ <section class="usage">
48
+
49
+ ## Usage
50
+
51
+ ```javascript
52
+ var signatures = require( '@stdlib/strided-base-unary-dtype-signatures' );
53
+ ```
54
+
55
+ #### signatures( dtypes1, dtypes2\[, options] )
56
+
57
+ Generates a list of unary interface signatures from strided array [data types][@stdlib/strided/dtypes].
58
+
59
+ ```javascript
60
+ var dtypes = [
61
+ 'float64',
62
+ 'float32',
63
+ 'int32',
64
+ 'uint8'
65
+ ];
66
+
67
+ var sigs = signatures( dtypes, dtypes );
68
+ // e.g., returns [ 'float32', 'float32', ... ]
69
+ ```
70
+
71
+ The function accepts the following arguments:
72
+
73
+ - **dtypes1**: list of supported [data types][@stdlib/strided/dtypes] for the input argument.
74
+ - **dtypes2**: list of supported [data types][@stdlib/strided/dtypes] for the output argument.
75
+ - **options**: options.
76
+
77
+ The function accepts the following options:
78
+
79
+ - **enums**: `boolean` flag indicating whether to return signatures as a list of [data type][@stdlib/strided/dtypes] enumeration constants. Default: `false`.
80
+
81
+ When the `enums` options is `false`, the function returns an array of [data type][@stdlib/strided/dtypes] strings. To return [data type][@stdlib/strided/dtypes] enumeration constants, set the `enums` option to `true`.
82
+
83
+ ```javascript
84
+ var dtypes = [
85
+ 'float64',
86
+ 'float32',
87
+ 'int32',
88
+ 'uint8'
89
+ ];
90
+ var options = {
91
+ 'enums': true
92
+ };
93
+
94
+ var sigs = signatures( dtypes, dtypes, options );
95
+ // returns [...]
96
+ ```
97
+
98
+ </section>
99
+
100
+ <!-- /.usage -->
101
+
102
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
103
+
104
+ <section class="notes">
105
+
106
+ ## Notes
107
+
108
+ - The function returns a strided array having a stride length of `2` (i.e., every `2` elements define a unary interface signature).
109
+ - For each signature (i.e., set of two consecutive non-overlapping strided array elements), the first element is the input data type and the second element is the return data type.
110
+ - All signatures follow type [promotion rules][@stdlib/ndarray/promotion-rules].
111
+
112
+ </section>
113
+
114
+ <!-- /.notes -->
115
+
116
+ <!-- Package usage examples. -->
117
+
118
+ <section class="examples">
119
+
120
+ ## Examples
121
+
122
+ <!-- eslint no-undef: "error" -->
123
+
124
+ ```javascript
125
+ var dtypes = require( '@stdlib/strided-dtypes' );
126
+ var replace = require( '@stdlib/string-replace' );
127
+ var signatures = require( '@stdlib/strided-base-unary-dtype-signatures' );
128
+
129
+ // Get the list of supported strided array data types:
130
+ var dt = dtypes();
131
+
132
+ // Generate unary interface signatures:
133
+ var sigs = signatures( dt, dt );
134
+
135
+ // Format the output:
136
+ var str = replace( JSON.stringify( sigs ), /("[^"]+","[^"]+"),/g, '$1,\n' );
137
+ console.log( str );
138
+ ```
139
+
140
+ </section>
141
+
142
+ <!-- /.examples -->
143
+
144
+ <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
145
+
146
+ <section class="references">
147
+
148
+ </section>
149
+
150
+ <!-- /.references -->
151
+
152
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
153
+
154
+ <section class="related">
155
+
156
+ </section>
157
+
158
+ <!-- /.related -->
159
+
160
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
161
+
162
+
163
+ <section class="main-repo" >
164
+
165
+ * * *
166
+
167
+ ## Notice
168
+
169
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
170
+
171
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
172
+
173
+ #### Community
174
+
175
+ [![Chat][chat-image]][chat-url]
176
+
177
+ ---
178
+
179
+ ## License
180
+
181
+ See [LICENSE][stdlib-license].
182
+
183
+
184
+ ## Copyright
185
+
186
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
187
+
188
+ </section>
189
+
190
+ <!-- /.stdlib -->
191
+
192
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
193
+
194
+ <section class="links">
195
+
196
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/strided-base-unary-dtype-signatures.svg
197
+ [npm-url]: https://npmjs.org/package/@stdlib/strided-base-unary-dtype-signatures
198
+
199
+ [test-image]: https://github.com/stdlib-js/strided-base-unary-dtype-signatures/actions/workflows/test.yml/badge.svg?branch=v0.0.1
200
+ [test-url]: https://github.com/stdlib-js/strided-base-unary-dtype-signatures/actions/workflows/test.yml?query=branch:v0.0.1
201
+
202
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/strided-base-unary-dtype-signatures/main.svg
203
+ [coverage-url]: https://codecov.io/github/stdlib-js/strided-base-unary-dtype-signatures?branch=main
204
+
205
+ <!--
206
+
207
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/strided-base-unary-dtype-signatures.svg
208
+ [dependencies-url]: https://david-dm.org/stdlib-js/strided-base-unary-dtype-signatures/main
209
+
210
+ -->
211
+
212
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
213
+ [chat-url]: https://gitter.im/stdlib-js/stdlib/
214
+
215
+ [stdlib]: https://github.com/stdlib-js/stdlib
216
+
217
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
218
+
219
+ [umd]: https://github.com/umdjs/umd
220
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
221
+
222
+ [deno-url]: https://github.com/stdlib-js/strided-base-unary-dtype-signatures/tree/deno
223
+ [umd-url]: https://github.com/stdlib-js/strided-base-unary-dtype-signatures/tree/umd
224
+ [esm-url]: https://github.com/stdlib-js/strided-base-unary-dtype-signatures/tree/esm
225
+ [branches-url]: https://github.com/stdlib-js/strided-base-unary-dtype-signatures/blob/main/branches.md
226
+
227
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/strided-base-unary-dtype-signatures/main/LICENSE
228
+
229
+ [@stdlib/strided/dtypes]: https://www.npmjs.com/package/@stdlib/stdlib
230
+
231
+ [@stdlib/ndarray/promotion-rules]: https://www.npmjs.com/package/@stdlib/stdlib
232
+
233
+ </section>
234
+
235
+ <!-- /.links -->
package/docs/repl.txt ADDED
@@ -0,0 +1,43 @@
1
+
2
+ {{alias}}( dtypes1, dtypes2[, options] )
3
+ Generates a list of unary interface signatures from strided array data
4
+ types.
5
+
6
+ The function returns a strided array having a stride length of two (i.e.,
7
+ every two elements define a unary interface signature).
8
+
9
+ For each signature (i.e., set of two consecutive non-overlapping strided
10
+ array elements), the first element is the input data type and the second
11
+ element is the return data type.
12
+
13
+ All signatures follow type promotion rules.
14
+
15
+ Parameters
16
+ ----------
17
+ dtypes1: ArrayLike<any>
18
+ List of supported data types for the input argument.
19
+
20
+ dtypes2: ArrayLike<any>
21
+ List of supported data types for the output argument.
22
+
23
+ options: Object (optional)
24
+ Options.
25
+
26
+ options.enums: boolean (optional)
27
+ Boolean flag indicating whether to return signatures as a list of data
28
+ type enumeration constants. Default: false.
29
+
30
+ Returns
31
+ -------
32
+ out: Array
33
+ Strided array containing unary interface signatures.
34
+
35
+ Examples
36
+ --------
37
+ > var dt = {{alias:@stdlib/strided/dtypes}}();
38
+ > var out = {{alias}}( dt, dt )
39
+ [...]
40
+
41
+ See Also
42
+ --------
43
+
@@ -0,0 +1,67 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ // TypeScript Version: 2.0
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { ArrayLike } from '@stdlib/types/array';
24
+
25
+ /**
26
+ * Interface describing function options.
27
+ */
28
+ interface Options {
29
+ /**
30
+ * Boolean flag indicating whether to return signatures as a list of enumeration constants.
31
+ */
32
+ enums?: boolean;
33
+ }
34
+
35
+ /**
36
+ * Generates a list of unary interface signatures from strided array data types.
37
+ *
38
+ * ## Notes
39
+ *
40
+ * - The function returns a strided array having a stride length of `2` (i.e., every `2` elements define a unary interface signature).
41
+ * - For each signature (i.e., set of two consecutive non-overlapping strided array elements), the first element is the input data type and the second element is the return data type.
42
+ * - All signatures follow type promotion rules.
43
+ *
44
+ * @param dtypes1 - list of supported data types for the first argument
45
+ * @param dtypes2 - list of supported data types for the output argument
46
+ * @param options - options
47
+ * @param options.enums - boolean flag indicating whether to return signatures as a list of enumeration constants
48
+ * @throws must provide recognized data types
49
+ * @returns strided array containing unary interface signatures
50
+ *
51
+ * @example
52
+ * var dtypes = [
53
+ * 'float64',
54
+ * 'float32',
55
+ * 'int32',
56
+ * 'uint8'
57
+ * ];
58
+ *
59
+ * var sigs = signatures( dtypes, dtypes );
60
+ * // e.g., returns [ 'float32', 'float32', ... ]
61
+ */
62
+ declare function signatures( dtypes1: ArrayLike<any>, dtypes2: ArrayLike<any>, options?: Options ): ArrayLike<string | number>; // tslint:disable-line:max-line-length
63
+
64
+
65
+ // EXPORTS //
66
+
67
+ export = signatures;
@@ -0,0 +1,103 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import signatures = require( './index' );
20
+
21
+
22
+ // TESTS //
23
+
24
+ // The function returns a list of signatures...
25
+ {
26
+ const dt = [ 'float64', 'float32' ];
27
+
28
+ signatures( dt, dt ); // $ExpectType ArrayLike<string | number>
29
+ signatures( dt, dt, {} ); // $ExpectType ArrayLike<string | number>
30
+ signatures( dt, dt, { 'enums': false } ); // $ExpectType ArrayLike<string | number>
31
+ signatures( dt, dt, { 'enums': true } ); // $ExpectType ArrayLike<string | number>
32
+ }
33
+
34
+ // The compiler throws an error if provided a first argument which is not an array-like object...
35
+ {
36
+ const dt = [ 'float64', 'float32' ];
37
+
38
+ signatures( 10, dt ); // $ExpectError
39
+ signatures( true, dt ); // $ExpectError
40
+ signatures( false, dt ); // $ExpectError
41
+ signatures( null, dt ); // $ExpectError
42
+ signatures( undefined, dt ); // $ExpectError
43
+ signatures( {}, dt ); // $ExpectError
44
+
45
+ signatures( 10, dt, {} ); // $ExpectError
46
+ signatures( true, dt, {} ); // $ExpectError
47
+ signatures( false, dt, {} ); // $ExpectError
48
+ signatures( null, dt, {} ); // $ExpectError
49
+ signatures( undefined, dt, {} ); // $ExpectError
50
+ signatures( {}, dt, {} ); // $ExpectError
51
+ }
52
+
53
+ // The compiler throws an error if provided a second argument which is not an array-like object...
54
+ {
55
+ const dt = [ 'float64', 'float32' ];
56
+
57
+ signatures( dt, 10 ); // $ExpectError
58
+ signatures( dt, true ); // $ExpectError
59
+ signatures( dt, false ); // $ExpectError
60
+ signatures( dt, null ); // $ExpectError
61
+ signatures( dt, undefined ); // $ExpectError
62
+ signatures( dt, {} ); // $ExpectError
63
+
64
+ signatures( dt, 10, {} ); // $ExpectError
65
+ signatures( dt, true, {} ); // $ExpectError
66
+ signatures( dt, false, {} ); // $ExpectError
67
+ signatures( dt, null, {} ); // $ExpectError
68
+ signatures( dt, undefined, {} ); // $ExpectError
69
+ signatures( dt, {}, {} ); // $ExpectError
70
+ }
71
+
72
+ // The compiler throws an error if provided a third argument which is not an options object...
73
+ {
74
+ const dt = [ 'float64', 'float32' ];
75
+
76
+ signatures( dt, dt, 10 ); // $ExpectError
77
+ signatures( dt, dt, '10' ); // $ExpectError
78
+ signatures( dt, dt, true ); // $ExpectError
79
+ signatures( dt, dt, false ); // $ExpectError
80
+ signatures( dt, dt, null ); // $ExpectError
81
+ }
82
+
83
+ // The compiler throws an error if provided an `enums` option which is not a boolean...
84
+ {
85
+ const dt = [ 'float64', 'float32' ];
86
+
87
+ signatures( dt, dt, { 'enums': 10 } ); // $ExpectError
88
+ signatures( dt, dt, { 'enums': '10' } ); // $ExpectError
89
+ signatures( dt, dt, { 'enums': null } ); // $ExpectError
90
+ signatures( dt, dt, { 'enums': {} } ); // $ExpectError
91
+ signatures( dt, dt, { 'enums': [] } ); // $ExpectError
92
+ signatures( dt, dt, { 'enums': ( x: number ): number => x } ); // $ExpectError
93
+ }
94
+
95
+ // The compiler throws an error if the function is provided an unsupported number of arguments...
96
+ {
97
+ const dt = [ 'float64', 'float32' ];
98
+
99
+ signatures(); // $ExpectError
100
+ signatures( dt ); // $ExpectError
101
+ signatures( dt, dt, dt, dt ); // $ExpectError
102
+ signatures( dt, dt, {}, {} ); // $ExpectError
103
+ }
package/lib/index.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Generate a list of unary interface signatures from strided array data types.
23
+ *
24
+ * @module @stdlib/strided-base-unary-dtype-signatures
25
+ *
26
+ * @example
27
+ * var signatures = require( '@stdlib/strided-base-unary-dtype-signatures' );
28
+ *
29
+ * var dtypes = [
30
+ * 'float64',
31
+ * 'float32',
32
+ * 'int32',
33
+ * 'uint8'
34
+ * ];
35
+ *
36
+ * var sigs = signatures( dtypes, dtypes );
37
+ * // e.g., returns [ 'float32', 'float32', ... ]
38
+ */
39
+
40
+ // MODULES //
41
+
42
+ var main = require( './main.js' );
43
+
44
+
45
+ // EXPORTS //
46
+
47
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,198 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var safeCasts = require( '@stdlib/ndarray-safe-casts' );
24
+ var resolveEnum = require( '@stdlib/strided-base-dtype-resolve-enum' );
25
+ var resolveStr = require( '@stdlib/strided-base-dtype-resolve-str' );
26
+ var format = require( '@stdlib/string-format' );
27
+
28
+
29
+ // FUNCTIONS //
30
+
31
+ /**
32
+ * Returns the intersection of two sorted lists.
33
+ *
34
+ * @private
35
+ * @param {ArrayLikeObject} list1 - first sorted list
36
+ * @param {ArrayLikeObject} list2 - second sorted list
37
+ * @returns {ArrayLikeObject} result
38
+ *
39
+ * @example
40
+ * var list1 = [ 'a', 'b', 'c', 'd' ];
41
+ * var list2 = [ 'b', 'd', 'e' ];
42
+ *
43
+ * var out = intersection( list1, list2 );
44
+ * // returns [ 'b', 'd' ]
45
+ */
46
+ function intersection( list1, list2 ) {
47
+ var out;
48
+ var M;
49
+ var N;
50
+ var v;
51
+ var i;
52
+ var j;
53
+ var k;
54
+
55
+ M = list1.length;
56
+ N = list2.length;
57
+
58
+ out = [];
59
+ k = 0;
60
+ for ( i = 0; i < M; i++ ) {
61
+ if ( k >= N ) {
62
+ break;
63
+ }
64
+ v = list1[ i ];
65
+ for ( j = k; j < N; j++ ) {
66
+ if ( v === list2[ j ] ) {
67
+ k = j + 1;
68
+ out.push( v );
69
+ break;
70
+ }
71
+ }
72
+ }
73
+ return out;
74
+ }
75
+
76
+ /**
77
+ * Resolves a list of data types to data type strings.
78
+ *
79
+ * @private
80
+ * @param {ArrayLikeObject} dtypes - list of data types
81
+ * @returns {(StringArray|Error)} data type strings (or an error)
82
+ *
83
+ * @example
84
+ * var out = resolve( [ 1, 2, 3 ] );
85
+ * // returns [...]
86
+ */
87
+ function resolve( dtypes ) {
88
+ var out;
89
+ var dt;
90
+ var i;
91
+
92
+ out = [];
93
+ for ( i = 0; i < dtypes.length; i++ ) {
94
+ dt = resolveStr( dtypes[ i ] );
95
+ if ( dt === null ) {
96
+ return new TypeError( format( 'invalid argument. Must provide recognized data types. Unable to resolve a data type string. Value: `%s`.', dtypes[ i ] ) );
97
+ }
98
+ out.push( dt );
99
+ }
100
+ return out;
101
+ }
102
+
103
+
104
+ // MAIN //
105
+
106
+ /**
107
+ * Generates a list of unary interface signatures from strided array data types.
108
+ *
109
+ * ## Notes
110
+ *
111
+ * - The function returns a strided array having a stride length of `2` (i.e., every `2` elements define a unary interface signature).
112
+ * - For each signature (i.e., set of two consecutive non-overlapping strided array elements), the first element is the input data type and the second element is the return data type.
113
+ * - All signatures follow type promotion rules.
114
+ *
115
+ * @param {Array} dtypes1 - list of supported data types for the first argument
116
+ * @param {Array} dtypes2 - list of supported data types for the output argument
117
+ * @param {Options} [options] - options
118
+ * @param {boolean} [options.enums=false] - boolean flag indicating whether to return signatures as a list of enumeration constants
119
+ * @throws {TypeError} must provide recognized data types
120
+ * @returns {Array} strided array containing unary interface signatures
121
+ *
122
+ * @example
123
+ * var dtypes = [
124
+ * 'float64',
125
+ * 'float32',
126
+ * 'int32',
127
+ * 'uint8'
128
+ * ];
129
+ *
130
+ * var sigs = signatures( dtypes, dtypes );
131
+ * // e.g., returns [ 'float32', 'float32', ... ]
132
+ */
133
+ function signatures( dtypes1, dtypes2, options ) {
134
+ var casts;
135
+ var opts;
136
+ var tmp;
137
+ var out;
138
+ var dt1;
139
+ var dt2;
140
+ var t1;
141
+ var M;
142
+ var i;
143
+ var j;
144
+
145
+ if ( arguments.length > 2 ) {
146
+ opts = options;
147
+ } else {
148
+ opts = {};
149
+ }
150
+ // Resolve the list of provided data types to data type strings:
151
+ dt1 = resolve( dtypes1 );
152
+ if ( dt1 instanceof Error ) {
153
+ throw dt1;
154
+ }
155
+ if ( dtypes2 === dtypes1 ) { // don't do work if we don't need to
156
+ dt2 = dt1;
157
+ } else {
158
+ dt2 = resolve( dtypes2 );
159
+ if ( dt2 instanceof Error ) {
160
+ throw dt2;
161
+ }
162
+ }
163
+ // Sort the list of return dtypes:
164
+ dt2.sort();
165
+
166
+ // Generate the list of signatures...
167
+ M = dt1.length;
168
+ out = [];
169
+ for ( i = 0; i < M; i++ ) {
170
+ t1 = dt1[ i ];
171
+
172
+ // Resolve the list of safe casts for the input dtype:
173
+ casts = safeCasts( t1 );
174
+ if ( casts === null ) {
175
+ continue;
176
+ }
177
+ // Remove safe casts which are not among the supported output dtypes:
178
+ casts = intersection( dt2, casts.sort() );
179
+
180
+ // Generate signatures for allowed casts...
181
+ for ( j = 0; j < casts.length; j++ ) {
182
+ out.push( t1, casts[ j ] );
183
+ }
184
+ }
185
+ if ( opts.enums ) {
186
+ tmp = [];
187
+ for ( i = 0; i < out.length; i++ ) {
188
+ tmp.push( resolveEnum( out[ i ] ) );
189
+ }
190
+ out = tmp;
191
+ }
192
+ return out;
193
+ }
194
+
195
+
196
+ // EXPORTS //
197
+
198
+ module.exports = signatures;
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@stdlib/strided-base-unary-dtype-signatures",
3
+ "version": "0.0.1",
4
+ "description": "Generate a list of unary interface signatures from strided array data types.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {
26
+ "test": "make test",
27
+ "test-cov": "make test-cov",
28
+ "examples": "make examples",
29
+ "benchmark": "make benchmark"
30
+ },
31
+ "homepage": "https://stdlib.io",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git://github.com/stdlib-js/strided-base-unary-dtype-signatures.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/stdlib-js/stdlib/issues"
38
+ },
39
+ "dependencies": {
40
+ "@stdlib/ndarray-safe-casts": "^0.0.x",
41
+ "@stdlib/strided-base-dtype-resolve-enum": "^0.0.x",
42
+ "@stdlib/strided-base-dtype-resolve-str": "^0.0.x",
43
+ "@stdlib/string-format": "^0.0.x",
44
+ "@stdlib/types": "^0.0.x"
45
+ },
46
+ "devDependencies": {
47
+ "@stdlib/assert-is-array": "^0.0.x",
48
+ "@stdlib/assert-is-integer-array": "^0.0.x",
49
+ "@stdlib/assert-is-string-array": "^0.0.x",
50
+ "@stdlib/bench": "^0.0.x",
51
+ "@stdlib/strided-base-dtype-str2enum": "^0.0.x",
52
+ "@stdlib/strided-dtypes": "^0.0.x",
53
+ "@stdlib/string-replace": "^0.0.x",
54
+ "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
55
+ "istanbul": "^0.4.1",
56
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
57
+ },
58
+ "engines": {
59
+ "node": ">=0.10.0",
60
+ "npm": ">2.7.0"
61
+ },
62
+ "os": [
63
+ "aix",
64
+ "darwin",
65
+ "freebsd",
66
+ "linux",
67
+ "macos",
68
+ "openbsd",
69
+ "sunos",
70
+ "win32",
71
+ "windows"
72
+ ],
73
+ "keywords": [
74
+ "stdlib",
75
+ "stdtypes",
76
+ "types",
77
+ "strided",
78
+ "dtypes",
79
+ "dtype",
80
+ "data",
81
+ "multidimensional",
82
+ "array",
83
+ "utilities",
84
+ "utility",
85
+ "utils",
86
+ "util",
87
+ "signatures",
88
+ "api",
89
+ "interface"
90
+ ],
91
+ "__stdlib__": {},
92
+ "funding": {
93
+ "type": "patreon",
94
+ "url": "https://www.patreon.com/athan"
95
+ }
96
+ }