Skip to content

Commit b42e11d

Browse files
committed
Auto-generated commit
1 parent 88e8013 commit b42e11d

File tree

9 files changed

+489
-6
lines changed

9 files changed

+489
-6
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
# Workflow name:
20+
name: test_published_package
21+
22+
# Workflow triggers:
23+
on:
24+
# Run workflow on a weekly schedule:
25+
schedule:
26+
# * is a special character in YAML so you have to quote this string
27+
- cron: '6 18 * * 0'
28+
29+
# Run workflow upon completion of `publish` workflow run:
30+
workflow_run:
31+
workflows: ["publish"]
32+
types: [completed]
33+
34+
# Allow workflow to be manually run:
35+
workflow_dispatch:
36+
37+
# Workflow jobs:
38+
jobs:
39+
test-published:
40+
# Define a display name:
41+
name: 'Test running examples of published package'
42+
43+
# Define the type of virtual host machine:
44+
runs-on: ubuntu-latest
45+
46+
# Define environment variables:
47+
env:
48+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
49+
50+
# Run workflow job if `publish` workflow run is successful or when the workflow is manually run:
51+
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
52+
53+
# Define the job's steps:
54+
steps:
55+
# Checkout the repository:
56+
- name: 'Checkout repository'
57+
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
58+
59+
# Install Node.js:
60+
- name: 'Install Node.js'
61+
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
62+
with:
63+
node-version: 20
64+
timeout-minutes: 5
65+
66+
# Create test directory and run examples:
67+
- name: 'Create test directory and run examples'
68+
run: |
69+
cd ..
70+
mkdir test-published
71+
cd test-published
72+
73+
# Copy example file:
74+
cp $GITHUB_WORKSPACE/examples/index.js .
75+
76+
# Create a minimal package.json
77+
echo '{
78+
"name": "test-published",
79+
"version": "1.0.0",
80+
"main": "index.js",
81+
"dependencies": {}
82+
}' > package.json
83+
84+
# Get package name and modify example file:
85+
PACKAGE_NAME=$(jq -r '.name' $GITHUB_WORKSPACE/package.json)
86+
ESCAPED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/[\/&]/\\&/g')
87+
88+
sed -i "s/require( '.\/..\/lib' )/require( '$ESCAPED_PACKAGE_NAME' )/g" index.js
89+
90+
# Extract and install dependencies:
91+
DEPS=$(grep -oP "require\(\s*'([^']+)'\s*\)" index.js | sed "s/require(\s*'//" | sed "s/'\s*)//" | grep -v "^\.")
92+
for dep in $DEPS; do
93+
npm install $dep --save
94+
done
95+
96+
# Run the example:
97+
node index.js
98+
99+
# Send Slack notification if job fails:
100+
- name: 'Send notification to Slack in case of failure'
101+
uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
102+
with:
103+
status: ${{ job.status }}
104+
channel: '#npm-ci'
105+
if: failure()

CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,39 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-11-18)
7+
## Unreleased (2024-11-20)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`b34732c`](https://github.com/stdlib-js/stdlib/commit/b34732cf655db60fbc798e12952f88c3edb07eaf) - add `at` method to `array/fixed-endian-factory` [(#3184)](https://github.com/stdlib-js/stdlib/pull/3184)
1314
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - add `forEach` method
1415
- [`a3a04e3`](https://github.com/stdlib-js/stdlib/commit/a3a04e32057b878529b86180e38ed3ae383c34ef) - add `array/fixed-endian-factory`
1516

1617
</section>
1718

1819
<!-- /.features -->
1920

21+
<section class="issues">
22+
23+
### Closed Issues
24+
25+
This release closes the following issue:
26+
27+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135)
28+
29+
</section>
30+
31+
<!-- /.issues -->
32+
2033
<section class="commits">
2134

2235
### Commits
2336

2437
<details>
2538

