@stdlib/ndarray-base-output-dtype 0.1.0

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-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2025 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
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # outputDataType
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Resolve the output ndarray [data type][@stdlib/ndarray/dtypes] from a list of input ndarray [data types][@stdlib/ndarray/dtypes].
37
+
38
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
39
+
40
+ <section class="intro">
41
+
42
+ </section>
43
+
44
+ <!-- /.intro -->
45
+
46
+ <!-- Package usage documentation. -->
47
+
48
+ <section class="installation">
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install @stdlib/ndarray-base-output-dtype
54
+ ```
55
+
56
+ </section>
57
+
58
+ <section class="usage">
59
+
60
+ ## Usage
61
+
62
+ ```javascript
63
+ var outputDataType = require( '@stdlib/ndarray-base-output-dtype' );
64
+ ```
65
+
66
+ #### outputDataType( dtypes, policy )
67
+
68
+ Resolves the output ndarray [data type][@stdlib/ndarray/dtypes] from a list of input ndarray [data types][@stdlib/ndarray/dtypes] according to a [data type policy][@stdlib/ndarray/output-dtype-policies].
69
+
70
+ ```javascript
71
+ var dt = outputDataType( [ 'int32', 'uint32' ], 'floating_point' );
72
+ // returns 'float64'
73
+ ```
74
+
75
+ The function supports the following parameters:
76
+
77
+ - **dtypes**: list of input ndarray [data types][@stdlib/ndarray/dtypes].
78
+ - **policy**: output [data type policy][@stdlib/ndarray/output-dtype-policies].
79
+
80
+ If `policy` is a [data type][@stdlib/ndarray/dtypes], the function always returns the `policy` value (i.e., the second argument).
81
+
82
+ ```javascript
83
+ var dt = outputDataType( [ 'float32', 'float32' ], 'float64' );
84
+ // returns 'float64'
85
+
86
+ dt = outputDataType( [ 'int32', 'complex128' ], 'float64' );
87
+ // returns 'float64'
88
+
89
+ // ...
90
+ ```
91
+
92
+ </section>
93
+
94
+ <!-- /.usage -->
95
+
96
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
97
+
98
+ <section class="notes">
99
+
100
+ ## Notes
101
+
102
+ - When provided more than [data type][@stdlib/ndarray/dtypes], the function **always** applies [type promotion][@stdlib/ndarray/promotion-rules] to the provided data types, except for the following [data type policies][@stdlib/ndarray/output-dtype-policies]:
103
+
104
+ - `default`
105
+ - `default_index`
106
+ - `same`
107
+ - `<dtype>`
108
+
109
+ </section>
110
+
111
+ <!-- /.notes -->
112
+
113
+ <!-- Package usage examples. -->
114
+
115
+ <section class="examples">
116
+
117
+ ## Examples
118
+
119
+ <!-- eslint no-undef: "error" -->
120
+
121
+ ```javascript
122
+ var naryFunction = require( '@stdlib/utils-nary-function' );
123
+ var unzip = require( '@stdlib/utils-unzip' );
124
+ var cartesianProduct = require( '@stdlib/array-base-cartesian-product' );
125
+ var dtypes = require( '@stdlib/ndarray-dtypes' );
126
+ var logEachMap = require( '@stdlib/console-log-each-map' );
127
+ var outputDataType = require( '@stdlib/ndarray-base-output-dtype' );
128
+
129
+ // Get the list of real-valued data types:
130
+ var dt = dtypes( 'real' );
131
+
132
+ // Define a list of output data type policies:
133
+ var policies = [
134
+ 'default',
135
+ 'real',
136
+ 'floating_point',
137
+ 'complex_floating_point',
138
+ 'promoted'
139
+ ];
140
+
141
+ // Generate data type pairs:
142
+ var pairs = cartesianProduct( dt, dt );
143
+
144
+ // Generate argument pairs:
145
+ var args = cartesianProduct( pairs, policies );
146
+
147
+ // Unzip the argument pair array:
148
+ args = unzip( args );
149
+
150
+ // Resolve output data types:
151
+ logEachMap( 'dtypes: (%15s). policy: %-24s. output dtype: %s.', args[ 0 ], args[ 1 ], naryFunction( outputDataType, 2 ) );
152
+ ```
153
+
154
+ </section>
155
+
156
+ <!-- /.examples -->
157
+
158
+ <!-- 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. -->
159
+
160
+ <section class="references">
161
+
162
+ </section>
163
+
164
+ <!-- /.references -->
165
+
166
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
167
+
168
+ <section class="related">
169
+
170
+ </section>
171
+
172
+ <!-- /.related -->
173
+
174
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
175
+
176
+
177
+ <section class="main-repo" >
178
+
179
+ * * *
180
+
181
+ ## Notice
182
+
183
+ 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.
184
+
185
+ 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].
186
+
187
+ #### Community
188
+
189
+ [![Chat][chat-image]][chat-url]
190
+
191
+ ---
192
+
193
+ ## License
194
+
195
+ See [LICENSE][stdlib-license].
196
+
197
+
198
+ ## Copyright
199
+
200
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
201
+
202
+ </section>
203
+
204
+ <!-- /.stdlib -->
205
+
206
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
207
+
208
+ <section class="links">
209
+
210
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-output-dtype.svg
211
+ [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-output-dtype
212
+
213
+ [test-image]: https://github.com/stdlib-js/ndarray-base-output-dtype/actions/workflows/test.yml/badge.svg?branch=v0.1.0
214
+ [test-url]: https://github.com/stdlib-js/ndarray-base-output-dtype/actions/workflows/test.yml?query=branch:v0.1.0
215
+
216
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-output-dtype/main.svg
217
+ [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-output-dtype?branch=main
218
+
219
+ <!--
220
+
221
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/ndarray-base-output-dtype.svg
222
+ [dependencies-url]: https://david-dm.org/stdlib-js/ndarray-base-output-dtype/main
223
+
224
+ -->
225
+
226
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
227
+ [chat-url]: https://stdlib.zulipchat.com
228
+
229
+ [stdlib]: https://github.com/stdlib-js/stdlib
230
+
231
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
232
+
233
+ [umd]: https://github.com/umdjs/umd
234
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
235
+
236
+ [deno-url]: https://github.com/stdlib-js/ndarray-base-output-dtype/tree/deno
237
+ [deno-readme]: https://github.com/stdlib-js/ndarray-base-output-dtype/blob/deno/README.md
238
+ [umd-url]: https://github.com/stdlib-js/ndarray-base-output-dtype/tree/umd
239
+ [umd-readme]: https://github.com/stdlib-js/ndarray-base-output-dtype/blob/umd/README.md
240
+ [esm-url]: https://github.com/stdlib-js/ndarray-base-output-dtype/tree/esm
241
+ [esm-readme]: https://github.com/stdlib-js/ndarray-base-output-dtype/blob/esm/README.md
242
+ [branches-url]: https://github.com/stdlib-js/ndarray-base-output-dtype/blob/main/branches.md
243
+
244
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-output-dtype/main/LICENSE
245
+
246
+ [@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
247
+
248
+ [@stdlib/ndarray/output-dtype-policies]: https://www.npmjs.com/package/@stdlib/ndarray-output-dtype-policies
249
+
250
+ [@stdlib/ndarray/promotion-rules]: https://www.npmjs.com/package/@stdlib/ndarray-promotion-rules
251
+
252
+ </section>
253
+
254
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import outputDataType from '../docs/types/index';
3
+ export = outputDataType;
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var b=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var A=b(function(z,F){
2
+ var o=require('@stdlib/ndarray-base-assert-is-floating-point-data-type/dist'),c=require('@stdlib/ndarray-base-assert-is-real-floating-point-data-type/dist'),f=require('@stdlib/ndarray-base-assert-is-complex-floating-point-data-type/dist'),y=require('@stdlib/ndarray-base-assert-is-integer-data-type/dist'),g=require('@stdlib/ndarray-base-assert-is-signed-integer-data-type/dist'),u=require('@stdlib/ndarray-base-assert-is-unsigned-integer-data-type/dist'),v=require('@stdlib/ndarray-base-assert-is-real-data-type/dist'),T=require('@stdlib/ndarray-base-assert-is-numeric-data-type/dist'),m=require('@stdlib/ndarray-base-assert-is-boolean-data-type/dist'),D=require('@stdlib/ndarray-base-assert-is-integer-index-data-type/dist'),x=require('@stdlib/ndarray-base-assert-is-boolean-index-data-type/dist'),E=require('@stdlib/ndarray-base-assert-is-mask-index-data-type/dist'),N=require('@stdlib/ndarray-base-assert-is-data-type/dist'),O=require('@stdlib/assert-is-string/dist').isPrimitive,l=require('@stdlib/ndarray-base-promote-dtypes/dist'),t=require('@stdlib/ndarray-defaults/dist'),I=require('@stdlib/array-base-join/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist'),h=t.get("dtypes.default"),w=t.get("dtypes.default_index"),d=t.get("dtypes.signed_integer"),_=t.get("dtypes.unsigned_integer"),L=t.get("dtypes.real_floating_point"),U=t.get("dtypes.complex_floating_point"),Y={default:k,default_index:S,same:B,promoted:s,accumulation:M},C={floating_point:[o,t.get("dtypes.floating_point")],floating_point_and_generic:[a(o),t.get("dtypes.floating_point")],real_floating_point:[c,P],real_floating_point_and_generic:[a(c),P],complex_floating_point:[f,q],complex_floating_point_and_generic:[a(f),q],integer:[y,t.get("dtypes.integer")],integer_and_generic:[a(y),t.get("dtypes.integer")],signed_integer:[g,d],signed_integer_and_generic:[a(g),d],unsigned_integer:[u,_],unsigned_integer_and_generic:[a(u),_],real:[v,t.get("dtypes.real")],real_and_generic:[a(v),t.get("dtypes.real")],numeric:[T,t.get("dtypes.numeric")],numeric_and_generic:[a(T),t.get("dtypes.numeric")],boolean:[m,t.get("dtypes.boolean")],boolean_and_generic:[a(m),t.get("dtypes.boolean")],integer_index:[D,t.get("dtypes.integer_index")],integer_index_and_generic:[a(D),t.get("dtypes.integer_index")],boolean_index:[x,t.get("dtypes.boolean_index")],boolean_index_and_generic:[a(x),t.get("dtypes.boolean_index")],mask_index:[E,t.get("dtypes.mask_index")],mask_index_and_generic:[a(E),t.get("dtypes.mask_index")]},G={complex128:"float64",complex64:"float32",complex32:"float16"},R={float64:"complex128",float32:"complex64",float16:"complex32"};function a(r){return e;function e(n){return n==="generic"||r(n)}}function k(){return h}function S(){return w}function B(r){var e,n;for(e=r[0],n=1;n<r.length;n++)if(r[n]!==e)throw new Error(p('2GnIH',I(r,", ")));return e}function s(r){var e=l(r);if(e===null)throw new Error(p('2GnII',I(r,", ")));return e}function M(r){var e=s(r);return o(e)||e==="generic"?e:u(e)?l([e,_]):g(e)?l([e,d]):L}function P(r){return G[r]||L}function q(r){return R[r]||U}function X(r,e){var n,i;if(N(e))return e;if(i=Y[e],i!==void 0)return i(r);if(n=s(r),i=C[e],i!==void 0)return i[0](n)?n:O(i[1])?i[1]:i[1](n);throw new TypeError(p('2GnDw',e))}F.exports=X
3
+ });var j=A();module.exports=j;
4
+ /** @license Apache-2.0 */
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable id-length */\n\n'use strict';\n\n// MODULES //\n\nvar isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );\nvar isRealFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-real-floating-point-data-type' );\nvar isComplexFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );\nvar isIntegerDataType = require( '@stdlib/ndarray-base-assert-is-integer-data-type' );\nvar isSignedIntegerDataType = require( '@stdlib/ndarray-base-assert-is-signed-integer-data-type' );\nvar isUnsignedIntegerDataType = require( '@stdlib/ndarray-base-assert-is-unsigned-integer-data-type' );\nvar isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );\nvar isNumericDataType = require( '@stdlib/ndarray-base-assert-is-numeric-data-type' );\nvar isBooleanDataType = require( '@stdlib/ndarray-base-assert-is-boolean-data-type' );\nvar isIntegerIndexDataType = require( '@stdlib/ndarray-base-assert-is-integer-index-data-type' );\nvar isBooleanIndexDataType = require( '@stdlib/ndarray-base-assert-is-boolean-index-data-type' );\nvar isMaskIndexDataType = require( '@stdlib/ndarray-base-assert-is-mask-index-data-type' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar promoteDataTypes = require( '@stdlib/ndarray-base-promote-dtypes' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar join = require( '@stdlib/array-base-join' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar DEFAULT_DTYPE = defaults.get( 'dtypes.default' );\nvar DEFAULT_INDEX_DTYPE = defaults.get( 'dtypes.default_index' );\nvar DEFAULT_SIGNED_INTEGER_DTYPE = defaults.get( 'dtypes.signed_integer' );\nvar DEFAULT_UNSIGNED_INTEGER_DTYPE = defaults.get( 'dtypes.unsigned_integer' );\nvar DEFAULT_REAL_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.real_floating_point' );\nvar DEFAULT_COMPLEX_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.complex_floating_point' );\n\n// Table where, for each respective policy, the value is a function which applies the policy to an input data type...\nvar POLICY_TABLE1 = {\n\t'default': defaultPolicy,\n\t'default_index': defaultIndexPolicy,\n\t'same': samePolicy,\n\t'promoted': promotedPolicy,\n\t'accumulation': accumulationPolicy\n};\n\n// Table where, for each respective policy, the value is an array whose first element is an assertion and whose second element is a fallback data type...\nvar POLICY_TABLE2 = {\n\t// Floating-point policies...\n\t'floating_point': [\n\t\tisFloatingPointDataType,\n\t\tdefaults.get( 'dtypes.floating_point' )\n\t],\n\t'floating_point_and_generic': [\n\t\twrap( isFloatingPointDataType ),\n\t\tdefaults.get( 'dtypes.floating_point' )\n\t],\n\t'real_floating_point': [\n\t\tisRealFloatingPointDataType,\n\t\tresolveDefaultRealFloatingPoint\n\t],\n\t'real_floating_point_and_generic': [\n\t\twrap( isRealFloatingPointDataType ),\n\t\tresolveDefaultRealFloatingPoint\n\t],\n\t'complex_floating_point': [\n\t\tisComplexFloatingPointDataType,\n\t\tresolveDefaultComplexFloatingPoint\n\t],\n\t'complex_floating_point_and_generic': [\n\t\twrap( isComplexFloatingPointDataType ),\n\t\tresolveDefaultComplexFloatingPoint\n\t],\n\n\t// Integer policies...\n\t'integer': [\n\t\tisIntegerDataType,\n\t\tdefaults.get( 'dtypes.integer' )\n\t],\n\t'integer_and_generic': [\n\t\twrap( isIntegerDataType ),\n\t\tdefaults.get( 'dtypes.integer' )\n\t],\n\t'signed_integer': [\n\t\tisSignedIntegerDataType,\n\t\tDEFAULT_SIGNED_INTEGER_DTYPE\n\t],\n\t'signed_integer_and_generic': [\n\t\twrap( isSignedIntegerDataType ),\n\t\tDEFAULT_SIGNED_INTEGER_DTYPE\n\t],\n\t'unsigned_integer': [\n\t\tisUnsignedIntegerDataType,\n\t\tDEFAULT_UNSIGNED_INTEGER_DTYPE\n\t],\n\t'unsigned_integer_and_generic': [\n\t\twrap( isUnsignedIntegerDataType ),\n\t\tDEFAULT_UNSIGNED_INTEGER_DTYPE\n\t],\n\n\t// Real-valued number policies...\n\t'real': [\n\t\tisRealDataType,\n\t\tdefaults.get( 'dtypes.real' )\n\t],\n\t'real_and_generic': [\n\t\twrap( isRealDataType ),\n\t\tdefaults.get( 'dtypes.real' )\n\t],\n\n\t// Real- and complex-valued number policies...\n\t'numeric': [\n\t\tisNumericDataType,\n\t\tdefaults.get( 'dtypes.numeric' )\n\t],\n\t'numeric_and_generic': [\n\t\twrap( isNumericDataType ),\n\t\tdefaults.get( 'dtypes.numeric' )\n\t],\n\n\t// Boolean policies...\n\t'boolean': [\n\t\tisBooleanDataType,\n\t\tdefaults.get( 'dtypes.boolean' )\n\t],\n\t'boolean_and_generic': [\n\t\twrap( isBooleanDataType ),\n\t\tdefaults.get( 'dtypes.boolean' )\n\t],\n\n\t// Index policies...\n\t'integer_index': [\n\t\tisIntegerIndexDataType,\n\t\tdefaults.get( 'dtypes.integer_index' )\n\t],\n\t'integer_index_and_generic': [\n\t\twrap( isIntegerIndexDataType ),\n\t\tdefaults.get( 'dtypes.integer_index' )\n\t],\n\t'boolean_index': [\n\t\tisBooleanIndexDataType,\n\t\tdefaults.get( 'dtypes.boolean_index' )\n\t],\n\t'boolean_index_and_generic': [\n\t\twrap( isBooleanIndexDataType ),\n\t\tdefaults.get( 'dtypes.boolean_index' )\n\t],\n\t'mask_index': [\n\t\tisMaskIndexDataType,\n\t\tdefaults.get( 'dtypes.mask_index' )\n\t],\n\t'mask_index_and_generic': [\n\t\twrap( isMaskIndexDataType ),\n\t\tdefaults.get( 'dtypes.mask_index' )\n\t]\n};\n\n// Table mapping complex-valued floating-point data types to real-valued floating-point data types having the same precision:\nvar COMPLEX2FLOAT = {\n\t'complex128': 'float64',\n\t'complex64': 'float32',\n\t'complex32': 'float16'\n};\n\n// Table mapping real-valued floating-point data types to complex-valued floating-point data types having the same precision:\nvar FLOAT2COMPLEX = {\n\t'float64': 'complex128',\n\t'float32': 'complex64',\n\t'float16': 'complex32'\n};\n\n\n// FUNCTIONS //\n\n/**\n* Wraps a data type validation function to also check for a \"generic\" data type.\n*\n* @private\n* @param {Function} fcn - validation function\n* @returns {Function} wrapped validation function\n*/\nfunction wrap( fcn ) {\n\treturn wrapper;\n\n\t/**\n\t* Tests whether a provided data type is either \"generic\" or satisfies a data type validation function.\n\t*\n\t* @private\n\t* @param {*} value - input value\n\t* @returns {boolean} boolean indicating whether a provided value passes a test\n\t*/\n\tfunction wrapper( value ) {\n\t\treturn ( value === 'generic' ) || fcn( value );\n\t}\n}\n\n/**\n* Returns the default data type.\n*\n* @private\n* @returns {string} output ndarray data type\n*/\nfunction defaultPolicy() {\n\t// When the policy is \"default\", the output data type should always be the default data type without consideration for the input data types:\n\treturn DEFAULT_DTYPE;\n}\n\n/**\n* Returns the default index data type.\n*\n* @private\n* @returns {string} output ndarray data type\n*/\nfunction defaultIndexPolicy() {\n\t// When the policy is \"default_index\", the output data type should always be the default index data type without consideration for the input data types:\n\treturn DEFAULT_INDEX_DTYPE;\n}\n\n/**\n* Applies the \"same\" policy by returning the common input data type.\n*\n* @private\n* @param {StringArray} dtypes - input ndarray data types\n* @throws {Error} invalid data types\n* @returns {string} output ndarray data type\n*/\nfunction samePolicy( dtypes ) {\n\tvar dt;\n\tvar i;\n\n\tdt = dtypes[ 0 ];\n\tfor ( i = 1; i < dtypes.length; i++ ) {\n\t\t// When the policy is \"same\", we require that all data types (both input and output) be the same...\n\t\tif ( dtypes[ i ] !== dt ) {\n\t\t\tthrow new Error( format( 'invalid argument. Unable to resolve an output data type. The output data type policy is \"same\" and yet the input data types are not equal. Data types: [%s].', join( dtypes, ', ' ) ) );\n\t\t}\n\t}\n\treturn dt;\n}\n\n/**\n* Applies the \"promoted\" policy by applying type promotion to the list of provided data types.\n*\n* @private\n* @param {StringArray} dtypes - input ndarray data types\n* @throws {Error} must provide data types which can be safely cast to a common data type\n* @returns {string} output ndarray data type\n*/\nfunction promotedPolicy( dtypes ) {\n\tvar dt = promoteDataTypes( dtypes );\n\tif ( dt === null ) {\n\t\tthrow new Error( format( 'invalid argument. Unable to apply type promotion rules when resolving a data type to which the input data types can be safely cast. Data types: [%s].', join( dtypes, ', ' ) ) );\n\t}\n\treturn dt;\n}\n\n/**\n* Applies the \"accumulation\" policy to the list of input data types.\n*\n* @private\n* @param {StringArray} dtypes - input ndarray data types\n* @throws {Error} must provide data types which can be safely cast to a common data type\n* @returns {string} output ndarray data type\n*/\nfunction accumulationPolicy( dtypes ) {\n\tvar dt = promotedPolicy( dtypes );\n\n\t// If the promoted data type is floating-point, allow accumulation in that data type as overflow/underflow is handled naturally as a built-in feature of that data type...\n\tif ( isFloatingPointDataType( dt ) || dt === 'generic' ) { // NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited\n\t\treturn dt;\n\t}\n\t// Unless the promoted data type value range is larger than the default un/signed integer data type, accumulate in the default un/signed integer data type, as accumulating in small range integer data types (e.g., `int8`) is at high risk for overflow, especially for ndarrays containing many elements...\n\tif ( isUnsignedIntegerDataType( dt ) ) {\n\t\treturn promoteDataTypes( [ dt, DEFAULT_UNSIGNED_INTEGER_DTYPE ] );\n\t}\n\tif ( isSignedIntegerDataType( dt ) ) {\n\t\treturn promoteDataTypes( [ dt, DEFAULT_SIGNED_INTEGER_DTYPE ] );\n\t}\n\t// For all other data types, accumulate in the default real-valued floating-point data type...\n\treturn DEFAULT_REAL_FLOATING_POINT_DTYPE;\n}\n\n/**\n* Resolves a default real-valued floating-point data type which preserves floating-point precision.\n*\n* @private\n* @param {string} dtype - input ndarray data type\n* @returns {string} output ndarray data type\n*/\nfunction resolveDefaultRealFloatingPoint( dtype ) {\n\treturn COMPLEX2FLOAT[ dtype ] || DEFAULT_REAL_FLOATING_POINT_DTYPE;\n}\n\n/**\n* Resolves a default complex-valued floating-point data type which preserves floating-point precision.\n*\n* @private\n* @param {string} dtype - input ndarray data type\n* @returns {string} output ndarray data type\n*/\nfunction resolveDefaultComplexFloatingPoint( dtype ) {\n\treturn FLOAT2COMPLEX[ dtype ] || DEFAULT_COMPLEX_FLOATING_POINT_DTYPE;\n}\n\n\n// MAIN //\n\n/**\n* Resolves the output data type from a list of input ndarray data types.\n*\n* @param {StringArray} dtypes - list of input ndarray data types\n* @param {string} policy - output ndarray data type policy\n* @throws {TypeError} second argument must be a recognized data type policy\n* @throws {Error} unexpected error\n* @returns {string} output ndarray data type\n*\n* @example\n* var dt = resolve( [ 'float64' ], 'complex_floating_point' );\n* // returns <string>\n*/\nfunction resolve( dtypes, policy ) {\n\tvar dt;\n\tvar p;\n\n\t// First, check whether the policy mandates that the output data type always be a specific data type...\n\tif ( isDataType( policy ) ) {\n\t\treturn policy;\n\t}\n\t// Next, check whether the policy is one in which we may be able to avoid type promotion...\n\tp = POLICY_TABLE1[ policy ];\n\tif ( p !== void 0 ) {\n\t\treturn p( dtypes );\n\t}\n\t// For all other policies, we always apply type promotion rules...\n\tdt = promotedPolicy( dtypes );\n\n\t// Check whether the policy requires determining the data type \"kind\"...\n\tp = POLICY_TABLE2[ policy ];\n\tif ( p !== void 0 ) {\n\t\t// Check whether the promoted data type belongs to the data type \"kind\"...\n\t\tif ( p[ 0 ]( dt ) ) {\n\t\t\t// If so, we can just return the promoted data type:\n\t\t\treturn dt;\n\t\t}\n\t\t// Otherwise, we need to fallback to a default data type belonging to that \"kind\"...\n\t\tif ( isString( p[ 1 ] ) ) {\n\t\t\treturn p[ 1 ];\n\t\t}\n\t\treturn p[ 1 ]( dt );\n\t}\n\tthrow new TypeError( format( 'invalid argument. Second argument must be a supported data type policy. Value: `%s`.', policy ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = resolve;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Resolve the output data type from a list of input ndarray data types.\n*\n* @module @stdlib/ndarray-base-output-dtype\n*\n* @example\n* var resolve = require( '@stdlib/ndarray-base-output-dtype' );\n*\n* var dt = resolve( [ 'float64' ], 'complex_floating_point' );\n* // returns <string>\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwBA,IAAIC,EAA0B,QAAS,yDAA0D,EAC7FC,EAA8B,QAAS,8DAA+D,EACtGC,EAAiC,QAAS,iEAAkE,EAC5GC,EAAoB,QAAS,kDAAmD,EAChFC,EAA0B,QAAS,yDAA0D,EAC7FC,EAA4B,QAAS,2DAA4D,EACjGC,EAAiB,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"isComplexFloatingPointDataType", "isIntegerDataType", "isSignedIntegerDataType", "isUnsignedIntegerDataType", "isRealDataType", "isNumericDataType", "isBooleanDataType", "isIntegerIndexDataType", "isBooleanIndexDataType", "isMaskIndexDataType", "isDataType", "isString", "promoteDataTypes", "defaults", "join", "format", "DEFAULT_DTYPE", "DEFAULT_INDEX_DTYPE", "DEFAULT_SIGNED_INTEGER_DTYPE", "DEFAULT_UNSIGNED_INTEGER_DTYPE", "DEFAULT_REAL_FLOATING_POINT_DTYPE", "DEFAULT_COMPLEX_FLOATING_POINT_DTYPE", "POLICY_TABLE1", "defaultPolicy", "defaultIndexPolicy", "samePolicy", "promotedPolicy", "accumulationPolicy", "POLICY_TABLE2", "wrap", "resolveDefaultRealFloatingPoint", "resolveDefaultComplexFloatingPoint", "COMPLEX2FLOAT", "FLOAT2COMPLEX", "fcn", "wrapper", "value", "dtypes", "dt", "i", "dtype", "resolve", "policy", "p", "main"]
7
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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: 4.1
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { ArrayLike } from '@stdlib/types/array';
24
+ import { DataType, OutputPolicy } from '@stdlib/types/ndarray';
25
+
26
+ /**
27
+ * Resolves the output data type from a list of input ndarray data types.
28
+ *
29
+ * @param dtypes - input ndarray data types
30
+ * @param policy - output ndarray data type policy
31
+ * @returns output ndarray data type
32
+ *
33
+ * @example
34
+ * var dt = outputDataType( [ 'float64' ], 'complex_floating_point' );
35
+ * // returns <string>
36
+ */
37
+ declare function outputDataType( dtypes: ArrayLike<DataType>, policy: OutputPolicy | DataType ): DataType;
38
+
39
+
40
+ // EXPORTS //
41
+
42
+ export = outputDataType;
package/lib/index.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ * Resolve the output data type from a list of input ndarray data types.
23
+ *
24
+ * @module @stdlib/ndarray-base-output-dtype
25
+ *
26
+ * @example
27
+ * var resolve = require( '@stdlib/ndarray-base-output-dtype' );
28
+ *
29
+ * var dt = resolve( [ 'float64' ], 'complex_floating_point' );
30
+ * // returns <string>
31
+ */
32
+
33
+ // MODULES //
34
+
35
+ var main = require( './main.js' );
36
+
37
+
38
+ // EXPORTS //
39
+
40
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,373 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ /* eslint-disable id-length */
20
+
21
+ 'use strict';
22
+
23
+ // MODULES //
24
+
25
+ var isFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-floating-point-data-type' );
26
+ var isRealFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-real-floating-point-data-type' );
27
+ var isComplexFloatingPointDataType = require( '@stdlib/ndarray-base-assert-is-complex-floating-point-data-type' );
28
+ var isIntegerDataType = require( '@stdlib/ndarray-base-assert-is-integer-data-type' );
29
+ var isSignedIntegerDataType = require( '@stdlib/ndarray-base-assert-is-signed-integer-data-type' );
30
+ var isUnsignedIntegerDataType = require( '@stdlib/ndarray-base-assert-is-unsigned-integer-data-type' );
31
+ var isRealDataType = require( '@stdlib/ndarray-base-assert-is-real-data-type' );
32
+ var isNumericDataType = require( '@stdlib/ndarray-base-assert-is-numeric-data-type' );
33
+ var isBooleanDataType = require( '@stdlib/ndarray-base-assert-is-boolean-data-type' );
34
+ var isIntegerIndexDataType = require( '@stdlib/ndarray-base-assert-is-integer-index-data-type' );
35
+ var isBooleanIndexDataType = require( '@stdlib/ndarray-base-assert-is-boolean-index-data-type' );
36
+ var isMaskIndexDataType = require( '@stdlib/ndarray-base-assert-is-mask-index-data-type' );
37
+ var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );
38
+ var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
39
+ var promoteDataTypes = require( '@stdlib/ndarray-base-promote-dtypes' );
40
+ var defaults = require( '@stdlib/ndarray-defaults' );
41
+ var join = require( '@stdlib/array-base-join' );
42
+ var format = require( '@stdlib/string-format' );
43
+
44
+
45
+ // VARIABLES //
46
+
47
+ var DEFAULT_DTYPE = defaults.get( 'dtypes.default' );
48
+ var DEFAULT_INDEX_DTYPE = defaults.get( 'dtypes.default_index' );
49
+ var DEFAULT_SIGNED_INTEGER_DTYPE = defaults.get( 'dtypes.signed_integer' );
50
+ var DEFAULT_UNSIGNED_INTEGER_DTYPE = defaults.get( 'dtypes.unsigned_integer' );
51
+ var DEFAULT_REAL_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.real_floating_point' );
52
+ var DEFAULT_COMPLEX_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.complex_floating_point' );
53
+
54
+ // Table where, for each respective policy, the value is a function which applies the policy to an input data type...
55
+ var POLICY_TABLE1 = {
56
+ 'default': defaultPolicy,
57
+ 'default_index': defaultIndexPolicy,
58
+ 'same': samePolicy,
59
+ 'promoted': promotedPolicy,
60
+ 'accumulation': accumulationPolicy
61
+ };
62
+
63
+ // Table where, for each respective policy, the value is an array whose first element is an assertion and whose second element is a fallback data type...
64
+ var POLICY_TABLE2 = {
65
+ // Floating-point policies...
66
+ 'floating_point': [
67
+ isFloatingPointDataType,
68
+ defaults.get( 'dtypes.floating_point' )
69
+ ],
70
+ 'floating_point_and_generic': [
71
+ wrap( isFloatingPointDataType ),
72
+ defaults.get( 'dtypes.floating_point' )
73
+ ],
74
+ 'real_floating_point': [
75
+ isRealFloatingPointDataType,
76
+ resolveDefaultRealFloatingPoint
77
+ ],
78
+ 'real_floating_point_and_generic': [
79
+ wrap( isRealFloatingPointDataType ),
80
+ resolveDefaultRealFloatingPoint
81
+ ],
82
+ 'complex_floating_point': [
83
+ isComplexFloatingPointDataType,
84
+ resolveDefaultComplexFloatingPoint
85
+ ],
86
+ 'complex_floating_point_and_generic': [
87
+ wrap( isComplexFloatingPointDataType ),
88
+ resolveDefaultComplexFloatingPoint
89
+ ],
90
+
91
+ // Integer policies...
92
+ 'integer': [
93
+ isIntegerDataType,
94
+ defaults.get( 'dtypes.integer' )
95
+ ],
96
+ 'integer_and_generic': [
97
+ wrap( isIntegerDataType ),
98
+ defaults.get( 'dtypes.integer' )
99
+ ],
100
+ 'signed_integer': [
101
+ isSignedIntegerDataType,
102
+ DEFAULT_SIGNED_INTEGER_DTYPE
103
+ ],
104
+ 'signed_integer_and_generic': [
105
+ wrap( isSignedIntegerDataType ),
106
+ DEFAULT_SIGNED_INTEGER_DTYPE
107
+ ],
108
+ 'unsigned_integer': [
109
+ isUnsignedIntegerDataType,
110
+ DEFAULT_UNSIGNED_INTEGER_DTYPE
111
+ ],
112
+ 'unsigned_integer_and_generic': [
113
+ wrap( isUnsignedIntegerDataType ),
114
+ DEFAULT_UNSIGNED_INTEGER_DTYPE
115
+ ],
116
+
117
+ // Real-valued number policies...
118
+ 'real': [
119
+ isRealDataType,
120
+ defaults.get( 'dtypes.real' )
121
+ ],
122
+ 'real_and_generic': [
123
+ wrap( isRealDataType ),
124
+ defaults.get( 'dtypes.real' )
125
+ ],
126
+
127
+ // Real- and complex-valued number policies...
128
+ 'numeric': [
129
+ isNumericDataType,
130
+ defaults.get( 'dtypes.numeric' )
131
+ ],
132
+ 'numeric_and_generic': [
133
+ wrap( isNumericDataType ),
134
+ defaults.get( 'dtypes.numeric' )
135
+ ],
136
+
137
+ // Boolean policies...
138
+ 'boolean': [
139
+ isBooleanDataType,
140
+ defaults.get( 'dtypes.boolean' )
141
+ ],
142
+ 'boolean_and_generic': [
143
+ wrap( isBooleanDataType ),
144
+ defaults.get( 'dtypes.boolean' )
145
+ ],
146
+
147
+ // Index policies...
148
+ 'integer_index': [
149
+ isIntegerIndexDataType,
150
+ defaults.get( 'dtypes.integer_index' )
151
+ ],
152
+ 'integer_index_and_generic': [
153
+ wrap( isIntegerIndexDataType ),
154
+ defaults.get( 'dtypes.integer_index' )
155
+ ],
156
+ 'boolean_index': [
157
+ isBooleanIndexDataType,
158
+ defaults.get( 'dtypes.boolean_index' )
159
+ ],
160
+ 'boolean_index_and_generic': [
161
+ wrap( isBooleanIndexDataType ),
162
+ defaults.get( 'dtypes.boolean_index' )
163
+ ],
164
+ 'mask_index': [
165
+ isMaskIndexDataType,
166
+ defaults.get( 'dtypes.mask_index' )
167
+ ],
168
+ 'mask_index_and_generic': [
169
+ wrap( isMaskIndexDataType ),
170
+ defaults.get( 'dtypes.mask_index' )
171
+ ]
172
+ };
173
+
174
+ // Table mapping complex-valued floating-point data types to real-valued floating-point data types having the same precision:
175
+ var COMPLEX2FLOAT = {
176
+ 'complex128': 'float64',
177
+ 'complex64': 'float32',
178
+ 'complex32': 'float16'
179
+ };
180
+
181
+ // Table mapping real-valued floating-point data types to complex-valued floating-point data types having the same precision:
182
+ var FLOAT2COMPLEX = {
183
+ 'float64': 'complex128',
184
+ 'float32': 'complex64',
185
+ 'float16': 'complex32'
186
+ };
187
+
188
+
189
+ // FUNCTIONS //
190
+
191
+ /**
192
+ * Wraps a data type validation function to also check for a "generic" data type.
193
+ *
194
+ * @private
195
+ * @param {Function} fcn - validation function
196
+ * @returns {Function} wrapped validation function
197
+ */
198
+ function wrap( fcn ) {
199
+ return wrapper;
200
+
201
+ /**
202
+ * Tests whether a provided data type is either "generic" or satisfies a data type validation function.
203
+ *
204
+ * @private
205
+ * @param {*} value - input value
206
+ * @returns {boolean} boolean indicating whether a provided value passes a test
207
+ */
208
+ function wrapper( value ) {
209
+ return ( value === 'generic' ) || fcn( value );
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Returns the default data type.
215
+ *
216
+ * @private
217
+ * @returns {string} output ndarray data type
218
+ */
219
+ function defaultPolicy() {
220
+ // When the policy is "default", the output data type should always be the default data type without consideration for the input data types:
221
+ return DEFAULT_DTYPE;
222
+ }
223
+
224
+ /**
225
+ * Returns the default index data type.
226
+ *
227
+ * @private
228
+ * @returns {string} output ndarray data type
229
+ */
230
+ function defaultIndexPolicy() {
231
+ // When the policy is "default_index", the output data type should always be the default index data type without consideration for the input data types:
232
+ return DEFAULT_INDEX_DTYPE;
233
+ }
234
+
235
+ /**
236
+ * Applies the "same" policy by returning the common input data type.
237
+ *
238
+ * @private
239
+ * @param {StringArray} dtypes - input ndarray data types
240
+ * @throws {Error} invalid data types
241
+ * @returns {string} output ndarray data type
242
+ */
243
+ function samePolicy( dtypes ) {
244
+ var dt;
245
+ var i;
246
+
247
+ dt = dtypes[ 0 ];
248
+ for ( i = 1; i < dtypes.length; i++ ) {
249
+ // When the policy is "same", we require that all data types (both input and output) be the same...
250
+ if ( dtypes[ i ] !== dt ) {
251
+ throw new Error( format( 'invalid argument. Unable to resolve an output data type. The output data type policy is "same" and yet the input data types are not equal. Data types: [%s].', join( dtypes, ', ' ) ) );
252
+ }
253
+ }
254
+ return dt;
255
+ }
256
+
257
+ /**
258
+ * Applies the "promoted" policy by applying type promotion to the list of provided data types.
259
+ *
260
+ * @private
261
+ * @param {StringArray} dtypes - input ndarray data types
262
+ * @throws {Error} must provide data types which can be safely cast to a common data type
263
+ * @returns {string} output ndarray data type
264
+ */
265
+ function promotedPolicy( dtypes ) {
266
+ var dt = promoteDataTypes( dtypes );
267
+ if ( dt === null ) {
268
+ throw new Error( format( 'invalid argument. Unable to apply type promotion rules when resolving a data type to which the input data types can be safely cast. Data types: [%s].', join( dtypes, ', ' ) ) );
269
+ }
270
+ return dt;
271
+ }
272
+
273
+ /**
274
+ * Applies the "accumulation" policy to the list of input data types.
275
+ *
276
+ * @private
277
+ * @param {StringArray} dtypes - input ndarray data types
278
+ * @throws {Error} must provide data types which can be safely cast to a common data type
279
+ * @returns {string} output ndarray data type
280
+ */
281
+ function accumulationPolicy( dtypes ) {
282
+ var dt = promotedPolicy( dtypes );
283
+
284
+ // If the promoted data type is floating-point, allow accumulation in that data type as overflow/underflow is handled naturally as a built-in feature of that data type...
285
+ if ( isFloatingPointDataType( dt ) || dt === 'generic' ) { // NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited
286
+ return dt;
287
+ }
288
+ // Unless the promoted data type value range is larger than the default un/signed integer data type, accumulate in the default un/signed integer data type, as accumulating in small range integer data types (e.g., `int8`) is at high risk for overflow, especially for ndarrays containing many elements...
289
+ if ( isUnsignedIntegerDataType( dt ) ) {
290
+ return promoteDataTypes( [ dt, DEFAULT_UNSIGNED_INTEGER_DTYPE ] );
291
+ }
292
+ if ( isSignedIntegerDataType( dt ) ) {
293
+ return promoteDataTypes( [ dt, DEFAULT_SIGNED_INTEGER_DTYPE ] );
294
+ }
295
+ // For all other data types, accumulate in the default real-valued floating-point data type...
296
+ return DEFAULT_REAL_FLOATING_POINT_DTYPE;
297
+ }
298
+
299
+ /**
300
+ * Resolves a default real-valued floating-point data type which preserves floating-point precision.
301
+ *
302
+ * @private
303
+ * @param {string} dtype - input ndarray data type
304
+ * @returns {string} output ndarray data type
305
+ */
306
+ function resolveDefaultRealFloatingPoint( dtype ) {
307
+ return COMPLEX2FLOAT[ dtype ] || DEFAULT_REAL_FLOATING_POINT_DTYPE;
308
+ }
309
+
310
+ /**
311
+ * Resolves a default complex-valued floating-point data type which preserves floating-point precision.
312
+ *
313
+ * @private
314
+ * @param {string} dtype - input ndarray data type
315
+ * @returns {string} output ndarray data type
316
+ */
317
+ function resolveDefaultComplexFloatingPoint( dtype ) {
318
+ return FLOAT2COMPLEX[ dtype ] || DEFAULT_COMPLEX_FLOATING_POINT_DTYPE;
319
+ }
320
+
321
+
322
+ // MAIN //
323
+
324
+ /**
325
+ * Resolves the output data type from a list of input ndarray data types.
326
+ *
327
+ * @param {StringArray} dtypes - list of input ndarray data types
328
+ * @param {string} policy - output ndarray data type policy
329
+ * @throws {TypeError} second argument must be a recognized data type policy
330
+ * @throws {Error} unexpected error
331
+ * @returns {string} output ndarray data type
332
+ *
333
+ * @example
334
+ * var dt = resolve( [ 'float64' ], 'complex_floating_point' );
335
+ * // returns <string>
336
+ */
337
+ function resolve( dtypes, policy ) {
338
+ var dt;
339
+ var p;
340
+
341
+ // First, check whether the policy mandates that the output data type always be a specific data type...
342
+ if ( isDataType( policy ) ) {
343
+ return policy;
344
+ }
345
+ // Next, check whether the policy is one in which we may be able to avoid type promotion...
346
+ p = POLICY_TABLE1[ policy ];
347
+ if ( p !== void 0 ) {
348
+ return p( dtypes );
349
+ }
350
+ // For all other policies, we always apply type promotion rules...
351
+ dt = promotedPolicy( dtypes );
352
+
353
+ // Check whether the policy requires determining the data type "kind"...
354
+ p = POLICY_TABLE2[ policy ];
355
+ if ( p !== void 0 ) {
356
+ // Check whether the promoted data type belongs to the data type "kind"...
357
+ if ( p[ 0 ]( dt ) ) {
358
+ // If so, we can just return the promoted data type:
359
+ return dt;
360
+ }
361
+ // Otherwise, we need to fallback to a default data type belonging to that "kind"...
362
+ if ( isString( p[ 1 ] ) ) {
363
+ return p[ 1 ];
364
+ }
365
+ return p[ 1 ]( dt );
366
+ }
367
+ throw new TypeError( format( 'invalid argument. Second argument must be a supported data type policy. Value: `%s`.', policy ) );
368
+ }
369
+
370
+
371
+ // EXPORTS //
372
+
373
+ module.exports = resolve;
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@stdlib/ndarray-base-output-dtype",
3
+ "version": "0.1.0",
4
+ "description": "Resolve the output data type from a list of input ndarray 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
+ "doc": "./docs",
19
+ "lib": "./lib",
20
+ "dist": "./dist"
21
+ },
22
+ "types": "./docs/types",
23
+ "scripts": {},
24
+ "homepage": "https://stdlib.io",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/stdlib-js/ndarray-base-output-dtype.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/stdlib-js/stdlib/issues"
31
+ },
32
+ "dependencies": {
33
+ "@stdlib/array-base-join": "^0.1.1",
34
+ "@stdlib/assert-is-string": "^0.2.2",
35
+ "@stdlib/ndarray-base-assert-is-boolean-data-type": "^0.2.0",
36
+ "@stdlib/ndarray-base-assert-is-boolean-index-data-type": "^0.1.0",
37
+ "@stdlib/ndarray-base-assert-is-complex-floating-point-data-type": "^0.3.0",
38
+ "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2",
39
+ "@stdlib/ndarray-base-assert-is-floating-point-data-type": "^0.3.0",
40
+ "@stdlib/ndarray-base-assert-is-integer-data-type": "^0.3.0",
41
+ "@stdlib/ndarray-base-assert-is-integer-index-data-type": "^0.1.0",
42
+ "@stdlib/ndarray-base-assert-is-mask-index-data-type": "^0.1.0",
43
+ "@stdlib/ndarray-base-assert-is-numeric-data-type": "^0.3.0",
44
+ "@stdlib/ndarray-base-assert-is-real-data-type": "^0.3.0",
45
+ "@stdlib/ndarray-base-assert-is-real-floating-point-data-type": "^0.3.0",
46
+ "@stdlib/ndarray-base-assert-is-signed-integer-data-type": "^0.3.0",
47
+ "@stdlib/ndarray-base-assert-is-unsigned-integer-data-type": "^0.3.0",
48
+ "@stdlib/ndarray-base-promote-dtypes": "^0.1.0",
49
+ "@stdlib/ndarray-defaults": "^0.4.0",
50
+ "@stdlib/string-format": "^0.2.2",
51
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
52
+ },
53
+ "devDependencies": {},
54
+ "engines": {
55
+ "node": ">=0.10.0",
56
+ "npm": ">2.7.0"
57
+ },
58
+ "os": [
59
+ "aix",
60
+ "darwin",
61
+ "freebsd",
62
+ "linux",
63
+ "macos",
64
+ "openbsd",
65
+ "sunos",
66
+ "win32",
67
+ "windows"
68
+ ],
69
+ "keywords": [
70
+ "stdlib",
71
+ "stdtypes",
72
+ "types",
73
+ "ndarray",
74
+ "dtypes",
75
+ "dtype",
76
+ "data",
77
+ "multidimensional",
78
+ "array",
79
+ "utilities",
80
+ "utility",
81
+ "utils",
82
+ "util",
83
+ "resolve",
84
+ "return",
85
+ "output"
86
+ ],
87
+ "funding": {
88
+ "type": "opencollective",
89
+ "url": "https://opencollective.com/stdlib"
90
+ }
91
+ }