@stdlib/math-tools-unary 0.2.2 → 0.3.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/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -33,12 +33,18 @@ limitations under the License.
33
33
 
34
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
35
 
36
- > Multiple dispatch for unary mathematical functions.
36
+ > Create a function which performs element-wise computation by applying a unary function to each element in an input ndarray.
37
37
 
38
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
39
 
40
40
  <section class="intro">
41
41
 
42
+ The purpose of this package is to provide a thin wrapper around a lower-level interface supporting multiple dispatch based on the data types of provided ndarray arguments. The wrapper performs the following tasks:
43
+
44
+ - validates input arguments.
45
+ - casts input ndarrays according to a casting policy.
46
+ - allocates an output ndarray according to an output data type policy.
47
+
42
48
  </section>
43
49
 
44
50
  <!-- /.intro -->
@@ -60,184 +66,210 @@ npm install @stdlib/math-tools-unary
60
66
  ## Usage
61
67
 
62
68
  ```javascript
63
- var dispatch = require( '@stdlib/math-tools-unary' );
69
+ var factory = require( '@stdlib/math-tools-unary' );
64
70
  ```
65
71
 
66
- #### dispatch( table )
72
+ #### factory( fcn, idtypes, odtypes, policies )
67
73
 
68
- Returns a function which dispatches to specified functions based on input argument types.
74
+ Returns a function which performs element-wise computation by applying a unary function to each element in an input ndarray.
69
75
 
70
76
  <!-- eslint-disable array-element-newline -->
71
77
 
72
78
  ```javascript
73
- var nabs = require( '@stdlib/math-base-special-abs' );
74
- var dabs = require( '@stdlib/math-strided-special-dabs' );
75
- var sabs = require( '@stdlib/math-strided-special-sabs' );
76
- var gabs = require( '@stdlib/math-strided-special-abs' );
77
-
78
- var table = {
79
- 'scalar': [
80
- 'number', nabs
81
- ],
82
- 'array': [
83
- 'float64', dabs,
84
- 'float32', sabs,
85
- 'generic', gabs
86
- ],
87
- 'ndarray': [
88
- 'float64', dabs.ndarray,
89
- 'float32', sabs.ndarray,
90
- 'generic', gabs.ndarray
91
- ]
92
- };
79
+ var base = require( '@stdlib/math-base-special-abs' );
80
+ var dispatch = require( '@stdlib/ndarray-dispatch' );
81
+ var unary = require( '@stdlib/ndarray-base-unary' );
82
+ var ndarray2array = require( '@stdlib/ndarray-to-array' );
83
+ var array = require( '@stdlib/ndarray-array' );
93
84
 
94
- var abs = dispatch( table );
85
+ var types = [
86
+ 'float64', 'float64',
87
+ 'float64', 'generic',
88
+ 'generic', 'generic'
89
+ ];
90
+ var data = [
91
+ base,
92
+ base,
93
+ base
94
+ ];
95
+ var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
96
+
97
+ var idt = [ 'float64', 'generic' ];
98
+ var odt = idt;
99
+
100
+ var policies = {
101
+ 'output': 'real_and_generic',
102
+ 'casting': 'none'
103
+ };
104
+ var ufunc = factory( dispatcher, [ idt ], odt, policies );
95
105
  ```
96
106
 
97
- The function accepts the following arguments:
98
-
99
- - **table**: resolution table object which maps input argument types to corresponding implementations.
100
-
101
- A `table` resolution object may contain one or more of the following fields:
107
+ The function has the following arguments:
102
108
 
103
- - **scalar**: strided look-up table for scalar arguments. Implementation functions must accept a single input argument: a scalar value. Supported data types: `'number'` and `'complex'`.
109
+ - **fcn**: function which applies a unary function to each element in an ndarray and assigns results to an output ndarray.
104
110
 
105
- - **array**: strided look-up table for array-like object arguments. Implementation functions must follow strided array interface argument conventions:
111
+ - **idtypes**: list containing lists of supported input data types for each input ndarray argument.
106
112
 
