Skip to content

Commit 1600c00

Browse files
committed
Auto-generated commit
1 parent 8b5d242 commit 1600c00

Some content is hidden

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

59 files changed

+13153
-12
lines changed

CHANGELOG.md

Lines changed: 111 additions & 1 deletion
Large diffs are not rendered by default.

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ Golden Kumar <103646877+AuenKr@users.noreply.github.com>
5959
Gunj Joshi <gunjjoshi8372@gmail.com>
6060
Gururaj Gurram <gururajgurram1512@gmail.com>
6161
Haroon Rasheed <51189276+haroon26@users.noreply.github.com>
62-
Harsh <149176984+hrshya@users.noreply.github.com>
62+
Harsh <harshyadav6078@gmail.com>
6363
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
6464
Harshita Kalani <harshitakalani02@gmail.com>
65+
Hemang Choudhary <coehemang@gmail.com>
6566
Hemant M Mehta <92446645+hemantmm@users.noreply.github.com>
6667
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
6768
Jaimin Godhani <112328542+Jai0401@users.noreply.github.com>

base/assign/lib/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var isRealDataType = require( './../../../base/assert/is-real-data-type' );
2525
var isComplexArray = require( '@stdlib/array/base/assert/is-complex-typed-array' );
2626
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
2727
var iterationOrder = require( './../../../base/iteration-order' );
28+
var strides2order = require( './../../../base/strides2order' );
2829
var castReturn = require( '@stdlib/complex/base/cast-return' );
2930
var complexCtors = require( '@stdlib/complex/ctors' );
3031
var minmaxViewBufferIndex = require( './../../../base/minmax-view-buffer-index' );
@@ -351,7 +352,7 @@ function assign( arrays ) {
351352
ioy = iterationOrder( sy ); // +/-1
352353

353354
// Determine whether we can avoid blocked iteration...
354-
if ( iox !== 0 && ioy !== 0 && iox === ioy ) {
355+
if ( iox !== 0 && ioy !== 0 && strides2order( sx ) === strides2order( sy ) ) { // eslint-disable-line max-len
355356
// Determine the minimum and maximum linear indices which are accessible by the array views:
356357
xmmv = minmaxViewBufferIndex( shx, sx, x.offset );
357358
ymmv = minmaxViewBufferIndex( shy, sy, y.offset );

base/binary/docs/repl.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
{{alias}}( arrays, fcn )
3+
Applies a binary callback to elements in input ndarrays and assigns results
4+
to elements in an output ndarray.
5+
6+
Each provided "ndarray" should be an object with the following properties:
7+
8+
- dtype: data type.
9+
- data: data buffer.
10+
- shape: dimensions.
11+
- strides: stride lengths.
12+
- offset: index offset.
13+
- order: specifies whether an ndarray is row-major (C-style) or column-major
14+
(Fortran-style).
15+
16+
Parameters
17+
----------
18+
arrays: ArrayLikeObject<ndarray>
19+
Array-like object containing two input ndarrays and one output ndarray.
20+
21+
fcn: Function
22+
Binary callback.
23+
24+
Examples
25+
--------
26+
// Define ndarray data and meta data...
27+
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
28+
> var ybuf = new {{alias:@stdlib/array/float64}}( [ 5.0, 6.0, 7.0, 8.0 ] );
29+
> var zbuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] );
30+
> var dtype = 'float64';
31+
> var shape = [ 2, 2 ];
32+
> var sx = [ 2, 1 ];
33+
> var sy = [ 2, 1 ];
34+
> var sz = [ 2, 1 ];
35+
> var ox = 0;
36+
> var oy = 0;
37+
> var oz = 0;
38+
> var order = 'row-major';
39+
40+
// Using ndarrays...
41+
> var x = {{alias:@stdlib/ndarray/ctor}}( dtype, xbuf, shape, sx, ox, order );
42+
> var y = {{alias:@stdlib/ndarray/ctor}}( dtype, ybuf, shape, sy, oy, order );
43+
> var z = {{alias:@stdlib/ndarray/ctor}}( dtype, zbuf, shape, sz, oz, order );
44+
> {{alias}}( [ x, y, z ], {{alias:@stdlib/number/float64/base/add}} );
45+
> {{alias:@stdlib/ndarray/data-buffer}}( z )
46+
<Float64Array>[ 6.0, 8.0, 10.0, 12.0 ]
47+
48+
// Using minimal ndarray-like objects...
49+
> x = {
50+
... 'dtype': dtype,
51+
... 'data': xbuf,
52+
... 'shape': shape,
53+
... 'strides': sx,
54+
... 'offset': ox,
55+
... 'order': order
56+
... };
57+
> y = {
58+
... 'dtype': dtype,
59+
... 'data': ybuf,
60+
... 'shape': shape,
61+
... 'strides': sy,
62+
... 'offset': oy,
63+
... 'order': order
64+
... };
65+
> z = {
66+
... 'dtype': dtype,
67+
... 'data': zbuf,
68+
... 'shape': shape,
69+
... 'strides': sz,
70+
... 'offset': oz,
71+
... 'order': order
72+
... };
73+
> {{alias}}( [ x, y, z ], {{alias:@stdlib/number/float64/base/add}} );
74+
> {{alias:@stdlib/ndarray/data-buffer}}( z )
75+
<Float64Array>[ 6.0, 8.0, 10.0, 12.0 ]
76+
77+
See Also
78+
--------
79+

base/binary/docs/types/index.d.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ArrayLike } from '@stdlib/types/array';
24+
import { ndarray } from '@stdlib/types/ndarray';
25+
26+
/**
27+
* Callback invoked for ndarray elements.
28+
*
29+
* @param x - first ndarray element
30+
* @param y - second ndarray element
31+
* @returns result
32+
*/
33+
type Binary = ( x: any, y: any ) => any;
34+
35+
/**
36+
* Applies a binary callback to elements in input ndarrays and assigns results to elements in an output ndarray.
37+
*
38+
* @param arrays - array-like object containing two input ndarrays and one output ndarray
39+
* @param fcn - binary callback
40+
* @throws arrays must have the same number of dimensions
41+
* @throws arrays must have the same shape
42+
*
43+
* @example
44+
* var Float64Array = require( '@stdlib/array/float64' );
45+
* var ndarray = require( '@stdlib/ndarray/ctor' );
46+
* var getData = require( '@stdlib/ndarray/data-buffer' );
47+
*
48+
* function add( a, b ) {
49+
* return a + b;
50+
* }
51+
*
52+
* // Create data buffers:
53+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
54+
* var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
55+
* var zbuf = new Float64Array( 6 );
56+
*
57+
* // Define the shape of the input and output arrays:
58+
* var shape = [ 3, 1, 2 ];
59+
*
60+
* // Define the array strides:
61+
* var sx = [ 2, 2, 1 ];
62+
* var sy = [ 2, 2, 1 ];
63+
* var sz = [ 2, 2, 1 ];
64+
*
65+
* // Define the index offsets:
66+
* var ox = 0;
67+
* var oy = 0;
68+
* var oz = 0;
69+
*
70+
* // Create the input and output ndarrays:
71+
* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
72+
* var y = new ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' );
73+
* var z = new ndarray( 'float64', zbuf, shape, sz, oz, 'row-major' );
74+
*
75+
* // Apply the binary function:
76+
* binary( [ x, y, z ], add );
77+
*
78+
* console.log( getData( z ) );
79+
* // => <Float64Array>[ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
80+
*/
81+
declare function binary( arrays: ArrayLike<ndarray>, fcn: Binary ): void;
82+
83+
84+
// EXPORTS //
85+
86+
export = binary;

