@stdlib/ndarray-base-buffer 0.3.0 → 0.3.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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -163,7 +163,7 @@ See [LICENSE][stdlib-license].
163
163
 
164
164
  ## Copyright
165
165
 
166
- Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
166
+ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
167
167
 
168
168
  </section>
169
169
 
@@ -176,8 +176,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
176
176
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-buffer.svg
177
177
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-buffer
178
178
 
179
- [test-image]: https://github.com/stdlib-js/ndarray-base-buffer/actions/workflows/test.yml/badge.svg?branch=v0.3.0
180
- [test-url]: https://github.com/stdlib-js/ndarray-base-buffer/actions/workflows/test.yml?query=branch:v0.3.0
179
+ [test-image]: https://github.com/stdlib-js/ndarray-base-buffer/actions/workflows/test.yml/badge.svg?branch=v0.3.1
180
+ [test-url]: https://github.com/stdlib-js/ndarray-base-buffer/actions/workflows/test.yml?query=branch:v0.3.1
181
181
 
182
182
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-buffer/main.svg
183
183
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-buffer?branch=main
@@ -189,8 +189,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
189
189
 
190
190
  -->
191
191
 
192
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
193
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
192
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
193
+ [chat-url]: https://stdlib.zulipchat.com
194
194
 
195
195
  [stdlib]: https://github.com/stdlib-js/stdlib
196
196
 
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
- "use strict";var u=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var i=u(function(h,t){
2
- function o(e){var r;for(r=0;r<e.length;r++)e[r]=0;return e}t.exports=o
3
- });var a=u(function(y,f){
4
- var c=require('@stdlib/ndarray-base-buffer-ctors/dist'),s=require('@stdlib/buffer-alloc-unsafe/dist'),v=i();function b(e){var r,n;for(r=[],n=0;n<e;n++)r.push(0);return r}function l(e){return v(s(e))}function q(e,r){var n=c(e);return n?new n(r):null}function g(e,r){return e==="generic"?b(r):e==="binary"?l(r):q(e,r)}f.exports=g
5
- });var p=a();module.exports=p;
1
+ "use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var t=i(function(p,n){
2
+ var a=require('@stdlib/ndarray-base-dtype-resolve-str/dist'),f=require('@stdlib/ndarray-base-buffer-ctors/dist'),o=require('@stdlib/buffer-alloc-unsafe/dist'),v=require('@stdlib/array-base-zeros/dist'),c=require('@stdlib/array-base-fill/dist');function l(e){return c(o(e),0,0,e)}function s(e,r){var u=f(e);return u?new u(r):null}function q(e,r){var u=a(e);return u==="generic"?v(r):u==="binary"?l(r):s(e,r)}n.exports=q
3
+ });var b=t();module.exports=b;
6
4
  /** @license Apache-2.0 */