107
- ```text
108
- fcn( N, x, strideX, y, strideY )
109
- ```
113
+ - **odtypes**: list of supported output data types.
110
114
 
111
- where
115
+ - **policies**: dispatch policies. Must have the following properties:
112
116
 
113
- - **N**: number of indexed elements.
114
- - **x**: input strided array.
115
- - **strideX**: index increment for `x`.
116
- - **y**: destination strided array.
117
- - **strideY**: index increment for `y`.
117
+ - **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies].
118
+ - **casting**: input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
118
119
 
119
- Supported array data types consist of all supported [ndarray][@stdlib/ndarray/dtypes] data types.
120
+ #### ufunc( x\[, options] )
120
121
 
121
- - **ndarray**: strided look-up table for [`ndarray`][@stdlib/ndarray/ctor] arguments. Implementation functions must follow strided array ndarray interface argument conventions:
122
+ Performs element-wise computation.
122
123
 
123
- ```text
124
- fcn( N, x, strideX, offsetX, y, strideY, offsetY )
125
- ```
124
+ <!-- eslint-disable array-element-newline -->
126
125
 
127
- where
126
+ ```javascript
127
+ var base = require( '@stdlib/math-base-special-abs' );
128
+ var dispatch = require( '@stdlib/ndarray-dispatch' );
129
+ var unary = require( '@stdlib/ndarray-base-unary' );
130
+ var ndarray2array = require( '@stdlib/ndarray-to-array' );
131
+ var array = require( '@stdlib/ndarray-array' );
128
132
 
129
- - **N**: number of indexed elements.
130
- - **x**: input strided array (i.e., underlying input [`ndarray`][@stdlib/ndarray/ctor] buffer).
131
- - **strideX**: index increment for `x`.
132
- - **offsetX**: starting index for `x`.
133
- - **y**: destination strided array (i.e., underlying output [`ndarray`][@stdlib/ndarray/ctor] buffer).
134
- - **strideY**: index increment for `y`.
135
- - **offsetY**: starting index for `y`.
133
+ var types = [
134
+ 'float64', 'float64',
135
+ 'float64', 'generic',
136
+ 'generic', 'generic'
137
+ ];
138
+ var data = [
139
+ base,
140
+ base,
141
+ base
142
+ ];
143
+ var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
144
+
145
+ var idt = [ 'float64', 'generic' ];
146
+ var odt = idt;
147
+
148
+ var policies = {
149
+ 'output': 'real_and_generic',
150
+ 'casting': 'none'
151
+ };
152
+ var ufunc = factory( dispatcher, [ idt ], odt, policies );
136
153
 
137
- Supported data types consist of all supported [ndarray][@stdlib/ndarray/dtypes] data types.
154
+ var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
155
+ // returns <ndarray>
138
156
 
139
- Each strided look-up table should be comprised as follows:
157
+ var y = ufunc( x );
158
+ // returns <ndarray>
140
159
 
141
- ```text
142
- [ <dtype>, <fcn>, <dtype>, <fcn>, ... ]
160
+ var arr = ndarray2array( y );
161
+ // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
143
162
  ```
144
163
 
145
- If an argument's data type is **not** found in the argument's corresponding look-up table and if a `'generic'` data type is present in that same table, the returned dispatch function will resolve the "generic" implementation. In other words, an implementation associated with a `'generic'` data type will be treated as the default implementation.
164
+ The function has the following parameters:
146
165
 
147
- If unable to resolve an implementation for a provided argument data type, the returned function throws an error.
166
+ - **x**: input ndarray.
167
+ - **options**: function options (_optional_).
148
168
 
149
- * * *
169
+ The function accepts the following options:
150
170
 
151
- #### dispatcher( x )
171
+ - **dtype**: output ndarray data type. Setting this option, overrides the output data type policy.
172
+ - **order**: output ndarray order.
152
173
 
153
- Dispatches to an underlying implementation based the data type of `x`.
174
+ By default, the function returns an ndarray having a data type determined by the output data type policy. To override the default behavior, set the `dtype` option.
154
175
 
155
176
  <!-- eslint-disable array-element-newline -->
156
177
 
157
178
  ```javascript
