Skip to content

Commit 6d1f0e9

Browse files
committed
Auto-generated commit
1 parent 20907a6 commit 6d1f0e9

Some content is hidden

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

58 files changed

+1982
-231
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@
251251

252252
### Bug Fixes
253253

254+
- [`ae2b9a3`](https://github.com/stdlib-js/stdlib/commit/ae2b9a327b74ca7bdc03996cbb77a87053d19896) - use resolved order when computing loop variables
255+
- [`9bc10d4`](https://github.com/stdlib-js/stdlib/commit/9bc10d4dc2b9afe6b55ca2b6e17c165e9dd2a88d) - use resolved order when computing loop variables
256+
- [`ccc7890`](https://github.com/stdlib-js/stdlib/commit/ccc7890aee959303e2defbc627b32f66b18535eb) - check for row-major value
257+
- [`d066ec9`](https://github.com/stdlib-js/stdlib/commit/d066ec94f0484e735ea8025e7c9339f248c8d450) - check for row-major value
258+
- [`4795826`](https://github.com/stdlib-js/stdlib/commit/47958261521f7d00ccd325cb978e55af39b9cbe0) - check for row-major value
259+
- [`a8bac64`](https://github.com/stdlib-js/stdlib/commit/a8bac644b23c4413a566f309b43857ad779f05cc) - check for row-major value
260+
- [`7583774`](https://github.com/stdlib-js/stdlib/commit/7583774f4307a69b9e364a2e60c14ee034fa02a9) - use resolved order when computing loop variables
254261
- [`b9e9eca`](https://github.com/stdlib-js/stdlib/commit/b9e9eca93c4611a77122090ab8e589e6ba82e47b) - use resolved order when computing loop variables
255262
- [`1e0917b`](https://github.com/stdlib-js/stdlib/commit/1e0917b1bba1d273d93e8fa97cc8a060661bbbf0) - use resolved order when computing loop variables
256263
- [`92bf1a1`](https://github.com/stdlib-js/stdlib/commit/92bf1a12b2398ec5823eb3094bdc89f88d9876a7) - use resolved order when computing loop variables
@@ -362,6 +369,18 @@ A total of 14 issues were closed in this release:
362369

363370
<details>
364371

372+
- [`f328b4f`](https://github.com/stdlib-js/stdlib/commit/f328b4f3b5bc69a79761c820e56c5849c7616dee) - **docs:** add README _(by Athan Reines)_
373+
- [`c713f5a`](https://github.com/stdlib-js/stdlib/commit/c713f5a247329781c52833ae42b7b86b5a585637) - **bench:** add 1d and 2d benchmarks _(by Athan Reines)_
374+
- [`ceb856d`](https://github.com/stdlib-js/stdlib/commit/ceb856d1e079781c58f713c2163b629cf561b963) - **test:** add 2d kernel tests _(by Athan Reines)_
375+
- [`4901ce8`](https://github.com/stdlib-js/stdlib/commit/4901ce89f5f80c080ec2db7d7f6e7405340fec1a) - **test:** add 1d kernel tests _(by Athan Reines)_
376+
- [`bcf1683`](https://github.com/stdlib-js/stdlib/commit/bcf1683a583934523896b342f8a1621d3aad9e1c) - **test:** add 0d kernel tests _(by Athan Reines)_
377+
- [`ae2b9a3`](https://github.com/stdlib-js/stdlib/commit/ae2b9a327b74ca7bdc03996cbb77a87053d19896) - **fix:** use resolved order when computing loop variables _(by Athan Reines)_
378+
- [`9bc10d4`](https://github.com/stdlib-js/stdlib/commit/9bc10d4dc2b9afe6b55ca2b6e17c165e9dd2a88d) - **fix:** use resolved order when computing loop variables _(by Athan Reines)_
379+
- [`ccc7890`](https://github.com/stdlib-js/stdlib/commit/ccc7890aee959303e2defbc627b32f66b18535eb) - **fix:** check for row-major value _(by Athan Reines)_
380+
- [`d066ec9`](https://github.com/stdlib-js/stdlib/commit/d066ec94f0484e735ea8025e7c9339f248c8d450) - **fix:** check for row-major value _(by Athan Reines)_
381+
- [`4795826`](https://github.com/stdlib-js/stdlib/commit/47958261521f7d00ccd325cb978e55af39b9cbe0) - **fix:** check for row-major value _(by Athan Reines)_
382+
- [`a8bac64`](https://github.com/stdlib-js/stdlib/commit/a8bac644b23c4413a566f309b43857ad779f05cc) - **fix:** check for row-major value _(by Athan Reines)_
383+
- [`7583774`](https://github.com/stdlib-js/stdlib/commit/7583774f4307a69b9e364a2e60c14ee034fa02a9) - **fix:** use resolved order when computing loop variables _(by Athan Reines)_
365384
- [`a616f66`](https://github.com/stdlib-js/stdlib/commit/a616f66172ea9e5ea730258daff8232f38675e39) - **refactor:** avoid duplicate computation _(by Athan Reines)_
366385
- [`1d2c4e2`](https://github.com/stdlib-js/stdlib/commit/1d2c4e2ef621e2304c5d855c4c8b6ed2f9e9e1ad) - **refactor:** avoid duplicate computation _(by Athan Reines)_
367386
- [`0fb7df7`](https://github.com/stdlib-js/stdlib/commit/0fb7df7fe84102add9858f53da605a6f2e0d42a9) - **docs:** document expected properties for accessor kernels _(by Athan Reines)_

base/binary/README.md

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# Binary
22+
23+
> Apply a binary callback to elements in input ndarrays and assign results to elements in an output ndarray.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var binary = require( '@stdlib/ndarray/base/binary' );
41+
```
42+
43+
#### binary( arrays, fcn )
44+
45+
Applies a binary callback to elements in input ndarrays and assigns results to elements in an output ndarray.
46+
47+
```javascript
48+
var Float64Array = require( '@stdlib/array/float64' );
49+
var add = require( '@stdlib/number/float64/base/add' );
50+
51+
// Create data buffers:
52+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
53+
var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
54+
var zbuf = new Float64Array( 6 );
55+
56+
// Define the shape of the input and output arrays:
57+
var shape = [ 3, 1, 2 ];
58+
59+
// Define the array strides:
60+
var sx = [ 2, 2, 1 ];
61+
var sy = [ 2, 2, 1 ];
62+
var sz = [ 2, 2, 1 ];
63+
64+
// Define the index offsets:
65+
var ox = 0;
66+
var oy = 0;
67+
var oz = 0;
68+
69+
// Create the input and output ndarray-like objects:
70+
var x = {
71+
'dtype': 'float64',
72+
'data': xbuf,
73+
'shape': shape,
74+
'strides': sx,
75+
'offset': ox,
76+
'order': 'row-major'
77+
};
78+
var y = {
79+
'dtype': 'float64',
80+
'data': ybuf,
81+
'shape': shape,
82+
'strides': sy,
83+
'offset': oy,
84+
'order': 'row-major'
85+
};
86+
var z = {
87+
'dtype': 'float64',
88+
'data': zbuf,
89+
'shape': shape,
90+
'strides': sz,
91+
'offset': oz,
92+
'order': 'row-major'
93+
};
94+
95+
// Apply the binary function:
96+
binary( [ x, y, z ], add );
97+
98+
console.log( z.data );
99+
// => <Float64Array>[ 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
100+
```
101+
102+
The function accepts the following arguments:
103+
104+
- **arrays**: array-like object containing two input ndarrays and one output ndarray.
105+
- **fcn**: binary function to apply.
106+
107+
Each provided ndarray should be an object with the following properties:
108+
109+
- **dtype**: data type.
110+
- **data**: data buffer.
111+
- **shape**: dimensions.
112+
- **strides**: stride lengths.
113+
- **offset**: index offset.
114+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
115+
116+
</section>
117+
118+
<!-- /.usage -->
119+
120+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="notes">
123+
124+
## Notes
125+
126+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a binary function in order to achieve better performance.
127+
128+
</section>
129+
130+
<!-- /.notes -->
131+
132+
<!-- Package usage examples. -->
133+
134+
<section class="examples">
135+
136+
## Examples
137+
138+
<!-- eslint no-undef: "error" -->
139+
140+
```javascript
141+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
142+
var filledarray = require( '@stdlib/array/filled' );
143+
var filledarrayBy = require( '@stdlib/array/filled-by' );
144+
var add = require( '@stdlib/number/float64/base/add' );
145+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
146+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
147+
var binary = require( '@stdlib/ndarray/base/binary' );
148+
149+
var N = 10;
150+
var x = {
151+
'dtype': 'generic',
152+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
153+
'shape': [ 5, 2 ],
154+
'strides': [ 2, 1 ],
155+
'offset': 0,
156+
'order': 'row-major'
157+
};
158+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
159+
160+
var y = {
161+
'dtype': 'generic',
162+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
163+
'shape': x.shape.slice(),
164+
'strides': shape2strides( x.shape, 'column-major' ),
165+
'offset': 0,
166+
'order': 'column-major'
167+
};
168+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
169+
170+
var z = {
171+
'dtype': 'generic',
172+
'data': filledarray( 0, N, 'generic' ),
173+
'shape': x.shape.slice(),
174+
'strides': shape2strides( x.shape, 'column-major' ),
175+
'offset': 0,
176+
'order': 'column-major'
177+
};
178+
179+
binary( [ x, y, z ], add );
180+
console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) );
181+
```
182+
183+
</section>
184+
185+
<!-- /.examples -->
186+
187+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
188+
189+
<section class="references">
190+
191+
</section>
192+
193+
<!-- /.references -->
194+
195+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
196+
197+
<section class="related">
198+
199+
</section>
200+
201+
<!-- /.related -->
202+
203+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
204+
205+
<section class="links">
206+
207+
</section>
208+
209+
<!-- /.links -->

base/binary/benchmark/benchmark.1d.js

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var add = require( '@stdlib/number/float64/base/add' );
28+
var filledarray = require( '@stdlib/array/filled' );
29+
var shape2strides = require( './../../../base/shape2strides' );
30+
var orders = require( './../../../orders' );
31+
var pkg = require( './../package.json' ).name;
32+
var binary = require( './../lib' );
33+
34+
35+
// VARIABLES //
36+
37+
var TYPES = [
38+
'float64'
39+
];
40+
var ORDERS = orders();
41+
42+
43+
// FUNCTIONS //
44+
45+
/**
46+
* Creates a benchmark function.
47+
*
48+
* @private
49+
* @param {PositiveInteger} len - ndarray length
50+
* @param {NonNegativeIntegerArray} shape - ndarray shape
51+
* @param {string} xtype - input ndarray data type
52+
* @param {string} ytype - output ndarray data type
53+
* @param {string} order - memory layout
54+
* @returns {Function} benchmark function
55+
*/
56+
function createBenchmark( len, shape, xtype, ytype, order ) {
57+
var x;
58+
var y;
59+
60+
x = discreteUniform( len, -100, 100, {
61+
'dtype': xtype
62+
});
63+
y = filledarray( 0.0, len, ytype );
64+
65+
x = {
66+
'dtype': xtype,
67+
'data': x,
68+
'shape': shape,
69+
'strides': shape2strides( shape, order ),
70+
'offset': 0,
71+
'order': order
72+
};
73+
y = {
74+
'dtype': ytype,
75+
'data': y,
76+
'shape': shape,
77+
'strides': shape2strides( shape, order ),
78+
'offset': 0,
79+
'order': order
80+
};
81+
return benchmark;
82+
83+
/**
84+
* Benchmark function.
85+
*
86+
* @private
87+
* @param {Benchmark} b - benchmark instance
88+
*/
89+
function benchmark( b ) {
90+
var i;
91+
92+
b.tic();
93+
for ( i = 0; i < b.iterations; i++ ) {
94+
binary( [ x, x, y ], add );
95+
if ( isnan( y.data[ i%len ] ) ) {
96+
b.fail( 'should not return NaN' );
97+
}
98+
}
99+
b.toc();
100+
if ( isnan( y.data[ i%len ] ) ) {
101+
b.fail( 'should not return NaN' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
}
106+
}
107+
108+
109+
// MAIN //
110+
111+
/**
112+
* Main execution sequence.
113+
*
114+
* @private
115+
*/
116+
function main() {
117+
var len;
118+
var min;
119+
var max;
120+
var ord;
121+
var sh;
122+
var t1;
123+
var t2;
124+
var f;
125+
var i;
126+
var j;
127+
var k;
128+
129+
min = 1; // 10^min
130+
max = 6; // 10^max
131+
132+
for ( k = 0; k < ORDERS.length; k++ ) {
133+
ord = ORDERS[ k ];
134+
for ( j = 0; j < TYPES.length; j++ ) {
135+
t1 = TYPES[ j ];
136+
t2 = TYPES[ j ];
137+
for ( i = min; i <= max; i++ ) {
138+
len = pow( 10, i );
139+
140+
sh = [ len ];
141+
f = createBenchmark( len, sh, t1, t2, ord );
142+
bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f );
143+
}
144+
}
145+
}
146+
}
147+
148+
main();

0 commit comments

Comments
 (0)