Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into #3154_add_slice_…
Browse files Browse the repository at this point in the history
…method_to_array/fixed-endian-factory
  • Loading branch information
stdlib-bot committed Nov 20, 2024
2 parents 274405f + 8f1a67c commit 2e1175a
Show file tree
Hide file tree
Showing 70 changed files with 1,376 additions and 596 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/markdown_equations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
# Define a display name:
name: 'Update equations'

# Only run this job if the pull request was merged and did not have label `automated-pr`:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'automated-pr') == false
# Ensure the job does not run on forks:
if: github.repository == 'stdlib-js/stdlib'

# Define the type of virtual host machine:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/markdown_tocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
# Define a display name:
name: 'Update namespace ToCs'

# Only run this job if the pull request was merged and did not have label `automated-pr` (or the job was triggered manually):
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'automated-pr') == false || github.event_name == 'workflow_dispatch'
# Ensure the job does not run on forks:
if: github.repository == 'stdlib-js/stdlib'

# Define the type of virtual host machine:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/namespace_declarations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
# Define a display name:
name: 'Update TypeScript Declarations'

# Only run this job if the pull request was merged and did not have label `automated-pr` (or the job was triggered manually):
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'automated-pr') == false || github.event_name == 'workflow_dispatch'
# Ensure the job does not run on forks:
if: github.repository == 'stdlib-js/stdlib'

# Define the type of virtual host machine:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/namespace_exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
# Define a display name:
name: 'Update Namespace Exports'

# Only run this job if the pull request was merged and did not have label `automated-pr` (or the job was triggered manually):
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'automated-pr') == false || github.event_name == 'workflow_dispatch'
# Ensure the job does not run on forks:
if: github.repository == 'stdlib-js/stdlib'

# Define the type of virtual host machine:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update_repl_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
# Define a display name:
name: 'Update REPL docs'

# Only run this job if the pull request was merged (or the job was triggered manually):
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
# Ensure the job does not run on forks:
if: github.repository == 'stdlib-js/stdlib'

# Define the type of virtual host machine:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Ruthwik Chikoti <[email protected]>
Ryan Seal <[email protected]>
Sai Srikar Dumpeti <[email protected]>
SarthakPaandey <[email protected]>
Saurabh Singh <[email protected]>
Seyyed Parsa Neshaei <[email protected]>
Shashank Shekhar Singh <[email protected]>
Shivam <[email protected]>
Expand Down
3 changes: 3 additions & 0 deletions docs/git-notes/74b235240970eb51397e4ba1601386d093f4b5e9.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
type: amend-message
---
feat: add C API for `@stdlib/math/base/special/tribonacci`

PR-URL: https://github.com/stdlib-js/stdlib/pull/903
Expand Down
32 changes: 32 additions & 0 deletions lib/node_modules/@stdlib/array/fixed-endian-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,38 @@ var v = arr.get( 0 );
// returns 1.0
```

<a name="method-at"></a>

#### TypedArrayFE.prototype.at( i )

Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions.

```javascript
var Float64ArrayFE = fixedEndianFactory( 'float64' );

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );

var out = arr.at( 0 );
// returns 1.0

out = arr.at( -1 );
// returns 3.0
```

If provided an out-of-bounds index, the method returns `undefined`.

```javascript
var Float64ArrayFE = fixedEndianFactory( 'float64' );

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] );

var v = arr.at( 100 );
// returns undefined

v = arr.at( -100 );
// returns undefined
```

<a name="method-for-each"></a>

#### TypedArrayFE.prototype.forEach( callbackFn\[, thisArg] )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* @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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var factory = require( './../lib' );


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// MAIN //

bench( pkg+'::nonnegative_indices:at:endianness=little-endian', function benchmark( b ) {
var arr;
var N;
var v;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( i );
}
arr = new Float64ArrayFE( 'little-endian', arr );
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.at( i % N );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( !isNumber( v ) ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::negative_indices:at:endianness=little-endian', function benchmark( b ) {
var arr;
var N;
var v;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( i );
}
arr = new Float64ArrayFE( 'little-endian', arr );
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.at( -( i % N ) - 1 );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( !isNumber( v ) ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::nonnegative_indices:at:endianness=big-endian', function benchmark( b ) {
var arr;
var N;
var v;
var i;

arr = [];
for ( i = 0; i < 1000; i++ ) {
arr.push( i );
}
arr = new Float64ArrayFE( 'big-endian', arr );
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.at( i % N );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( !isNumber( v ) ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::negative_indices:at:endianness=big-endian', function benchmark( b ) {
var arr;
var N;
var v;
var i;

arr = [];
for ( i = 0; i < 1000; i++ ) {
arr.push( i );
}
arr = new Float64ArrayFE( 'big-endian', arr );
N = arr.length;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.at( -( i % N ) - 1 );
if ( typeof v !== 'number' ) {
b.fail( 'should return a number' );
}
}
b.toc();
if ( !isNumber( v ) ) {
b.fail( 'should return a number' );
}
b.pass( 'benchmark finished' );
b.end();
});
31 changes: 31 additions & 0 deletions lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// MODULES //

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

/**
* Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices.
*
* @private
* @name at
* @memberof TypedArray.prototype
* @type {Function}
* @param {integer} idx - element index
* @throws {TypeError} `this` must be a typed array instance
* @throws {TypeError} must provide an integer
* @returns {(*|void)} array element
*/
setReadOnly( TypedArray.prototype, 'at', function at( idx ) {
var len;
if ( !isTypedArray( this ) ) {
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
}
if ( !isInteger( idx ) ) {
throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) );
}
len = this._length;
if ( idx < 0 ) {
idx += len;
}
if ( idx < 0 || idx >= len ) {
return;
}
return this._buffer[ GETTER ]( idx * BYTES_PER_ELEMENT, this._isLE );
});

/**
* Pointer to the underlying data buffer.
*
Expand Down
Loading

0 comments on commit 2e1175a

Please sign in to comment.