Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 13, 2024
1 parent b2f6c57 commit 1b846f1
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 51 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@

<!-- /.package -->

<section class="package" id="ndarray-base-buffer-unreleased">

#### [@stdlib/ndarray/base/buffer](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/buffer)

<details>

<section class="features">

##### 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)

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="ndarray-base-buffer-ctors-unreleased">

#### [@stdlib/ndarray/base/buffer-ctors](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/buffer-ctors)
Expand Down Expand Up @@ -463,6 +485,7 @@ A total of 3 people contributed to this release. Thank you to the following cont

<details>

- [`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)_
Expand Down
32 changes: 11 additions & 21 deletions base/buffer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

Expand All @@ -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 <Float64Array>[ 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 );
Expand All @@ -80,6 +64,10 @@ var buf = buffer( 'float', 3 );

<section class="notes">

## Notes

- When provided a numeric [data type][@stdlib/ndarray/dtypes], "generic", or "binary", the function returns a zero-filled contiguous linear ndarray data buffer.

</section>

<!-- /.notes -->
Expand All @@ -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 );
Expand Down Expand Up @@ -130,6 +118,8 @@ for ( i = 0; i < DTYPES.length; i++ ) {

<section class="links">

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes

</section>

<!-- /.links -->
59 changes: 58 additions & 1 deletion base/buffer/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion base/buffer/benchmark/benchmark.length.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 );

Expand Down
18 changes: 1 addition & 17 deletions base/buffer/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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
----------
Expand Down
6 changes: 3 additions & 3 deletions base/buffer/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
/// <reference types="node"/>

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<any> | TypedArray | Buffer | null;
type ArrayOrBufferOrTypedArray = Array<any> | 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
Expand Down
2 changes: 1 addition & 1 deletion base/buffer/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion base/buffer/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 3 additions & 3 deletions base/buffer/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/buffer/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 8 additions & 2 deletions base/buffer/test/test.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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' );
Expand All @@ -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' );


Expand All @@ -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;
Expand All @@ -67,6 +69,7 @@ tape( 'the function returns zero-filled contiguous ndarray data buffers', functi

dtypes = [
'binary',
'bool',
'complex64',
'complex128',
'float64',
Expand All @@ -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 ],
Expand Down Expand Up @@ -115,6 +119,7 @@ tape( 'the function returns ndarray data buffers (large allocations)', function

dtypes = [
'binary',
'bool',
'complex64',
'complex128',
'float64',
Expand All @@ -134,6 +139,7 @@ tape( 'the function returns ndarray data buffers (large allocations)', function
}
expected = [
isBuffer,
isBooleanArray,
isComplex64Array,
isComplex128Array,
isFloat64Array,
Expand Down

0 comments on commit 1b846f1

Please sign in to comment.