7
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lib/zeros.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// MAIN //\n\n/**\n* Fills an array-like object with zeros.\n*\n* @private\n* @param {(Array|TypedArray|Buffer)} v - array-like object to fill\n* @returns {(Array|TypedArray|Buffer)} input value\n*\n* @example\n* var arr = zeros( new Array( 2 ) );\n* // returns [ 0, 0 ]\n*/\nfunction zeros( v ) {\n\tvar i;\n\tfor ( i = 0; i < v.length; i++ ) {\n\t\tv[ i ] = 0;\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = zeros;\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 bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\nvar zeros = require( './zeros.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Returns a zero-filled generic array.\n*\n* @private\n* @param {NonNegativeInteger} size - buffer size\n* @returns {Array} zero-filled generic array\n*/\nfunction generic( size ) {\n\tvar buf;\n\tvar i;\n\n\tbuf = [];\n\tfor ( i = 0; i < size; i++ ) {\n\t\tbuf.push( 0 );\n\t}\n\treturn buf;\n}\n\n/**\n* Returns a zero-filled binary buffer.\n*\n* @private\n* @param {NonNegativeInteger} size - buffer size\n* @returns {Buffer} zero-filled binary buffer\n*/\nfunction binary( size ) {\n\treturn zeros( allocUnsafe( size ) );\n}\n\n/**\n* Returns a typed array.\n*\n* @private\n* @param {string} dtype - data type\n* @param {NonNegativeInteger} size - buffer size\n* @returns {(TypedArray|null)} typed array\n*/\nfunction typedarray( dtype, size ) {\n\tvar ctor = bufferCtors( dtype );\n\tif ( ctor ) {\n\t\treturn new ctor( size );\n\t}\n\treturn null;\n}\n\n\n// MAIN //\n\n/**\n* Returns a contiguous linear ndarray data buffer.\n*\n* @param {string} dtype - data type\n* @param {NonNegativeInteger} size - buffer size\n* @returns {(Array|TypedArray|Buffer|null)} data buffer\n*\n* @example\n* var buf = buffer( 'float64', 3 );\n* // returns <Float64Array>[ 0.0, 0.0, 0.0 ]\n*/\nfunction buffer( dtype, size ) {\n\tif ( dtype === 'generic' ) {\n\t\treturn generic( size );\n\t}\n\tif ( dtype === 'binary' ) {\n\t\treturn binary( size );\n\t}\n\treturn typedarray( dtype, size );\n}\n\n\n// EXPORTS //\n\nmodule.exports = buffer;\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* Create a contiguous linear ndarray data buffer.\n*\n* @module @stdlib/ndarray-base-buffer\n*\n* @example\n* var buffer = require( '@stdlib/ndarray-base-buffer' );\n*\n* var buf = buffer( 'float64', 3 );\n* // returns <Float64Array>[ 0.0, 0.0, 0.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,cAiCA,SAASC,EAAOC,EAAI,CACnB,IAAIC,EACJ,IAAMA,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAC1BD,EAAGC,CAAE,EAAI,EAEV,OAAOD,CACR,CAKAF,EAAO,QAAUC,IC5CjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,mCAAoC,EAC3DC,EAAc,QAAS,6BAA8B,EACrDC,EAAQ,IAYZ,SAASC,EAASC,EAAO,CACxB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAME,IACtBD,EAAI,KAAM,CAAE,EAEb,OAAOA,CACR,CASA,SAASE,EAAQH,EAAO,CACvB,OAAOF,EAAOD,EAAaG,CAAK,CAAE,CACnC,CAUA,SAASI,EAAYC,EAAOL,EAAO,CAClC,IAAIM,EAAOV,EAAaS,CAAM,EAC9B,OAAKC,EACG,IAAIA,EAAMN,CAAK,EAEhB,IACR,CAgBA,SAASO,EAAQF,EAAOL,EAAO,CAC9B,OAAKK,IAAU,UACPN,EAASC,CAAK,EAEjBK,IAAU,SACPF,EAAQH,CAAK,EAEdI,EAAYC,EAAOL,CAAK,CAChC,CAKAL,EAAO,QAAUY,ICnEjB,IAAIC,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_zeros", "__commonJSMin", "exports", "module", "zeros", "v", "i", "require_main", "__commonJSMin", "exports", "module", "bufferCtors", "allocUnsafe", "zeros", "generic", "size", "buf", "i", "binary", "typedarray", "dtype", "ctor", "buffer", "main"]
3
+ "sources": ["../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 resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar fill = require( '@stdlib/array-base-fill' );\n\n\n// FUNCTIONS //\n\n/**\n* Returns a zero-filled binary buffer.\n*\n* @private\n* @param {NonNegativeInteger} size - buffer size\n* @returns {Buffer} zero-filled binary buffer\n*/\nfunction binary( size ) {\n\treturn fill( allocUnsafe( size ), 0, 0, size );\n}\n\n/**\n* Returns a typed array.\n*\n* @private\n* @param {*} dtype - data type\n* @param {NonNegativeInteger} size - buffer size\n* @returns {(TypedArray|null)} typed array\n*/\nfunction typedarray( dtype, size ) {\n\tvar ctor = bufferCtors( dtype );\n\tif ( ctor ) {\n\t\treturn new ctor( size );\n\t}\n\treturn null;\n}\n\n\n// MAIN //\n\n/**\n* Returns a contiguous linear ndarray data buffer.\n*\n* @param {*} dtype - data type\n* @param {NonNegativeInteger} size - buffer size\n* @returns {(Array|TypedArray|Buffer|null)} data buffer\n*\n* @example\n* var buf = buffer( 'float64', 3 );\n* // returns <Float64Array>[ 0.0, 0.0, 0.0 ]\n*/\nfunction buffer( dtype, size ) {\n\tvar dt = resolveStr( dtype );\n\tif ( dt === 'generic' ) {\n\t\treturn zeros( size );\n\t}\n\tif ( dt === 'binary' ) {\n\t\treturn binary( size );\n\t}\n\treturn typedarray( dtype, size );\n}\n\n\n// EXPORTS //\n\nmodule.exports = buffer;\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* Create a contiguous linear ndarray data buffer.\n*\n* @module @stdlib/ndarray-base-buffer\n*\n* @example\n* var buffer = require( '@stdlib/ndarray-base-buffer' );\n*\n* var buf = buffer( 'float64', 3 );\n* // returns <Float64Array>[ 0.0, 0.0, 0.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,EAAa,QAAS,wCAAyC,EAC/DC,EAAc,QAAS,mCAAoC,EAC3DC,EAAc,QAAS,6BAA8B,EACrDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAO,QAAS,yBAA0B,EAY9C,SAASC,EAAQC,EAAO,CACvB,OAAOF,EAAMF,EAAaI,CAAK,EAAG,EAAG,EAAGA,CAAK,CAC9C,CAUA,SAASC,EAAYC,EAAOF,EAAO,CAClC,IAAIG,EAAOR,EAAaO,CAAM,EAC9B,OAAKC,EACG,IAAIA,EAAMH,CAAK,EAEhB,IACR,CAgBA,SAASI,EAAQF,EAAOF,EAAO,CAC9B,IAAIK,EAAKX,EAAYQ,CAAM,EAC3B,OAAKG,IAAO,UACJR,EAAOG,CAAK,EAEfK,IAAO,SACJN,EAAQC,CAAK,EAEdC,EAAYC,EAAOF,CAAK,CAChC,CAKAP,EAAO,QAAUW,ICpDjB,IAAIE,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "resolveStr", "bufferCtors", "allocUnsafe", "zeros", "fill", "binary", "size", "typedarray", "dtype", "ctor", "buffer", "dt", "main"]
7
7
  }
