Skip to content

Commit 5256af3

Browse files
committed
Auto-generated commit
1 parent e5882b9 commit 5256af3

File tree

97 files changed

+15362
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+15362
-202
lines changed

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ jobs:
164164
# Publish package to npm:
165165
- name: 'Publish package to npm'
166166
# Pin action to full length commit SHA
167-
uses: JS-DevTools/npm-publish@4b07b26a2f6e0a51846e1870223e545bae91c552 # v3.0.1
167+
uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c # v3.1.1
168168
with:
169169
token: ${{ secrets.NPM_TOKEN }}
170170
access: public

.npmrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ shrinkwrap = false
2727
# Disable automatically "saving" dependencies on install:
2828
save = false
2929

30-
# Generate provenance metadata:
31-
provenance = true
30+
# Do not generate provenance metadata:
31+
provenance = false

CHANGELOG.md

+43-199
Large diffs are not rendered by default.

base/for-each/README.md

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# forEach
22+
23+
> Invoke a callback function once for each ndarray element.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var forEach = require( '@stdlib/ndarray/base/for-each' );
37+
```
38+
39+
#### forEach( arrays, fcn\[, thisArg] )
40+
41+
Invokes a callback function once for each ndarray element.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
var naryFunction = require( '@stdlib/utils/nary-function' );
46+
var log = require( '@stdlib/console/log' );
47+
48+
// Create data buffers:
49+
var xbuf = new Float64Array( 12 );
50+
51+
// Define the shape of the array:
52+
var shape = [ 3, 1, 2 ];
53+
54+
// Define the array strides:
55+
var sx = [ 4, 4, 1 ];
56+
57+
// Define the index offset:
58+
var ox = 1;
59+
60+
// Create an ndarray-like object:
61+
var x = {
62+
'dtype': 'float64',
63+
'data': xbuf,
64+
'shape': shape,
65+
'strides': sx,
66+
'offset': ox,
67+
'order': 'row-major'
68+
};
69+
70+
// Apply the callback function:
71+
forEach( [ x ], naryFunction( log, 1 ) );
72+
```
73+
74+
The function accepts the following arguments:
75+
76+
- **arrays**: array-like object containing an ndarray.
77+
- **fcn**: callback to apply.
78+
- **thisArg**: callback execution context.
79+
80+
The callback function is provided the following arguments:
81+
82+
- **value**: current array element.
83+
- **indices**: current array element indices.
84+
- **arr**: the input ndarray.
85+
86+
</section>
87+
88+
<!-- /.usage -->
89+
90+
<section class="notes">
91+
92+
## Notes
93+
94+
- The provided ndarray should be an `object` with the following properties:
95+
96+
- **dtype**: data type.
97+
- **data**: data buffer.
98+
- **shape**: dimensions.
99+
- **strides**: stride lengths.
100+
- **offset**: index offset.
101+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
102+
103+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a callback function in order to achieve better performance.
104+
105+
</section>
106+
107+
<!-- /.notes -->
108+
109+
<section class="examples">
110+
111+
## Examples
112+
113+
<!-- eslint no-undef: "error" -->
114+
115+
```javascript
116+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
117+
var zeroTo = require( '@stdlib/array/base/zero-to' );
118+
var naryFunction = require( '@stdlib/utils/nary-function' );
119+
var log = require( '@stdlib/console/log' );
120+
var forEach = require( '@stdlib/ndarray/base/for-each' );
121+
122+
var x = {
123+
'dtype': 'generic',
124+
'data': zeroTo( 10 ),
125+
'shape': [ 5, 2 ],
126+
'strides': [ -2, 1 ],
127+
'offset': 8,
128+
'order': 'row-major'
129+
};
130+
131+
log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
132+
forEach( [ x ], naryFunction( log, 2 ) );
133+
134+
x = {
135+
'dtype': 'generic',
136+
'data': zeroTo( 10 ),
137+
'shape': [ 5, 2 ],
138+
'strides': [ 1, -5 ],
139+
'offset': 5,
140+
'order': 'column-major'
141+
};
142+
143+
log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
144+
forEach( [ x ], naryFunction( log, 2 ) );
145+
146+
x = {
147+
'dtype': 'generic',
148+
'data': zeroTo( 18 ),
149+
'shape': [ 2, 3, 3 ],
150+
'strides': [ 9, 3, 1 ],
151+
'offset': 0,
152+
'order': 'row-major'
153+
};
154+
155+
log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
156+
forEach( [ x ], naryFunction( log, 2 ) );
157+
158+
x = {
159+
'dtype': 'generic',
160+
'data': zeroTo( 18 ),
161+
'shape': [ 2, 3, 3 ],
162+
'strides': [ -1, -2, -6 ],
163+
'offset': 17,
164+
'order': 'column-major'
165+
};
166+
167+
log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
168+
forEach( [ x ], naryFunction( log, 2 ) );
169+
```
170+
171+
</section>
172+
173+
<!-- /.examples -->
174+
175+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
176+
177+
<section class="related">
178+
179+
</section>
180+
181+
<!-- /.related -->
182+
183+
<section class="links">
184+
185+
<!-- <related-links> -->
186+
187+
<!-- </related-links> -->
188+
189+
</section>
190+
191+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var floor = require( '@stdlib/math/base/special/floor' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var shape2strides = require( './../../../base/shape2strides' );
29+
var pkg = require( './../package.json' ).name;
30+
var forEach = require( './../lib/10d_blocked.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var types = [ 'float64' ];
36+
var order = 'column-major';
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Callback invoked for each ndarray element.
43+
*
44+
* @private
45+
* @param {number} value - array element
46+
* @throws {Error} unexpected error
47+
*/
48+
function fcn( value ) {
49+
if ( isnan( value ) ) {
50+
throw new Error( 'unexpected error' );
51+
}
52+
}
53+
54+
/**
55+
* Creates a benchmark function.
56+
*
57+
* @private
58+
* @param {PositiveInteger} len - ndarray length
59+
* @param {NonNegativeIntegerArray} shape - ndarray shape
60+
* @param {string} xtype - output ndarray data type
61+
* @returns {Function} benchmark function
62+
*/
63+
function createBenchmark( len, shape, xtype ) {
64+
var x;
65+
66+
x = discreteUniform( len, -100, 100 );
67+
x = {
68+
'dtype': xtype,
69+
'data': x,
70+
'shape': shape,
71+
'strides': shape2strides( shape, order ),
72+
'offset': 0,
73+
'order': order
74+
};
75+
return benchmark;
76+
77+
/**
78+
* Benchmark function.
79+
*
80+
* @private
81+
* @param {Benchmark} b - benchmark instance
82+
*/
83+
function benchmark( b ) {
84+
var i;
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
forEach( x, fcn );
89+
if ( isnan( x.data[ i%len ] ) ) {
90+
b.fail( 'should not return NaN' );
91+
}
92+
}
93+
b.toc();
94+
if ( isnan( x.data[ i%len ] ) ) {
95+
b.fail( 'should not return NaN' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
}
100+
}
101+
102+
103+
// MAIN //
104+
105+
/**
106+
* Main execution sequence.
107+
*
108+
* @private
109+
*/
110+
function main() {
111+
var len;
112+
var min;
113+
var max;
114+
var sh;
115+
var t1;
116+
var f;
117+
var i;
118+
var j;
119+
120+
min = 1; // 10^min
121+
max = 6; // 10^max
122+
123+
for ( j = 0; j < types.length; j++ ) {
124+
t1 = types[ j ];
125+
for ( i = min; i <= max; i++ ) {
126+
len = pow( 10, i );
127+
128+
sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ];
129+
f = createBenchmark( len, sh, t1 );
130+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
131+
132+
sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ];
133+
f = createBenchmark( len, sh, t1 );
134+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
135+
136+
len = floor( pow( len, 1.0/10.0 ) );
137+
sh = [ len, len, len, len, len, len, len, len, len, len ];
138+
len *= pow( len, 9 );
139+
f = createBenchmark( len, sh, t1 );
140+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
141+
}
142+
}
143+
}
144+
145+
main();

0 commit comments

Comments
 (0)