@stdlib/ndarray-base-buffer-ctors 0.2.1 → 0.4.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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  @license Apache-2.0
4
4
 
5
- Copyright (c) 2018 The Stdlib Authors.
5
+ Copyright (c) 2024 The Stdlib Authors.
6
6
 
7
7
  Licensed under the Apache License, Version 2.0 (the "License");
8
8
  you may not use this file except in compliance with the License.
@@ -65,30 +65,14 @@ var ctors = require( '@stdlib/ndarray-base-buffer-ctors' );
65
65
 
66
66
  #### ctors( dtype )
67
67
 
68
- Returns an ndarray data buffer constructor for a specified data type.
68
+ Returns an ndarray data buffer constructor for a specified [data type][@stdlib/ndarray/dtypes].
69
69
 
70
70
  ```javascript
71
71
  var ctor = ctors( 'float64' );
72
72
  // returns <Function>
73
73
  ```
74
74
 
75
- The function returns constructors for the following data types:
76
-
77
- - `binary`: binary.
78
- - `complex64`: single-precision complex floating-point numbers.
79
- - `complex128`: double-precision complex floating-point numbers.
80
- - `float32`: single-precision floating-point numbers.
81
- - `float64`: double-precision floating-point numbers.
82
- - `generic`: values of any type.
83
- - `int16`: signed 16-bit integers.
84
- - `int32`: signed 32-bit integers.
85
- - `int8`: signed 8-bit integers.
86
- - `uint16`: unsigned 16-bit integers.
87
- - `uint32`: unsigned 32-bit integers.
88
- - `uint8`: unsigned 8-bit integers.
89
- - `uint8c`: unsigned clamped 8-bit integers.
90
-
91
- If provided an unknown or unsupported data type, the function returns `null`.
75
+ If provided an unknown or unsupported [data type][@stdlib/ndarray/dtypes], the function returns `null`.
92
76
 
93
77
  ```javascript
94
78
  var ctor = ctors( 'float' );
@@ -116,17 +100,12 @@ var ctor = ctors( 'float' );
116
100
  <!-- eslint no-undef: "error" -->
117
101
 
118
102
  ```javascript
103
+ var logEachMap = require( '@stdlib/console-log-each-map' );
119
104
  var dtypes = require( '@stdlib/ndarray-dtypes' );
120
105
  var ctors = require( '@stdlib/ndarray-base-buffer-ctors' );
121
106
 