39+
- [`b34732c`](https://github.com/stdlib-js/stdlib/commit/b34732cf655db60fbc798e12952f88c3edb07eaf) - **feat:** add `at` method to `array/fixed-endian-factory` [(#3184)](https://github.com/stdlib-js/stdlib/pull/3184) _(by Aayush Khanna, Athan Reines)_
2640
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - **feat:** add `forEach` method _(by Athan Reines)_
2741
- [`b9f3b77`](https://github.com/stdlib-js/stdlib/commit/b9f3b776e5f3d426629b77206b682836fe6b390f) - **refactor:** reduce string literals _(by Athan Reines)_
2842
- [`17fa3d2`](https://github.com/stdlib-js/stdlib/commit/17fa3d277b28d85634444424f2af75edf60ab030) - **docs:** fix example _(by Athan Reines)_
@@ -38,8 +52,9 @@
3852

3953
### Contributors
4054

41-
A total of 1 person contributed to this release. Thank you to this contributor:
55+
A total of 2 people contributed to this release. Thank you to the following contributors:
4256

57+
- Aayush Khanna
4358
- Athan Reines
4459

4560
</section>

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,38 @@ var v = arr.get( 0 );
339339
// returns 1.0
340340
```
341341

342+
<a name="method-at"></a>
343+
344+
#### TypedArrayFE.prototype.at( i )
345+
346+
Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions.
347+
348+
```javascript
349+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
350+
351+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );
352+
353+
var out = arr.at( 0 );
354+
// returns 1.0
355+
356+
out = arr.at( -1 );
357+
// returns 3.0
358+
```
359+
360+
If provided an out-of-bounds index, the method returns `undefined`.
361+
362+
```javascript
363+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
364+
365+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );
366+
367+
var v = arr.at( 100 );
368+
// returns undefined
369+
370+
v = arr.at( -100 );
371+
// returns undefined
372+
```
373+
342374
<a name="method-for-each"></a>
343375

344376
#### TypedArrayFE.prototype.forEach( callbackFn\[, thisArg] )

benchmark/benchmark.at.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var factory = require( './../lib' );
27+
28+
29+
// VARIABLES //
30+
31+
var Float64ArrayFE = factory( 'float64' );
32+
33+
34+
// MAIN //
35+
36+
bench( pkg+'::nonnegative_indices:at:endianness=little-endian', function benchmark( b ) {
37+
var arr;
38+
var N;
39+
var v;
40+
var i;
41+
42+
arr = [];
43+
for ( i = 0; i < 10; i++ ) {
44+
arr.push( i );
45+
}
46+
arr = new Float64ArrayFE( 'little-endian', arr );
47+
N = arr.length;
48+
49+
b.tic();
50+
for ( i = 0; i < b.iterations; i++ ) {
51+
v = arr.at( i % N );
52+
if ( typeof v !== 'number' ) {
53+
b.fail( 'should return a number' );
54+
}
55+
}
56+
b.toc();
57+
if ( !isNumber( v ) ) {
58+
b.fail( 'should return a number' );
59+
}
60+
b.pass( 'benchmark finished' );
61+
b.end();
62+
});
63+
64+
bench( pkg+'::negative_indices:at:endianness=little-endian', function benchmark( b ) {
65+
var arr;
66+
var N;
67+
var v;
68+
var i;
69+
70+
arr = [];
71+
for ( i = 0; i < 10; i++ ) {
72+
arr.push( i );
73+
}
74+
arr = new Float64ArrayFE( 'little-endian', arr );
75+
N = arr.length;
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
v = arr.at( -( i % N ) - 1 );
80+
if ( typeof v !== 'number' ) {
81+
b.fail( 'should return a number' );
82+
}
83+
}
84+
b.toc();
85+
if ( !isNumber( v ) ) {
86+
b.fail( 'should return a number' );
87+
}
88+
b.pass( 'benchmark finished' );
89+
b.end();
90+
});
91+
92+
bench( pkg+'::nonnegative_indices:at:endianness=big-endian', function benchmark( b ) {
93+
var arr;
94+
var N;
95+
var v;
96+
var i;
97+
98+
arr = [];
99+
for ( i = 0; i < 1000; i++ ) {
100+
arr.push( i );
101+
}
102+
arr = new Float64ArrayFE( 'big-endian', arr );
103+
N = arr.length;
104+
105+
b.tic();
106+
for ( i = 0; i < b.iterations; i++ ) {
107+
v = arr.at( i % N );
108+
if ( typeof v !== 'number' ) {
109+
b.fail( 'should return a number' );
110+
}
111+
}
112+
b.toc();
113+
if ( !isNumber( v ) ) {
114+
b.fail( 'should return a number' );
115+
}
116+
b.pass( 'benchmark finished' );
117+
b.end();
118+
});
119+
120+
bench( pkg+'::negative_indices:at:endianness=big-endian', function benchmark( b ) {
121+
var arr;
122+
var N;
123+
var v;
124+
var i;
125+
126+
arr = [];
127+
for ( i = 0; i < 1000; i++ ) {
128+
arr.push( i );
129+
}
130+
arr = new Float64ArrayFE( 'big-endian', arr );
131+
N = arr.length;
132+
133+
b.tic();
134+
for ( i = 0; i < b.iterations; i++ ) {
135+
v = arr.at( -( i % N ) - 1 );
136+
if ( typeof v !== 'number' ) {
137+
b.fail( 'should return a number' );
138+
}
139+
}
140+
b.toc();
141+
if ( !isNumber( v ) ) {
142+
b.fail( 'should return a number' );
143+
}
144+
b.pass( 'benchmark finished' );
145+
b.end();
146+
});

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// MODULES //
2424

2525
var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
26+
var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
2627
var isCollection = require( '@stdlib/assert-is-collection' );
2728
var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' );
2829
var isObject = require( '@stdlib/assert-is-object' );
@@ -457,6 +458,36 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
457458
return new this( order, args );
458459
});
459460

461+
/**
462+
* Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices.
463+
*
464+
* @private
465+
* @name at
466+
* @memberof TypedArray.prototype
467+
* @type {Function}
468+
* @param {integer} idx - element index
469+
* @throws {TypeError} `this` must be a typed array instance
470+
* @throws {TypeError} must provide an integer
471+
* @returns {(*|void)} array element
472+
*/
473+
setReadOnly( TypedArray.prototype, 'at', function at( idx ) {
474+
var len;
475+
if ( !isTypedArray( this ) ) {
476+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
477+
}
478+
if ( !isInteger( idx ) ) {
479+
throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) );
480+
}
481+
len = this._length;
482+
if ( idx < 0 ) {
483+
idx += len;
484+
}
485+
if ( idx < 0 || idx >= len ) {
486+
return;
487+
}
488+
return this._buffer[ GETTER ]( idx * BYTES_PER_ELEMENT, this._isLE );
489+
});
490+
460491
/**
461492
* Pointer to the underlying data buffer.
462493
*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@stdlib/assert-is-arraybuffer": "^0.2.2",
4747
"@stdlib/assert-is-collection": "^0.2.2",
4848
"@stdlib/assert-is-function": "^0.2.2",
49+
"@stdlib/assert-is-integer": "^0.2.2",
4950
"@stdlib/assert-is-nonnegative-integer": "^0.2.2",
5051
"@stdlib/assert-is-object": "^0.2.2",
5152
"@stdlib/assert-is-prototype-of": "^0.2.2",

0 commit comments

Comments
 (0)