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 3, 2024
1 parent 062ecbc commit 1ce821e
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 42 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

## Unreleased (2024-07-01)
## Unreleased (2024-07-03)

<section class="packages">

Expand Down Expand Up @@ -1414,6 +1414,28 @@ This release closes the following issue:

<!-- /.package -->

<section class="package" id="array-convert-same-unreleased">

#### [@stdlib/array/convert-same](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/convert-same)

<details>

<section class="features">

##### Features

- [`48fd331`](https://github.com/stdlib-js/stdlib/commit/48fd331d8f79ee2d51cd2618e70f79809f52336e) - add boolean dtype support to `array/convert-same` [(#2494)](https://github.com/stdlib-js/stdlib/pull/2494)

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="array-ctors-unreleased">

#### [@stdlib/array/ctors](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/ctors)
Expand Down Expand Up @@ -2337,6 +2359,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`48fd331`](https://github.com/stdlib-js/stdlib/commit/48fd331d8f79ee2d51cd2618e70f79809f52336e) - **feat:** add boolean dtype support to `array/convert-same` [(#2494)](https://github.com/stdlib-js/stdlib/pull/2494) _(by Jaysukh Makvana, Athan Reines)_
- [`adb47ab`](https://github.com/stdlib-js/stdlib/commit/adb47abbac01e5bcc673f1ddd6815cb8ff22d8e3) - **feat:** add boolean dtype support to `array/convert` [(#2488)](https://github.com/stdlib-js/stdlib/pull/2488) _(by Jaysukh Makvana, Athan Reines)_
- [`ccaf9fe`](https://github.com/stdlib-js/stdlib/commit/ccaf9fe07622dcbb1816e8678a8de685c075b4e6) - **feat:** update namespace TypeScript declarations [(#2490)](https://github.com/stdlib-js/stdlib/pull/2490) _(by stdlib-bot, Athan Reines)_
- [`6b0e763`](https://github.com/stdlib-js/stdlib/commit/6b0e763f6763fcad684f7cc82bb3300837dad71b) - **docs:** update example and add return description [(#2489)](https://github.com/stdlib-js/stdlib/pull/2489) _(by Jaysukh Makvana)_
Expand Down
23 changes: 5 additions & 18 deletions convert-same/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.

# convertSame

> Convert an array to the same data type as a second input array.
> Convert an array to the same [data type][@stdlib/array/dtypes] as a second input array.
<!-- 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,7 +42,7 @@ var convertSame = require( '@stdlib/array/convert-same' );

#### convertSame( x, y )

Converts an array to the same data type as a second input array.
Converts an array to the same [data type][@stdlib/array/dtypes] as a second input array.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -54,21 +54,6 @@ var out = convertSame( x, y );
// returns <Float32Array>[ 1.0, 2.0, 3.0 ]
```

The function supports input arrays having the following data types:

- `float32`: single-precision floating-point numbers.
- `float64`: double-precision floating-point numbers.
- `complex64`: single-precision complex floating-point numbers.
- `complex128`: double-precision complex 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.

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -147,6 +132,8 @@ for ( i = 0; i < DTYPES.length; i++ ) {

[@stdlib/array/convert]: https://github.com/stdlib-js/array/tree/main/convert

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

<!-- </related-links> -->

</section>
Expand Down
31 changes: 30 additions & 1 deletion convert-same/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 @@ -33,6 +33,7 @@ var Uint8Array = require( './../../uint8' );
var Uint8ClampedArray = require( './../../uint8c' );
var Complex64Array = require( './../../complex64' );
var Complex128Array = require( './../../complex128' );
var BooleanArray = require( './../../bool' );
var pkg = require( './../package.json' ).name;
var convertArraySame = require( './../lib' );

Expand Down Expand Up @@ -120,6 +121,34 @@ bench( pkg+':dtype=float32', function benchmark( b ) {
b.end();
});

bench( pkg+':dtype=bool', function benchmark( b ) {
var arr;
var out;
var v;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( i );
}
v = new BooleanArray( 0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr[ 0 ] += 1;
out = convertArraySame( arr, v );
if ( out.length !== arr.length ) {
b.fail( 'should have expected length' );
}
}
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 arr;
var out;
Expand Down
6 changes: 5 additions & 1 deletion convert-same/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 @@ -34,6 +34,7 @@ var Uint8Array = require( './../../uint8' );
var Uint8ClampedArray = require( './../../uint8c' );
var Complex64Array = require( './../../complex64' );
var Complex128Array = require( './../../complex128' );
var BooleanArray = require( './../../bool' );
var pkg = require( './../package.json' ).name;
var convertArraySame = require( './../lib' );

Expand Down Expand Up @@ -135,6 +136,9 @@ function main() {
f = createBenchmark( len, new Uint8ClampedArray( 0 ) );
bench( pkg+':len='+len+',dtype=uint8c', f );

f = createBenchmark( len, new BooleanArray( 0 ) );
bench( pkg+':len='+len+',dtype=bool', f );

f = createBenchmark( len, new Complex128Array( 0 ) );
bench( pkg+':len='+len+',dtype=complex128', f );

Expand Down
15 changes: 0 additions & 15 deletions convert-same/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
{{alias}}( x, y )
Converts an input array to the same data type as a second input array.

The function supports input arrays having the following data types:

- float32: single-precision floating-point numbers.
- float64: double-precision floating-point numbers.
- complex64: single-precision complex floating-point numbers.
- complex128: double-precision complex 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.

Parameters
----------
x: ArrayLikeObject
Expand Down
22 changes: 20 additions & 2 deletions convert-same/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2021 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 @@

/// <reference types="@stdlib/types"/>

import { AnyArray, Collection, Complex128Array, Complex64Array } from '@stdlib/types/array';
import { AnyArray, Collection, Complex128Array, Complex64Array, BooleanArray } from '@stdlib/types/array';

/**
* Converts an array to the same data type as a `Float64Array`.
Expand Down Expand Up @@ -184,6 +184,24 @@ declare function convertSame( x: Collection, y: Uint8Array ): Uint8Array;
*/
declare function convertSame( x: Collection, y: Uint8ClampedArray ): Uint8ClampedArray;

/**
* Converts an array to a `BooleanArray`.
*
* @param x - array to convert
* @param y - array having the desired output data type
* @returns output array
*
* @example
* var BooleanArray = require( '@stdlib/array/bool' );
*
* var x = [ -1, 0, 1, 2 ];
* var y = new BooleanArray( 0 );
*
* var out = convertSame( x, y );
* // returns <BooleanArray>
*/
declare function convertSame( x: Collection, y: BooleanArray ): BooleanArray;

/**
* Converts an array to a `Complex128Array`.
*
Expand Down
4 changes: 3 additions & 1 deletion convert-same/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2021 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 @@ -18,6 +18,7 @@

import Complex128Array = require( './../../../complex128' );
import Complex64Array = require( './../../../complex64' );
import BooleanArray = require( './../../../bool' );
import convertSame = require( './index' );


Expand All @@ -36,6 +37,7 @@ import convertSame = require( './index' );
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Uint8ClampedArray( 0 ) ); // $ExpectType Uint8ClampedArray
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Complex128Array( 0 ) ); // $ExpectType Complex128Array
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Complex64Array( 0 ) ); // $ExpectType Complex64Array
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new BooleanArray( 0 ) ); // $ExpectType BooleanArray
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], [] ); // $ExpectType any[]
}

Expand Down
Loading

0 comments on commit 1ce821e

Please sign in to comment.