Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 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 @@ -837,6 +837,73 @@ A few notes:
- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error.
- If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range.

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

#### TypedArrayFE.prototype.slice( \[start\[, end]] )

Copies a portion of a typed array to a new typed array.

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

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
// returns <Float64ArrayFE>

var out = arr.slice();
// returns <Float64ArrayFE>

var len = out.length;
// returns 5

var v = out.get( 0 );
// returns 1.0

v = out.get( len-1 );
// returns 5.0
```

By default, the method returns a typed array beginning with the first array element. To specify an alternative array index at which to begin, provide a `start` index (inclusive).

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

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
// returns <Float64ArrayFE>

var out = arr.slice( 1 );
// returns <Float64ArrayFE>

var len = out.length;
// returns 4

var v = out.get( 0 );
// returns 2.0

v = out.get( len-1 );
// returns 5.0
```

By default, the method returns a typed array which includes all array elements after `start`. To limit the number of array elements after `start`, provide an `end` index (exclusive).

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

var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
// returns <Float64ArrayFE>

var out = arr.slice( 1, -2 );
// returns <Float64ArrayFE>

var len = out.length;
// returns 2

var v = out.get( 0 );
// returns 2.0

v = out.get( len-1 );
// returns 3.0
```

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

#### TypedArrayFE.prototype.some( predicate\[, thisArg] )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var factory = require( './../lib' );


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// MAIN //

bench( format( '%s:slice', pkg ), function benchmark( b ) {
var out;
var arr;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.slice();
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Float64ArrayFE ) ) {
b.fail( 'should return a typed array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' );
var zeroTo = require( '@stdlib/array/zero-to' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var factory = require( './../lib' );


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.slice();
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Float64ArrayFE ) ) {
b.fail( 'should return a typed array' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:slice:len=%d', pkg, len ), f );
}
}

main();
66 changes: 65 additions & 1 deletion lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
* Typed array constructor which returns a typed array representing an array of values in a specified byte order.
*
* @private
* @constructor
* @param {string} endianness - byte order
* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable
* @param {NonNegativeInteger} [byteOffset=0] - byte offset
Expand Down Expand Up @@ -1069,6 +1068,71 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
buf[ SETTER ]( idx*BYTES_PER_ELEMENT, value, this._isLE );
});

/**
* Copies a portion of a typed array to a new typed array.
*
* @private
* @name slice
* @memberof TypedArray.prototype
* @type {Function}
* @param {integer} [start=0] - starting index (inclusive)
* @param {integer} [end] - ending index (exclusive)
* @throws {TypeError} `this` must be a typed array instance
* @throws {TypeError} first argument must be an integer
* @throws {TypeError} second argument must be an integer
* @returns {TypedArray} typed array
*/
setReadOnly( TypedArray.prototype, 'slice', function slice( start, end ) {
var nbytes;
var dest;
var src;
var buf;
var len;

if ( !isTypedArray( this ) ) {
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
}
buf = this._buffer;
len = this._length;
if ( arguments.length === 0 ) {
start = 0;
end = len;
} else {
if ( !isInteger( start ) ) {
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', start ) );
}
if ( start < 0 ) {
start += len;
if ( start < 0 ) {
start = 0;
}
}
if ( arguments.length === 1 ) {
end = len;
} else {
if ( !isInteger( end ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) );
}
if ( end < 0 ) {
end += len;
if ( end < 0 ) {
end = 0;
}
} else if ( end > len ) {
end = len;
}
}
}
if ( start >= end ) {
return new this.constructor( flag2byteOrder( this._isLE ), 0 );
}
nbytes = ( end-start ) * BYTES_PER_ELEMENT;
src = new Uint8Array( buf.buffer, buf.byteOffset+(start*BYTES_PER_ELEMENT), nbytes );
dest = new Uint8Array( new ArrayBuffer( nbytes ) );
dest.set( src );
return new this.constructor( flag2byteOrder( this._isLE ), dest.buffer );
});

/**
* Tests whether at least one element in the typed array passes a test implemented by a predicate function.
*
Expand Down
Loading
Loading