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 Jun 16, 2024
1 parent 47ad0eb commit 118a2c5
Show file tree
Hide file tree
Showing 13 changed files with 1,433 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@

##### Features

- [`60fa5ac`](https://github.com/stdlib-js/stdlib/commit/60fa5ac214d2e5dfe310f93928a07515eeeb4a3b) - add `cuevery` to namespace
- [`0a0ba83`](https://github.com/stdlib-js/stdlib/commit/0a0ba837315759799d35a24a8d9ded4af82622e0) - add `cuany` to namespace
- [`dc42597`](https://github.com/stdlib-js/stdlib/commit/dc42597ff2b21239797a71eb9cec84fe4e319fbc) - add `put` to namespace
- [`25e7a6e`](https://github.com/stdlib-js/stdlib/commit/25e7a6e0dd6fea3b5c42a557eb8ade2ac8f575ac) - update namespace TypeScript declarations [(##2146)](#2146)
- [`b54dc66`](https://github.com/stdlib-js/stdlib/commit/b54dc660bac4d6c2be5e51752dd6b57ba61e689b) - add `join` to namespace
- [`0a6cefd`](https://github.com/stdlib-js/stdlib/commit/0a6cefd854a121ec4cf59bbbf5c4745b549e3bed) - add `countIf` to namespace
Expand Down Expand Up @@ -909,6 +912,28 @@ This release closes the following issue:

<!-- /.package -->

<section class="package" id="array-base-put-unreleased">

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

<details>

<section class="features">

##### Features

- [`ce18c49`](https://github.com/stdlib-js/stdlib/commit/ce18c49136d11f7333477882c9276d4ea3adc1af) - add `array/base/put`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="array-base-take-unreleased">

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

<details>

- [`dd9c4bc`](https://github.com/stdlib-js/stdlib/commit/dd9c4bc35241e586975c709ab63db13e684b0c24) - **bench:** fix array dtypes _(by Athan Reines)_
- [`cd60396`](https://github.com/stdlib-js/stdlib/commit/cd60396033ffc3035a57332c503b3747a76eaf44) - **bench:** fix broadcasting bug _(by Athan Reines)_
- [`9cd273a`](https://github.com/stdlib-js/stdlib/commit/9cd273ad970ecc7baeb4b36d2e054a702369c622) - **bench:** fix mutation bug _(by Athan Reines)_
- [`a35f2d1`](https://github.com/stdlib-js/stdlib/commit/a35f2d1cd5b94d38a5bda0386f35010c6f67e7e1) - **bench:** fix limits _(by Athan Reines)_
- [`1cbef01`](https://github.com/stdlib-js/stdlib/commit/1cbef0199d62d9add807612c1297b1e0bb12b5b6) - **docs:** fix examples _(by Athan Reines)_
- [`60fa5ac`](https://github.com/stdlib-js/stdlib/commit/60fa5ac214d2e5dfe310f93928a07515eeeb4a3b) - **feat:** add `cuevery` to namespace _(by Athan Reines)_
- [`0a0ba83`](https://github.com/stdlib-js/stdlib/commit/0a0ba837315759799d35a24a8d9ded4af82622e0) - **feat:** add `cuany` to namespace _(by Athan Reines)_
- [`dc42597`](https://github.com/stdlib-js/stdlib/commit/dc42597ff2b21239797a71eb9cec84fe4e319fbc) - **feat:** add `put` to namespace _(by Athan Reines)_
- [`ce18c49`](https://github.com/stdlib-js/stdlib/commit/ce18c49136d11f7333477882c9276d4ea3adc1af) - **feat:** add `array/base/put` _(by Athan Reines)_
- [`a59c8bf`](https://github.com/stdlib-js/stdlib/commit/a59c8bfbfed0a5fad9a46625cfca6b869b03515e) - **docs:** add `repl.txt` to `array/bool` [(#2385)](https://github.com/stdlib-js/stdlib/pull/2385) _(by Jaysukh Makvana, Athan Reines)_
- [`5cd4a70`](https://github.com/stdlib-js/stdlib/commit/5cd4a70beaa7663d2a822b0922b3fb3cc6ec539f) - **feat:** add `findIndex` and `findLastIndex` methods to `array/bool` [(#2384)](https://github.com/stdlib-js/stdlib/pull/2384) _(by Jaysukh Makvana, Athan Reines)_
- [`9445e22`](https://github.com/stdlib-js/stdlib/commit/9445e22fabf3546afe9a6dd33c9131917f960b2a) - **feat:** add `array/base/cuevery` (#2380) [(#2380)](https://github.com/stdlib-js/stdlib/pull/2380) _(by Aditya Sapra, Athan Reines)_
Expand Down
27 changes: 27 additions & 0 deletions base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,24 @@ setReadOnly( ns, 'countSameValueZero', require( './../../base/count-same-value-z
*/
setReadOnly( ns, 'countTruthy', require( './../../base/count-truthy' ) );

/**
* @name cuany
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/base/cuany}
*/
setReadOnly( ns, 'cuany', require( './../../base/cuany' ) );

/**
* @name cuevery
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/base/cuevery}
*/
setReadOnly( ns, 'cuevery', require( './../../base/cuevery' ) );

/**
* @name dedupe
* @memberof ns
Expand Down Expand Up @@ -1143,6 +1161,15 @@ setReadOnly( ns, 'ones5d', require( './../../base/ones5d' ) );
*/
setReadOnly( ns, 'onesnd', require( './../../base/onesnd' ) );

/**
* @name put
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/base/put}
*/
setReadOnly( ns, 'put', require( './../../base/put' ) );

/**
* @name quaternary2d
* @memberof ns
Expand Down
141 changes: 141 additions & 0 deletions base/put/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!--
@license Apache-2.0
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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# put

> Replace specified elements of an array with provided values.
<section class="usage">

## Usage

```javascript
var put = require( '@stdlib/array/base/put' );
```

#### put( x, indices, values, mode )

Replaces specified elements of an array with provided values.

```javascript
var x = [ 1, 2, 3, 4 ];

var out = put( x, [ 1, 3 ], [ 20, 40 ], 'throw' );
// returns [ 1, 20, 3, 40 ]

var bool = ( out === x );
// returns true
```

The function supports the following parameters:

- **x**: input array.
- **indices**: list of indices.
- **values**: values to set. When `indices` contains one or more elements, `values` must be broadcast [compatible][@stdlib/ndarray/base/broadcast-shapes] with `indices` (i.e., must have either one element or the same number of elements as `indices`).
- **mode**: index [mode][@stdlib/ndarray/base/ind].

If `indices` is an empty array, the function returns the input array unchanged.

```javascript
var x = [ 1, 2, 3, 4 ];

var out = put( x, [], [ 20, 40 ], 'throw' );
// returns [ 1, 2, 3, 4 ]
```

The function supports broadcasting a `values` array containing a single element against an `indices` array containing one or more elements.

```javascript
var x = [ 1, 2, 3, 4 ];

var out = put( x, [ 1, 3 ], [ 20 ], 'throw' );
// returns [ 1, 20, 3, 20 ]

var bool = ( out === x );
// returns true
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The function mutates the input array `x`.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var filledBy = require( '@stdlib/array/base/filled-by' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var linspace = require( '@stdlib/array/base/linspace' );
var put = require( '@stdlib/array/base/put' );

// Generate a linearly spaced array:
var x = linspace( 0, 100, 11 );
console.log( x );

// Generate an array of random indices:
var N = discreteUniform( 5, 15 );
var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) );
console.log( indices );

// Generate an array of random values:
var values = filledBy( N, discreteUniform.factory( 1000, 2000 ) );
console.log( values );

// Update a random sample of elements in `x`:
var out = put( x, indices, values, 'throw' );
console.log( out );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/base/ind]: https://github.com/stdlib-js/ndarray-base-ind

[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes

</section>

<!-- /.links -->
78 changes: 78 additions & 0 deletions base/put/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @license Apache-2.0
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isArray = require( '@stdlib/assert/is-array' );
var zeroTo = require( './../../../base/zero-to' );
var pkg = require( './../package.json' ).name;
var put = require( './../lib' );


// MAIN //

bench( pkg+'::no_broadcasting:len=100', function benchmark( b ) {
var idx;
var x;
var i;
var v;

x = zeroTo( 100 );
idx = zeroTo( 100 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = put( x, idx, x, 'throw' );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( !isArray( v ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::broadcasting:len=100', function benchmark( b ) {
var idx;
var x;
var i;
var v;

x = zeroTo( 100 );
idx = zeroTo( 100 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = put( x, idx, [ i ], 'throw' );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( !isArray( v ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading

0 comments on commit 118a2c5

Please sign in to comment.