@stdlib/math-array-tools-unary-factory 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +287 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +140 -0
- package/lib/index.js +46 -0
- package/lib/main.js +113 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
# factory
|
|
33
|
+
|
|
34
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
|
+
|
|
36
|
+
> Create a function for applying a unary function to each element in an input array.
|
|
37
|
+
|
|
38
|
+
<section class="installation">
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @stdlib/math-array-tools-unary-factory
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
</section>
|
|
47
|
+
|
|
48
|
+
<section class="usage">
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
var factory = require( '@stdlib/math-array-tools-unary-factory' );
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### factory( fcn, idtypes, odtypes, policy )
|
|
57
|
+
|
|
58
|
+
Returns a function for applying a unary function to each element in an input array.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
62
|
+
|
|
63
|
+
var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
64
|
+
var policy = 'same';
|
|
65
|
+
|
|
66
|
+
var unary = factory( abs, dtypes, dtypes, policy );
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The function has the following parameters:
|
|
70
|
+
|
|
71
|
+
- **fcn**: unary function to apply.
|
|
72
|
+
- **idtypes**: list of supported input data types.
|
|
73
|
+
- **odtypes**: list of supported input data types.
|
|
74
|
+
- **policy**: output data type policy.
|
|
75
|
+
|
|
76
|
+
#### unary( x\[, options] )
|
|
77
|
+
|
|
78
|
+
Applies a unary function to each element in a provided input array.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
82
|
+
|
|
83
|
+
var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
84
|
+
var policy = 'same';
|
|
85
|
+
|
|
86
|
+
var unary = factory( abs, dtypes, dtypes, policy );
|
|
87
|
+
|
|
88
|
+
var v = unary( [ -1.0, 2.0, -3.0, 4.0 ] );
|
|
89
|
+
// returns [ 1.0, 2.0, 3.0, 4.0 ]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The function has the following parameters:
|
|
93
|
+
|
|
94
|
+
- **x**: input array.
|
|
95
|
+
- **options**: function options.
|
|
96
|
+
|
|
97
|
+
The function accepts the following options:
|
|
98
|
+
|
|
99
|
+
- **dtype**: output array data type. Setting this option, overrides the output data type policy.
|
|
100
|
+
|
|
101
|
+
By default, the function returns an array having a data type determined by the output data type policy. To override the default behavior, set the `dtype` option.
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
105
|
+
|
|
106
|
+
var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
107
|
+
var policy = 'same';
|
|
108
|
+
|
|
109
|
+
var unary = factory( abs, dtypes, dtypes, policy );
|
|
110
|
+
|
|
111
|
+
var v = unary( [ -1.0, 2.0, -3.0, 4.0 ], {
|
|
112
|
+
'dtype': 'float64'
|
|
113
|
+
});
|
|
114
|
+
// returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### unary.assign( x, out )
|
|
118
|
+
|
|
119
|
+
Applies a unary function to each element in a provided input array and assigns results to a provided output array.
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
123
|
+
var zeros = require( '@stdlib/array-zeros' );
|
|
124
|
+
|
|
125
|
+
var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
126
|
+
var policy = 'same';
|
|
127
|
+
|
|
128
|
+
var unary = factory( abs, dtypes, dtypes, policy );
|
|
129
|
+
|
|
130
|
+
var out = zeros( 4, 'float64' );
|
|
131
|
+
// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0 ]
|
|
132
|
+
|
|
133
|
+
var v = unary.assign( [ -1.0, 2.0, -3.0, 4.0 ], out );
|
|
134
|
+
// returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
|
|
135
|
+
|
|
136
|
+
var bool = ( v === out );
|
|
137
|
+
// returns true
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The method has the following parameters:
|
|
141
|
+
|
|
142
|
+
- **x**: input array.
|
|
143
|
+
- **out**: output array.
|
|
144
|
+
|
|
145
|
+
</section>
|
|
146
|
+
|
|
147
|
+
<!-- /.usage -->
|
|
148
|
+
|
|
149
|
+
<section class="notes">
|
|
150
|
+
|
|
151
|
+
## Notes
|
|
152
|
+
|
|
153
|
+
- The output data type policy only applies to the function returned by `factory`. For the `assign` method, the output array is allowed to be any array-like object, including [accessor arrays][@stdlib/array/base/accessor].
|
|
154
|
+
|
|
155
|
+
</section>
|
|
156
|
+
|
|
157
|
+
<!-- /.notes -->
|
|
158
|
+
|
|
159
|
+
<section class="examples">
|
|
160
|
+
|
|
161
|
+
## Examples
|
|
162
|
+
|
|
163
|
+
<!-- eslint no-undef: "error" -->
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
var base = require( '@stdlib/math-base-special-sin' );
|
|
167
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
168
|
+
var dtypes = require( '@stdlib/array-dtypes' );
|
|
169
|
+
var dtype = require( '@stdlib/array-dtype' );
|
|
170
|
+
var logEach = require( '@stdlib/console-log-each' );
|
|
171
|
+
var factory = require( '@stdlib/math-array-tools-unary-factory' );
|
|
172
|
+
|
|
173
|
+
// Define the supported input and output data types:
|
|
174
|
+
var idt = dtypes( 'real_and_generic' );
|
|
175
|
+
var odt = dtypes( 'real_floating_point_and_generic' );
|
|
176
|
+
|
|
177
|
+
// Define the policy mapping an input data type to an output data type:
|
|
178
|
+
var policy = 'real_floating_point_and_generic';
|
|
179
|
+
|
|
180
|
+
// Create an interface for computing the element-wise sine:
|
|
181
|
+
var sin = factory( base, idt, odt, policy );
|
|
182
|
+
|
|
183
|
+
// Generate an array of random numbers:
|
|
184
|
+
var x = uniform( 10, -1.0, 1.0, {
|
|
185
|
+
'dtype': 'generic'
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Compute the element-wise sine:
|
|
189
|
+
var y = sin( x );
|
|
190
|
+
|
|
191
|
+
// Resolve the output array data type:
|
|
192
|
+
var dt = dtype( y );
|
|
193
|
+
console.log( dt );
|
|
194
|
+
|
|
195
|
+
// Print the results:
|
|
196
|
+
logEach( 'sin(%0.5f) = %0.5f', x, y );
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
</section>
|
|
200
|
+
|
|
201
|
+
<!-- /.examples -->
|
|
202
|
+
|
|
203
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
204
|
+
|
|
205
|
+
<section class="related">
|
|
206
|
+
|
|
207
|
+
</section>
|
|
208
|
+
|
|
209
|
+
<!-- /.related -->
|
|
210
|
+
|
|
211
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
<section class="main-repo" >
|
|
215
|
+
|
|
216
|
+
* * *
|
|
217
|
+
|
|
218
|
+
## Notice
|
|
219
|
+
|
|
220
|
+
This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
|
|
221
|
+
|
|
222
|
+
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
223
|
+
|
|
224
|
+
#### Community
|
|
225
|
+
|
|
226
|
+
[![Chat][chat-image]][chat-url]
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
See [LICENSE][stdlib-license].
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
## Copyright
|
|
236
|
+
|
|
237
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
238
|
+
|
|
239
|
+
</section>
|
|
240
|
+
|
|
241
|
+
<!-- /.stdlib -->
|
|
242
|
+
|
|
243
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
244
|
+
|
|
245
|
+
<section class="links">
|
|
246
|
+
|
|
247
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-array-tools-unary-factory.svg
|
|
248
|
+
[npm-url]: https://npmjs.org/package/@stdlib/math-array-tools-unary-factory
|
|
249
|
+
|
|
250
|
+
[test-image]: https://github.com/stdlib-js/math-array-tools-unary-factory/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
251
|
+
[test-url]: https://github.com/stdlib-js/math-array-tools-unary-factory/actions/workflows/test.yml?query=branch:v0.1.0
|
|
252
|
+
|
|
253
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-array-tools-unary-factory/main.svg
|
|
254
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/math-array-tools-unary-factory?branch=main
|
|
255
|
+
|
|
256
|
+
<!--
|
|
257
|
+
|
|
258
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/math-array-tools-unary-factory.svg
|
|
259
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/math-array-tools-unary-factory/main
|
|
260
|
+
|
|
261
|
+
-->
|
|
262
|
+
|
|
263
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
264
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
265
|
+
|
|
266
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
267
|
+
|
|
268
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
269
|
+
|
|
270
|
+
[umd]: https://github.com/umdjs/umd
|
|
271
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
272
|
+
|
|
273
|
+
[deno-url]: https://github.com/stdlib-js/math-array-tools-unary-factory/tree/deno
|
|
274
|
+
[deno-readme]: https://github.com/stdlib-js/math-array-tools-unary-factory/blob/deno/README.md
|
|
275
|
+
[umd-url]: https://github.com/stdlib-js/math-array-tools-unary-factory/tree/umd
|
|
276
|
+
[umd-readme]: https://github.com/stdlib-js/math-array-tools-unary-factory/blob/umd/README.md
|
|
277
|
+
[esm-url]: https://github.com/stdlib-js/math-array-tools-unary-factory/tree/esm
|
|
278
|
+
[esm-readme]: https://github.com/stdlib-js/math-array-tools-unary-factory/blob/esm/README.md
|
|
279
|
+
[branches-url]: https://github.com/stdlib-js/math-array-tools-unary-factory/blob/main/branches.md
|
|
280
|
+
|
|
281
|
+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-array-tools-unary-factory/main/LICENSE
|
|
282
|
+
|
|
283
|
+
[@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
|
|
284
|
+
|
|
285
|
+
</section>
|
|
286
|
+
|
|
287
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var p=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=p(function(q,s){
|
|
2
|
+
var g=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),y=require('@stdlib/math-array-tools-unary/dist');function l(e,r,c,f){var t=new y(e,r,c,f);return g(i,"assign",o),i;function i(n,a){return arguments.length<2?t.apply(n):t.apply(n,a)}function o(n,a){return t.assign(n,a)}}s.exports=l
|
|
3
|
+
});var v=u();module.exports=v;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar Unary = require( '@stdlib/math-array-tools-unary' );\n\n\n// MAIN //\n\n/**\n* Returns a function for applying a unary function to each element in a provided input array.\n*\n* @param {Function} fcn - unary function to apply\n* @param {StringArray} idtypes - list of supported input data types\n* @param {StringArray} odtypes - list of supported output data types\n* @param {string} policy - output data type policy\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be a supported output data type policy\n* @returns {Function} function for applying a unary function to each element in an array\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n*\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var abs = factory( base, dtypes, dtypes, 'same' );\n* // returns <Function>\n*\n* var x = abs( [ -1.0, 2.0, -3.0, 4.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0 ]\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n*\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var abs = factory( base, dtypes, dtypes, 'same' );\n*\n* var x = [ -1.0, -2.0, -3.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* var out = abs.assign( x, y );\n* // returns [ 1.0, 2.0, 3.0 ]\n*\n* var bool = ( out === y );\n* // returns true\n*/\nfunction factory( fcn, idtypes, odtypes, policy ) {\n\tvar f = new Unary( fcn, idtypes, odtypes, policy );\n\tsetReadOnly( main, 'assign', assign );\n\treturn main;\n\n\t/**\n\t* Applies a unary function to each element in a provided input array.\n\t*\n\t* @private\n\t* @param {Collection} x - input array\n\t* @param {Options} [options] - function options\n\t* @param {string} [options.dtype] - output array data type\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} first argument must have 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 {Collection} output array\n\t*/\n\tfunction main( x, options ) {\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn f.apply( x );\n\t\t}\n\t\treturn f.apply( x, options );\n\t}\n\n\t/**\n\t* Applies a unary function to each element in a provided input array and assigns results to a provided output array.\n\t*\n\t* @private\n\t* @param {Collection} x - input array\n\t* @param {Collection} out - output array\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} first argument must have a supported data type\n\t* @throws {TypeError} second argument must be a collection\n\t* @returns {Collection} output array\n\t*/\n\tfunction assign( x, out ) {\n\t\treturn f.assign( x, out );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create a function for applying a unary function to each element in a provided array.\n*\n* @module @stdlib/math-array-tools-unary-factory\n*\n* @example\n* var base = require( '@stdlib/math-base-special-abs' );\n* var unaryFactory = require( '@stdlib/math-array-tools-unary-factory' );\n*\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var abs = unaryFactory( base, dtypes, dtypes, 'same' );\n* // returns <Function>\n*\n* var x = abs( [ -1.0, 2.0, -3.0, 4.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAQ,QAAS,gCAAiC,EA6CtD,SAASC,EAASC,EAAKC,EAASC,EAASC,EAAS,CACjD,IAAIC,EAAI,IAAIN,EAAOE,EAAKC,EAASC,EAASC,CAAO,EACjD,OAAAN,EAAaQ,EAAM,SAAUC,CAAO,EAC7BD,EAeP,SAASA,EAAME,EAAGC,EAAU,CAC3B,OAAK,UAAU,OAAS,EAChBJ,EAAE,MAAOG,CAAE,EAEZH,EAAE,MAAOG,EAAGC,CAAQ,CAC5B,CAaA,SAASF,EAAQC,EAAGE,EAAM,CACzB,OAAOL,EAAE,OAAQG,EAAGE,CAAI,CACzB,CACD,CAKAb,EAAO,QAAUG,ICxEjB,IAAIW,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "Unary", "factory", "fcn", "idtypes", "odtypes", "policy", "f", "main", "assign", "x", "options", "out", "main"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
import { DataType, ArrayLike, AccessorArrayLike } from '@stdlib/types/array';
|
|
24
|
+
import { OutputPolicy } from '@stdlib/types/ndarray';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Input array.
|
|
28
|
+
*/
|
|
29
|
+
type InputArray<T> = ArrayLike<T> | AccessorArrayLike<T>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Output array.
|
|
33
|
+
*/
|
|
34
|
+
type OutputArray<U> = ArrayLike<U> | AccessorArrayLike<U>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Interface defining options.
|
|
38
|
+
*/
|
|
39
|
+
interface Options {
|
|
40
|
+
/**
|
|
41
|
+
* Output array data type.
|
|
42
|
+
*/
|
|
43
|
+
dtype?: DataType;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Unary function.
|
|
48
|
+
*
|
|
49
|
+
* @param value - input value
|
|
50
|
+
* @returns result
|
|
51
|
+
*/
|
|
52
|
+
type Unary<T, U> = ( x: T ) => U;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Interface for applying a unary function to each element in an input array.
|
|
56
|
+
*/
|
|
57
|
+
interface UnaryFunction<T, U> {
|
|
58
|
+
/**
|
|
59
|
+
* Applies a unary function to each element in a provided input array.
|
|
60
|
+
*
|
|
61
|
+
* @param x - input array
|
|
62
|
+
* @param options - function options
|
|
63
|
+
* @returns output array
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var base = require( '@stdlib/math-base-special-abs' );
|
|
67
|
+
* var dtypes = require( '@stdlib/array-dtypes' );
|
|
68
|
+
*
|
|
69
|
+
* var idt = dtypes( 'real_and_generic' );
|
|
70
|
+
* var odt = idt;
|
|
71
|
+
* var policy = 'same';
|
|
72
|
+
*
|
|
73
|
+
* var abs = factory( base, idt, odt, policy );
|
|
74
|
+
*
|
|
75
|
+
* var x = [ -1.0, -2.0, -3.0 ];
|
|
76
|
+
*
|
|
77
|
+
* var y = abs( x );
|
|
78
|
+
* // returns [ 1.0, 2.0, 3.0 ]
|
|
79
|
+
*/
|
|
80
|
+
( x: InputArray<T>, options?: Options ): OutputArray<U>; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output array data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. In principle, as well, based on the policy, it is possible to know more exactly which `InputArray` types are actually allowed.
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Applies a unary function to each element in a provided input array and assigns results to a provided output array.
|
|
84
|
+
*
|
|
85
|
+
* @param x - input array
|
|
86
|
+
* @param out - output array
|
|
87
|
+
* @returns output array
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* var base = require( '@stdlib/math-base-special-abs' );
|
|
91
|
+
* var dtypes = require( '@stdlib/array-dtypes' );
|
|
92
|
+
*
|
|
93
|
+
* var idt = dtypes( 'real_and_generic' );
|
|
94
|
+
* var odt = idt;
|
|
95
|
+
* var policy = 'same';
|
|
96
|
+
*
|
|
97
|
+
* var abs = factory( base, idt, odt, policy );
|
|
98
|
+
*
|
|
99
|
+
* var x = [ -1.0, -2.0, -3.0 ];
|
|
100
|
+
* var y = [ 0.0, 0.0, 0.0 ];
|
|
101
|
+
*
|
|
102
|
+
* var out = abs.assign( x, y );
|
|
103
|
+
* // returns [ 1.0, 2.0, 3.0 ]
|
|
104
|
+
*
|
|
105
|
+
* var bool = ( out === y );
|
|
106
|
+
* // returns true
|
|
107
|
+
*/
|
|
108
|
+
assign<V extends OutputArray<U>>( x: InputArray<T>, out: V ): V;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Creates a function for applying a unary function to each element in a provided array.
|
|
113
|
+
*
|
|
114
|
+
* @param fcn - unary function to apply
|
|
115
|
+
* @param idtypes - list of supported input data types
|
|
116
|
+
* @param odtypes - list of supported output data types
|
|
117
|
+
* @param policy - output data type policy
|
|
118
|
+
* @returns function for applying a unary function
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* var base = require( '@stdlib/math-base-special-abs' );
|
|
122
|
+
* var dtypes = require( '@stdlib/array-dtypes' );
|
|
123
|
+
*
|
|
124
|
+
* var idt = dtypes( 'real_and_generic' );
|
|
125
|
+
* var odt = idt;
|
|
126
|
+
* var policy = 'same';
|
|
127
|
+
*
|
|
128
|
+
* var abs = factory( base, idt, odt, policy );
|
|
129
|
+
*
|
|
130
|
+
* var x = [ -1.0, -2.0, -3.0 ];
|
|
131
|
+
*
|
|
132
|
+
* var y = abs( x );
|
|
133
|
+
* // returns [ 1.0, 2.0, 3.0 ]
|
|
134
|
+
*/
|
|
135
|
+
declare function factory<T = unknown, U = unknown>( fcn: Unary<T, U>, idtypes: ArrayLike<DataType>, odtypes: ArrayLike<DataType>, policy: OutputPolicy ): UnaryFunction<T, U>;
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
// EXPORTS //
|
|
139
|
+
|
|
140
|
+
export = factory;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a function for applying a unary function to each element in a provided array.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/math-array-tools-unary-factory
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var base = require( '@stdlib/math-base-special-abs' );
|
|
28
|
+
* var unaryFactory = require( '@stdlib/math-array-tools-unary-factory' );
|
|
29
|
+
*
|
|
30
|
+
* var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
31
|
+
*
|
|
32
|
+
* var abs = unaryFactory( base, dtypes, dtypes, 'same' );
|
|
33
|
+
* // returns <Function>
|
|
34
|
+
*
|
|
35
|
+
* var x = abs( [ -1.0, 2.0, -3.0, 4.0 ] );
|
|
36
|
+
* // returns [ 1.0, 2.0, 3.0, 4.0 ]
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// MODULES //
|
|
40
|
+
|
|
41
|
+
var main = require( './main.js' );
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// EXPORTS //
|
|
45
|
+
|
|
46
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
24
|
+
var Unary = require( '@stdlib/math-array-tools-unary' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns a function for applying a unary function to each element in a provided input array.
|
|
31
|
+
*
|
|
32
|
+
* @param {Function} fcn - unary function to apply
|
|
33
|
+
* @param {StringArray} idtypes - list of supported input data types
|
|
34
|
+
* @param {StringArray} odtypes - list of supported output data types
|
|
35
|
+
* @param {string} policy - output data type policy
|
|
36
|
+
* @throws {TypeError} first argument must be a function
|
|
37
|
+
* @throws {TypeError} second argument must be an array of supported data types
|
|
38
|
+
* @throws {TypeError} third argument must be an array of supported data types
|
|
39
|
+
* @throws {TypeError} fourth argument must be a supported output data type policy
|
|
40
|
+
* @returns {Function} function for applying a unary function to each element in an array
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* var base = require( '@stdlib/math-base-special-abs' );
|
|
44
|
+
*
|
|
45
|
+
* var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
46
|
+
*
|
|
47
|
+
* var abs = factory( base, dtypes, dtypes, 'same' );
|
|
48
|
+
* // returns <Function>
|
|
49
|
+
*
|
|
50
|
+
* var x = abs( [ -1.0, 2.0, -3.0, 4.0 ] );
|
|
51
|
+
* // returns [ 1.0, 2.0, 3.0, 4.0 ]
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var base = require( '@stdlib/math-base-special-abs' );
|
|
55
|
+
*
|
|
56
|
+
* var dtypes = [ 'float64', 'float32', 'generic' ];
|
|
57
|
+
*
|
|
58
|
+
* var abs = factory( base, dtypes, dtypes, 'same' );
|
|
59
|
+
*
|
|
60
|
+
* var x = [ -1.0, -2.0, -3.0 ];
|
|
61
|
+
* var y = [ 0.0, 0.0, 0.0 ];
|
|
62
|
+
*
|
|
63
|
+
* var out = abs.assign( x, y );
|
|
64
|
+
* // returns [ 1.0, 2.0, 3.0 ]
|
|
65
|
+
*
|
|
66
|
+
* var bool = ( out === y );
|
|
67
|
+
* // returns true
|
|
68
|
+
*/
|
|
69
|
+
function factory( fcn, idtypes, odtypes, policy ) {
|
|
70
|
+
var f = new Unary( fcn, idtypes, odtypes, policy );
|
|
71
|
+
setReadOnly( main, 'assign', assign );
|
|
72
|
+
return main;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Applies a unary function to each element in a provided input array.
|
|
76
|
+
*
|
|
77
|
+
* @private
|
|
78
|
+
* @param {Collection} x - input array
|
|
79
|
+
* @param {Options} [options] - function options
|
|
80
|
+
* @param {string} [options.dtype] - output array data type
|
|
81
|
+
* @throws {TypeError} first argument must be a collection
|
|
82
|
+
* @throws {TypeError} first argument must have a supported data type
|
|
83
|
+
* @throws {TypeError} options argument must be an object
|
|
84
|
+
* @throws {TypeError} must provide valid options
|
|
85
|
+
* @returns {Collection} output array
|
|
86
|
+
*/
|
|
87
|
+
function main( x, options ) {
|
|
88
|
+
if ( arguments.length < 2 ) {
|
|
89
|
+
return f.apply( x );
|
|
90
|
+
}
|
|
91
|
+
return f.apply( x, options );
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Applies a unary function to each element in a provided input array and assigns results to a provided output array.
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
* @param {Collection} x - input array
|
|
99
|
+
* @param {Collection} out - output array
|
|
100
|
+
* @throws {TypeError} first argument must be a collection
|
|
101
|
+
* @throws {TypeError} first argument must have a supported data type
|
|
102
|
+
* @throws {TypeError} second argument must be a collection
|
|
103
|
+
* @returns {Collection} output array
|
|
104
|
+
*/
|
|
105
|
+
function assign( x, out ) {
|
|
106
|
+
return f.assign( x, out );
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
// EXPORTS //
|
|
112
|
+
|
|
113
|
+
module.exports = factory;
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/math-array-tools-unary-factory",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a function for applying a unary function to each element in a provided array.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib",
|
|
20
|
+
"dist": "./dist"
|
|
21
|
+
},
|
|
22
|
+
"types": "./docs/types",
|
|
23
|
+
"scripts": {},
|
|
24
|
+
"homepage": "https://stdlib.io",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git://github.com/stdlib-js/math-array-tools-unary-factory.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/math-array-tools-unary": "github:stdlib-js/math-array-tools-unary#main",
|
|
34
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=0.10.0",
|
|
39
|
+
"npm": ">2.7.0"
|
|
40
|
+
},
|
|
41
|
+
"os": [
|
|
42
|
+
"aix",
|
|
43
|
+
"darwin",
|
|
44
|
+
"freebsd",
|
|
45
|
+
"linux",
|
|
46
|
+
"macos",
|
|
47
|
+
"openbsd",
|
|
48
|
+
"sunos",
|
|
49
|
+
"win32",
|
|
50
|
+
"windows"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"stdlib",
|
|
54
|
+
"stdmath",
|
|
55
|
+
"mathematics",
|
|
56
|
+
"math",
|
|
57
|
+
"factory",
|
|
58
|
+
"function",
|
|
59
|
+
"func",
|
|
60
|
+
"fcn",
|
|
61
|
+
"vector",
|
|
62
|
+
"array",
|
|
63
|
+
"apply",
|
|
64
|
+
"element-wise",
|
|
65
|
+
"elementwise"
|
|
66
|
+
],
|
|
67
|
+
"funding": {
|
|
68
|
+
"type": "opencollective",
|
|
69
|
+
"url": "https://opencollective.com/stdlib"
|
|
70
|
+
}
|
|
71
|
+
}
|