122
- var DTYPES = dtypes();
123
- var ctor;
124
- var i;
125
-
126
- for ( i = 0; i < DTYPES.length; i++ ) {
127
- ctor = ctors( DTYPES[ i ] );
128
- console.log( ctor );
129
- }
107
+ var dts = dtypes( 'integer_and_generic' );
108
+ logEachMap( '%s => %s', dts, ctors );
130
109
  ```
131
110
 
132
111
  </section>
@@ -175,7 +154,7 @@ See [LICENSE][stdlib-license].
175
154
 
176
155
  ## Copyright
177
156
 
178
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
157
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
179
158
 
180
159
  </section>
181
160
 
@@ -188,8 +167,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
188
167
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-buffer-ctors.svg
189
168
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-buffer-ctors
190
169
 
191
- [test-image]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml/badge.svg?branch=v0.2.1
192
- [test-url]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml?query=branch:v0.2.1
170
+ [test-image]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml/badge.svg?branch=v0.4.0
171
+ [test-url]: https://github.com/stdlib-js/ndarray-base-buffer-ctors/actions/workflows/test.yml?query=branch:v0.4.0
193
172
 
194
173
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-buffer-ctors/main.svg
195
174
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-buffer-ctors?branch=main
@@ -201,8 +180,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
201
180
 
202
181
  -->
203
182
 
204
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
205
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
183
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
184
+ [chat-url]: https://stdlib.zulipchat.com
206
185
 
207
186
  [stdlib]: https://github.com/stdlib-js/stdlib
208
187
 
@@ -221,6 +200,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
221
200
 
222
201
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-buffer-ctors/main/LICENSE
223
202
 
203
+ [@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
204
+
224
205
  </section>
225
206
 
226
207
  <!-- /.links -->
package/dist/index.js CHANGED
@@ -1,7 +1,36 @@
1
- "use strict";var a=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var t=a(function(d,i){
2
- var v=require('@stdlib/buffer-ctor/dist'),o=require('@stdlib/array-float64/dist'),q=require('@stdlib/array-float32/dist'),y=require('@stdlib/array-int16/dist'),l=require('@stdlib/array-int32/dist'),A=require('@stdlib/array-int8/dist'),s=require('@stdlib/array-uint16/dist'),c=require('@stdlib/array-uint32/dist'),p=require('@stdlib/array-uint8/dist'),x=require('@stdlib/array-uint8c/dist'),m=require('@stdlib/array-complex64/dist'),f=require('@stdlib/array-complex128/dist'),U={binary:v,float64:o,float32:q,generic:Array,int16:y,int32:l,int8:A,uint16:s,uint32:c,uint8:p,uint8c:x,complex64:m,complex128:f};i.exports=U
3
- });var n=a(function(g,u){
4
- var C=t();function I(e){return C[e]||null}u.exports=I
5
- });var b=n();module.exports=b;
6
- /** @license Apache-2.0 */
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
+ */
7
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) 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 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' );\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};\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 {string} 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\treturn table[ dtype ] || 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,EAMtDC,EAAQ,CACX,OAAUZ,EACV,QAAWC,EACX,QAAWC,EACX,QAAW,MACX,MAASC,EACT,MAASC,EACT,KAAQC,EACR,OAAUC,EACV,OAAUC,EACV,MAASC,EACT,OAAUC,EACV,UAAaC,EACb,WAAcC,CACf,EAKAZ,EAAO,QAAUa,IC1DjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAmBZ,SAASC,EAAOC,EAAQ,CACvB,OAAOF,EAAOE,CAAM,GAAK,IAC1B,CAKAH,EAAO,QAAUE,ICXjB,IAAIE,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_ctors", "__commonJSMin", "exports", "module", "Buffer", "Float64Array", "Float32Array", "Int16Array", "Int32Array", "Int8Array", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray", "Complex64Array", "Complex128Array", "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
  }
@@ -32,7 +32,7 @@
32
32
  * var ctor = ctors( 'float' );
33
33
  * // returns null
34
34
  */
35
- declare function ctors( dtype: string ): Function | null;
35
+ declare function ctors( dtype: any ): Function | null;
36
36
 
37
37
 
38
38
  // EXPORTS //
package/lib/ctors.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2018 The Stdlib Authors.
4
+ * Copyright (c) 2024 The Stdlib Authors.
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -32,15 +32,30 @@ var Uint8Array = require( '@stdlib/array-uint8' );
32
32
  var Uint8ClampedArray = require( '@stdlib/array-uint8c' );
33
33
  var Complex64Array = require( '@stdlib/array-complex64' );
34
34
  var Complex128Array = require( '@stdlib/array-complex128' );
35
+ var BooleanArray = require( '@stdlib/array-bool' );
36
+
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
+ }
35
49
 
36
50
 
37
51
  // MAIN //
38
52
 
39
53
  // Mapping from data types to underlying buffer constructors...
40
- var ctors = {
54
+ var ctors = { // eslint-disable-line vars-on-top
41
55
  'binary': Buffer,
42
56
  'float64': Float64Array,
43
57
  'float32': Float32Array,
58
+ 'float16': notImplemented, // FIXME: replace with Float16Array constructor once implemented
44
59
  'generic': Array, // TODO: replace with `stdlib` pkg
45
60
  'int16': Int16Array,
46
61
  'int32': Int32Array,
@@ -49,8 +64,10 @@ var ctors = {
49
64
  'uint32': Uint32Array,
50
65
  'uint8': Uint8Array,
51
66
  'uint8c': Uint8ClampedArray,
67
+ 'complex32': notImplemented, // FIXME: replace with Complex32Array constructor once implemented
52
68
  'complex64': Complex64Array,
53
- 'complex128': Complex128Array
69
+ 'complex128': Complex128Array,
70
+ 'bool': BooleanArray
54
71
  };
55
72
 
56
73
 
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 {string} dtype - data type
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
- return table[ dtype ] || null;
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.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "ndarray data buffer constructors.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,18 +30,23 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/array-complex128": "^0.2.1",
34
- "@stdlib/array-complex64": "^0.2.1",
35
- "@stdlib/array-float32": "^0.2.1",
36
- "@stdlib/array-float64": "^0.2.1",
37
- "@stdlib/array-int16": "^0.2.1",
38
- "@stdlib/array-int32": "^0.2.1",
39
- "@stdlib/array-int8": "^0.2.1",
40
- "@stdlib/array-uint16": "^0.2.1",
41
- "@stdlib/array-uint32": "^0.2.1",
42
- "@stdlib/array-uint8": "^0.2.1",
43
- "@stdlib/array-uint8c": "^0.2.1",
44
- "@stdlib/buffer-ctor": "^0.2.1"
33
+ "@stdlib/array-bool": "^0.1.1",
34
+ "@stdlib/array-complex128": "^0.3.1",
35
+ "@stdlib/array-complex64": "^0.3.1",
36
+ "@stdlib/array-float32": "^0.2.2",
37
+ "@stdlib/array-float64": "^0.2.2",
38
+ "@stdlib/array-int16": "^0.2.2",
39
+ "@stdlib/array-int32": "^0.2.2",
40
+ "@stdlib/array-int8": "^0.2.2",
41
+ "@stdlib/array-struct-factory": "github:stdlib-js/array-struct-factory#main",
42
+ "@stdlib/array-uint16": "^0.2.2",
43
+ "@stdlib/array-uint32": "^0.2.2",
44
+ "@stdlib/array-uint8": "^0.2.2",
45
+ "@stdlib/array-uint8c": "^0.2.2",
46
+ "@stdlib/assert-is-function": "^0.2.2",
47
+ "@stdlib/buffer-ctor": "^0.2.2",
48
+ "@stdlib/ndarray-base-assert-is-struct-data-type": "^0.1.0",
49
+ "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.0"
45
50
  },
46
51
  "devDependencies": {},
47
52
  "engines": {
@@ -80,7 +85,6 @@
80
85
  "utils",
81
86
  "util"
82
87
  ],
83
- "__stdlib__": {},
84
88
  "funding": {
85
89
  "type": "opencollective",
86
90
  "url": "https://opencollective.com/stdlib"