base/binary/docs/types/test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
import zeros = require( './../../../../zeros' );
20+
import binary = require( './index' );
21+
22+
/**
23+
* Callback function.
24+
*
25+
* @param x - first input value
26+
* @param y - second input value
27+
* @returns result
28+
*/
29+
function fcn( x: number, y: number ): number {
30+
return x + y;
31+
}
32+
33+
34+
// TESTS //
35+
36+
// The function returns `undefined`...
37+
{
38+
const x = zeros( [ 2, 2 ] );
39+
const y = zeros( [ 2, 2 ] );
40+
const z = zeros( [ 2, 2 ] );
41+
const arrays = [ x, y, z ];
42+
43+
binary( arrays, fcn ); // $ExpectType void
44+
}
45+
46+
// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects...
47+
{
48+
binary( 5, fcn ); // $ExpectError
49+
binary( true, fcn ); // $ExpectError
50+
binary( false, fcn ); // $ExpectError
51+
binary( null, fcn ); // $ExpectError
52+
binary( undefined, fcn ); // $ExpectError
53+
binary( {}, fcn ); // $ExpectError
54+
binary( [ 1 ], fcn ); // $ExpectError
55+
binary( ( x: number ): number => x, fcn ); // $ExpectError
56+
}
57+
58+
// The compiler throws an error if the function is provided a second argument which is not a binary function...
59+
{
60+
const x = zeros( [ 2, 2 ] );
61+
const y = zeros( [ 2, 2 ] );
62+
const z = zeros( [ 2, 2 ] );
63+
const arrays = [ x, y, z ];
64+
65+
binary( arrays, '10' ); // $ExpectError
66+
binary( arrays, 5 ); // $ExpectError
67+
binary( arrays, true ); // $ExpectError
68+
binary( arrays, false ); // $ExpectError
69+
binary( arrays, null ); // $ExpectError
70+
binary( arrays, undefined ); // $ExpectError
71+
binary( arrays, [] ); // $ExpectError
72+
binary( arrays, {} ); // $ExpectError
73+
}
74+
75+
// The compiler throws an error if the function is provided an unsupported number of arguments...
76+
{
77+
const x = zeros( [ 2, 2 ] );
78+
const y = zeros( [ 2, 2 ] );
79+
const z = zeros( [ 2, 2 ] );
80+
const arrays = [ x, y, z ];
81+
82+
binary(); // $ExpectError
83+
binary( arrays ); // $ExpectError
84+
binary( arrays, fcn, 10 ); // $ExpectError
85+
}

base/binary/examples/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
22+
var filledarray = require( '@stdlib/array/filled' );
23+
var filledarrayBy = require( '@stdlib/array/filled-by' );
24+
var add = require( '@stdlib/number/float64/base/add' );
25+
var shape2strides = require( './../../../base/shape2strides' );
26+
var ndarray2array = require( './../../../base/to-array' );
27+
var binary = require( './../lib' );
28+
29+
var N = 10;
30+
var x = {
31+
'dtype': 'generic',
32+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
33+
'shape': [ 5, 2 ],
34+
'strides': [ 2, 1 ],
35+
'offset': 0,
36+
'order': 'row-major'
37+
};
38+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
39+
40+
var y = {
41+
'dtype': 'generic',
42+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
43+
'shape': x.shape.slice(),
44+
'strides': shape2strides( x.shape, 'column-major' ),
45+
'offset': 0,
46+
'order': 'column-major'
47+
};
48+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
49+
50+
var z = {
51+
'dtype': 'generic',
52+
'data': filledarray( 0, N, 'generic' ),
53+
'shape': x.shape.slice(),
54+
'strides': shape2strides( x.shape, 'column-major' ),
55+
'offset': 0,
56+
'order': 'column-major'
57+
};
58+
59+
binary( [ x, y, z ], add );
60+
console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) );

0 commit comments

Comments
 (0)