diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e199452..75e9a792 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,28 @@ +
+ +#### [@stdlib/ndarray/base/buffer](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/buffer) + +
+ +
+ +##### Features + +- [`fa118f2`](https://github.com/stdlib-js/stdlib/commit/fa118f279848e1c85ea6e5cf9799f3089649214c) - add boolean dtype support to `ndarray/base/buffer` [(#2574)](https://github.com/stdlib-js/stdlib/pull/2574) + +
+ + + +
+ +
+ + +
#### [@stdlib/ndarray/base/buffer-ctors](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/buffer-ctors) @@ -463,6 +485,7 @@ A total of 3 people contributed to this release. Thank you to the following cont
+- [`fa118f2`](https://github.com/stdlib-js/stdlib/commit/fa118f279848e1c85ea6e5cf9799f3089649214c) - **feat:** add boolean dtype support to `ndarray/base/buffer` [(#2574)](https://github.com/stdlib-js/stdlib/pull/2574) _(by Jaysukh Makvana, Athan Reines)_ - [`e92152b`](https://github.com/stdlib-js/stdlib/commit/e92152baba61ab358640cba9d0506d75123a5f60) - **feat:** add boolean dtype support to `ndarray/defaults` [(#2551)](https://github.com/stdlib-js/stdlib/pull/2551) _(by Jaysukh Makvana, Athan Reines)_ - [`16e0808`](https://github.com/stdlib-js/stdlib/commit/16e0808004b7bd4f16eea7eced5229ee1120b577) - **feat:** add boolean dtype support to `ndarray/dtypes` [(#2550)](https://github.com/stdlib-js/stdlib/pull/2550) _(by Jaysukh Makvana, Athan Reines)_ - [`21052a2`](https://github.com/stdlib-js/stdlib/commit/21052a211289b86b0e8a2e1f43a4d4c5b2379ffb) - **feat:** add boolean dtype support to `ndarray/min-dtype` [(#2552)](https://github.com/stdlib-js/stdlib/pull/2552) _(by Jaysukh Makvana, Athan Reines)_ diff --git a/base/buffer/README.md b/base/buffer/README.md index 08e63547..741006af 100644 --- a/base/buffer/README.md +++ b/base/buffer/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ limitations under the License. # Contiguous Data Buffer -> Create a zero-filled contiguous linear ndarray data buffer. +> Create a contiguous linear ndarray data buffer. @@ -42,30 +42,14 @@ var buffer = require( '@stdlib/ndarray/base/buffer' ); #### buffer( dtype, size ) -Returns a zero-filled contiguous linear ndarray data buffer. +Returns a contiguous linear ndarray data buffer having a specified [data type][@stdlib/ndarray/dtypes]. ```javascript var buf = buffer( 'float64', 3 ); // returns [ 0.0, 0.0, 0.0 ] ``` -The function supports the following data types: - -- `binary`: binary. -- `complex64`: single-precision complex floating-point numbers. -- `complex128`: double-precision complex floating-point numbers. -- `float32`: single-precision floating-point numbers. -- `float64`: double-precision floating-point numbers. -- `generic`: values of any type. -- `int16`: signed 16-bit integers. -- `int32`: signed 32-bit integers. -- `int8`: signed 8-bit integers. -- `uint16`: unsigned 16-bit integers. -- `uint32`: unsigned 32-bit integers. -- `uint8`: unsigned 8-bit integers. -- `uint8c`: unsigned clamped 8-bit integers. - -If provided an unknown or unsupported data type, the function returns `null`. +If provided an unknown or unsupported [data type][@stdlib/ndarray/dtypes], the function returns `null`. ```javascript var buf = buffer( 'float', 3 ); @@ -80,6 +64,10 @@ var buf = buffer( 'float', 3 );
+## Notes + +- When provided a numeric [data type][@stdlib/ndarray/dtypes], "generic", or "binary", the function returns a zero-filled contiguous linear ndarray data buffer. +
@@ -97,9 +85,9 @@ var dtypes = require( '@stdlib/ndarray/dtypes' ); var buffer = require( '@stdlib/ndarray/base/buffer' ); var DTYPES = dtypes(); + var buf; var i; - for ( i = 0; i < DTYPES.length; i++ ) { buf = buffer( DTYPES[ i ], 10 ); console.log( buf ); @@ -130,6 +118,8 @@ for ( i = 0; i < DTYPES.length; i++ ) { diff --git a/base/buffer/benchmark/benchmark.js b/base/buffer/benchmark/benchmark.js index f4366644..4a387c72 100644 --- a/base/buffer/benchmark/benchmark.js +++ b/base/buffer/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,63 @@ bench( pkg+':dtype=binary', function benchmark( b ) { b.end(); }); +bench( pkg+':dtype=bool', function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = buffer( 'bool', 10 ); + if ( out.length !== 10 ) { + b.fail( 'should have length 10' ); + } + } + b.toc(); + if ( !isCollection( out ) ) { + b.fail( 'should return an array-like object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=complex64', function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = buffer( 'complex64', 10 ); + if ( out.length !== 10 ) { + b.fail( 'should have length 10' ); + } + } + b.toc(); + if ( !isCollection( out ) ) { + b.fail( 'should return an array-like object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=complex128', function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = buffer( 'complex128', 10 ); + if ( out.length !== 10 ) { + b.fail( 'should have length 10' ); + } + } + b.toc(); + if ( !isCollection( out ) ) { + b.fail( 'should return an array-like object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( pkg+':dtype=float64', function benchmark( b ) { var out; var i; diff --git a/base/buffer/benchmark/benchmark.length.js b/base/buffer/benchmark/benchmark.length.js index f0d908a8..e5df612d 100644 --- a/base/buffer/benchmark/benchmark.length.js +++ b/base/buffer/benchmark/benchmark.length.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,6 +90,15 @@ function main() { f = createBenchmark( 'binary', len ); bench( pkg+':len='+len+',dtype=binary', f ); + f = createBenchmark( 'bool', len ); + bench( pkg+':len='+len+',dtype=bool', f ); + + f = createBenchmark( 'complex64', len ); + bench( pkg+':len='+len+',dtype=complex64', f ); + + f = createBenchmark( 'complex128', len ); + bench( pkg+':len='+len+',dtype=complex128', f ); + f = createBenchmark( 'float64', len ); bench( pkg+':len='+len+',dtype=float64', f ); diff --git a/base/buffer/docs/repl.txt b/base/buffer/docs/repl.txt index 5dcf5fe7..0ded6101 100644 --- a/base/buffer/docs/repl.txt +++ b/base/buffer/docs/repl.txt @@ -1,22 +1,6 @@ {{alias}}( dtype, size ) - Returns a zero-filled contiguous linear ndarray data buffer. - - The function supports the following data types: - - - binary: binary. - - complex64: single-precision complex floating-point numbers. - - complex128: double-precision complex floating-point numbers. - - float32: single-precision floating-point numbers. - - float64: double-precision floating-point numbers. - - generic: values of any type. - - int16: signed 16-bit integers. - - int32: signed 32-bit integers. - - int8: signed 8-bit integers. - - uint16: unsigned 16-bit integers. - - uint32: unsigned 32-bit integers. - - uint8: unsigned 8-bit integers. - - uint8c: unsigned clamped 8-bit integers. + Returns a contiguous linear ndarray data buffer. Parameters ---------- diff --git a/base/buffer/docs/types/index.d.ts b/base/buffer/docs/types/index.d.ts index 1325c502..63e041de 100644 --- a/base/buffer/docs/types/index.d.ts +++ b/base/buffer/docs/types/index.d.ts @@ -22,16 +22,16 @@ /// import { Buffer } from 'buffer'; -import { TypedArray } from '@stdlib/types/array'; +import { TypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; import { DataType } from '@stdlib/types/ndarray'; /** * Array or typed array. */ -type ArrayOrBufferOrTypedArray = Array | TypedArray | Buffer | null; +type ArrayOrBufferOrTypedArray = Array | TypedArray | ComplexTypedArray | BooleanTypedArray | Buffer | null; /** -* Returns a zero-filled contiguous linear ndarray data buffer. +* Returns a contiguous linear ndarray data buffer. * * @param dtype - data type * @param size - buffer size diff --git a/base/buffer/examples/index.js b/base/buffer/examples/index.js index 2b908946..9bc37114 100644 --- a/base/buffer/examples/index.js +++ b/base/buffer/examples/index.js @@ -22,9 +22,9 @@ var dtypes = require( './../../../dtypes' ); var buffer = require( './../lib' ); var DTYPES = dtypes(); + var buf; var i; - for ( i = 0; i < DTYPES.length; i++ ) { buf = buffer( DTYPES[ i ], 10 ); console.log( buf ); diff --git a/base/buffer/lib/index.js b/base/buffer/lib/index.js index fdf2060a..120bce03 100644 --- a/base/buffer/lib/index.js +++ b/base/buffer/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Create a zero-filled contiguous linear ndarray data buffer. +* Create a contiguous linear ndarray data buffer. * * @module @stdlib/ndarray/base/buffer * diff --git a/base/buffer/lib/main.js b/base/buffer/lib/main.js index 0bacc0f2..eb4ed0cc 100644 --- a/base/buffer/lib/main.js +++ b/base/buffer/lib/main.js @@ -57,12 +57,12 @@ function binary( size ) { } /** -* Returns a zero-filled typed array. +* Returns a typed array. * * @private * @param {string} dtype - data type * @param {NonNegativeInteger} size - buffer size -* @returns {(TypedArray|null)} zero-filled typed array +* @returns {(TypedArray|null)} typed array */ function typedarray( dtype, size ) { var ctor = bufferCtors( dtype ); @@ -76,7 +76,7 @@ function typedarray( dtype, size ) { // MAIN // /** -* Returns a zero-filled contiguous linear ndarray data buffer. +* Returns a contiguous linear ndarray data buffer. * * @param {string} dtype - data type * @param {NonNegativeInteger} size - buffer size diff --git a/base/buffer/package.json b/base/buffer/package.json index 4de61f99..dbd746b4 100644 --- a/base/buffer/package.json +++ b/base/buffer/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/buffer", "version": "0.0.0", - "description": "Create a zero-filled contiguous linear ndarray data buffer.", + "description": "Create a contiguous linear ndarray data buffer.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/base/buffer/test/test.js b/base/buffer/test/test.js index 14af9508..99470bbc 100644 --- a/base/buffer/test/test.js +++ b/base/buffer/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ var Uint8Array = require( '@stdlib/array/uint8' ); var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex128Array = require( '@stdlib/array/complex128' ); +var BooleanArray = require( '@stdlib/array/bool' ); var isBuffer = require( '@stdlib/assert/is-buffer' ); var isArray = require( '@stdlib/assert/is-array' ); var isFloat64Array = require( '@stdlib/assert/is-float64array' ); @@ -46,6 +47,7 @@ var isUint8Array = require( '@stdlib/assert/is-uint8array' ); var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); var isComplex64Array = require( '@stdlib/assert/is-complex64array' ); var isComplex128Array = require( '@stdlib/assert/is-complex128array' ); +var isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); var buffer = require( './../lib' ); @@ -57,7 +59,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns zero-filled contiguous ndarray data buffers', function test( t ) { +tape( 'the function returns contiguous ndarray data buffers', function test( t ) { var expected; var dtypes; var vals; @@ -67,6 +69,7 @@ tape( 'the function returns zero-filled contiguous ndarray data buffers', functi dtypes = [ 'binary', + 'bool', 'complex64', 'complex128', 'float64', @@ -83,6 +86,7 @@ tape( 'the function returns zero-filled contiguous ndarray data buffers', functi vals = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; expected = [ [ array2buffer( vals ), isBuffer ], + [ new BooleanArray( vals ), isBooleanArray ], [ new Complex64Array( vals ), isComplex64Array ], [ new Complex128Array( vals ), isComplex128Array ], [ new Float64Array( vals ), isFloat64Array ], @@ -115,6 +119,7 @@ tape( 'the function returns ndarray data buffers (large allocations)', function dtypes = [ 'binary', + 'bool', 'complex64', 'complex128', 'float64', @@ -134,6 +139,7 @@ tape( 'the function returns ndarray data buffers (large allocations)', function } expected = [ isBuffer, + isBooleanArray, isComplex64Array, isComplex128Array, isFloat64Array,