package/lib/main.js CHANGED
@@ -20,31 +20,15 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
+ var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );
23
24
  var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );
24
25
  var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
25
- var zeros = require( './zeros.js' );
26
+ var zeros = require( '@stdlib/array-base-zeros' );
27
+ var fill = require( '@stdlib/array-base-fill' );
26
28
 
27
29
 
28
30
  // FUNCTIONS //
29
31
 
30
- /**
31
- * Returns a zero-filled generic array.
32
- *
33
- * @private
34
- * @param {NonNegativeInteger} size - buffer size
35
- * @returns {Array} zero-filled generic array
36
- */
37
- function generic( size ) {
38
- var buf;
39
- var i;
40
-
41
- buf = [];
42
- for ( i = 0; i < size; i++ ) {
43
- buf.push( 0 );
44
- }
45
- return buf;
46
- }
47
-
48
32
  /**
49
33
  * Returns a zero-filled binary buffer.
50
34
  *
@@ -53,14 +37,14 @@ function generic( size ) {
53
37
  * @returns {Buffer} zero-filled binary buffer
54
38
  */
55
39
  function binary( size ) {
56
- return zeros( allocUnsafe( size ) );
40
+ return fill( allocUnsafe( size ), 0, 0, size );
57
41
  }
58
42
 
59
43
  /**
60
44
  * Returns a typed array.
61
45
  *
62
46
  * @private
63
- * @param {string} dtype - data type
47
+ * @param {*} dtype - data type
64
48
  * @param {NonNegativeInteger} size - buffer size
65
49
  * @returns {(TypedArray|null)} typed array
66
50
  */
@@ -78,7 +62,7 @@ function typedarray( dtype, size ) {
78
62
  /**
79
63
  * Returns a contiguous linear ndarray data buffer.
80
64
  *
81
- * @param {string} dtype - data type
65
+ * @param {*} dtype - data type
82
66
  * @param {NonNegativeInteger} size - buffer size
83
67
  * @returns {(Array|TypedArray|Buffer|null)} data buffer
84
68
  *
@@ -87,10 +71,11 @@ function typedarray( dtype, size ) {
87
71
  * // returns <Float64Array>[ 0.0, 0.0, 0.0 ]
88
72
  */
89
73
  function buffer( dtype, size ) {
90
- if ( dtype === 'generic' ) {
91
- return generic( size );
74
+ var dt = resolveStr( dtype );
75
+ if ( dt === 'generic' ) {
76
+ return zeros( size );
92
77
  }
93
- if ( dtype === 'binary' ) {
78
+ if ( dt === 'binary' ) {
94
79
  return binary( size );
95
80
  }
96
81
  return typedarray( dtype, size );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-buffer",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Create a contiguous linear ndarray data buffer.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,8 +30,11 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/buffer-alloc-unsafe": "^0.2.2",
34
- "@stdlib/ndarray-base-buffer-ctors": "^0.2.1"
33
+ "@stdlib/array-base-fill": "^0.1.0",
34
+ "@stdlib/array-base-zeros": "^0.2.3",
35
+ "@stdlib/buffer-alloc-unsafe": "^0.2.3",
36
+ "@stdlib/ndarray-base-buffer-ctors": "^0.4.0",
37
+ "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1"
35
38
  },
36
39
  "devDependencies": {},
37
40
  "engines": {
@@ -67,7 +70,6 @@
67
70
  "utils",
68
71
  "util"
69
72
  ],
70
- "__stdlib__": {},
71
73
  "funding": {
72
74
  "type": "opencollective",
73
75
  "url": "https://opencollective.com/stdlib"
package/lib/zeros.js DELETED
@@ -1,45 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 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
- // MAIN //
22
-
23
- /**
24
- * Fills an array-like object with zeros.
25
- *
26
- * @private
27
- * @param {(Array|TypedArray|Buffer)} v - array-like object to fill
28
- * @returns {(Array|TypedArray|Buffer)} input value
29
- *
30
- * @example
31
- * var arr = zeros( new Array( 2 ) );
32
- * // returns [ 0, 0 ]
33
- */
34
- function zeros( v ) {
35
- var i;
36
- for ( i = 0; i < v.length; i++ ) {
37
- v[ i ] = 0;
38
- }
39
- return v;
40
- }
41
-
42
-
43
- // EXPORTS //
44
-
45
- module.exports = zeros;