158
- var nabs = require( '@stdlib/math-base-special-abs' );
159
- var dabs = require( '@stdlib/math-strided-special-dabs' );
160
- var sabs = require( '@stdlib/math-strided-special-sabs' );
161
- var gabs = require( '@stdlib/math-strided-special-abs' );
162
-
163
- var table = {
164
- 'scalar': [
165
- 'number', nabs
166
- ],
167
- 'array': [
168
- 'float64', dabs,
169
- 'float32', sabs,
170
- 'generic', gabs
171
- ],
172
- 'ndarray': [
173
- 'float64', dabs.ndarray,
174
- 'float32', sabs.ndarray,
175
- 'generic', gabs.ndarray
176
- ]
179
+ var base = require( '@stdlib/math-base-special-abs' );
180
+ var dispatch = require( '@stdlib/ndarray-dispatch' );
181
+ var unary = require( '@stdlib/ndarray-base-unary' );
182
+ var getDType = require( '@stdlib/ndarray-dtype' );
183
+ var array = require( '@stdlib/ndarray-array' );
184
+
185
+ var types = [
186
+ 'float64', 'float64',
187
+ 'float64', 'generic',
188
+ 'generic', 'generic'
189
+ ];
190
+ var data = [
191
+ base,
192
+ base,
193
+ base
194
+ ];
195
+ var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
196
+
197
+ var idt = [ 'float64', 'generic' ];
198
+ var odt = idt;
199
+
200
+ var policies = {
201
+ 'output': 'real_and_generic',
202
+ 'casting': 'none'
177
203
  };
204
+ var ufunc = factory( dispatcher, [ idt ], odt, policies );
178
205
 
179
- var abs = dispatch( table );
206
+ var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
207
+ // returns <ndarray>
180
208
 
181
- var y = abs( -1.0 );
182
- // returns 1.0
183
- ```
209
+ var y = ufunc( x, {
210
+ 'dtype': 'generic'
211
+ });
212
+ // returns <ndarray>
184
213
 
185
- The returned dispatch function accepts the following arguments:
214
+ var dt = getDType( y );
215
+ // returns 'generic'
216
+ ```
186
217
 
187
- - **x**: input [`ndarray`][@stdlib/ndarray/ctor], array-like object, or number. If provided an [`ndarray`][@stdlib/ndarray/ctor] or array-like object, the function performs element-wise computation.
218
+ #### ufunc.assign( x, out )
188
219
 
189
- If provided an [`ndarray`][@stdlib/ndarray/ctor], the function returns an [`ndarray`][@stdlib/ndarray/ctor] having the same shape and data type as `x`.
220
+ Performs element-wise computation and assigns results to a provided output ndarray.
190
221
 
191
222
  <!-- eslint-disable array-element-newline -->
192
223
 
193
224
  ```javascript
194
- var dabs = require( '@stdlib/math-strided-special-dabs' );
195
- var sabs = require( '@stdlib/math-strided-special-sabs' );
196
- var gabs = require( '@stdlib/math-strided-special-abs' );
225
+ var base = require( '@stdlib/math-base-special-abs' );
226
+ var dispatch = require( '@stdlib/ndarray-dispatch' );
227
+ var unary = require( '@stdlib/ndarray-base-unary' );
228
+ var ndarray2array = require( '@stdlib/ndarray-to-array' );
229
+ var zerosLike = require( '@stdlib/ndarray-zeros-like' );
197
230
  var array = require( '@stdlib/ndarray-array' );
198
231
 
199
- var table = {
200
- 'ndarray': [
201
- 'float64', dabs.ndarray,
202
- 'float32', sabs.ndarray,
203
- 'generic', gabs.ndarray
204
- ]
232
+ var types = [
233
+ 'float64', 'float64',
234
+ 'float64', 'generic',
235
+ 'generic', 'generic'
236
+ ];
237
+ var data = [
238
+ base,
239
+ base,
240
+ base
241
+ ];
242
+ var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
243
+
244
+ var idt = [ 'float64', 'generic' ];
245
+ var odt = idt;
246
+
247
+ var policies = {
248
+ 'output': 'real_and_generic',
249
+ 'casting': 'none'
205
250
  };
251
+ var ufunc = factory( dispatcher, [ idt ], odt, policies );
206
252
 
207
- var abs = dispatch( table );
208
-
209
- var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] ); // 2x2
210
- var y = abs( x );
253
+ var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
211
254
  // returns <ndarray>
212
255
 
213
- var v = y.get( 0, 1 );
214
- // returns 2.0
215
- ```
256
+ var y = zerosLike( x );
257
+ // returns <ndarray>
216
258
 
217
- If provided an array-like object, the function returns an array-like object having the same length and data type as `x`.
259
+ var out = ufunc.assign( x, y );
260
+ // returns <ndarray>
218
261
 
219
- <!-- eslint-disable array-element-newline -->
262
+ var bool = ( out === y );
263
+ // returns true
220
264
 
221
- ```javascript
222
- var dabs = require( '@stdlib/math-strided-special-dabs' );
223
- var sabs = require( '@stdlib/math-strided-special-sabs' );
224
- var gabs = require( '@stdlib/math-strided-special-abs' );
225
- var Float64Array = require( '@stdlib/array-float64' );
226
-
227
- var table = {
228
- 'array': [
229
- 'float64', dabs,
230
- 'float32', sabs,
231
- 'generic', gabs
232
- ]
233
- };
265
+ var arr = ndarray2array( out );
266
+ // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
267
+ ```
234
268
 
235
- var abs = dispatch( table );
269
+ The method has the following parameters:
236
270
 
237
- var x = new Float64Array( [ -1.0, -2.0 ] );
238
- var y = abs( x );
239
- // returns <Float64Array>[ 1.0, 2.0 ]
240
- ```
271
+ - **x**: input ndarray.
272
+ - **out**: output ndarray.
241
273
 
242
274
  </section>
243
275
 
@@ -247,14 +279,27 @@ var y = abs( x );
247
279
 
248
280
  <section class="notes">
249
281
 
282
+ ## Notes
283
+
284
+ - A provided unary function should have the following signature:
285
+
286
+ ```text
287
+ f( x, y )
288
+ ```
289
+
290
+ where
291
+
292
+ - **x**: input ndarray.
293
+ - **y**: output ndarray.
294
+
295
+ - The output data type policy only applies to the function returned by the main function. For the `assign` method, the output ndarray is allowed to have any supported output data type.
296
+
250
297
  </section>
251
298
 
252
299
  <!-- /.notes -->
253
300
 
254
301
  <!-- Package usage examples. -->
255
302
 
256
- * * *
257
-
258
303
  <section class="examples">
259
304
 
260
305
  ## Examples
@@ -264,63 +309,49 @@ var y = abs( x );
264
309
  <!-- eslint no-undef: "error" -->
265
310
 
266
311
  ```javascript
267
- var nabs = require( '@stdlib/math-base-special-abs' );
268
- var dabs = require( '@stdlib/math-strided-special-dabs' );
269
- var sabs = require( '@stdlib/math-strided-special-sabs' );
270
- var gabs = require( '@stdlib/math-strided-special-abs' );
271
- var Float64Array = require( '@stdlib/array-float64' );
272
- var array = require( '@stdlib/ndarray-array' );
273
- var ind2sub = require( '@stdlib/ndarray-ind2sub' );
274
- var dispatch = require( '@stdlib/math-tools-unary' );
275
-
276
- var table;
277
- var sub;
278
- var abs;
279
- var sh;
280
- var x;
281
- var y;
282
- var i;
283
-
284
- // Define a table for resolving unary functions based on argument data types:
285
- table = {
286
- 'scalar': [
287
- 'number', nabs
288
- ],
289
- 'array': [
290
- 'float64', dabs,
291
- 'float32', sabs,
292
- 'generic', gabs
293
- ],
294
- 'ndarray': [
295
- 'float64', dabs.ndarray,
296
- 'float32', sabs.ndarray,
297
- 'generic', gabs.ndarray
298
- ]
299
- };
312
+ var base = require( '@stdlib/math-base-special-abs' );
313
+ var basef = require( '@stdlib/math-base-special-absf' );
314
+ var uniform = require( '@stdlib/random-uniform' );
315
+ var dispatch = require( '@stdlib/ndarray-dispatch' );
316
+ var ndarray2array = require( '@stdlib/ndarray-to-array' );
317
+ var unary = require( '@stdlib/ndarray-base-unary' );
318
+ var ufunc = require( '@stdlib/math-tools-unary' );
300
319
 
301
320
  // Create a function which dispatches based on argument data types:
302
- abs = dispatch( table );
303
-
304
- // Provide a number...
305
- y = abs( -1.0 );
306
- console.log( 'x = %d => abs(x) = %d', -1.0, y );
307
-
308
- // Provide an array-like object...
309
- x = new Float64Array( [ -1.0, -2.0, -3.0 ] );
310
- y = abs( x );
311
- for ( i = 0; i < x.length; i++ ) {
312
- console.log( 'x_%d = %d => abs(x_%d) = %d', i, x[ i ], i, y[ i ] );
313
- }
314
-
315
- // Provide an ndarray...
316
- x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
317
- sh = x.shape;
318
-
319
- y = abs( x );
320
- for ( i = 0; i < x.length; i++ ) {
321
- sub = ind2sub( sh, i );
322
- console.log( 'x_%d%d = %d => abs(x_%d%d) = %d', sub[ 0 ], sub[ 1 ], x.iget( i ), sub[ 0 ], sub[ 1 ], y.iget( i ) );
323
- }
321
+ var types = [
322
+ 'float64', 'float64',
323
+ 'float32', 'float32',
324
+ 'generic', 'generic'
325
+ ];
326
+ var data = [
327
+ base,
328
+ basef,
329
+ base
330
+ ];
331
+ var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
332
+
333
+ // Define the supported input and output data types:
334
+ var idt = [ 'float64', 'float32', 'generic' ];
335
+ var odt = [ 'float64', 'float32', 'generic' ];
336
+
337
+ // Define dispatch policies:
338
+ var policies = {
339
+ 'output': 'same',
340
+ 'casting': 'none'
341
+ };
342
+
343
+ // Create a function that performs element-wise computation:
344
+ var abs = ufunc( dispatcher, [ idt ], odt, policies );
345
+
346
+ // Generate an array of random numbers:
347
+ var x = uniform( [ 5, 5 ], -10.0, 10.0, {
348
+ 'dtype': 'float64'
349
+ });
350
+ console.log( ndarray2array( x ) );
351
+
352
+ // Perform element-wise computation:
353
+ var y = abs( x );
354
+ console.log( ndarray2array( y ) );
324
355
  ```
325
356
 
326
357
  </section>
@@ -369,7 +400,7 @@ See [LICENSE][stdlib-license].
369
400
 
370
401
  ## Copyright
371
402
 
372
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
403
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
373
404
 
374
405
  </section>
375
406
 
@@ -382,8 +413,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
382
413
  [npm-image]: http://img.shields.io/npm/v/@stdlib/math-tools-unary.svg
383
414
  [npm-url]: https://npmjs.org/package/@stdlib/math-tools-unary
384
415
 
385
- [test-image]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml/badge.svg?branch=v0.2.2
386
- [test-url]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml?query=branch:v0.2.2
416
+ [test-image]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml/badge.svg?branch=v0.3.1
417
+ [test-url]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml?query=branch:v0.3.1
387
418
 
388
419
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-tools-unary/main.svg
389
420
  [coverage-url]: https://codecov.io/github/stdlib-js/math-tools-unary?branch=main
@@ -395,8 +426,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
395
426
 
396
427
  -->
397
428
 
398
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
399
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
429
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
430
+ [chat-url]: https://stdlib.zulipchat.com
400
431
 
401
432
  [stdlib]: https://github.com/stdlib-js/stdlib
402
433
 
@@ -415,9 +446,9 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
415
446
 
416
447
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-tools-unary/main/LICENSE
417
448
 
418
- [@stdlib/ndarray/ctor]: https://www.npmjs.com/package/@stdlib/ndarray-ctor
449
+ [@stdlib/ndarray/output-dtype-policies]: https://www.npmjs.com/package/@stdlib/ndarray-output-dtype-policies
419
450
 
420
- [@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
451
+ [@stdlib/ndarray/input-casting-policies]: https://www.npmjs.com/package/@stdlib/ndarray-input-casting-policies
421
452
 
422
453
  </section>
423
454
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="../docs/types/index.d.ts" />
2
- import dispatch from '../docs/types/index';
3
- export = dispatch;
2
+ import factory from '../docs/types/index';
3
+ export = factory;
package/dist/index.js CHANGED
@@ -1,19 +1,7 @@
1
- "use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var b=v(function(Pr,w){"use strict";var h=require("@stdlib/ndarray-ctor"),q=require("@stdlib/ndarray-base-buffer"),B=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-numel"),H=require("@stdlib/array-base-copy-indexed");function J(r,e,u,n){var t,i,d;return t=H(e.shape),t.length===0?(i=q(u,1),d=h(u,i,[],[0],0,n)):(i=q(u,e.length||G(t)),d=h(u,i,t,B(t,n),0,n)),r(e,d),d}w.exports=J});var T=v(function(jr,E){"use strict";var Q=require("@stdlib/string-format");function W(r,e){switch(e){case"same":return r;case"floating-point":return r==="float64"||r==="float32"||r==="generic"||r==="complex128"||r==="complex64"?r:"float64";case"real floating-point":return r==="float64"||r==="float32"||r==="generic"?r:"float64";case"complex floating-point":return r==="complex128"||r==="complex64"?r:"complex128";default:throw new Error(Q("invalid option. Unsupported policy for determining an output array data type. Option: `%s`.",e))}}E.exports=W});var O=v(function(_r,X){X.exports={output_dtype_policy:"floating-point"}});var _=v(function(kr,j){"use strict";var Z=require("@stdlib/assert-is-plain-object"),$=require("@stdlib/assert-has-own-property"),x=require("@stdlib/assert-is-function"),rr=require("@stdlib/assert-is-null"),er=require("@stdlib/utils-keys"),P=require("@stdlib/string-format");function ar(r,e){var u,n,t,i;if(!Z(e))return new TypeError(P("invalid argument. Resolution table must be an object. Value: `%s`.",e));for(u=er(r),i=0;i<u.length;i++)if(t=u[i],$(e,t)){if(n=e[t],!x(n)&&!rr(n))return new TypeError(P("invalid argument. Resolution table `%s` field value must be either a function or null. Value: `%s`.",t,n));r[t]=n}return null}j.exports=ar});var k=v(function(Rr,ir){ir.exports=["same","floating-point","real floating-point","complex floating-point"]});var z=v(function(Vr,V){"use strict";var nr=require("@stdlib/assert-is-plain-object"),tr=require("@stdlib/assert-has-own-property"),ur=require("@stdlib/assert-contains"),R=require("@stdlib/string-format"),or=k();function lr(r,e){return nr(e)?tr(e,"output_dtype_policy")&&(r.policy=e.output_dtype_policy,!ur(or,r.policy))?new TypeError(R("invalid option. `%s` option must be a recognized/supported output array data type policy. Option: `%s`.","output_dtype_policy",r.policy)):null:new TypeError(R("invalid argument. Options argument must be an object. Value: `%s`.",e))}V.exports=lr});var L=v(function(zr,S){"use strict";var sr=require("@stdlib/assert-is-plain-object"),C=require("@stdlib/assert-has-own-property"),I=require("@stdlib/assert-contains"),pr=require("@stdlib/ndarray-orders"),vr=require("@stdlib/ndarray-dtypes"),c=require("@stdlib/string-format"),dr=pr(),fr=vr();function cr(r,e){return sr(e)?C(e,"dtype")&&(r.dtype=e.dtype,!I(fr,r.dtype))?new TypeError(c("invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.","dtype",r.dtype)):C(e,"order")&&(r.order=e.order,!I(dr,r.order))?new TypeError(c("invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.","order",r.order)):null:new TypeError(c("invalid argument. Options argument must be an object. Value: `%s`.",e))}S.exports=cr});var Y=v(function(Cr,U){"use strict";var mr=require("@stdlib/utils-define-nonenumerable-read-only-property"),D=require("@stdlib/assert-is-number").isPrimitive,M=require("@stdlib/assert-is-complex-like"),m=require("@stdlib/assert-is-ndarray-like"),g=require("@stdlib/assert-is-collection"),y=require("@stdlib/ndarray-base-buffer-dtype"),gr=require("@stdlib/ndarray-base-buffer"),N=require("@stdlib/ndarray-base-broadcast-array"),F=require("@stdlib/string-format"),yr=b(),K=T(),hr=O(),qr=_(),wr=z(),br=L();function Er(r,e){var u,n,t,i;if(i={number:null,complex:null,array:null,ndarray:null},n=qr(i,r),n||(u={policy:hr.output_dtype_policy},arguments.length>1&&(n=wr(u,e),n)))throw n;return t=d,mr(t,"assign",A),t;function d(a){var o,s,l,p,f;if(D(a)){if(i.number)return i.number(a);throw new TypeError("invalid argument. Providing a number is not supported.")}if(M(a)){if(i.complex)return i.complex(a);throw new TypeError("invalid argument. Providing a complex number is not supported.")}if(l={},arguments.length>1&&(p=br(l,arguments[1]),p))throw p;if(m(a)){if(i.ndarray===null)throw new TypeError("invalid argument. Providing an ndarray is not supported.");return s=l.dtype||K(a.dtype,u.policy),yr(i.ndarray,a,s,l.order||a.order)}if(g(a)){if(i.array===null)throw new TypeError("invalid argument. Providing an array-like object is not supported.");return o=y(a)||"generic",s=l.dtype||K(o,u.policy),f=gr(s,a.length),i.array(a.length,o,a,1,s,f,1),f}throw new TypeError(F("invalid argument. Must provide an argument having a supported data type. Value: `%s`.",a))}function A(a,o){var s,l,p;if(m(a)){if(m(o)){if(s=a.shape,l=o.shape,s.length===l.length){for(p=0;p<s.length;p++)if(s[p]!==l[p]){a=N(a,l);break}}else a=N(a,l);return i.ndarray(a,o),o}throw new TypeError("invalid argument. If the first argument is an ndarray, the second argument must be an ndarray.")}if(g(a)){if(g(o)){if(o.length!==a.length)throw new RangeError("invalid argument. Output array must have the same number of elements (i.e., length) as the input array.");return i.array(a.length,y(a)||"generic",a,1,y(o)||"generic",o,1),o}throw new TypeError("invalid argument. If the first argument is an array-like object, the second argument must be an array-like object.")}throw D(a)?new TypeError("invalid argument. Providing a number is not supported. Consider providing a zero-dimensional ndarray containing the numeric value."):M(a)?new TypeError("invalid argument. Providing a complex number is not supported. Consider providing a zero-dimensional ndarray containing the complex number value."):new TypeError(F("invalid argument. Must provide an argument having a supported data type. Value: `%s`.",a))}}U.exports=Er});var Tr=Y();module.exports=Tr;
2
- /**
3
- * @license Apache-2.0
4
- *
5
- * Copyright (c) 2021 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
- */
1
+ "use strict";var O=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var D=O(function(tr,F){
2
+ var H=require('@stdlib/assert-is-plain-object/dist'),V=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/ndarray-base-assert-is-order/dist'),K=require('@stdlib/array-base-assert-contains/dist'),M=require('@stdlib/ndarray-orders/dist'),j=require('@stdlib/array-base-join/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist');function N(a,r,t){return H(t)?V(t,"dtype")&&(a.dtype=t.dtype,!K(r,String(a.dtype)))?new TypeError(h('0gz4S',"dtype",j(r,'", "'),a.dtype)):V(t,"order")&&(a.order=t.order,!J(a.order))?new TypeError(h('0gz4S',"order",j(M(),'", "'),a.order)):null:new TypeError(h('0gz2V',t));}F.exports=N
3
+ });var z=O(function(nr,R){
4
+ var Q=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),q=require('@stdlib/assert-is-ndarray-like/dist'),U=require('@stdlib/assert-is-function/dist'),W=require('@stdlib/assert-is-object/dist'),c=require('@stdlib/assert-is-collection/dist'),X=require('@stdlib/ndarray-base-assert-is-output-data-type-policy/dist'),Y=require('@stdlib/ndarray-base-assert-is-input-casting-policy/dist'),S=require('@stdlib/ndarray-base-assert-is-data-type/dist'),P=require('@stdlib/array-base-assert-contains/dist'),Z=require('@stdlib/ndarray-base-unary-output-dtype/dist'),C=require('@stdlib/ndarray-base-unary-input-casting-dtype/dist'),I=require('@stdlib/ndarray-base-assign/dist'),k=require('@stdlib/ndarray-base-empty/dist'),_=require('@stdlib/ndarray-maybe-broadcast-array/dist'),b=require('@stdlib/ndarray-shape/dist'),A=require('@stdlib/ndarray-order/dist'),T=require('@stdlib/ndarray-dtype/dist'),$=require('@stdlib/ndarray-empty/dist'),B=require('@stdlib/array-base-every-by/dist'),L=require('@stdlib/array-base-join/dist'),n=require('@stdlib/error-tools-fmtprodmsg/dist'),x=D();function rr(a,r,t,o){var m,d,l;if(!U(a))throw new TypeError(n('0gz3c',a));if(!c(r))throw new TypeError(n('0gz2y',r));for(l=0;l<r.length;l++)if(d=r[l],!c(d)||d.length<1||!B(d,S))throw new TypeError(n('0gzHw',r));if(!c(t)||t.length<1||!B(t,S))throw new TypeError(n('0gzHX',t));if(!W(o))throw new TypeError(n('0gz43',o));if(!X(o.output))throw new TypeError(n('0gzI6',o.output));if(!Y(o.casting))throw new TypeError(n('0gzI7',o.casting));return m={output:o.output,casting:o.casting},Q(E,"assign",G),E;function E(e){var u,i,v,s,g,y,p,f,w;if(!q(e))throw new TypeError(n('0gz4f',e));if(g=T(e),!P(r[0],g))throw new TypeError(n('0gzHZ',L(r[0],'", "'),g));if(u={},arguments.length>1&&(i=x(u,t,arguments[1]),i))throw i;return v=b(e),s=A(e),y=u.dtype||Z(g,m.output),w=$(v,{dtype:y,order:u.order||s}),f=C(g,y,m.casting),g!==f&&(p=k(f,v,s),I([e,p]),e=p),a(e,w),w}function G(e,u){var i,v,s;if(!q(e))throw new TypeError(n('0gz4f',e));if(!q(u))throw new TypeError(n('0gzF1',u));if(i=T(e),!P(r[0],i))throw new TypeError(n('0gzHZ',L(r[0],'", "'),i));return s=C(i,T(u),m.casting),i!==s&&(v=k(s,b(e),A(e)),I([e,v]),e=v),a(_(e,b(u)),u),u}}R.exports=rr
5
+ });var er=z();module.exports=er;
6
+ /** @license Apache-2.0 */
19
7
  //# sourceMappingURL=index.js.map