@stdlib/ndarray-base-buffer-ctors 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +8 -13
- package/dist/index.js +35 -7
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +1 -1
- package/lib/ctors.js +16 -1
- package/lib/main.js +42 -2
- package/package.json +18 -15
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -100,17 +100,12 @@ var ctor = ctors( 'float' );
|
|
|
100
100
|
<!-- eslint no-undef: "error" -->
|
|
101
101
|
|
|
102
102
|
```javascript
|
|
103
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
103
104
|
var dtypes = require( '@stdlib/ndarray-dtypes' );
|
|
104
105
|
var ctors = require( '@stdlib/ndarray-base-buffer-ctors' );
|
|
105
106
|
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
var ctor;
|
|
109
|
-
var i;
|
|
110
|
-
for ( i = 0; i < DTYPES.length; i++ ) {
|
|
111
|
-
ctor = ctors( DTYPES[ i ] );
|
|
112
|
-
console.log( ctor );
|
|
113
|
-
}
|
|
107
|
+
var dts = dtypes( 'integer_and_generic' );
|
|
108
|
+
logEachMap( '%s => %s', dts, ctors );
|
|
114
109
|
```
|
|
115
110
|
|
|
116
111
|
</section>
|
|
@@ -159,7 +154,7 @@ See [LICENSE][stdlib-license].
|
|
|
159
154
|
|
|
160
155
|
## Copyright
|
|
161
156
|
|
|
162
|
-
Copyright © 2016-
|
|
157
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
163
158
|
|
|
164
159
|
</section>
|
|
165
160
|
|
|
@@ -172,8 +167,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
172
167
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-buffer-ctors.svg
|
|
173
168
|
[npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-buffer-ctors
|
|
174
169
|
|
|
175
|
-
[test-image]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
176
|
-
[test-url]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml?query=branch:v0.
|
|
170
|
+
[test-image]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml/badge.svg?branch=v0.4.1
|
|
171
|
+
[test-url]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml?query=branch:v0.4.1
|
|
177
172
|
|
|
178
173
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-buffer-ctors/main.svg
|
|
179
174
|
[coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-buffer-ctors?branch=main
|
|
@@ -185,8 +180,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
185
180
|
|
|
186
181
|
-->
|
|
187
182
|
|
|
188
|
-
[chat-image]: https://img.shields.io/
|
|
189
|
-
[chat-url]: https://
|
|
183
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
184
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
190
185
|
|
|
191
186
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
192
187
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";var i=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var o=i(function(T,n){"use strict";var c=require("@stdlib/buffer-ctor"),s=require("@stdlib/array-float64"),y=require("@stdlib/array-float32"),A=require("@stdlib/array-int16"),f=require("@stdlib/array-int32"),m=require("@stdlib/array-int8"),p=require("@stdlib/array-uint16"),x=require("@stdlib/array-uint32"),C=require("@stdlib/array-uint8"),F=require("@stdlib/array-uint8c"),I=require("@stdlib/array-complex64"),U=require("@stdlib/array-complex128"),b=require("@stdlib/array-bool");function u(){throw new Error("not implemented")}var w={binary:c,float64:s,float32:y,float16:u,generic:Array,int16:A,int32:f,int8:m,uint16:p,uint32:x,uint8:C,uint8c:F,complex32:u,complex64:I,complex128:U,bool:b};n.exports=w});var q=i(function(j,l){"use strict";var B=require("@stdlib/assert-is-function"),E=require("@stdlib/ndarray-base-assert-is-struct-data-type"),S=require("@stdlib/ndarray-base-dtype-resolve-str"),g=require("@stdlib/array-struct-factory"),h=o(),v={};function k(a){var r,e,t;return!B(a)&&(t=S(a),e=h[t]||null,e)?e:E(a)?(t?r=a.value:(r=a,t=r.layout),e=v[t],e||(e=g(r),v[t]=e,e)):null}l.exports=k});var D=q();module.exports=D;
|
|
2
|
+
/**
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2024 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
|
+
* @license Apache-2.0
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) 2018 The Stdlib Authors.
|
|
23
|
+
*
|
|
24
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
25
|
+
* you may not use this file except in compliance with the License.
|
|
26
|
+
* You may obtain a copy of the License at
|
|
27
|
+
*
|
|
28
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29
|
+
*
|
|
30
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
31
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
32
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33
|
+
* See the License for the specific language governing permissions and
|
|
34
|
+
* limitations under the License.
|
|
35
|
+
*/
|
|
8
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/ctors.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 Buffer = require( '@stdlib/buffer-ctor' );\nvar Float64Array = require( '@stdlib/array-float64' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Complex64Array = require( '@stdlib/array-complex64' );\nvar Complex128Array = require( '@stdlib/array-complex128' );\nvar BooleanArray = require( '@stdlib/array-bool' );\n\n\n// MAIN //\n\n// Mapping from data types to underlying buffer constructors...\nvar ctors = {\n\t'binary': Buffer,\n\t'float64': Float64Array,\n\t'float32': Float32Array,\n\t'generic': Array, // TODO: replace with `stdlib` pkg\n\t'int16': Int16Array,\n\t'int32': Int32Array,\n\t'int8': Int8Array,\n\t'uint16': Uint16Array,\n\t'uint32': Uint32Array,\n\t'uint8': Uint8Array,\n\t'uint8c': Uint8ClampedArray,\n\t'complex64': Complex64Array,\n\t'complex128': Complex128Array,\n\t'bool': BooleanArray\n};\n\n\n// EXPORTS //\n\nmodule.exports = ctors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 table = require( './ctors.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray data buffer constructor.\n*\n* @param {
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,qBAAsB,EACxCC,EAAe,QAAS,uBAAwB,EAChDC,EAAe,QAAS,uBAAwB,EAChDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAY,QAAS,oBAAqB,EAC1CC,EAAc,QAAS,sBAAuB,EAC9CC,EAAc,QAAS,sBAAuB,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAoB,QAAS,sBAAuB,EACpDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAkB,QAAS,0BAA2B,EACtDC,EAAe,QAAS,oBAAqB,
|
|
6
|
-
"names": ["require_ctors", "__commonJSMin", "exports", "module", "Buffer", "Float64Array", "Float32Array", "Int16Array", "Int32Array", "Int8Array", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray", "Complex64Array", "Complex128Array", "BooleanArray", "ctors", "require_main", "__commonJSMin", "exports", "module", "table", "ctors", "dtype", "main"]
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 Buffer = require( '@stdlib/buffer-ctor' );\nvar Float64Array = require( '@stdlib/array-float64' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Complex64Array = require( '@stdlib/array-complex64' );\nvar Complex128Array = require( '@stdlib/array-complex128' );\nvar BooleanArray = require( '@stdlib/array-bool' );\n\n\n// FUNCTIONS //\n\n/**\n* Throws an error.\n*\n* @private\n* @throws {Error} not implemented\n*/\nfunction notImplemented() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// MAIN //\n\n// Mapping from data types to underlying buffer constructors...\nvar ctors = { // eslint-disable-line vars-on-top\n\t'binary': Buffer,\n\t'float64': Float64Array,\n\t'float32': Float32Array,\n\t'float16': notImplemented, // FIXME: replace with Float16Array constructor once implemented\n\t'generic': Array, // TODO: replace with `stdlib` pkg\n\t'int16': Int16Array,\n\t'int32': Int32Array,\n\t'int8': Int8Array,\n\t'uint16': Uint16Array,\n\t'uint32': Uint32Array,\n\t'uint8': Uint8Array,\n\t'uint8c': Uint8ClampedArray,\n\t'complex32': notImplemented, // FIXME: replace with Complex32Array constructor once implemented\n\t'complex64': Complex64Array,\n\t'complex128': Complex128Array,\n\t'bool': BooleanArray\n};\n\n\n// EXPORTS //\n\nmodule.exports = ctors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isFunction = require( '@stdlib/assert-is-function' );\nvar isStructDataType = require( '@stdlib/ndarray-base-assert-is-struct-data-type' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar structFactory = require( '@stdlib/array-struct-factory' );\nvar table = require( './ctors.js' );\n\n\n// VARIABLES //\n\n// Initialize a cache to storing memoized struct array constructors:\nvar CACHE = {}; // TODO: consider adding/using `@stdlib/array/memoized-struct-factory`; should we need to memoize struct array constructors elsewhere, we should centralize that logic, rather than have multiple caches.\n\n\n// MAIN //\n\n/**\n* Returns an ndarray data buffer constructor.\n*\n* @param {*} dtype - data type\n* @returns {(Function|null)} data buffer constructor or null\n*\n* @example\n* var ctor = ctors( 'float64' );\n* // returns <Function>\n*\n* @example\n* var ctor = ctors( 'float' );\n* // returns null\n*/\nfunction ctors( dtype ) {\n\tvar struct;\n\tvar ctor;\n\tvar key;\n\n\t// Case: string || dtype_instance_with_string\n\tif ( !isFunction( dtype ) ) {\n\t\tkey = resolveStr( dtype );\n\t\tctor = table[ key ] || null;\n\t\tif ( ctor ) {\n\t\t\treturn ctor;\n\t\t}\n\t}\n\t// Case: struct_ctor || dtype_instance_with_struct_ctor\n\tif ( isStructDataType( dtype ) ) {\n\t\tif ( key ) {\n\t\t\t// Data type instance (note: we assume that `key === struct.layout`):\n\t\t\tstruct = dtype.value;\n\t\t} else {\n\t\t\t// Struct constructor:\n\t\t\tstruct = dtype;\n\t\t\tkey = struct.layout;\n\t\t}\n\t\tctor = CACHE[ key ];\n\t\tif ( ctor ) {\n\t\t\treturn ctor;\n\t\t}\n\t\tctor = structFactory( struct );\n\t\tCACHE[ key ] = ctor;\n\t\treturn ctor;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctors;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* ndarray data buffer constructors.\n*\n* @module @stdlib/ndarray-base-buffer-ctors\n*\n* @example\n* var ctors = require( '@stdlib/ndarray-base-buffer-ctors' );\n*\n* var ctor = ctors( 'float64' );\n* // returns <Function>\n*\n* ctor = ctors( 'int' );\n* // returns null\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,EAAS,QAAS,qBAAsB,EACxCC,EAAe,QAAS,uBAAwB,EAChDC,EAAe,QAAS,uBAAwB,EAChDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAY,QAAS,oBAAqB,EAC1CC,EAAc,QAAS,sBAAuB,EAC9CC,EAAc,QAAS,sBAAuB,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAoB,QAAS,sBAAuB,EACpDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAkB,QAAS,0BAA2B,EACtDC,EAAe,QAAS,oBAAqB,EAWjD,SAASC,GAAiB,CACzB,MAAM,IAAI,MAAO,iBAAkB,CACpC,CAMA,IAAIC,EAAQ,CACX,OAAUd,EACV,QAAWC,EACX,QAAWC,EACX,QAAWW,EACX,QAAW,MACX,MAASV,EACT,MAASC,EACT,KAAQC,EACR,OAAUC,EACV,OAAUC,EACV,MAASC,EACT,OAAUC,EACV,UAAaI,EACb,UAAaH,EACb,WAAcC,EACd,KAAQC,CACT,EAKAb,EAAO,QAAUe,IC3EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAmB,QAAS,iDAAkD,EAC9EC,EAAa,QAAS,wCAAyC,EAC/DC,EAAgB,QAAS,8BAA+B,EACxDC,EAAQ,IAMRC,EAAQ,CAAC,EAmBb,SAASC,EAAOC,EAAQ,CACvB,IAAIC,EACAC,EACAC,EAGJ,MAAK,CAACV,EAAYO,CAAM,IACvBG,EAAMR,EAAYK,CAAM,EACxBE,EAAOL,EAAOM,CAAI,GAAK,KAClBD,GACGA,EAIJR,EAAkBM,CAAM,GACvBG,EAEJF,EAASD,EAAM,OAGfC,EAASD,EACTG,EAAMF,EAAO,QAEdC,EAAOJ,EAAOK,CAAI,EACbD,IAGLA,EAAON,EAAeK,CAAO,EAC7BH,EAAOK,CAAI,EAAID,EACRA,IAED,IACR,CAKAV,EAAO,QAAUO,ICnDjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_ctors", "__commonJSMin", "exports", "module", "Buffer", "Float64Array", "Float32Array", "Int16Array", "Int32Array", "Int8Array", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray", "Complex64Array", "Complex128Array", "BooleanArray", "notImplemented", "ctors", "require_main", "__commonJSMin", "exports", "module", "isFunction", "isStructDataType", "resolveStr", "structFactory", "table", "CACHE", "ctors", "dtype", "struct", "ctor", "key", "main"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
package/lib/ctors.js
CHANGED
|
@@ -35,13 +35,27 @@ var Complex128Array = require( '@stdlib/array-complex128' );
|
|
|
35
35
|
var BooleanArray = require( '@stdlib/array-bool' );
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
// FUNCTIONS //
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Throws an error.
|
|
42
|
+
*
|
|
43
|
+
* @private
|
|
44
|
+
* @throws {Error} not implemented
|
|
45
|
+
*/
|
|
46
|
+
function notImplemented() {
|
|
47
|
+
throw new Error( 'not implemented' );
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
38
51
|
// MAIN //
|
|
39
52
|
|
|
40
53
|
// Mapping from data types to underlying buffer constructors...
|
|
41
|
-
var ctors = {
|
|
54
|
+
var ctors = { // eslint-disable-line vars-on-top
|
|
42
55
|
'binary': Buffer,
|
|
43
56
|
'float64': Float64Array,
|
|
44
57
|
'float32': Float32Array,
|
|
58
|
+
'float16': notImplemented, // FIXME: replace with Float16Array constructor once implemented
|
|
45
59
|
'generic': Array, // TODO: replace with `stdlib` pkg
|
|
46
60
|
'int16': Int16Array,
|
|
47
61
|
'int32': Int32Array,
|
|
@@ -50,6 +64,7 @@ var ctors = {
|
|
|
50
64
|
'uint32': Uint32Array,
|
|
51
65
|
'uint8': Uint8Array,
|
|
52
66
|
'uint8c': Uint8ClampedArray,
|
|
67
|
+
'complex32': notImplemented, // FIXME: replace with Complex32Array constructor once implemented
|
|
53
68
|
'complex64': Complex64Array,
|
|
54
69
|
'complex128': Complex128Array,
|
|
55
70
|
'bool': BooleanArray
|
package/lib/main.js
CHANGED
|
@@ -20,15 +20,25 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
+
var isFunction = require( '@stdlib/assert-is-function' );
|
|
24
|
+
var isStructDataType = require( '@stdlib/ndarray-base-assert-is-struct-data-type' );
|
|
25
|
+
var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );
|
|
26
|
+
var structFactory = require( '@stdlib/array-struct-factory' );
|
|
23
27
|
var table = require( './ctors.js' );
|
|
24
28
|
|
|
25
29
|
|
|
30
|
+
// VARIABLES //
|
|
31
|
+
|
|
32
|
+
// Initialize a cache to storing memoized struct array constructors:
|
|
33
|
+
var CACHE = {}; // TODO: consider adding/using `@stdlib/array/memoized-struct-factory`; should we need to memoize struct array constructors elsewhere, we should centralize that logic, rather than have multiple caches.
|
|
34
|
+
|
|
35
|
+
|
|
26
36
|
// MAIN //
|
|
27
37
|
|
|
28
38
|
/**
|
|
29
39
|
* Returns an ndarray data buffer constructor.
|
|
30
40
|
*
|
|
31
|
-
* @param {
|
|
41
|
+
* @param {*} dtype - data type
|
|
32
42
|
* @returns {(Function|null)} data buffer constructor or null
|
|
33
43
|
*
|
|
34
44
|
* @example
|
|
@@ -40,7 +50,37 @@ var table = require( './ctors.js' );
|
|
|
40
50
|
* // returns null
|
|
41
51
|
*/
|
|
42
52
|
function ctors( dtype ) {
|
|
43
|
-
|
|
53
|
+
var struct;
|
|
54
|
+
var ctor;
|
|
55
|
+
var key;
|
|
56
|
+
|
|
57
|
+
// Case: string || dtype_instance_with_string
|
|
58
|
+
if ( !isFunction( dtype ) ) {
|
|
59
|
+
key = resolveStr( dtype );
|
|
60
|
+
ctor = table[ key ] || null;
|
|
61
|
+
if ( ctor ) {
|
|
62
|
+
return ctor;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Case: struct_ctor || dtype_instance_with_struct_ctor
|
|
66
|
+
if ( isStructDataType( dtype ) ) {
|
|
67
|
+
if ( key ) {
|
|
68
|
+
// Data type instance (note: we assume that `key === struct.layout`):
|
|
69
|
+
struct = dtype.value;
|
|
70
|
+
} else {
|
|
71
|
+
// Struct constructor:
|
|
72
|
+
struct = dtype;
|
|
73
|
+
key = struct.layout;
|
|
74
|
+
}
|
|
75
|
+
ctor = CACHE[ key ];
|
|
76
|
+
if ( ctor ) {
|
|
77
|
+
return ctor;
|
|
78
|
+
}
|
|
79
|
+
ctor = structFactory( struct );
|
|
80
|
+
CACHE[ key ] = ctor;
|
|
81
|
+
return ctor;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
44
84
|
}
|
|
45
85
|
|
|
46
86
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/ndarray-base-buffer-ctors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "ndarray data buffer constructors.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,19 +30,23 @@
|
|
|
30
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@stdlib/array-bool": "^0.
|
|
34
|
-
"@stdlib/array-complex128": "^0.2
|
|
35
|
-
"@stdlib/array-complex64": "^0.2
|
|
36
|
-
"@stdlib/array-float32": "^0.2.
|
|
37
|
-
"@stdlib/array-float64": "^0.2.
|
|
38
|
-
"@stdlib/array-int16": "^0.2.
|
|
39
|
-
"@stdlib/array-int32": "^0.2.
|
|
40
|
-
"@stdlib/array-int8": "^0.2.
|
|
41
|
-
"@stdlib/array-
|
|
42
|
-
"@stdlib/array-
|
|
43
|
-
"@stdlib/array-
|
|
44
|
-
"@stdlib/array-
|
|
45
|
-
"@stdlib/
|
|
33
|
+
"@stdlib/array-bool": "^0.1.2",
|
|
34
|
+
"@stdlib/array-complex128": "^0.3.2",
|
|
35
|
+
"@stdlib/array-complex64": "^0.3.2",
|
|
36
|
+
"@stdlib/array-float32": "^0.2.3",
|
|
37
|
+
"@stdlib/array-float64": "^0.2.3",
|
|
38
|
+
"@stdlib/array-int16": "^0.2.3",
|
|
39
|
+
"@stdlib/array-int32": "^0.2.3",
|
|
40
|
+
"@stdlib/array-int8": "^0.2.3",
|
|
41
|
+
"@stdlib/array-struct-factory": "^0.1.0",
|
|
42
|
+
"@stdlib/array-uint16": "^0.2.3",
|
|
43
|
+
"@stdlib/array-uint32": "^0.2.3",
|
|
44
|
+
"@stdlib/array-uint8": "^0.2.3",
|
|
45
|
+
"@stdlib/array-uint8c": "^0.2.3",
|
|
46
|
+
"@stdlib/assert-is-function": "^0.2.3",
|
|
47
|
+
"@stdlib/buffer-ctor": "^0.2.3",
|
|
48
|
+
"@stdlib/ndarray-base-assert-is-struct-data-type": "^0.1.1",
|
|
49
|
+
"@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {},
|
|
48
52
|
"engines": {
|
|
@@ -81,7 +85,6 @@
|
|
|
81
85
|
"utils",
|
|
82
86
|
"util"
|
|
83
87
|
],
|
|
84
|
-
"__stdlib__": {},
|
|
85
88
|
"funding": {
|
|
86
89
|
"type": "opencollective",
|
|
87
90
|
"url": "https://opencollective.com/stdlib"
|