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
41 changes: 41 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 @@ -511,6 +511,47 @@ var count = context.count;
// returns 3
```

<a name="values"></a>

### TypedArrayFE.prototype.values()

Returns an iterator for the values of the typed array.

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

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

var iter = arr.values();

var result = iter.next();
// returns { 'value': 1.0, 'done': false }

result = iter.next();
// returns { 'value': 2.0, 'done': false }

result = iter.next();
// returns { 'value': 3.0, 'done': false }

result = iter.next();
// returns { 'done': true }
```

use the iterator with a `for...of` loop.

```javascript
var value;
for ( value of arr.values() ) {
console.log( value );
}
// print each value of array
// 1.0
// 2.0
// 3.0
```


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

#### TypedArrayFE.prototype.get( i )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var factory = require( './../lib' );


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// MAIN //

bench( pkg+':values', function benchmark( b ) {
var value;
var iter;
var arr;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.values();
for ( value of iter ) {
if ( isnan( value ) ) {
b.fail( 'should not return NaN' );
}
}
}
b.toc();
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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/utils/zero-to' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var factory = require( './../lib' );


// VARIABLES //

var Float64ArrayFE = factory( 'float64' );


// FUNCTIONS //

/**
* Creates a benchmark function for `values` iterator.
*
* @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
* @throws {Error} throws an error if NaN value is encountered
*/
function benchmark( b ) {
var value;
var iter;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
iter = arr.values(); // Get the iterator for values

// Use for...of loop to iterate over the values
for ( value of iter ) {
if ( isnan( value ) ) {
throw new Error( 'something went wrong' );
}
}
if ( arr.length !== len ) {
b.fail( 'should not change an array length' );
}
}
b.toc();
if ( arr.length !== len ) {
b.fail( 'should not change an array length' );
}
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( pkg+':values:len='+len, f );
}
}

main();
41 changes: 41 additions & 0 deletions lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* @license Apache-2.0
*

Check failure on line 3 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
* Copyright (c) 2024 The Stdlib Authors.

Check failure on line 4 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
*

Check failure on line 5 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
* Licensed under the Apache License, Version 2.0 (the "License");

Check failure on line 6 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
* you may not use this file except in compliance with the License.

Check failure on line 7 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
* You may obtain a copy of the License at

Check failure on line 8 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
*

Check failure on line 9 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
* http://www.apache.org/licenses/LICENSE-2.0

Check failure on line 10 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
*

Check failure on line 11 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use spaces instead of tabs
* 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.
Expand Down Expand Up @@ -1095,6 +1095,47 @@
return false;
});

/**
* Returns an iterator for array elements.
*
* @private
* @name values
* @memberof TypedArray.prototype
* @type {Function}
* @throws {TypeError} `this` must be a typed array instance
* @returns {Object} iterator for array elements
*/
setReadOnly( TypedArray.prototype, 'values', function values() {
var iterator;
var index = 0;
var value;
var isLE = this._isLE;
var buf = this._buffer;
var len = this._length;
if ( !isTypedArray( this ) ) {
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
}
iterator = {
'next': function next() {
if ( index < len ) {
value = buf[ GETTER ]( index * BYTES_PER_ELEMENT, isLE );
index += 1;
return {
'value': value,
'done': false
};
}
return {
'done': true
};
}
};
iterator[ Symbol.iterator ] = function iterator() {
return this;
};
return iterator;
});

/**
* Serializes an array as a string.
*
Expand Down
Loading
Loading