@stdlib/array-base-accessor-setter 0.0.1 → 0.2.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/NOTICE +1 -1
- package/README.md +19 -5
- 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 +14 -14
- package/package.json +22 -21
- package/docs/repl.txt +0 -60
- package/docs/types/test.ts +0 -177
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2024 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
|
# accessorSetter
|
|
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] -->
|
|
@@ -186,7 +197,7 @@ See [LICENSE][stdlib-license].
|
|
|
186
197
|
|
|
187
198
|
## Copyright
|
|
188
199
|
|
|
189
|
-
Copyright © 2016-
|
|
200
|
+
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
190
201
|
|
|
191
202
|
</section>
|
|
192
203
|
|
|
@@ -199,8 +210,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
199
210
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-accessor-setter.svg
|
|
200
211
|
[npm-url]: https://npmjs.org/package/@stdlib/array-base-accessor-setter
|
|
201
212
|
|
|
202
|
-
[test-image]: https://github.com/stdlib-js/array-base-accessor-setter/actions/workflows/test.yml/badge.svg?branch=v0.0
|
|
203
|
-
[test-url]: https://github.com/stdlib-js/array-base-accessor-setter/actions/workflows/test.yml?query=branch:v0.0
|
|
213
|
+
[test-image]: https://github.com/stdlib-js/array-base-accessor-setter/actions/workflows/test.yml/badge.svg?branch=v0.2.0
|
|
214
|
+
[test-url]: https://github.com/stdlib-js/array-base-accessor-setter/actions/workflows/test.yml?query=branch:v0.2.0
|
|
204
215
|
|
|
205
216
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-accessor-setter/main.svg
|
|
206
217
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-accessor-setter?branch=main
|
|
@@ -213,7 +224,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
213
224
|
-->
|
|
214
225
|
|
|
215
226
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
216
|
-
[chat-url]: https://gitter.im
|
|
227
|
+
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
|
|
217
228
|
|
|
218
229
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
219
230
|
|
|
@@ -223,13 +234,16 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
223
234
|
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
224
235
|
|
|
225
236
|
[deno-url]: https://github.com/stdlib-js/array-base-accessor-setter/tree/deno
|
|
237
|
+
[deno-readme]: https://github.com/stdlib-js/array-base-accessor-setter/blob/deno/README.md
|
|
226
238
|
[umd-url]: https://github.com/stdlib-js/array-base-accessor-setter/tree/umd
|
|
239
|
+
[umd-readme]: https://github.com/stdlib-js/array-base-accessor-setter/blob/umd/README.md
|
|
227
240
|
[esm-url]: https://github.com/stdlib-js/array-base-accessor-setter/tree/esm
|
|
241
|
+
[esm-readme]: https://github.com/stdlib-js/array-base-accessor-setter/blob/esm/README.md
|
|
228
242
|
[branches-url]: https://github.com/stdlib-js/array-base-accessor-setter/blob/main/branches.md
|
|
229
243
|
|
|
230
244
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-accessor-setter/main/LICENSE
|
|
231
245
|
|
|
232
|
-
[@stdlib/array/dtypes]: https://www.npmjs.com/package/@stdlib/
|
|
246
|
+
[@stdlib/array/dtypes]: https://www.npmjs.com/package/@stdlib/array-dtypes
|
|
233
247
|
|
|
234
248
|
</section>
|
|
235
249
|
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var u=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var o=u(function(x,s){
|
|
2
|
+
var n={complex128:i,complex64:f,default:c};function i(t,e,r){t.set(r,e)}function f(t,e,r){t.set(r,e)}function c(t,e,r){t.set(r,e)}function a(t){var e=n[t];return typeof e=="function"?e:n.default}s.exports=a
|
|
3
|
+
});var p=o();module.exports=p;
|
|
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) 2022 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// VARIABLES //\n\nvar SETTERS = {\n\t'complex128': setComplex128,\n\t'complex64': setComplex64,\n\t'default': setArrayLike\n};\n\n\n// FUNCTIONS //\n\n/**\n* Sets an element in a `Complex128Array`.\n*\n* @private\n* @param {Complex128Array} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @param {(Collection|Complex|ComplexArray)} value - value(s)\n*\n* @example\n* var Complex128Array = require( '@stdlib/array-complex128' );\n* var Complex128 = require( '@stdlib/complex-float64' );\n* var real = require( '@stdlib/complex-real' );\n* var imag = require( '@stdlib/complex-imag' );\n*\n* var arr = new Complex128Array( [ 1, 2, 3, 4 ] );\n*\n* setComplex128( arr, 1, new Complex128( 10.0, 11.0 ) );\n* var v = arr.get( 1 );\n* // returns <Complex128>\n*\n* var re = real( v );\n* // returns 10.0\n*\n* var im = imag( v );\n* // returns 11.0\n*/\nfunction setComplex128( arr, idx, value ) {\n\tarr.set( value, idx );\n}\n\n/**\n* Sets an element in a `Complex64Array`.\n*\n* @private\n* @param {Complex64Array} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @param {(Collection|Complex|ComplexArray)} value - value(s)\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* setComplex64( arr, 1, new Complex64( 10.0, 11.0 ) );\n* var v = arr.get( 1 );\n* // returns <Complex64>\n*\n* var re = realf( v );\n* // returns 10.0\n*\n* var im = imagf( v );\n* // returns 11.0\n*/\nfunction setComplex64( arr, idx, value ) {\n\tarr.set( value, idx );\n}\n\n/**\n* Sets an element in an array-like object supporting the get/set protocol.\n*\n* @private\n* @param {Collection} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @param {(Collection|Complex|ComplexArray)} value - value(s)\n*\n* @example\n* var arr = [ 1, 2, 3, 4 ];\n*\n* function get( idx ) {\n* return arr[ idx ];\n* }\n*\n* function set( value, idx ) {\n* arr[ idx ] = value;\n* }\n*\n* arr.get = get;\n* arr.set = set;\n*\n* setArrayLike( arr, 2, 10 );\n*\n* var v = arr[ 2 ];\n* // returns 10\n*/\nfunction setArrayLike( arr, idx, value ) {\n\tarr.set( value, idx );\n}\n\n\n// MAIN //\n\n/**\n* Returns an accessor function for setting an element in an array-like object supporting the get/set protocol.\n*\n* @param {string} dtype - array dtype\n* @returns {Function} accessor\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var dtype = require( '@stdlib/array-dtype' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var set = setter( dtype( arr ) );\n* set( arr, 1, new Complex64( 10.0, 11.0 ) );\n*\n* var v = arr.get( 1 );\n* // returns <Complex64>\n*\n* var re = realf( v );\n* // returns 10.0\n*\n* var im = imagf( v );\n* // returns 11.0\n*/\nfunction setter( dtype ) {\n\tvar f = SETTERS[ dtype ];\n\tif ( typeof f === 'function' ) {\n\t\treturn f;\n\t}\n\treturn SETTERS.default;\n}\n\n\n// EXPORTS //\n\nmodule.exports = setter;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 an accessor function for setting an element in an array-like object supporting the get/set protocol.\n*\n* @module @stdlib/array-base-accessor-setter\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var dtype = require( '@stdlib/array-dtype' );\n* var setter = require( '@stdlib/array-base-accessor-setter' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var set = setter( dtype( arr ) );\n* set( arr, 1, new Complex64( 10.0, 11.0 ) );\n*\n* var v = arr.get( 1 );\n* // returns <Complex64>\n*\n* var re = realf( v );\n* // returns 10.0\n*\n* var im = imagf( v );\n* // returns 11.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,EAAU,CACb,WAAcC,EACd,UAAaC,EACb,QAAWC,CACZ,EA+BA,SAASF,EAAeG,EAAKC,EAAKC,EAAQ,CACzCF,EAAI,IAAKE,EAAOD,CAAI,CACrB,CA4BA,SAASH,EAAcE,EAAKC,EAAKC,EAAQ,CACxCF,EAAI,IAAKE,EAAOD,CAAI,CACrB,CA6BA,SAASF,EAAcC,EAAKC,EAAKC,EAAQ,CACxCF,EAAI,IAAKE,EAAOD,CAAI,CACrB,CAgCA,SAASE,EAAQC,EAAQ,CACxB,IAAIC,EAAIT,EAASQ,CAAM,EACvB,OAAK,OAAOC,GAAM,WACVA,EAEDT,EAAQ,OAChB,CAKAD,EAAO,QAAUQ,ICjHjB,IAAIG,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "SETTERS", "setComplex128", "setComplex64", "setArrayLike", "arr", "idx", "value", "setter", "dtype", "f", "main"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
21
|
/// <reference types="@stdlib/types"/>
|
|
22
22
|
|
|
23
|
-
import { ComplexLike } from '@stdlib/types/
|
|
23
|
+
import { ComplexLike } from '@stdlib/types/complex';
|
|
24
24
|
import { Complex64Array, Complex128Array, AccessorArrayLike } from '@stdlib/types/array';
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -30,7 +30,7 @@ import { Complex64Array, Complex128Array, AccessorArrayLike } from '@stdlib/type
|
|
|
30
30
|
* @param idx - element index
|
|
31
31
|
* @param value - value to set
|
|
32
32
|
*/
|
|
33
|
-
type SetComplex128 = ( arr: Complex128Array, idx: number, value: ComplexLike ) => void;
|
|
33
|
+
type SetComplex128 = ( arr: Complex128Array, idx: number, value: ComplexLike ) => void;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Sets an element in a `Complex64Array`.
|
|
@@ -39,7 +39,7 @@ type SetComplex128 = ( arr: Complex128Array, idx: number, value: ComplexLike ) =
|
|
|
39
39
|
* @param idx - element index
|
|
40
40
|
* @param value - value to set
|
|
41
41
|
*/
|
|
42
|
-
type SetComplex64 = ( arr: Complex64Array, idx: number, value: ComplexLike ) => void;
|
|
42
|
+
type SetComplex64 = ( arr: Complex64Array, idx: number, value: ComplexLike ) => void;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Sets an element in an array-like object supporting the get/set protocol.
|
|
@@ -48,7 +48,7 @@ type SetComplex64 = ( arr: Complex64Array, idx: number, value: ComplexLike ) =>
|
|
|
48
48
|
* @param idx - element index
|
|
49
49
|
* @param value - value to set
|
|
50
50
|
*/
|
|
51
|
-
type SetArrayLike = ( arr: AccessorArrayLike<
|
|
51
|
+
type SetArrayLike<T> = ( arr: AccessorArrayLike<T>, idx: number, value: T ) => void;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Returns an accessor function for setting an element in a `Complex128Array`.
|
|
@@ -57,10 +57,10 @@ type SetArrayLike = ( arr: AccessorArrayLike<any>, idx: number, value: any ) =>
|
|
|
57
57
|
* @returns accessor function
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
|
-
* var Complex128Array = require(
|
|
61
|
-
* var Complex128 = require(
|
|
62
|
-
* var real = require(
|
|
63
|
-
* var imag = require(
|
|
60
|
+
* var Complex128Array = require( '@stdlib/array-complex128' );
|
|
61
|
+
* var Complex128 = require( '@stdlib/complex-float64' );
|
|
62
|
+
* var real = require( '@stdlib/array-real' );
|
|
63
|
+
* var imag = require( '@stdlib/array-imag' );
|
|
64
64
|
*
|
|
65
65
|
* var arr = new Complex128Array( [ 1, 2, 3, 4 ] );
|
|
66
66
|
*
|
|
@@ -85,10 +85,10 @@ declare function setter( dtype: 'complex128' ): SetComplex128;
|
|
|
85
85
|
* @returns accessor function
|
|
86
86
|
*
|
|
87
87
|
* @example
|
|
88
|
-
* var Complex64Array = require(
|
|
89
|
-
* var Complex64 = require(
|
|
90
|
-
* var realf = require(
|
|
91
|
-
* var imagf = require(
|
|
88
|
+
* var Complex64Array = require( '@stdlib/array-complex64' );
|
|
89
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
90
|
+
* var realf = require( '@stdlib/array-realf' );
|
|
91
|
+
* var imagf = require( '@stdlib/array-imagf' );
|
|
92
92
|
*
|
|
93
93
|
* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );
|
|
94
94
|
*
|
|
@@ -132,7 +132,7 @@ declare function setter( dtype: 'complex64' ): SetComplex64;
|
|
|
132
132
|
* var v = arr.get( 2 );
|
|
133
133
|
* // returns 3
|
|
134
134
|
*/
|
|
135
|
-
declare function setter( dtype: string ): SetArrayLike
|
|
135
|
+
declare function setter<T = unknown>( dtype: string ): SetArrayLike<T>;
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
// EXPORTS //
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/array-base-accessor-setter",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Return an accessor function for setting an element in an array-like object supporting the get/set protocol.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,28 +37,29 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/types": "^0.
|
|
40
|
+
"@stdlib/types": "^0.3.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@stdlib/array-base-zero-to": "^0.0
|
|
44
|
-
"@stdlib/array-complex128": "^0.0
|
|
45
|
-
"@stdlib/array-complex64": "^0.0
|
|
46
|
-
"@stdlib/array-dtype": "^0.0
|
|
47
|
-
"@stdlib/array-filled-by": "^0.0
|
|
48
|
-
"@stdlib/assert-is-function": "^0.0
|
|
49
|
-
"@stdlib/
|
|
50
|
-
"@stdlib/complex-
|
|
51
|
-
"@stdlib/complex-
|
|
52
|
-
"@stdlib/complex-
|
|
53
|
-
"@stdlib/complex-
|
|
54
|
-
"@stdlib/complex-
|
|
55
|
-
"@stdlib/
|
|
56
|
-
"@stdlib/math-base-assert-is-
|
|
57
|
-
"@stdlib/
|
|
58
|
-
"@stdlib/random-base-discrete-uniform": "^0.0.x",
|
|
43
|
+
"@stdlib/array-base-zero-to": "^0.1.0",
|
|
44
|
+
"@stdlib/array-complex128": "^0.1.0",
|
|
45
|
+
"@stdlib/array-complex64": "^0.1.0",
|
|
46
|
+
"@stdlib/array-dtype": "^0.1.0",
|
|
47
|
+
"@stdlib/array-filled-by": "^0.1.0",
|
|
48
|
+
"@stdlib/assert-is-function": "^0.2.0",
|
|
49
|
+
"@stdlib/complex-float32": "^0.2.0",
|
|
50
|
+
"@stdlib/complex-float64": "^0.2.0",
|
|
51
|
+
"@stdlib/complex-imag": "^0.2.0",
|
|
52
|
+
"@stdlib/complex-imagf": "^0.2.0",
|
|
53
|
+
"@stdlib/complex-real": "^0.2.0",
|
|
54
|
+
"@stdlib/complex-realf": "^0.2.0",
|
|
55
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.0",
|
|
56
|
+
"@stdlib/math-base-assert-is-nanf": "^0.2.0",
|
|
57
|
+
"@stdlib/random-base-discrete-uniform": "^0.1.0",
|
|
59
58
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
60
59
|
"istanbul": "^0.4.1",
|
|
61
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
60
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
61
|
+
"@stdlib/bench-harness": "^0.2.0",
|
|
62
|
+
"@stdlib/bench": "^0.3.1"
|
|
62
63
|
},
|
|
63
64
|
"engines": {
|
|
64
65
|
"node": ">=0.10.0",
|
|
@@ -86,7 +87,7 @@
|
|
|
86
87
|
"setter"
|
|
87
88
|
],
|
|
88
89
|
"funding": {
|
|
89
|
-
"type": "
|
|
90
|
-
"url": "https://
|
|
90
|
+
"type": "opencollective",
|
|
91
|
+
"url": "https://opencollective.com/stdlib"
|
|
91
92
|
}
|
|
92
93
|
}
|
package/docs/repl.txt
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( dtype )
|
|
3
|
-
Returns an accessor function for setting an element in an array-like object
|
|
4
|
-
supporting the get/set protocol.
|
|
5
|
-
|
|
6
|
-
An accessor function accepts the following arguments:
|
|
7
|
-
|
|
8
|
-
- arr: input array
|
|
9
|
-
- idx: element index
|
|
10
|
-
- value: value to set
|
|
11
|
-
|
|
12
|
-
If provided an unsupported `dtype`, the function returns a default accessor
|
|
13
|
-
function for accessing elements in any indexed array-like object supporting
|
|
14
|
-
the get/set protocol.
|
|
15
|
-
|
|
16
|
-
Otherwise, the function returns an accessor function which should *only* be
|
|
17
|
-
provided an array instance corresponding to `dtype` (e.g., if `dtype` is
|
|
18
|
-
'complex64', the returned accessor function should only be provided
|
|
19
|
-
instances of Complex64Array).
|
|
20
|
-
|
|
21
|
-
Accessor functions do *not* verify that provided input arrays are array
|
|
22
|
-
instances corresponding to `dtype`, as doing so would introduce performance
|
|
23
|
-
overhead. If array instances corresponding to other data types are provided
|
|
24
|
-
to an accessor function, JavaScript runtimes will consider the function
|
|
25
|
-
polymorphic, potentially triggering de-optimization. In order to ensure
|
|
26
|
-
maximum performance, *always* ensure that an accessor function is
|
|
27
|
-
monomorphic.
|
|
28
|
-
|
|
29
|
-
Accessor functions do *not* perform bounds checking.
|
|
30
|
-
|
|
31
|
-
Accessor functions do *not* validate input values.
|
|
32
|
-
|
|
33
|
-
Accessor functions do *not* verify that provided input arrays actually
|
|
34
|
-
implement the get/set protocol.
|
|
35
|
-
|
|
36
|
-
Parameters
|
|
37
|
-
----------
|
|
38
|
-
dtype: string
|
|
39
|
-
Array data type.
|
|
40
|
-
|
|
41
|
-
Returns
|
|
42
|
-
-------
|
|
43
|
-
f: Function
|
|
44
|
-
Accessor function.
|
|
45
|
-
|
|
46
|
-
Examples
|
|
47
|
-
--------
|
|
48
|
-
> var f = {{alias}}( 'complex64' );
|
|
49
|
-
> var x = {{alias:@stdlib/array/complex64}}( [ 1, 2, 3, 4 ] );
|
|
50
|
-
> f( x, 1, new {{alias:@stdlib/complex/float32}}( 10.0, 11.0 ) );
|
|
51
|
-
> var v = x.get( 1 )
|
|
52
|
-
<Complex64>
|
|
53
|
-
> var r = {{alias:@stdlib/complex/realf}}( v )
|
|
54
|
-
10.0
|
|
55
|
-
> var i = {{alias:@stdlib/complex/imagf}}( v )
|
|
56
|
-
11.0
|
|
57
|
-
|
|
58
|
-
See Also
|
|
59
|
-
--------
|
|
60
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2022 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/// <reference types="@stdlib/types"/>
|
|
20
|
-
|
|
21
|
-
import { AccessorArrayLike } from '@stdlib/types/array';
|
|
22
|
-
import Complex128Array = require( '@stdlib/array-complex128' );
|
|
23
|
-
import Complex64Array = require( '@stdlib/array-complex64' );
|
|
24
|
-
import Complex128 = require( '@stdlib/complex-float64' );
|
|
25
|
-
import Complex64 = require( '@stdlib/complex-float32' );
|
|
26
|
-
import setter = require( './index' );
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns an array-like object supporting the get/set protocol.
|
|
30
|
-
*
|
|
31
|
-
* @return array-like object
|
|
32
|
-
*/
|
|
33
|
-
function accessorArray(): AccessorArrayLike<number> {
|
|
34
|
-
let arr: AccessorArrayLike<number>;
|
|
35
|
-
arr = {
|
|
36
|
-
'0': 1,
|
|
37
|
-
'1': 2,
|
|
38
|
-
'2': 3,
|
|
39
|
-
'3': 4,
|
|
40
|
-
'length': 4,
|
|
41
|
-
'get': ( idx: number ): number => {
|
|
42
|
-
return arr[ idx ]; // tslint:disable-line:no-unsafe-any
|
|
43
|
-
},
|
|
44
|
-
'set': ( value: number, idx: number ): void => {
|
|
45
|
-
arr[ idx ] = value;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
return arr;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// TESTS //
|
|
53
|
-
|
|
54
|
-
// The function returns a function...
|
|
55
|
-
{
|
|
56
|
-
setter( 'complex128' ); // $ExpectType SetComplex128
|
|
57
|
-
setter( 'complex64' ); // $ExpectType SetComplex64
|
|
58
|
-
setter( 'foo' ); // $ExpectType SetArrayLike
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// The compiler throws an error if the function is provided a first argument which is not a string...
|
|
62
|
-
{
|
|
63
|
-
setter( 5 ); // $ExpectError
|
|
64
|
-
setter( true ); // $ExpectError
|
|
65
|
-
setter( false ); // $ExpectError
|
|
66
|
-
setter( null ); // $ExpectError
|
|
67
|
-
setter( {} ); // $ExpectError
|
|
68
|
-
setter( [] ); // $ExpectError
|
|
69
|
-
setter( ( x: number ): number => x ); // $ExpectError
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
73
|
-
{
|
|
74
|
-
setter(); // $ExpectError
|
|
75
|
-
setter( 'complex128', {} ); // $ExpectError
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// The function returns a function which sets an array element...
|
|
79
|
-
{
|
|
80
|
-
const set1 = setter( 'foo' );
|
|
81
|
-
const x1 = accessorArray();
|
|
82
|
-
set1( x1, 2, 10 ); // $ExpectType void
|
|
83
|
-
|
|
84
|
-
const set2 = setter( 'complex128' );
|
|
85
|
-
const x2 = new Complex128Array( [ 1, 2, 3, 4 ] );
|
|
86
|
-
set2( x2, 1, new Complex128( 5, 6 ) ); // $ExpectType void
|
|
87
|
-
|
|
88
|
-
const set3 = setter( 'complex64' );
|
|
89
|
-
const x3 = new Complex64Array( [ 1, 2, 3, 4 ] );
|
|
90
|
-
set3( x3, 1, new Complex64( 7, 8 ) ); // $ExpectType void
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// The compiler throws an error if the returned function is provided a first argument which is not a accessor array...
|
|
94
|
-
{
|
|
95
|
-
const set1 = setter( 'foo' );
|
|
96
|
-
set1( 5, 1, 3 ); // $ExpectError
|
|
97
|
-
set1( true, 1, 3 ); // $ExpectError
|
|
98
|
-
set1( false, 1, 3 ); // $ExpectError
|
|
99
|
-
set1( null, 1, 3 ); // $ExpectError
|
|
100
|
-
set1( {}, 1, 3 ); // $ExpectError
|
|
101
|
-
|
|
102
|
-
const set2 = setter( 'complex128' );
|
|
103
|
-
set2( 5, 1, new Complex128( 5, 6 ) ); // $ExpectError
|
|
104
|
-
set2( true, 1, new Complex128( 5, 6 ) ); // $ExpectError
|
|
105
|
-
set2( false, 1, new Complex128( 5, 6 ) ); // $ExpectError
|
|
106
|
-
set2( null, 1, new Complex128( 5, 6 ) ); // $ExpectError
|
|
107
|
-
set2( {}, 1, new Complex128( 5, 6 ) ); // $ExpectError
|
|
108
|
-
|
|
109
|
-
const set3 = setter( 'complex64' );
|
|
110
|
-
set3( 5, 1, new Complex64( 7, 8 ) ); // $ExpectError
|
|
111
|
-
set3( true, 1, new Complex64( 7, 8 ) ); // $ExpectError
|
|
112
|
-
set3( false, 1, new Complex64( 7, 8 ) ); // $ExpectError
|
|
113
|
-
set3( null, 1, new Complex64( 7, 8 ) ); // $ExpectError
|
|
114
|
-
set3( {}, 1, new Complex64( 7, 8 ) ); // $ExpectError
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// The compiler throws an error if the returned function is provided a second argument which is not a number...
|
|
118
|
-
{
|
|
119
|
-
const set1 = setter( 'foo' );
|
|
120
|
-
set1( accessorArray(), '5', 3 ); // $ExpectError
|
|
121
|
-
set1( accessorArray(), true, 3 ); // $ExpectError
|
|
122
|
-
set1( accessorArray(), false, 3 ); // $ExpectError
|
|
123
|
-
set1( accessorArray(), null, 3 ); // $ExpectError
|
|
124
|
-
set1( accessorArray(), {}, 3 ); // $ExpectError
|
|
125
|
-
|
|
126
|
-
const set2 = setter( 'complex128' );
|
|
127
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), '5', new Complex128( 5, 6 ) ); // $ExpectError
|
|
128
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), true, new Complex128( 5, 6 ) ); // $ExpectError
|
|
129
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), false, new Complex128( 5, 6 ) ); // $ExpectError
|
|
130
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), null, new Complex128( 5, 6 ) ); // $ExpectError
|
|
131
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), {}, new Complex128( 5, 6 ) ); // $ExpectError
|
|
132
|
-
|
|
133
|
-
const set3 = setter( 'complex64' );
|
|
134
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), '5', new Complex64( 7, 8 ) ); // $ExpectError
|
|
135
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), true, new Complex64( 7, 8 ) ); // $ExpectError
|
|
136
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), false, new Complex64( 7, 8 ) ); // $ExpectError
|
|
137
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), null, new Complex64( 7, 8 ) ); // $ExpectError
|
|
138
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), {}, new Complex64( 7, 8 ) ); // $ExpectError
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// The compiler throws an error if the returned function is provided a third argument which is not a valid value...
|
|
142
|
-
{
|
|
143
|
-
const set2 = setter( 'complex128' );
|
|
144
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), 1, '5' ); // $ExpectError
|
|
145
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), 1, true ); // $ExpectError
|
|
146
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), 1, false ); // $ExpectError
|
|
147
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), 1, null ); // $ExpectError
|
|
148
|
-
set2( new Complex128Array( [ 1, 2, 3, 4 ] ), 1, {} ); // $ExpectError
|
|
149
|
-
|
|
150
|
-
const set3 = setter( 'complex64' );
|
|
151
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), 1, '5' ); // $ExpectError
|
|
152
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), 1, true ); // $ExpectError
|
|
153
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), 1, false ); // $ExpectError
|
|
154
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), 1, null ); // $ExpectError
|
|
155
|
-
set3( new Complex64Array( [ 1, 2, 3, 4 ] ), 1, {} ); // $ExpectError
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// The compiler throws an error if the returned function is provided an unsupported number of arguments...
|
|
159
|
-
{
|
|
160
|
-
const set1 = setter( 'foo' );
|
|
161
|
-
set1(); // $ExpectError
|
|
162
|
-
set1( [] ); // $ExpectError
|
|
163
|
-
set1( [], 1 ); // $ExpectError
|
|
164
|
-
set1( [], 1, 2, 2 ); // $ExpectError
|
|
165
|
-
|
|
166
|
-
const set2 = setter( 'complex128' );
|
|
167
|
-
set2(); // $ExpectError
|
|
168
|
-
set2( new Complex128Array( [] ) ); // $ExpectError
|
|
169
|
-
set2( new Complex128Array( [] ), 1 ); // $ExpectError
|
|
170
|
-
set2( new Complex128Array( [] ), 1, new Complex128( 5, 6 ), 2 ); // $ExpectError
|
|
171
|
-
|
|
172
|
-
const set3 = setter( 'complex64' );
|
|
173
|
-
set3(); // $ExpectError
|
|
174
|
-
set3( new Complex64Array( [] ) ); // $ExpectError
|
|
175
|
-
set3( new Complex64Array( [] ), 1 ); // $ExpectError
|
|
176
|
-
set3( new Complex64Array( [] ), 1, new Complex64( 7, 8 ), 2 ); // $ExpectError
|
|
177
|
-
}
|