@stdlib/math-tools-unary 0.0.6 → 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/CITATION.cff +30 -0
- package/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +22 -10
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1 -1
- package/lib/defaults.json +1 -1
- package/lib/main.js +8 -10
- package/lib/ndarray.js +1 -22
- package/lib/policies.json +3 -1
- package/lib/resolve_output_dtype.js +29 -2
- package/lib/validate.js +4 -3
- package/lib/validate_options.js +3 -2
- package/lib/validate_table.js +3 -2
- package/package.json +39 -39
- package/docs/repl.txt +0 -119
- package/docs/types/test.ts +0 -288
package/CITATION.cff
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
title: stdlib
|
|
3
|
+
message: >-
|
|
4
|
+
If you use this software, please cite it using the
|
|
5
|
+
metadata from this file.
|
|
6
|
+
|
|
7
|
+
type: software
|
|
8
|
+
|
|
9
|
+
authors:
|
|
10
|
+
- name: The Stdlib Authors
|
|
11
|
+
url: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
12
|
+
|
|
13
|
+
repository-code: https://github.com/stdlib-js/stdlib
|
|
14
|
+
url: https://stdlib.io
|
|
15
|
+
|
|
16
|
+
abstract: |
|
|
17
|
+
Standard library for JavaScript and Node.js.
|
|
18
|
+
|
|
19
|
+
keywords:
|
|
20
|
+
- JavaScript
|
|
21
|
+
- Node.js
|
|
22
|
+
- TypeScript
|
|
23
|
+
- standard library
|
|
24
|
+
- scientific computing
|
|
25
|
+
- numerical computing
|
|
26
|
+
- statistical computing
|
|
27
|
+
|
|
28
|
+
license: Apache-2.0 AND BSL-1.0
|
|
29
|
+
|
|
30
|
+
date-released: 2016
|
package/LICENSE
CHANGED
|
@@ -175,307 +175,3 @@
|
|
|
175
175
|
of your accepting any such warranty or additional liability.
|
|
176
176
|
|
|
177
177
|
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
Boost Software License - Version 1.0 - August 17th, 2003
|
|
182
|
-
|
|
183
|
-
Permission is hereby granted, free of charge, to any person or organization
|
|
184
|
-
obtaining a copy of the software and accompanying documentation covered by this
|
|
185
|
-
license (the "Software") to use, reproduce, display, distribute, execute, and
|
|
186
|
-
transmit the Software, and to prepare derivative works of the Software, and to
|
|
187
|
-
permit third-parties to whom the Software is furnished to do so, all subject to
|
|
188
|
-
the following:
|
|
189
|
-
|
|
190
|
-
The copyright notices in the Software and this entire statement, including the
|
|
191
|
-
above license grant, this restriction and the following disclaimer, must be
|
|
192
|
-
included in all copies of the Software, in whole or in part, and all derivative
|
|
193
|
-
works of the Software, unless such copies or derivative works are solely in the
|
|
194
|
-
form of machine-executable object code generated by a source language processor.
|
|
195
|
-
|
|
196
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
197
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
198
|
-
FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
199
|
-
COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES
|
|
200
|
-
OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
|
201
|
-
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
DEPENDENCIES
|
|
207
|
-
|
|
208
|
-
The library links against the following external libraries, which have their own
|
|
209
|
-
licenses:
|
|
210
|
-
|
|
211
|
-
* OpenBLAS <https://raw.githubusercontent.com/xianyi/OpenBLAS/
|
|
212
|
-
def146efed8d5908ea04e22668feeab7099599a0/LICENSE>
|
|
213
|
-
|
|
214
|
-
Copyright (c) 2011-2014, The OpenBLAS Project
|
|
215
|
-
All rights reserved.
|
|
216
|
-
|
|
217
|
-
Redistribution and use in source and binary forms, with or without
|
|
218
|
-
modification, are permitted provided that the following conditions are
|
|
219
|
-
met:
|
|
220
|
-
|
|
221
|
-
1. Redistributions of source code must retain the above copyright
|
|
222
|
-
notice, this list of conditions and the following disclaimer.
|
|
223
|
-
|
|
224
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
225
|
-
notice, this list of conditions and the following disclaimer in
|
|
226
|
-
the documentation and/or other materials provided with the
|
|
227
|
-
distribution.
|
|
228
|
-
|
|
229
|
-
3. Neither the name of the OpenBLAS project nor the names of
|
|
230
|
-
its contributors may be used to endorse or promote products
|
|
231
|
-
derived from this software without specific prior written
|
|
232
|
-
permission.
|
|
233
|
-
|
|
234
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
235
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
236
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
237
|
-
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
238
|
-
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
239
|
-
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
240
|
-
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
241
|
-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
242
|
-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
243
|
-
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
* Electron <https://raw.githubusercontent.com/electron/electron/
|
|
247
|
-
c4cfb3e7110266b9d7ad80e1ae097c4db564501c/LICENSE>
|
|
248
|
-
|
|
249
|
-
Copyright (c) 2013-2017 GitHub Inc.
|
|
250
|
-
|
|
251
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
252
|
-
a copy of this software and associated documentation files (the
|
|
253
|
-
"Software"), to deal in the Software without restriction, including
|
|
254
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
255
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
256
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
257
|
-
the following conditions:
|
|
258
|
-
|
|
259
|
-
The above copyright notice and this permission notice shall be
|
|
260
|
-
included in all copies or substantial portions of the Software.
|
|
261
|
-
|
|
262
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
263
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
264
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
265
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
266
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
267
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
268
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
* Boost <http://www.boost.org/LICENSE_1_0.txt>
|
|
272
|
-
|
|
273
|
-
Boost Software License - Version 1.0 - August 17th, 2003
|
|
274
|
-
|
|
275
|
-
Permission is hereby granted, free of charge, to any person or organization
|
|
276
|
-
obtaining a copy of the software and accompanying documentation covered by
|
|
277
|
-
this license (the "Software") to use, reproduce, display, distribute,
|
|
278
|
-
execute, and transmit the Software, and to prepare derivative works of the
|
|
279
|
-
Software, and to permit third-parties to whom the Software is furnished to
|
|
280
|
-
do so, all subject to the following:
|
|
281
|
-
|
|
282
|
-
The copyright notices in the Software and this entire statement, including
|
|
283
|
-
the above license grant, this restriction and the following disclaimer,
|
|
284
|
-
must be included in all copies of the Software, in whole or in part, and
|
|
285
|
-
all derivative works of the Software, unless such copies or derivative
|
|
286
|
-
works are solely in the form of machine-executable object code generated by
|
|
287
|
-
a source language processor.
|
|
288
|
-
|
|
289
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
290
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
291
|
-
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
292
|
-
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
293
|
-
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
294
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
295
|
-
DEALINGS IN THE SOFTWARE.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
* Cephes <http://www.netlib.org/cephes/readme>
|
|
299
|
-
|
|
300
|
-
Copyright (c) 1984-2000 Stephen L. Moshier
|
|
301
|
-
|
|
302
|
-
Some software in this archive may be from the book _Methods and Programs for
|
|
303
|
-
Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989)
|
|
304
|
-
or from the Cephes Mathematical Library, a commercial product. In either event,
|
|
305
|
-
it is copyrighted by the author. What you see here may be used freely but it
|
|
306
|
-
comes with no support or guarantee.
|
|
307
|
-
|
|
308
|
-
Stephen L. Moshier
|
|
309
|
-
moshier@na-net.ornl.gov
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
ATTRIBUTION
|
|
314
|
-
|
|
315
|
-
The library contains implementations from the following external libraries,
|
|
316
|
-
which have their own licenses:
|
|
317
|
-
|
|
318
|
-
* FreeBSD <https://svnweb.freebsd.org/>
|
|
319
|
-
|
|
320
|
-
Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved.
|
|
321
|
-
|
|
322
|
-
Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
323
|
-
Permission to use, copy, modify, and distribute this
|
|
324
|
-
software is freely granted, provided that this notice
|
|
325
|
-
is preserved.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
* FDLIBM <http://www.netlib.org/fdlibm/>
|
|
329
|
-
|
|
330
|
-
Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
|
|
331
|
-
|
|
332
|
-
Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
333
|
-
Permission to use, copy, modify, and distribute this
|
|
334
|
-
software is freely granted, provided that this notice
|
|
335
|
-
is preserved.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
* Go <https://raw.githubusercontent.com/golang/go/master/LICENSE>
|
|
339
|
-
|
|
340
|
-
Copyright (c) 2009 The Go Authors. All rights reserved.
|
|
341
|
-
|
|
342
|
-
Redistribution and use in source and binary forms, with or without
|
|
343
|
-
modification, are permitted provided that the following conditions are
|
|
344
|
-
met:
|
|
345
|
-
|
|
346
|
-
* Redistributions of source code must retain the above copyright
|
|
347
|
-
notice, this list of conditions and the following disclaimer.
|
|
348
|
-
* Redistributions in binary form must reproduce the above
|
|
349
|
-
copyright notice, this list of conditions and the following disclaimer
|
|
350
|
-
in the documentation and/or other materials provided with the
|
|
351
|
-
distribution.
|
|
352
|
-
* Neither the name of Google Inc. nor the names of its
|
|
353
|
-
contributors may be used to endorse or promote products derived from
|
|
354
|
-
this software without specific prior written permission.
|
|
355
|
-
|
|
356
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
357
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
358
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
359
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
360
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
361
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
362
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
363
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
364
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
365
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
366
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* SLATEC Common Mathematical Library <http://www.netlib.no/netlib/slatec/>
|
|
370
|
-
|
|
371
|
-
Public domain.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
* ESLint <https://raw.githubusercontent.com/eslint/eslint/master/LICENSE>
|
|
375
|
-
|
|
376
|
-
Copyright JS Foundation and other contributors, https://js.foundation
|
|
377
|
-
|
|
378
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
379
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
380
|
-
in the Software without restriction, including without limitation the rights
|
|
381
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
382
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
383
|
-
furnished to do so, subject to the following conditions:
|
|
384
|
-
|
|
385
|
-
The above copyright notice and this permission notice shall be included in
|
|
386
|
-
all copies or substantial portions of the Software.
|
|
387
|
-
|
|
388
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
389
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
390
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
391
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
392
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
393
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
394
|
-
THE SOFTWARE.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
* StatsFuns.jl <https://raw.githubusercontent.com/JuliaStats/StatsFuns.jl/
|
|
398
|
-
e66dd973650c375bc1739c820e5b96bb5bd000a8/LICENSE.md>
|
|
399
|
-
|
|
400
|
-
Copyright (c) 2015: Dahua Lin.
|
|
401
|
-
|
|
402
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
403
|
-
a copy of this software and associated documentation files (the
|
|
404
|
-
"Software"), to deal in the Software without restriction, including
|
|
405
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
406
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
407
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
408
|
-
the following conditions:
|
|
409
|
-
|
|
410
|
-
The above copyright notice and this permission notice shall be
|
|
411
|
-
included in all copies or substantial portions of the Software.
|
|
412
|
-
|
|
413
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
414
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
415
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
416
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
417
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
418
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
419
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
* SpecialFunctions.jl <https://raw.githubusercontent.com/JuliaMath/
|
|
423
|
-
SpecialFunctions.jl/02a173fbe24a61c4b392aec17a9764ac5727feb1/LICENSE>
|
|
424
|
-
|
|
425
|
-
The MIT License (MIT)
|
|
426
|
-
|
|
427
|
-
Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others:
|
|
428
|
-
|
|
429
|
-
https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors
|
|
430
|
-
|
|
431
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
432
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
433
|
-
in the Software without restriction, including without limitation the rights
|
|
434
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
435
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
436
|
-
furnished to do so, subject to the following conditions:
|
|
437
|
-
|
|
438
|
-
The above copyright notice and this permission notice shall be included in all
|
|
439
|
-
copies or substantial portions of the Software.
|
|
440
|
-
|
|
441
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
442
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
443
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
444
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
445
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
446
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
447
|
-
SOFTWARE.
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
* MT19937 <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/
|
|
451
|
-
mt19937ar.c>
|
|
452
|
-
|
|
453
|
-
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
|
454
|
-
All rights reserved.
|
|
455
|
-
|
|
456
|
-
Redistribution and use in source and binary forms, with or without
|
|
457
|
-
modification, are permitted provided that the following conditions
|
|
458
|
-
are met:
|
|
459
|
-
|
|
460
|
-
1. Redistributions of source code must retain the above copyright
|
|
461
|
-
notice, this list of conditions and the following disclaimer.
|
|
462
|
-
|
|
463
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
464
|
-
notice, this list of conditions and the following disclaimer in the
|
|
465
|
-
documentation and/or other materials provided with the distribution.
|
|
466
|
-
|
|
467
|
-
3. The names of its contributors may not be used to endorse or promote
|
|
468
|
-
products derived from this software without specific prior written
|
|
469
|
-
permission.
|
|
470
|
-
|
|
471
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
472
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
473
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
474
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
475
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
476
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
477
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
478
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
479
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
480
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
481
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2023 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -18,6 +18,17 @@ limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
-->
|
|
20
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
|
+
|
|
21
32
|
# Unary
|
|
22
33
|
|
|
23
34
|
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
@@ -358,7 +369,7 @@ See [LICENSE][stdlib-license].
|
|
|
358
369
|
|
|
359
370
|
## Copyright
|
|
360
371
|
|
|
361
|
-
Copyright © 2016-
|
|
372
|
+
Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
362
373
|
|
|
363
374
|
</section>
|
|
364
375
|
|
|
@@ -371,8 +382,8 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
371
382
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-tools-unary.svg
|
|
372
383
|
[npm-url]: https://npmjs.org/package/@stdlib/math-tools-unary
|
|
373
384
|
|
|
374
|
-
[test-image]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml/badge.svg
|
|
375
|
-
[test-url]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml
|
|
385
|
+
[test-image]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
386
|
+
[test-url]: https://github.com/stdlib-js/math-tools-unary/actions/workflows/test.yml?query=branch:v0.1.0
|
|
376
387
|
|
|
377
388
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-tools-unary/main.svg
|
|
378
389
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-tools-unary?branch=main
|
|
@@ -384,19 +395,20 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
384
395
|
|
|
385
396
|
-->
|
|
386
397
|
|
|
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
|
|
400
|
+
|
|
401
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
402
|
+
|
|
403
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
404
|
+
|
|
387
405
|
[umd]: https://github.com/umdjs/umd
|
|
388
406
|
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
389
407
|
|
|
390
408
|
[deno-url]: https://github.com/stdlib-js/math-tools-unary/tree/deno
|
|
391
409
|
[umd-url]: https://github.com/stdlib-js/math-tools-unary/tree/umd
|
|
392
410
|
[esm-url]: https://github.com/stdlib-js/math-tools-unary/tree/esm
|
|
393
|
-
|
|
394
|
-
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
395
|
-
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
396
|
-
|
|
397
|
-
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
398
|
-
|
|
399
|
-
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
411
|
+
[branches-url]: https://github.com/stdlib-js/math-tools-unary/blob/main/branches.md
|
|
400
412
|
|
|
401
413
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-tools-unary/main/LICENSE
|
|
402
414
|
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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){
|
|
2
|
+
var h=require('@stdlib/ndarray-ctor/dist'),q=require('@stdlib/ndarray-base-buffer/dist'),B=require('@stdlib/ndarray-base-shape2strides/dist'),G=require('@stdlib/ndarray-base-numel/dist'),H=require('@stdlib/array-base-copy-indexed/dist');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
|
|
3
|
+
});var T=v(function(jr,E){
|
|
4
|
+
var Q=require('@stdlib/error-tools-fmtprodmsg/dist');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('0gz4W',e))}}E.exports=W
|
|
5
|
+
});var O=v(function(_r,X){X.exports={output_dtype_policy:"floating-point"}});var _=v(function(kr,j){
|
|
6
|
+
var Z=require('@stdlib/assert-is-plain-object/dist'),$=require('@stdlib/assert-has-own-property/dist'),x=require('@stdlib/assert-is-function/dist'),rr=require('@stdlib/assert-is-null/dist'),er=require('@stdlib/utils-keys/dist'),P=require('@stdlib/error-tools-fmtprodmsg/dist');function ar(r,e){var u,n,t,i;if(!Z(e))return new TypeError(P('0gz4Z',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('0gz4a',t,n));r[t]=n}return null}j.exports=ar
|
|
7
|
+
});var k=v(function(Rr,ir){ir.exports=["same","floating-point","real floating-point","complex floating-point"]});var z=v(function(Vr,V){
|
|
8
|
+
var nr=require('@stdlib/assert-is-plain-object/dist'),tr=require('@stdlib/assert-has-own-property/dist'),ur=require('@stdlib/assert-contains/dist'),R=require('@stdlib/error-tools-fmtprodmsg/dist'),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('0gz4Y',"output_dtype_policy",r.policy)):null:new TypeError(R('0gz2V',e));}V.exports=lr
|
|
9
|
+
});var L=v(function(zr,S){
|
|
10
|
+
var sr=require('@stdlib/assert-is-plain-object/dist'),C=require('@stdlib/assert-has-own-property/dist'),I=require('@stdlib/assert-contains/dist'),pr=require('@stdlib/ndarray-orders/dist'),vr=require('@stdlib/ndarray-dtypes/dist'),c=require('@stdlib/error-tools-fmtprodmsg/dist'),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('0gz4X',"dtype",r.dtype)):C(e,"order")&&(r.order=e.order,!I(dr,r.order))?new TypeError(c('0gz4X',"order",r.order)):null:new TypeError(c('0gz2V',e));}S.exports=cr
|
|
11
|
+
});var Y=v(function(Cr,U){
|
|
12
|
+
var mr=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),D=require('@stdlib/assert-is-number/dist').isPrimitive,M=require('@stdlib/assert-is-complex-like/dist'),m=require('@stdlib/assert-is-ndarray-like/dist'),g=require('@stdlib/assert-is-collection/dist'),y=require('@stdlib/ndarray-base-buffer-dtype/dist'),gr=require('@stdlib/ndarray-base-buffer/dist'),N=require('@stdlib/ndarray-base-broadcast-array/dist'),F=require('@stdlib/error-tools-fmtprodmsg/dist'),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(format('0gz0O'))}if(M(a)){if(i.complex)return i.complex(a);throw new TypeError(format('0gz0P'))}if(l={},arguments.length>1&&(p=br(l,arguments[1]),p))throw p;if(m(a)){if(i.ndarray===null)throw new TypeError(format('0gz0Q'));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(format('0gz0R'));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('0gz4V',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(format('0gz0S'))}if(g(a)){if(g(o)){if(o.length!==a.length)throw new RangeError(format('0gz0T'));return i.array(a.length,y(a)||"generic",a,1,y(o)||"generic",o,1),o}throw new TypeError(format('0gz0U'))}throw D(a)?new TypeError(format('0gz0V')):M(a)?new TypeError(format('0gz0W')):new TypeError(F('0gz4V',a))}}U.exports=Er
|
|
13
|
+
});var Tr=Y();module.exports=Tr;
|
|
14
|
+
/** @license Apache-2.0 */
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/ndarray.js", "../lib/resolve_output_dtype.js", "../lib/defaults.json", "../lib/validate_table.js", "../lib/policies.json", "../lib/validate_options.js", "../lib/validate.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar copy = require( '@stdlib/array-base-copy-indexed' );\n\n\n// MAIN //\n\n/**\n* Applies a function to an ndarray.\n*\n* @private\n* @param {Function} fcn - function to apply\n* @param {ndarray} x - input array\n* @param {string} ydtype - output array data type\n* @param {string} yorder - output array order\n* @returns {ndarray} output array\n*/\nfunction ndarrayfcn( fcn, x, ydtype, yorder ) {\n\tvar shape;\n\tvar buf;\n\tvar y;\n\n\t// Check if we were provided a zero-dimensional array...\n\tshape = copy( x.shape ); // Note: we need to copy the shape to avoid a shared shape object between `x` and `y` which could lead to unintended mutations (e.g., if either `x` or `y` is reshaped)\n\tif ( shape.length === 0 ) {\n\t\tbuf = buffer( ydtype, 1 );\n\t\ty = ndarray( ydtype, buf, [], [ 0 ], 0, yorder );\n\t} else {\n\t\tbuf = buffer( ydtype, x.length || numel( shape ) ); // WARNING: `x.length` is a property found on ndarray instances, but not strictly necessary to describe an ndarray; accordingly, used here to avoid unnecessary computation, but a potential source of bugs if provided an ndarray-like object having a `length` property which is not equal to the product of the dimensions.\n\t\ty = ndarray( ydtype, buf, shape, shape2strides( shape, yorder ), 0, yorder ); // eslint-disable-line max-len\n\t}\n\tfcn( x, y );\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ndarrayfcn;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Resolves an output array data type.\n*\n* @private\n* @param {string} xdtype - input array data type\n* @param {string} policy - policy determining an output array data type\n* @throws {Error} unsupported policy\n* @returns {string} output array data type\n*/\nfunction resolve( xdtype, policy ) {\n\tswitch ( policy ) {\n\tcase 'same':\n\t\treturn xdtype;\n\tcase 'floating-point':\n\t\t// TODO: we may want to delegate checking for a floating-point dtype to a utility function/package (e.g., isFloatDtype), in order to centralize logic for testing whether a dtype is \"floating-point\". Otherwise, this will be yet another place to update logic should we ever add, e.g., a `float128` or `float16` dtype.\n\t\tif (\n\t\t\txdtype === 'float64' ||\n\t\t\txdtype === 'float32' ||\n\t\t\txdtype === 'generic' ||\n\t\t\txdtype === 'complex128' ||\n\t\t\txdtype === 'complex64'\n\t\t) {\n\t\t\treturn xdtype;\n\t\t}\n\t\treturn 'float64'; // TODO: constants/math/default-real-floating-point-dtype?\n\tcase 'real floating-point':\n\t\tif (\n\t\t\txdtype === 'float64' ||\n\t\t\txdtype === 'float32' ||\n\t\t\txdtype === 'generic'\n\t\t) {\n\t\t\treturn xdtype;\n\t\t}\n\t\treturn 'float64';\n\tcase 'complex floating-point':\n\t\tif (\n\t\t\txdtype === 'complex128' ||\n\t\t\txdtype === 'complex64'\n\t\t) {\n\t\t\treturn xdtype;\n\t\t}\n\t\treturn 'complex128'; // TODO: constants/math/default-complex-floating-point-dtype?\n\tdefault:\n\t\tthrow new Error( format( 'invalid option. Unsupported policy for determining an output array data type. Option: `%s`.', policy ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = resolve;\n", "{\n\t\"output_dtype_policy\": \"floating-point\"\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isNull = require( '@stdlib/assert-is-null' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates a resolution table object.\n*\n* @private\n* @param {Object} out - destination object\n* @param {Object} table - resolution table object\n* @param {(Function|null)} [table.number] - function to invoke upon receiving a number\n* @param {(Function|null)} [table.complex] - function to invoke upon receiving a complex number\n* @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object\n* @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var out = {};\n* var table = {\n* 'number': null,\n* 'complex': null,\n* 'array': null,\n* 'ndarray': null\n* };\n* var err = validate( out, table );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( out, table ) {\n\tvar fields;\n\tvar tmp;\n\tvar key;\n\tvar i;\n\n\tif ( !isPlainObject( table ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Resolution table must be an object. Value: `%s`.', table ) );\n\t}\n\tfields = objectKeys( out );\n\tfor ( i = 0; i < fields.length; i++ ) {\n\t\tkey = fields[ i ];\n\t\tif ( hasOwnProp( table, key ) ) {\n\t\t\ttmp = table[ key ];\n\t\t\tif ( !isFunction( tmp ) && !isNull( tmp ) ) {\n\t\t\t\treturn new TypeError( format( 'invalid argument. Resolution table `%s` field value must be either a function or null. Value: `%s`.', key, tmp ) );\n\t\t\t}\n\t\t\tout[ key ] = tmp;\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "[\n\t\"same\",\n\t\"floating-point\",\n \"real floating-point\",\n \"complex floating-point\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/assert-contains' );\nvar format = require( '@stdlib/string-format' );\nvar POLICIES = require( './policies.json' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Object} options - options\n* @param {string} [options.output_dtype_policy] - policy for determining the output array data type\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'output_dtype_policy': 'float'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isPlainObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'output_dtype_policy' ) ) {\n\t\topts.policy = options.output_dtype_policy;\n\t\tif ( !contains( POLICIES, opts.policy ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized/supported output array data type policy. Option: `%s`.', 'output_dtype_policy', opts.policy ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/assert-contains' );\nvar orders = require( '@stdlib/ndarray-orders' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar ORDERS = orders();\nvar DTYPES = dtypes();\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Object} options - options\n* @param {string} [options.dtype] - output array data type\n* @param {string} [options.order] - output array order\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'order': 'row-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isPlainObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( DTYPES, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'dtype', opts.dtype ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !contains( ORDERS, opts.order ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar dtype = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayfcn = require( './ndarray.js' );\nvar odtype = require( './resolve_output_dtype.js' );\nvar defaults = require( './defaults.json' );\nvar validateTable = require( './validate_table.js' );\nvar validateOptions = require( './validate_options.js' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function which dispatches to specified functions based on input argument types.\n*\n* @param {Object} table - resolution table object\n* @param {(Function|null)} [table.number] - function to invoke upon receiving a number\n* @param {(Function|null)} [table.complex] - function to invoke upon receiving a complex number\n* @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object\n* @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object\n* @param {Options} [options] - options\n* @param {string} [options.output_dtype_policy='floating-point'] - policy for determining the output array data type\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} first argument must have valid table fields\n* @throws {Error} each table field value must be either a function or `null`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Function} dispatch function\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var strided = require( '@stdlib/math-strided-special-abs' );\n* var dispatcher = require( '@stdlib/ndarray-dispatch' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64',\n* 'float32', 'float32',\n* 'generic', 'generic'\n* ];\n* var data = [\n* base,\n* base,\n* base\n* ];\n* var nd = dispatcher( unary, types, data, 2, 1, 1 );\n*\n* var table = {\n* 'number': base,\n* 'complex': null,\n* 'array': strided,\n* 'ndarray': nd\n* };\n*\n* var abs = dispatch( table, {\n* 'output_dtype_policy': 'same'\n* });\n*\n* var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );\n*\n* var y = abs( x );\n* // returns <Float64Array>[ 1.0, 2.0, 3.0 ]\n*/\nfunction dispatch( table, options ) {\n\tvar OPTS;\n\tvar err;\n\tvar fcn;\n\tvar t;\n\n\tt = {\n\t\t'number': null,\n\t\t'complex': null,\n\t\t'array': null,\n\t\t'ndarray': null\n\t};\n\terr = validateTable( t, table );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\tOPTS = {\n\t\t'policy': defaults.output_dtype_policy\n\t};\n\tif ( arguments.length > 1 ) {\n\t\terr = validateOptions( OPTS, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tfcn = dispatcher;\n\tsetReadOnly( fcn, 'assign', assign );\n\treturn fcn;\n\n\t/**\n\t* Function interface which performs dispatch.\n\t*\n\t* @private\n\t* @param {(ndarray|Collection|number|Complex)} x - input value\n\t* @param {Options} [options] - options\n\t* @param {string} [options.dtype] - output array data type\n\t* @param {string} [options.order] - output array order (row-major or column-major)\n\t* @throws {TypeError} first argument must be a supported data type\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {(ndarray|Collection|number|Complex)} results\n\t*/\n\tfunction dispatcher( x ) {\n\t\tvar xdtype;\n\t\tvar ydtype;\n\t\tvar opts;\n\t\tvar err;\n\t\tvar y;\n\t\tif ( isNumber( x ) ) {\n\t\t\tif ( t.number ) {\n\t\t\t\treturn t.number( x );\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. Providing a number is not supported.' );\n\t\t}\n\t\tif ( isComplexLike( x ) ) {\n\t\t\tif ( t.complex ) {\n\t\t\t\treturn t.complex( x );\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. Providing a complex number is not supported.' );\n\t\t}\n\t\topts = {};\n\t\tif ( arguments.length > 1 ) {\n\t\t\terr = validate( opts, arguments[ 1 ] );\n\t\t\tif ( err ) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\tif ( isndarrayLike( x ) ) {\n\t\t\tif ( t.ndarray === null ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Providing an ndarray is not supported.' );\n\t\t\t}\n\t\t\tydtype = opts.dtype || odtype( x.dtype, OPTS.policy );\n\t\t\treturn ndarrayfcn( t.ndarray, x, ydtype, opts.order || x.order );\n\t\t}\n\t\tif ( isCollection( x ) ) {\n\t\t\tif ( t.array === null ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Providing an array-like object is not supported.' );\n\t\t\t}\n\t\t\txdtype = dtype( x ) || 'generic';\n\t\t\tydtype = opts.dtype || odtype( xdtype, OPTS.policy );\n\t\t\ty = buffer( ydtype, x.length );\n\t\t\tt.array( x.length, xdtype, x, 1, ydtype, y, 1 );\n\t\t\treturn y;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );\n\t}\n\n\t/**\n\t* Function interface which performs dispatch and assigns results to a provided output array.\n\t*\n\t* @private\n\t* @param {(ndarray|Collection)} x - input array\n\t* @param {(ndarray|Collection)} y - output array\n\t* @throws {TypeError} first argument must be a supported data type\n\t* @throws {TypeError} second argument must be a supported data type\n\t* @throws {TypeError} first and second argument must be the same \"kind\" (i.e., either both ndarrays or both collections)\n\t* @throws {RangeError} output array must have sufficient elements\n\t* @throws {Error} unable to broadcast the input array against the output array\n\t* @returns {(ndarray|Collection)} output array\n\t*/\n\tfunction assign( x, y ) {\n\t\tvar xsh;\n\t\tvar ysh;\n\t\tvar i;\n\t\tif ( isndarrayLike( x ) ) {\n\t\t\tif ( isndarrayLike( y ) ) {\n\t\t\t\txsh = x.shape;\n\t\t\t\tysh = y.shape;\n\n\t\t\t\t// Check whether we need to broadcast `x`...\n\t\t\t\tif ( xsh.length === ysh.length ) {\n\t\t\t\t\tfor ( i = 0; i < xsh.length; i++ ) {\n\t\t\t\t\t\t// Check whether dimensions match...\n\t\t\t\t\t\tif ( xsh[ i ] !== ysh[ i ] ) {\n\t\t\t\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that `x` is broadcast compatible with the output array shape...\n\t\t\t\t\t\t\tx = broadcast( x, ysh );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// If we are provided arrays with different ranks (i.e., number of dimensions), assume we need to broadcast, delegating to `broadcast` to ensure that `x` is broadcast compatible with the output array shape...\n\t\t\t\t\tx = broadcast( x, ysh );\n\t\t\t\t}\n\t\t\t\tt.ndarray( x, y );\n\t\t\t\treturn y;\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. If the first argument is an ndarray, the second argument must be an ndarray.' );\n\t\t}\n\t\tif ( isCollection( x ) ) {\n\t\t\tif ( isCollection( y ) ) {\n\t\t\t\tif ( y.length !== x.length ) {\n\t\t\t\t\tthrow new RangeError( 'invalid argument. Output array must have the same number of elements (i.e., length) as the input array.' );\n\t\t\t\t}\n\t\t\t\tt.array( x.length, dtype( x ) || 'generic', x, 1, dtype( y ) || 'generic', y, 1 );\n\t\t\t\treturn y;\n\t\t\t}\n\t\t\tthrow new TypeError( 'invalid argument. If the first argument is an array-like object, the second argument must be an array-like object.' );\n\t\t}\n\t\tif ( isNumber( x ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Providing a number is not supported. Consider providing a zero-dimensional ndarray containing the numeric value.' );\n\t\t}\n\t\tif ( isComplexLike( x ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Providing a complex number is not supported. Consider providing a zero-dimensional ndarray containing the complex number value.' );\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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* Return a function which dispatches to specified functions based on input argument types.\n*\n* @module @stdlib/math-tools-unary\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var strided = require( '@stdlib/math-strided-special-abs' );\n* var dispatcher = require( '@stdlib/ndarray-dispatch' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/math-tools-unary' );\n*\n* var types = [\n* 'float64', 'float64',\n* 'float32', 'float32',\n* 'generic', 'generic'\n* ];\n* var data = [\n* base,\n* base,\n* base\n* ];\n* var nd = dispatcher( unary, types, data, 2, 1, 1 );\n*\n* var table = {\n* 'number': base,\n* 'complex': null,\n* 'array': strided,\n* 'ndarray': nd\n* };\n*\n* var abs = dispatch( table );\n*\n* var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );\n* var y = abs( x );\n* // returns <Float64Array>[ 1.0, 2.0, 3.0 ]\n*/\n\n// MAIN //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "ndarray", "buffer", "shape2strides", "numel", "copy", "ndarrayfcn", "fcn", "x", "ydtype", "yorder", "shape", "buf", "y", "require_resolve_output_dtype", "__commonJSMin", "exports", "module", "format", "resolve", "xdtype", "policy", "require_defaults", "__commonJSMin", "exports", "module", "require_validate_table", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "isFunction", "isNull", "objectKeys", "format", "validate", "out", "table", "fields", "tmp", "key", "require_policies", "__commonJSMin", "exports", "module", "require_validate_options", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "contains", "format", "POLICIES", "validate", "opts", "options", "require_validate", "__commonJSMin", "exports", "module", "isPlainObject", "hasOwnProp", "contains", "orders", "dtypes", "format", "ORDERS", "DTYPES", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNumber", "isComplexLike", "isndarrayLike", "isCollection", "dtype", "buffer", "broadcast", "format", "ndarrayfcn", "odtype", "defaults", "validateTable", "validateOptions", "validate", "dispatch", "table", "options", "OPTS", "err", "fcn", "t", "dispatcher", "assign", "x", "xdtype", "ydtype", "opts", "y", "xsh", "ysh", "i", "main"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
package/lib/defaults.json
CHANGED
package/lib/main.js
CHANGED
|
@@ -28,6 +28,7 @@ var isCollection = require( '@stdlib/assert-is-collection' );
|
|
|
28
28
|
var dtype = require( '@stdlib/ndarray-base-buffer-dtype' );
|
|
29
29
|
var buffer = require( '@stdlib/ndarray-base-buffer' );
|
|
30
30
|
var broadcast = require( '@stdlib/ndarray-base-broadcast-array' );
|
|
31
|
+
var format = require( '@stdlib/string-format' );
|
|
31
32
|
var ndarrayfcn = require( './ndarray.js' );
|
|
32
33
|
var odtype = require( './resolve_output_dtype.js' );
|
|
33
34
|
var defaults = require( './defaults.json' );
|
|
@@ -47,7 +48,7 @@ var validate = require( './validate.js' );
|
|
|
47
48
|
* @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object
|
|
48
49
|
* @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object
|
|
49
50
|
* @param {Options} [options] - options
|
|
50
|
-
* @param {string} [options.output_dtype_policy='
|
|
51
|
+
* @param {string} [options.output_dtype_policy='floating-point'] - policy for determining the output array data type
|
|
51
52
|
* @throws {TypeError} first argument must be an object
|
|
52
53
|
* @throws {TypeError} first argument must have valid table fields
|
|
53
54
|
* @throws {Error} each table field value must be either a function or `null`
|
|
@@ -132,7 +133,7 @@ function dispatch( table, options ) {
|
|
|
132
133
|
* @throws {TypeError} must provide valid options
|
|
133
134
|
* @returns {(ndarray|Collection|number|Complex)} results
|
|
134
135
|
*/
|
|
135
|
-
function dispatcher( x
|
|
136
|
+
function dispatcher( x ) {
|
|
136
137
|
var xdtype;
|
|
137
138
|
var ydtype;
|
|
138
139
|
var opts;
|
|
@@ -152,7 +153,7 @@ function dispatch( table, options ) {
|
|
|
152
153
|
}
|
|
153
154
|
opts = {};
|
|
154
155
|
if ( arguments.length > 1 ) {
|
|
155
|
-
err = validate( opts,
|
|
156
|
+
err = validate( opts, arguments[ 1 ] );
|
|
156
157
|
if ( err ) {
|
|
157
158
|
throw err;
|
|
158
159
|
}
|
|
@@ -171,12 +172,10 @@ function dispatch( table, options ) {
|
|
|
171
172
|
xdtype = dtype( x ) || 'generic';
|
|
172
173
|
ydtype = opts.dtype || odtype( xdtype, OPTS.policy );
|
|
173
174
|
y = buffer( ydtype, x.length );
|
|
174
|
-
|
|
175
|
-
// FIXME: need to supply dtype enum argument for each array argument...
|
|
176
|
-
t.array( x.length, x, 1, y, 1 );
|
|
175
|
+
t.array( x.length, xdtype, x, 1, ydtype, y, 1 );
|
|
177
176
|
return y;
|
|
178
177
|
}
|
|
179
|
-
throw new TypeError( 'invalid argument. Must provide an argument having a supported data type. Value:
|
|
178
|
+
throw new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );
|
|
180
179
|
}
|
|
181
180
|
|
|
182
181
|
/**
|
|
@@ -225,8 +224,7 @@ function dispatch( table, options ) {
|
|
|
225
224
|
if ( y.length !== x.length ) {
|
|
226
225
|
throw new RangeError( 'invalid argument. Output array must have the same number of elements (i.e., length) as the input array.' );
|
|
227
226
|
}
|
|
228
|
-
|
|
229
|
-
t.array( x.length, x, 1, y, 1 );
|
|
227
|
+
t.array( x.length, dtype( x ) || 'generic', x, 1, dtype( y ) || 'generic', y, 1 );
|
|
230
228
|
return y;
|
|
231
229
|
}
|
|
232
230
|
throw new TypeError( 'invalid argument. If the first argument is an array-like object, the second argument must be an array-like object.' );
|
|
@@ -237,7 +235,7 @@ function dispatch( table, options ) {
|
|
|
237
235
|
if ( isComplexLike( x ) ) {
|
|
238
236
|
throw new TypeError( 'invalid argument. Providing a complex number is not supported. Consider providing a zero-dimensional ndarray containing the complex number value.' );
|
|
239
237
|
}
|
|
240
|
-
throw new TypeError( 'invalid argument. Must provide an argument having a supported data type. Value:
|
|
238
|
+
throw new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );
|
|
241
239
|
}
|
|
242
240
|
}
|
|
243
241
|
|
package/lib/ndarray.js
CHANGED
|
@@ -24,27 +24,7 @@ var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
|
24
24
|
var buffer = require( '@stdlib/ndarray-base-buffer' );
|
|
25
25
|
var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
26
26
|
var numel = require( '@stdlib/ndarray-base-numel' );
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// FUNCTIONS //
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Copies an array-like object to a generic array.
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @param {ArrayLikeObject} x - input array
|
|
36
|
-
* @returns {Array} output array
|
|
37
|
-
*/
|
|
38
|
-
function copy( x ) {
|
|
39
|
-
var out;
|
|
40
|
-
var i;
|
|
41
|
-
|
|
42
|
-
out = [];
|
|
43
|
-
for ( i = 0; i < x.length; i++ ) {
|
|
44
|
-
out.push( x[ i ] );
|
|
45
|
-
}
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
27
|
+
var copy = require( '@stdlib/array-base-copy-indexed' );
|
|
48
28
|
|
|
49
29
|
|
|
50
30
|
// MAIN //
|
|
@@ -57,7 +37,6 @@ function copy( x ) {
|
|
|
57
37
|
* @param {ndarray} x - input array
|
|
58
38
|
* @param {string} ydtype - output array data type
|
|
59
39
|
* @param {string} yorder - output array order
|
|
60
|
-
* @throws {TypeError} must provide an input array argument with a supported data type
|
|
61
40
|
* @returns {ndarray} output array
|
|
62
41
|
*/
|
|
63
42
|
function ndarrayfcn( fcn, x, ydtype, yorder ) {
|
package/lib/policies.json
CHANGED
|
@@ -18,6 +18,13 @@
|
|
|
18
18
|
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var format = require( '@stdlib/string-format' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
21
28
|
/**
|
|
22
29
|
* Resolves an output array data type.
|
|
23
30
|
*
|
|
@@ -31,7 +38,19 @@ function resolve( xdtype, policy ) {
|
|
|
31
38
|
switch ( policy ) {
|
|
32
39
|
case 'same':
|
|
33
40
|
return xdtype;
|
|
34
|
-
case '
|
|
41
|
+
case 'floating-point':
|
|
42
|
+
// TODO: we may want to delegate checking for a floating-point dtype to a utility function/package (e.g., isFloatDtype), in order to centralize logic for testing whether a dtype is "floating-point". Otherwise, this will be yet another place to update logic should we ever add, e.g., a `float128` or `float16` dtype.
|
|
43
|
+
if (
|
|
44
|
+
xdtype === 'float64' ||
|
|
45
|
+
xdtype === 'float32' ||
|
|
46
|
+
xdtype === 'generic' ||
|
|
47
|
+
xdtype === 'complex128' ||
|
|
48
|
+
xdtype === 'complex64'
|
|
49
|
+
) {
|
|
50
|
+
return xdtype;
|
|
51
|
+
}
|
|
52
|
+
return 'float64'; // TODO: constants/math/default-real-floating-point-dtype?
|
|
53
|
+
case 'real floating-point':
|
|
35
54
|
if (
|
|
36
55
|
xdtype === 'float64' ||
|
|
37
56
|
xdtype === 'float32' ||
|
|
@@ -40,8 +59,16 @@ function resolve( xdtype, policy ) {
|
|
|
40
59
|
return xdtype;
|
|
41
60
|
}
|
|
42
61
|
return 'float64';
|
|
62
|
+
case 'complex floating-point':
|
|
63
|
+
if (
|
|
64
|
+
xdtype === 'complex128' ||
|
|
65
|
+
xdtype === 'complex64'
|
|
66
|
+
) {
|
|
67
|
+
return xdtype;
|
|
68
|
+
}
|
|
69
|
+
return 'complex128'; // TODO: constants/math/default-complex-floating-point-dtype?
|
|
43
70
|
default:
|
|
44
|
-
throw new Error( 'invalid option. Unsupported policy for determining an output array data type. Option:
|
|
71
|
+
throw new Error( format( 'invalid option. Unsupported policy for determining an output array data type. Option: `%s`.', policy ) );
|
|
45
72
|
}
|
|
46
73
|
}
|
|
47
74
|
|
package/lib/validate.js
CHANGED
|
@@ -25,6 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
|
25
25
|
var contains = require( '@stdlib/assert-contains' );
|
|
26
26
|
var orders = require( '@stdlib/ndarray-orders' );
|
|
27
27
|
var dtypes = require( '@stdlib/ndarray-dtypes' );
|
|
28
|
+
var format = require( '@stdlib/string-format' );
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
// VARIABLES //
|
|
@@ -57,18 +58,18 @@ var DTYPES = dtypes();
|
|
|
57
58
|
*/
|
|
58
59
|
function validate( opts, options ) {
|
|
59
60
|
if ( !isPlainObject( options ) ) {
|
|
60
|
-
return new TypeError( 'invalid argument. Options argument must be
|
|
61
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
61
62
|
}
|
|
62
63
|
if ( hasOwnProp( options, 'dtype' ) ) {
|
|
63
64
|
opts.dtype = options.dtype;
|
|
64
65
|
if ( !contains( DTYPES, opts.dtype ) ) {
|
|
65
|
-
return new TypeError( 'invalid option. `
|
|
66
|
+
return new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'dtype', opts.dtype ) );
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
if ( hasOwnProp( options, 'order' ) ) {
|
|
69
70
|
opts.order = options.order;
|
|
70
71
|
if ( !contains( ORDERS, opts.order ) ) {
|
|
71
|
-
return new TypeError( 'invalid option. `
|
|
72
|
+
return new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'order', opts.order ) );
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
return null;
|
package/lib/validate_options.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
24
|
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
25
|
var contains = require( '@stdlib/assert-contains' );
|
|
26
|
+
var format = require( '@stdlib/string-format' );
|
|
26
27
|
var POLICIES = require( './policies.json' );
|
|
27
28
|
|
|
28
29
|
|
|
@@ -49,12 +50,12 @@ var POLICIES = require( './policies.json' );
|
|
|
49
50
|
*/
|
|
50
51
|
function validate( opts, options ) {
|
|
51
52
|
if ( !isPlainObject( options ) ) {
|
|
52
|
-
return new TypeError( 'invalid argument. Options argument must be
|
|
53
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
53
54
|
}
|
|
54
55
|
if ( hasOwnProp( options, 'output_dtype_policy' ) ) {
|
|
55
56
|
opts.policy = options.output_dtype_policy;
|
|
56
57
|
if ( !contains( POLICIES, opts.policy ) ) {
|
|
57
|
-
return new TypeError( 'invalid option. `
|
|
58
|
+
return new TypeError( format( 'invalid option. `%s` option must be a recognized/supported output array data type policy. Option: `%s`.', 'output_dtype_policy', opts.policy ) );
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
return null;
|
package/lib/validate_table.js
CHANGED
|
@@ -25,6 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
|
25
25
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
26
26
|
var isNull = require( '@stdlib/assert-is-null' );
|
|
27
27
|
var objectKeys = require( '@stdlib/utils-keys' );
|
|
28
|
+
var format = require( '@stdlib/string-format' );
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
// MAIN //
|
|
@@ -61,7 +62,7 @@ function validate( out, table ) {
|
|
|
61
62
|
var i;
|
|
62
63
|
|
|
63
64
|
if ( !isPlainObject( table ) ) {
|
|
64
|
-
return new TypeError( 'invalid argument. Resolution table must be
|
|
65
|
+
return new TypeError( format( 'invalid argument. Resolution table must be an object. Value: `%s`.', table ) );
|
|
65
66
|
}
|
|
66
67
|
fields = objectKeys( out );
|
|
67
68
|
for ( i = 0; i < fields.length; i++ ) {
|
|
@@ -69,7 +70,7 @@ function validate( out, table ) {
|
|
|
69
70
|
if ( hasOwnProp( table, key ) ) {
|
|
70
71
|
tmp = table[ key ];
|
|
71
72
|
if ( !isFunction( tmp ) && !isNull( tmp ) ) {
|
|
72
|
-
return new TypeError( 'invalid argument. Resolution table `
|
|
73
|
+
return new TypeError( format( 'invalid argument. Resolution table `%s` field value must be either a function or null. Value: `%s`.', key, tmp ) );
|
|
73
74
|
}
|
|
74
75
|
out[ key ] = tmp;
|
|
75
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-tools-unary",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Multiple dispatch for unary mathematical functions.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,46 +37,46 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/
|
|
41
|
-
"@stdlib/assert-
|
|
42
|
-
"@stdlib/assert-
|
|
43
|
-
"@stdlib/assert-is-
|
|
44
|
-
"@stdlib/assert-is-
|
|
45
|
-
"@stdlib/assert-is-
|
|
46
|
-
"@stdlib/assert-is-
|
|
47
|
-
"@stdlib/assert-is-
|
|
48
|
-
"@stdlib/assert-is-
|
|
49
|
-
"@stdlib/
|
|
50
|
-
"@stdlib/ndarray-base-
|
|
51
|
-
"@stdlib/ndarray-base-buffer
|
|
52
|
-
"@stdlib/ndarray-base-
|
|
53
|
-
"@stdlib/ndarray-base-
|
|
54
|
-
"@stdlib/ndarray-
|
|
55
|
-
"@stdlib/ndarray-
|
|
56
|
-
"@stdlib/ndarray-
|
|
57
|
-
"@stdlib/
|
|
58
|
-
"@stdlib/
|
|
59
|
-
"@stdlib/
|
|
40
|
+
"@stdlib/array-base-copy-indexed": "^0.1.0",
|
|
41
|
+
"@stdlib/assert-contains": "^0.1.0",
|
|
42
|
+
"@stdlib/assert-has-own-property": "^0.1.0",
|
|
43
|
+
"@stdlib/assert-is-collection": "^0.1.0",
|
|
44
|
+
"@stdlib/assert-is-complex-like": "^0.1.0",
|
|
45
|
+
"@stdlib/assert-is-function": "^0.1.0",
|
|
46
|
+
"@stdlib/assert-is-ndarray-like": "^0.1.0",
|
|
47
|
+
"@stdlib/assert-is-null": "^0.1.0",
|
|
48
|
+
"@stdlib/assert-is-number": "^0.1.0",
|
|
49
|
+
"@stdlib/assert-is-plain-object": "^0.1.0",
|
|
50
|
+
"@stdlib/ndarray-base-broadcast-array": "^0.1.0",
|
|
51
|
+
"@stdlib/ndarray-base-buffer": "^0.1.0",
|
|
52
|
+
"@stdlib/ndarray-base-buffer-dtype": "^0.1.0",
|
|
53
|
+
"@stdlib/ndarray-base-numel": "^0.1.0",
|
|
54
|
+
"@stdlib/ndarray-base-shape2strides": "^0.1.0",
|
|
55
|
+
"@stdlib/ndarray-ctor": "^0.1.0",
|
|
56
|
+
"@stdlib/ndarray-dtypes": "^0.1.0",
|
|
57
|
+
"@stdlib/ndarray-orders": "^0.1.0",
|
|
58
|
+
"@stdlib/string-format": "^0.1.0",
|
|
59
|
+
"@stdlib/types": "^0.1.0",
|
|
60
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0",
|
|
61
|
+
"@stdlib/utils-keys": "^0.1.0",
|
|
62
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.1.0"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
|
-
"@stdlib/array-float32": "^0.0
|
|
63
|
-
"@stdlib/array-float64": "^0.0
|
|
64
|
-
"@stdlib/
|
|
65
|
-
"@stdlib/
|
|
66
|
-
"@stdlib/math-base-
|
|
67
|
-
"@stdlib/math-base-special-
|
|
68
|
-
"@stdlib/math-
|
|
69
|
-
"@stdlib/
|
|
70
|
-
"@stdlib/
|
|
71
|
-
"@stdlib/
|
|
72
|
-
"@stdlib/ndarray-
|
|
73
|
-
"@stdlib/
|
|
74
|
-
"@stdlib/ndarray-dispatch": "^0.0.x",
|
|
75
|
-
"@stdlib/ndarray-ind2sub": "^0.0.x",
|
|
76
|
-
"@stdlib/random-base-uniform": "^0.0.x",
|
|
65
|
+
"@stdlib/array-float32": "^0.1.0",
|
|
66
|
+
"@stdlib/array-float64": "^0.1.0",
|
|
67
|
+
"@stdlib/bench": "^0.1.0",
|
|
68
|
+
"@stdlib/math-base-assert-is-nan": "^0.1.0",
|
|
69
|
+
"@stdlib/math-base-special-abs": "^0.1.0",
|
|
70
|
+
"@stdlib/math-base-special-pow": "^0.1.0",
|
|
71
|
+
"@stdlib/math-strided-special-abs": "^0.1.0",
|
|
72
|
+
"@stdlib/ndarray-array": "^0.0.9",
|
|
73
|
+
"@stdlib/ndarray-base-unary": "^0.1.0",
|
|
74
|
+
"@stdlib/ndarray-dispatch": "^0.1.0",
|
|
75
|
+
"@stdlib/ndarray-ind2sub": "^0.1.0",
|
|
76
|
+
"@stdlib/random-base-uniform": "^0.0.6",
|
|
77
77
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
78
78
|
"istanbul": "^0.4.1",
|
|
79
|
-
"tap-
|
|
79
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
80
80
|
},
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=0.10.0",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
],
|
|
109
109
|
"__stdlib__": {},
|
|
110
110
|
"funding": {
|
|
111
|
-
"type": "
|
|
112
|
-
"url": "https://
|
|
111
|
+
"type": "opencollective",
|
|
112
|
+
"url": "https://opencollective.com/stdlib"
|
|
113
113
|
}
|
|
114
114
|
}
|
package/docs/repl.txt
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( table )
|
|
3
|
-
Returns a function which dispatches to specified functions based on input
|
|
4
|
-
argument types.
|
|
5
|
-
|
|
6
|
-
A `table` resolution object may contain one or more of the following fields:
|
|
7
|
-
|
|
8
|
-
- scalar: strided look-up table for scalar arguments.
|
|
9
|
-
- array: strided look-up table for array-like object arguments.
|
|
10
|
-
- ndarray: strided look-up table for ndarray arguments.
|
|
11
|
-
|
|
12
|
-
Each strided look-up table should be comprised as follows:
|
|
13
|
-
|
|
14
|
-
[ <dtype>, <fcn>, <dtype>, <fcn>, ... ]
|
|
15
|
-
|
|
16
|
-
If an argument's data type is *not* found in the argument's corresponding
|
|
17
|
-
look-up table and if a 'generic' data type is present in that same table,
|
|
18
|
-
the returned dispatch function will resolve the "generic" implementation. In
|
|
19
|
-
other words, an implementation associated with a 'generic' data type will be
|
|
20
|
-
treated as the default implementation.
|
|
21
|
-
|
|
22
|
-
If unable to resolve an implementation for a provided argument data type,
|
|
23
|
-
the returned function throws an error.
|
|
24
|
-
|
|
25
|
-
If provided a number, the returned function returns a number.
|
|
26
|
-
|
|
27
|
-
If provided an ndarray or array-like object, the returned function performs
|
|
28
|
-
element-wise computation.
|
|
29
|
-
|
|
30
|
-
If provided an array-like object, the returned function returns an array-
|
|
31
|
-
like object having the same length and data type as the provided input
|
|
32
|
-
argument.
|
|
33
|
-
|
|
34
|
-
If provided an ndarray, the returned function returns an ndarray having the
|
|
35
|
-
same shape and data type as the provided input argument.
|
|
36
|
-
|
|
37
|
-
Parameters
|
|
38
|
-
----------
|
|
39
|
-
table: Object
|
|
40
|
-
Table resolution object.
|
|
41
|
-
|
|
42
|
-
table.scalar: ArrayLikeObject (optional)
|
|
43
|
-
Strided look-up table for scalar arguments. Supported data types:
|
|
44
|
-
'number' and 'complex'.
|
|
45
|
-
|
|
46
|
-
table.array: ArrayLikeObject (optional)
|
|
47
|
-
Strided look-up table for array-like object arguments. Implementation
|
|
48
|
-
functions must follow strided array interface argument conventions:
|
|
49
|
-
|
|
50
|
-
fcn( N, x, strideX, y, strideY )
|
|
51
|
-
|
|
52
|
-
where
|
|
53
|
-
|
|
54
|
-
- N: number of indexed elements.
|
|
55
|
-
- x: input strided array.
|
|
56
|
-
- strideX: index increment for `x`.
|
|
57
|
-
- y: destination strided array.
|
|
58
|
-
- strideY: index increment for `y`.
|
|
59
|
-
|
|
60
|
-
Supported array data types consist of all supported ndarray data types.
|
|
61
|
-
|
|
62
|
-
table.ndarray: ArrayLikeObject (optional)
|
|
63
|
-
Strided look-up table for ndarray arguments. Implementation functions
|
|
64
|
-
must follow strided array ndarray interface argument conventions:
|
|
65
|
-
|
|
66
|
-
fcn( N, x, strideX, offsetX, y, strideY, offsetY )
|
|
67
|
-
|
|
68
|
-
where
|
|
69
|
-
|
|
70
|
-
- N: number of indexed elements.
|
|
71
|
-
- x: input strided array (i.e., underlying input ndarray buffer).
|
|
72
|
-
- strideX: index increment for `x`.
|
|
73
|
-
- offsetX: starting index for `x`.
|
|
74
|
-
- y: destination strided array (i.e., underlying output ndarray buffer).
|
|
75
|
-
- strideY: index increment for `y`.
|
|
76
|
-
- offsetY: starting index for `y`.
|
|
77
|
-
|
|
78
|
-
Supported data types consist of all supported ndarray data types.
|
|
79
|
-
|
|
80
|
-
Returns
|
|
81
|
-
-------
|
|
82
|
-
fcn: Function
|
|
83
|
-
Dispatch function.
|
|
84
|
-
|
|
85
|
-
Examples
|
|
86
|
-
--------
|
|
87
|
-
> var t = {};
|
|
88
|
-
> t.scalar = [ 'number', {{alias:@stdlib/math/base/special/abs}} ];
|
|
89
|
-
> t.array = [
|
|
90
|
-
... 'float64', {{alias:@stdlib/math/strided/special/dabs}},
|
|
91
|
-
... 'float32', {{alias:@stdlib/math/strided/special/sabs}},
|
|
92
|
-
... 'generic', {{alias:@stdlib/math/strided/special/abs}}
|
|
93
|
-
... ];
|
|
94
|
-
> t.ndarray = [
|
|
95
|
-
... 'float64', {{alias:@stdlib/math/strided/special/dabs}}.ndarray,
|
|
96
|
-
... 'float32', {{alias:@stdlib/math/strided/special/sabs}}.ndarray,
|
|
97
|
-
... 'generic', {{alias:@stdlib/math/strided/special/abs}}.ndarray
|
|
98
|
-
... ];
|
|
99
|
-
> var fcn = {{alias}}( t );
|
|
100
|
-
|
|
101
|
-
// Provide a number:
|
|
102
|
-
> var y = fcn( -1.0 )
|
|
103
|
-
1.0
|
|
104
|
-
|
|
105
|
-
// Provide an array-like object:
|
|
106
|
-
> var x = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0 ] );
|
|
107
|
-
> y = fcn( x )
|
|
108
|
-
<Float64Array>[ 1.0, 2.0 ]
|
|
109
|
-
|
|
110
|
-
// Provide an ndarray:
|
|
111
|
-
> x = {{alias:@stdlib/ndarray/array}}( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
|
|
112
|
-
> y = fcn( x )
|
|
113
|
-
<ndarray>
|
|
114
|
-
> y.get( 0, 1 )
|
|
115
|
-
2.0
|
|
116
|
-
|
|
117
|
-
See Also
|
|
118
|
-
--------
|
|
119
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 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
|
-
/// <reference types="@stdlib/types"/>
|
|
20
|
-
|
|
21
|
-
import { ndarray } from '@stdlib/types/ndarray';
|
|
22
|
-
import dispatch = require( './index' );
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Identity function.
|
|
26
|
-
*
|
|
27
|
-
* @param x - input value
|
|
28
|
-
* @returns return value
|
|
29
|
-
*/
|
|
30
|
-
function identity( x: number ): number {
|
|
31
|
-
return x;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Function which operates on a strided array.
|
|
36
|
-
*
|
|
37
|
-
* @param N - number of indexed elements
|
|
38
|
-
* @param x - input array
|
|
39
|
-
* @param strideX - `x` stride length
|
|
40
|
-
* @param y - destination array
|
|
41
|
-
* @param strideY - `y` stride length
|
|
42
|
-
* @returns `y`
|
|
43
|
-
*/
|
|
44
|
-
function stridedArrayFunction( N: number, x: ArrayLike<number>, strideX: number, y: ArrayLike<number>, strideY: number ): ArrayLike<number> { // tslint:disable-line:max-line-length
|
|
45
|
-
let ix;
|
|
46
|
-
let iy;
|
|
47
|
-
if ( N <= 0 ) {
|
|
48
|
-
return y;
|
|
49
|
-
}
|
|
50
|
-
if ( strideX < 0 ) {
|
|
51
|
-
ix = ( 1 - N ) * strideX;
|
|
52
|
-
} else {
|
|
53
|
-
ix = 0;
|
|
54
|
-
}
|
|
55
|
-
if ( strideY < 0 ) {
|
|
56
|
-
iy = ( 1 - N ) * strideY;
|
|
57
|
-
} else {
|
|
58
|
-
iy = 0;
|
|
59
|
-
}
|
|
60
|
-
if ( x[ ix ] !== x[ ix ] ) {
|
|
61
|
-
return y;
|
|
62
|
-
}
|
|
63
|
-
if ( y[ iy ] !== y[ iy ] ) {
|
|
64
|
-
return y;
|
|
65
|
-
}
|
|
66
|
-
return y;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Function which operates on a strided array using alternative indexing semantics.
|
|
71
|
-
*
|
|
72
|
-
* @param N - number of indexed elements
|
|
73
|
-
* @param x - input array
|
|
74
|
-
* @param strideX - `x` stride length
|
|
75
|
-
* @param offsetX - starting index for `x`
|
|
76
|
-
* @param y - destination array
|
|
77
|
-
* @param strideY - `y` stride length
|
|
78
|
-
* @param offsetY - starting index for `y`
|
|
79
|
-
* @returns `y`
|
|
80
|
-
*/
|
|
81
|
-
function stridedArrayFunctionWithOffsets( N: number, x: ArrayLike<number>, strideX: number, offsetX: number, y: ArrayLike<number>, strideY: number, offsetY: number ): ArrayLike<number> { // tslint:disable-line:max-line-length
|
|
82
|
-
let ix;
|
|
83
|
-
let iy;
|
|
84
|
-
if ( N <= 0 ) {
|
|
85
|
-
return y;
|
|
86
|
-
}
|
|
87
|
-
ix = offsetX;
|
|
88
|
-
iy = offsetY;
|
|
89
|
-
if ( x[ ix + strideX ] !== x[ ix + strideX ] ) {
|
|
90
|
-
return y;
|
|
91
|
-
}
|
|
92
|
-
if ( y[ iy + strideY ] !== y[ iy + strideY ] ) {
|
|
93
|
-
return y;
|
|
94
|
-
}
|
|
95
|
-
return y;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// TESTS //
|
|
100
|
-
|
|
101
|
-
// The function returns a dispatch function...
|
|
102
|
-
{
|
|
103
|
-
const t1 = {};
|
|
104
|
-
dispatch( t1 ); // $ExpectType DispatchFunction
|
|
105
|
-
|
|
106
|
-
const t2 = {
|
|
107
|
-
'scalar': [ 'number', identity ]
|
|
108
|
-
};
|
|
109
|
-
dispatch( t2 ); // $ExpectType DispatchFunction
|
|
110
|
-
|
|
111
|
-
const t3 = {
|
|
112
|
-
'array': [ 'generic', stridedArrayFunction ]
|
|
113
|
-
};
|
|
114
|
-
dispatch( t3 ); // $ExpectType DispatchFunction
|
|
115
|
-
|
|
116
|
-
const t4 = {
|
|
117
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
118
|
-
};
|
|
119
|
-
dispatch( t4 ); // $ExpectType DispatchFunction
|
|
120
|
-
|
|
121
|
-
const t5 = {
|
|
122
|
-
'scalar': [ 'number', identity ],
|
|
123
|
-
'array': [ 'generic', stridedArrayFunction ]
|
|
124
|
-
};
|
|
125
|
-
dispatch( t5 ); // $ExpectType DispatchFunction
|
|
126
|
-
|
|
127
|
-
const t6 = {
|
|
128
|
-
'scalar': [ 'number', identity ],
|
|
129
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
130
|
-
};
|
|
131
|
-
dispatch( t6 ); // $ExpectType DispatchFunction
|
|
132
|
-
|
|
133
|
-
const t7 = {
|
|
134
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
135
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
136
|
-
};
|
|
137
|
-
dispatch( t7 ); // $ExpectType DispatchFunction
|
|
138
|
-
|
|
139
|
-
const t8 = {
|
|
140
|
-
'scalar': [ 'number', identity ],
|
|
141
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
142
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
143
|
-
};
|
|
144
|
-
dispatch( t8 ); // $ExpectType DispatchFunction
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// The function does not compile if not provided a table resolution object...
|
|
148
|
-
{
|
|
149
|
-
dispatch( '5' ); // $ExpectError
|
|
150
|
-
dispatch( 5 ); // $ExpectError
|
|
151
|
-
dispatch( true ); // $ExpectError
|
|
152
|
-
dispatch( false ); // $ExpectError
|
|
153
|
-
dispatch( null ); // $ExpectError
|
|
154
|
-
dispatch( undefined ); // $ExpectError
|
|
155
|
-
dispatch( [ '5' ] ); // $ExpectError
|
|
156
|
-
dispatch( ( x: number ): number => x ); // $ExpectError
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// The function does not compile if provided a table resolution object having an invalid `scalar` field...
|
|
160
|
-
{
|
|
161
|
-
dispatch( { 'scalar': 5 } ); // $ExpectError
|
|
162
|
-
dispatch( { 'scalar': true } ); // $ExpectError
|
|
163
|
-
dispatch( { 'scalar': false } ); // $ExpectError
|
|
164
|
-
dispatch( { 'scalar': null } ); // $ExpectError
|
|
165
|
-
dispatch( { 'scalar': [ 5 ] } ); // $ExpectError
|
|
166
|
-
dispatch( { 'scalar': [ '5', 5 ] } ); // $ExpectError
|
|
167
|
-
dispatch( { 'scalar': ( x: number ): number => x } ); // $ExpectError
|
|
168
|
-
dispatch( { 'scalar': [ '5', ( x: string ): string => x ] } ); // $ExpectError
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// The function does not compile if provided a table resolution object having an invalid `array` field...
|
|
172
|
-
{
|
|
173
|
-
dispatch( { 'array': 5 } ); // $ExpectError
|
|
174
|
-
dispatch( { 'array': true } ); // $ExpectError
|
|
175
|
-
dispatch( { 'array': false } ); // $ExpectError
|
|
176
|
-
dispatch( { 'array': null } ); // $ExpectError
|
|
177
|
-
dispatch( { 'array': [ 5 ] } ); // $ExpectError
|
|
178
|
-
dispatch( { 'array': [ '5', 5 ] } ); // $ExpectError
|
|
179
|
-
dispatch( { 'array': ( x: number ): number => x } ); // $ExpectError
|
|
180
|
-
dispatch( { 'array': [ '5', ( x: string ): string => x ] } ); // $ExpectError
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// The function does not compile if provided a table resolution object having an invalid `ndarray` field...
|
|
184
|
-
{
|
|
185
|
-
dispatch( { 'ndarray': 5 } ); // $ExpectError
|
|
186
|
-
dispatch( { 'ndarray': true } ); // $ExpectError
|
|
187
|
-
dispatch( { 'ndarray': false } ); // $ExpectError
|
|
188
|
-
dispatch( { 'ndarray': null } ); // $ExpectError
|
|
189
|
-
dispatch( { 'ndarray': [ 5 ] } ); // $ExpectError
|
|
190
|
-
dispatch( { 'ndarray': [ '5', 5 ] } ); // $ExpectError
|
|
191
|
-
dispatch( { 'ndarray': ( x: number ): number => x } ); // $ExpectError
|
|
192
|
-
dispatch( { 'ndarray': [ '5', ( x: string ): string => x ] } ); // $ExpectError
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// The function returns a function which returns a number if provided a number...
|
|
196
|
-
{
|
|
197
|
-
const t = {
|
|
198
|
-
'scalar': [ 'number', identity ],
|
|
199
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
200
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
201
|
-
};
|
|
202
|
-
const abs = dispatch( t ); // $ExpectType DispatchFunction
|
|
203
|
-
|
|
204
|
-
abs( 8 ); // $ExpectType number
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// The function returns a function which returns an array-like object if provided an array-like object...
|
|
208
|
-
{
|
|
209
|
-
const t = {
|
|
210
|
-
'scalar': [ 'number', identity ],
|
|
211
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
212
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
213
|
-
};
|
|
214
|
-
const abs = dispatch( t ); // $ExpectType DispatchFunction
|
|
215
|
-
|
|
216
|
-
const x = new Float64Array( 10 );
|
|
217
|
-
|
|
218
|
-
abs( x ); // $ExpectType ArrayLike<number>
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// The function returns a function which returns an ndarray if provided an ndarray...
|
|
222
|
-
{
|
|
223
|
-
const t = {
|
|
224
|
-
'scalar': [ 'number', identity ],
|
|
225
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
226
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
227
|
-
};
|
|
228
|
-
const abs = dispatch( t ); // $ExpectType DispatchFunction
|
|
229
|
-
|
|
230
|
-
const buf = [ 1, 2, 3, 4 ];
|
|
231
|
-
|
|
232
|
-
const x: ndarray = {
|
|
233
|
-
'byteLength': null,
|
|
234
|
-
'BYTES_PER_ELEMENT': null,
|
|
235
|
-
'data': buf,
|
|
236
|
-
'dtype': 'generic',
|
|
237
|
-
'flags': {
|
|
238
|
-
'ROW_MAJOR_CONTIGUOUS': true,
|
|
239
|
-
'COLUMN_MAJOR_CONTIGUOUS': false
|
|
240
|
-
},
|
|
241
|
-
'length': 4,
|
|
242
|
-
'ndims': 1,
|
|
243
|
-
'offset': 0,
|
|
244
|
-
'order': 'row-major',
|
|
245
|
-
'shape': [ 4 ],
|
|
246
|
-
'strides': [ 1 ],
|
|
247
|
-
'get': ( i: number ): number => {
|
|
248
|
-
return buf[ i ];
|
|
249
|
-
},
|
|
250
|
-
'set': ( i: number, v: number ): ndarray => {
|
|
251
|
-
buf[ i ] = v;
|
|
252
|
-
return x;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
abs( x ); // $ExpectType ndarray
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// The function returns a function which does not compile if provided a value other than an ndarray, array-like object, or number...
|
|
260
|
-
{
|
|
261
|
-
const t = {
|
|
262
|
-
'scalar': [ 'number', identity ],
|
|
263
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
264
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
265
|
-
};
|
|
266
|
-
const abs = dispatch( t ); // $ExpectType DispatchFunction
|
|
267
|
-
|
|
268
|
-
abs( '5' ); // $ExpectError
|
|
269
|
-
abs( true ); // $ExpectError
|
|
270
|
-
abs( false ); // $ExpectError
|
|
271
|
-
abs( null ); // $ExpectError
|
|
272
|
-
abs( undefined ); // $ExpectError
|
|
273
|
-
abs( {} ); // $ExpectError
|
|
274
|
-
abs( [ '5' ] ); // $ExpectError
|
|
275
|
-
abs( ( x: number ): number => x ); // $ExpectError
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// The function returns a function which does not compile if provided insufficient arguments...
|
|
279
|
-
{
|
|
280
|
-
const t = {
|
|
281
|
-
'scalar': [ 'number', identity ],
|
|
282
|
-
'array': [ 'generic', stridedArrayFunction ],
|
|
283
|
-
'ndarray': [ 'generic', stridedArrayFunctionWithOffsets ]
|
|
284
|
-
};
|
|
285
|
-
const abs = dispatch( t ); // $ExpectType DispatchFunction
|
|
286
|
-
|
|
287
|
-
abs(); // $ExpectError
|
|
288
|
-
}
|