@stdlib/ndarray-base-buffer 0.2.1 → 0.3.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/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.
@@ -33,7 +33,7 @@ limitations under the License.
33
33
 
34
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
35
 
36
- > Create a zero-filled contiguous linear ndarray data buffer.
36
+ > Create a contiguous linear ndarray data buffer.
37
37
 
38
38
  <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
39
39
 
@@ -65,30 +65,14 @@ var buffer = require( '@stdlib/ndarray-base-buffer' );
65
65
 
66
66
  #### buffer( dtype, size )
67
67
 
68
- Returns a zero-filled contiguous linear ndarray data buffer.
68
+ Returns a contiguous linear ndarray data buffer having a specified [data type][@stdlib/ndarray/dtypes].
69
69
 
70
70
  ```javascript
71
71
  var buf = buffer( 'float64', 3 );
72
72
  // returns <Float64Array>[ 0.0, 0.0, 0.0 ]
73
73
  ```
74
74
 
75
- The function supports 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 buf = buffer( 'float', 3 );
@@ -103,6 +87,10 @@ var buf = buffer( 'float', 3 );
103
87
 
104
88
  <section class="notes">
105
89
 
90
+ ## Notes
91
+
92
+ - When provided a numeric [data type][@stdlib/ndarray/dtypes], "generic", or "binary", the function returns a zero-filled contiguous linear ndarray data buffer.
93
+
106
94
  </section>
107
95
 
108
96
  <!-- /.notes -->
@@ -120,9 +108,9 @@ var dtypes = require( '@stdlib/ndarray-dtypes' );
120
108
  var buffer = require( '@stdlib/ndarray-base-buffer' );
121
109
 
122
110
  var DTYPES = dtypes();
111
+
123
112
  var buf;
124
113
  var i;
125
-
126
114
  for ( i = 0; i < DTYPES.length; i++ ) {
127
115
  buf = buffer( DTYPES[ i ], 10 );
128
116
  console.log( buf );
@@ -188,8 +176,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
188
176
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-buffer.svg
189
177
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-buffer
190
178
 
191
- [test-image]: https://github.com/stdlib-js/ndarray-base-buffer/actions/workflows/test.yml/badge.svg?branch=v0.2.1
192
- [test-url]: https://github.com/stdlib-js/ndarray-base-buffer/actions/workflows/test.yml?query=branch:v0.2.1
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
193
181
 
194
182
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-buffer/main.svg
195
183
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-buffer?branch=main
@@ -221,6 +209,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
221
209
 
222
210
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-buffer/main/LICENSE
223
211
 
212
+ [@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
213
+
224
214
  </section>
225
215
 
226
216
  <!-- /.links -->
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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 zero-filled typed array.\n*\n* @private\n* @param {string} dtype - data type\n* @param {NonNegativeInteger} size - buffer size\n* @returns {(TypedArray|null)} zero-filled 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 zero-filled 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 zero-filled 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"],
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
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
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"]
7
7
  }
@@ -22,16 +22,16 @@
22
22
  /// <reference types="node"/>
23
23
 
24
24
  import { Buffer } from 'buffer';
25
- import { TypedArray } from '@stdlib/types/array';
25
+ import { TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array';
26
26
  import { DataType } from '@stdlib/types/ndarray';
27
27
 
28
28
  /**
29
29
  * Array or typed array.
30
30
  */
31
- type ArrayOrBufferOrTypedArray = Array<any> | TypedArray | Buffer | null;
31
+ type ArrayOrBufferOrTypedArray = Array<any> | TypedArray | ComplexTypedArray | BooleanTypedArray | Buffer | null;
32
32
 
33
33
  /**
34
- * Returns a zero-filled contiguous linear ndarray data buffer.
34
+ * Returns a contiguous linear ndarray data buffer.
35
35
  *
36
36
  * @param dtype - data type
37
37
  * @param size - buffer size
package/lib/index.js CHANGED
@@ -19,7 +19,7 @@
19
19
  'use strict';
20
20
 
21
21
  /**
22
- * Create a zero-filled contiguous linear ndarray data buffer.
22
+ * Create a contiguous linear ndarray data buffer.
23
23
  *
24
24
  * @module @stdlib/ndarray-base-buffer
25
25
  *
package/lib/main.js CHANGED
@@ -57,12 +57,12 @@ function binary( size ) {
57
57
  }
58
58
 
59
59
  /**
60
- * Returns a zero-filled typed array.
60
+ * Returns a typed array.
61
61
  *
62
62
  * @private
63
63
  * @param {string} dtype - data type
64
64
  * @param {NonNegativeInteger} size - buffer size
65
- * @returns {(TypedArray|null)} zero-filled typed array
65
+ * @returns {(TypedArray|null)} typed array
66
66
  */
67
67
  function typedarray( dtype, size ) {
68
68
  var ctor = bufferCtors( dtype );
@@ -76,7 +76,7 @@ function typedarray( dtype, size ) {
76
76
  // MAIN //
77
77
 
78
78
  /**
79
- * Returns a zero-filled contiguous linear ndarray data buffer.
79
+ * Returns a contiguous linear ndarray data buffer.
80
80
  *
81
81
  * @param {string} dtype - data type
82
82
  * @param {NonNegativeInteger} size - buffer size
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-buffer",
3
- "version": "0.2.1",
4
- "description": "Create a zero-filled contiguous linear ndarray data buffer.",
3
+ "version": "0.3.0",
4
+ "description": "Create a contiguous linear ndarray data buffer.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
7
7
  "name": "The Stdlib Authors",
@@ -30,8 +30,8 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/buffer-alloc-unsafe": "^0.2.1",
34
- "@stdlib/ndarray-base-buffer-ctors": "^0.2.0"
33
+ "@stdlib/buffer-alloc-unsafe": "^0.2.2",
34
+ "@stdlib/ndarray-base-buffer-ctors": "^0.2.1"
35
35
  },
36
36
  "devDependencies": {},
37
37
  "engines": {