Skip to content

Commit c074d7c

Browse files
committed
Auto-generated commit
1 parent c208911 commit c074d7c

File tree

9 files changed

+460
-11
lines changed

9 files changed

+460
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-12-01)
7+
## Unreleased (2024-12-02)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`a0ba090`](https://github.com/stdlib-js/stdlib/commit/a0ba090515dfdfe617e1179ddb7581db24fec44b) - add `with` method to `array/fixed-endian-factory` [(#3291)](https://github.com/stdlib-js/stdlib/pull/3291)
1314
- [`1242bbf`](https://github.com/stdlib-js/stdlib/commit/1242bbf3e43a142f8d0bd4a66aece5baa33c03fe) - add `filter` method to `array/fixed-endian-factory` [(#3278)](https://github.com/stdlib-js/stdlib/pull/3278)
1415
- [`41af546`](https://github.com/stdlib-js/stdlib/commit/41af5467a9067f22ec8facdb535389bac10093bd) - add `reduceRight` method to `array/fixed-endian-factory` [(#3300)](https://github.com/stdlib-js/stdlib/pull/3300)
1516
- [`b679536`](https://github.com/stdlib-js/stdlib/commit/b679536e73bb91b1f9194bb6897232a3aa5cf2f2) - add `reduce` method to `array/fixed-endian-factory` [(#3296)](https://github.com/stdlib-js/stdlib/pull/3296)
@@ -31,9 +32,9 @@
3132

3233
### Closed Issues
3334

34-
A total of 10 issues were closed in this release:
35+
A total of 11 issues were closed in this release:
3536

36-
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3140](https://github.com/stdlib-js/stdlib/issues/3140), [#3146](https://github.com/stdlib-js/stdlib/issues/3146), [#3147](https://github.com/stdlib-js/stdlib/issues/3147), [#3149](https://github.com/stdlib-js/stdlib/issues/3149), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3151](https://github.com/stdlib-js/stdlib/issues/3151), [#3152](https://github.com/stdlib-js/stdlib/issues/3152), [#3155](https://github.com/stdlib-js/stdlib/issues/3155)
37+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138), [#3140](https://github.com/stdlib-js/stdlib/issues/3140), [#3146](https://github.com/stdlib-js/stdlib/issues/3146), [#3147](https://github.com/stdlib-js/stdlib/issues/3147), [#3149](https://github.com/stdlib-js/stdlib/issues/3149), [#3150](https://github.com/stdlib-js/stdlib/issues/3150), [#3151](https://github.com/stdlib-js/stdlib/issues/3151), [#3152](https://github.com/stdlib-js/stdlib/issues/3152), [#3155](https://github.com/stdlib-js/stdlib/issues/3155), [#3162](https://github.com/stdlib-js/stdlib/issues/3162)
3738

3839
</section>
3940

@@ -45,6 +46,7 @@ A total of 10 issues were closed in this release:
4546

4647
<details>
4748

49+
- [`a0ba090`](https://github.com/stdlib-js/stdlib/commit/a0ba090515dfdfe617e1179ddb7581db24fec44b) - **feat:** add `with` method to `array/fixed-endian-factory` [(#3291)](https://github.com/stdlib-js/stdlib/pull/3291) _(by Aayush Khanna, Philipp Burckhardt)_
4850
- [`1242bbf`](https://github.com/stdlib-js/stdlib/commit/1242bbf3e43a142f8d0bd4a66aece5baa33c03fe) - **feat:** add `filter` method to `array/fixed-endian-factory` [(#3278)](https://github.com/stdlib-js/stdlib/pull/3278) _(by Aayush Khanna, Philipp Burckhardt)_
4951
- [`41af546`](https://github.com/stdlib-js/stdlib/commit/41af5467a9067f22ec8facdb535389bac10093bd) - **feat:** add `reduceRight` method to `array/fixed-endian-factory` [(#3300)](https://github.com/stdlib-js/stdlib/pull/3300) _(by Aayush Khanna, Philipp Burckhardt)_
5052
- [`b679536`](https://github.com/stdlib-js/stdlib/commit/b679536e73bb91b1f9194bb6897232a3aa5cf2f2) - **feat:** add `reduce` method to `array/fixed-endian-factory` [(#3296)](https://github.com/stdlib-js/stdlib/pull/3296) _(by Aayush Khanna)_

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,25 @@ var str = arr.join( 0 );
941941
// returns '10203'
942942
```
943943

944+
<a name="method-with"></a>
945+
946+
#### TypedArrayFE.prototype.with( index, value )
947+
948+
Returns a new typed array with the element at a provided index replaced with a provided value.
949+
950+
```javascript
951+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
952+
953+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );
954+
// returns <Float64ArrayFE>
955+
956+
var out = arr.with( 0, 0.0 );
957+
// returns <Float64ArrayFE>
958+
959+
var v = out.get( 0 );
960+
// returns 0.0
961+
```
962+
944963
</section>
945964

946965
<!-- /.usage -->

benchmark/benchmark.with.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench-harness' );
24+
var pkg = require( './../package.json' ).name;
25+
var factory = require( './../lib' );
26+
27+
28+
// VARIABLES //
29+
30+
var Float64ArrayFE = factory( 'float64' );
31+
32+
33+
// MAIN //
34+
35+
bench( pkg+':with', function benchmark( b ) {
36+
var values;
37+
var out;
38+
var arr;
39+
var i;
40+
41+
values = [
42+
1.0,
43+
2.0,
44+
3.0
45+
];
46+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] );
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
out = arr.with( i % arr.length, values[ i % values.length ] );
51+
if ( typeof out !== 'object' ) {
52+
b.fail( 'should return an object' );
53+
}
54+
}
55+
b.toc();
56+
if ( !( out instanceof Float64ArrayFE ) ) {
57+
b.fail( 'should return a typed array' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});

benchmark/benchmark.with.length.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench-harness' );
24+
var pow = require( '@stdlib/math-base-special-pow' );
25+
var zeroTo = require( '@stdlib/array-zero-to' );
26+
var pkg = require( './../package.json' ).name;
27+
var factory = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var Float64ArrayFE = factory( 'float64' );
33+
34+
35+
// FUNCTIONS //
36+
37+
/**
38+
* Creates a benchmark function.
39+
*
40+
* @private
41+
* @param {PositiveInteger} len - array length
42+
* @returns {Function} benchmark function
43+
*/
44+
function createBenchmark( len ) {
45+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
46+
return benchmark;
47+
48+
/**
49+
* Benchmark function.
50+
*
51+
* @private
52+
* @param {Benchmark} b - benchmark instance
53+
*/
54+
function benchmark( b ) {
55+
var values;
56+
var out;
57+
var i;
58+
59+
values = [
60+
1.0,
61+
2.0,
62+
3.0
63+
];
64+
65+
b.tic();
66+
for ( i = 0; i < b.iterations; i++ ) {
67+
out = arr.with( i % arr.length, values[ i % values.length ] );
68+
if ( typeof out !== 'object' ) {
69+
b.fail( 'should return an object' );
70+
}
71+
}
72+
b.toc();
73+
if ( !( out instanceof Float64ArrayFE ) ) {
74+
b.fail( 'should return a typed array' );
75+
}
76+
b.pass( 'benchmark finished' );
77+
b.end();
78+
}
79+
}
80+
81+
82+
// MAIN //
83+
84+
/**
85+
* Main execution sequence.
86+
*
87+
* @private
88+
*/
89+
function main() {
90+
var len;
91+
var min;
92+
var max;
93+
var f;
94+
var i;
95+
96+
min = 1; // 10^min
97+
max = 6; // 10^max
98+
99+
for ( i = min; i <= max; i++ ) {
100+
len = pow( 10, i );
101+
f = createBenchmark( len );
102+
bench( pkg+':with:len='+len, f );
103+
}
104+
}
105+
106+
main();

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
2626
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
27+
var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
2728
var isCollection = require( '@stdlib/assert-is-collection' );
2829
var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' );
2930
var isObject = require( '@stdlib/assert-is-object' );
@@ -1059,22 +1060,62 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
10591060
if ( !isTypedArray( this ) ) {
10601061
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
10611062
}
1062-
10631063
if ( arguments.length > 0 ) {
10641064
sep = String( separator );
10651065
} else {
10661066
sep = ',';
10671067
}
1068-
10691068
out = [];
10701069
buf = this._buffer;
10711070
for ( i = 0; i < this._length; i++ ) {
10721071
out.push( buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ) );
10731072
}
1074-
10751073
return out.join( sep );
10761074
});
10771075

1076+
/**
1077+
* Returns a new typed array with the element at a provided index replaced with a provided value.
1078+
*
1079+
* @name with
1080+
* @memberof TypedArray.prototype
1081+
* @type {Function}
1082+
* @param {integer} index - element index
1083+
* @param {number} value - new value
1084+
* @throws {TypeError} `this` must be a typed array instance
1085+
* @throws {TypeError} first argument must be an integer
1086+
* @throws {RangeError} index argument is out-of-bounds
1087+
* @throws {TypeError} second argument must be a number
1088+
* @returns {TypedArray} new typed array
1089+
*/
1090+
setReadOnly( TypedArray.prototype, 'with', function copyWith( index, value ) {
1091+
var outbuf;
1092+
var buf;
1093+
var out;
1094+
var len;
1095+
1096+
if ( !isTypedArray( this ) ) {
1097+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
1098+
}
1099+
if ( !isInteger( index ) ) {
1100+
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) );
1101+
}
1102+
len = this._length;
1103+
buf = this._buffer;
1104+
if ( index < 0 ) {
1105+
index += len;
1106+
}
1107+
if ( index < 0 || index >= len ) {
1108+
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) );
1109+
}
1110+
if ( !isNumber( value ) ) {
1111+
throw new TypeError( format( 'invalid argument. Second argument must be a number. Value: `%s`.', value ) );
1112+
}
1113+
out = new this.constructor( flag2byteOrder( this._isLE ), buf.buffer );
1114+
outbuf = out._buffer; // eslint-disable-line no-underscore-dangle
1115+
outbuf[ SETTER ]( index * BYTES_PER_ELEMENT, value, this._isLE );
1116+
return out;
1117+
});
1118+
10781119
return TypedArray;
10791120

10801121
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@stdlib/assert-is-function": "^0.2.2",
4949
"@stdlib/assert-is-integer": "^0.2.2",
5050
"@stdlib/assert-is-nonnegative-integer": "^0.2.2",
51+
"@stdlib/assert-is-number": "^0.2.2",
5152
"@stdlib/assert-is-object": "^0.2.2",
5253
"@stdlib/assert-is-prototype-of": "^0.2.2",
5354
"@stdlib/assert-is-string": "^0.2.2",
@@ -65,7 +66,6 @@
6566
"@stdlib/array-zero-to": "^0.2.2",
6667
"@stdlib/assert-has-own-property": "^0.2.2",
6768
"@stdlib/assert-is-boolean": "^0.2.2",
68-
"@stdlib/assert-is-number": "^0.2.2",
6969
"@stdlib/console-log-each": "^0.2.2",
7070
"@stdlib/math-base-assert-is-nan": "^0.2.2",
7171
"@stdlib/math-base-special-pow": "^0.3.0",

0 commit comments

Comments
 (0)