Skip to content
Draft
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
142 changes: 142 additions & 0 deletions lib/node_modules/@stdlib/ndarray/concat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<!--

@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.

-->

# concat

> Concatenate a list of ndarrays along a specified ndarray dimension.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var concat = require( '@stdlib/ndarray/concat' );
```

#### concat( arrays, dim )

Concatenates a list of ndarrays along a specified ndarray dimension.

```javascript
var ndarray = require( '@stdlib/ndarray/ctor' );
var Float64Array = require( '@stdlib/array/float64' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );

var xbuf = new Float64Array( [ -1.0, 2.0, -3.0, 4.0 ] );
var x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );

var ybuf = new Float64Array( [ -5.0, 6.0, -7.0, 8.0, -9.0, 10.0 ] );
var y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' );

var out = concat( [ x, y ], -1 );
// returns <ndarray>

var arr = ndarray2array( out );
// returns [ [ -1.0, 2.0, -5.0, 6.0, 7.0 ], [ -3.0, 4.0, 8.0, 9.0, 10.0 ] ]
```

The function accepts the following arguments:

- **arrays**: a list of input ndarrays.
- **dim**: dimension along which the arrays are concatenated. Default: `-1`.

#### concat.assign( arrays, out, dim )

<!-- TODO: Add documentation -->

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var concat = require( '@stdlib/ndarray/concat' );

var xbuf = discreteUniform( 6, 0, 10, {
'dtype': 'generic'
});
var x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );

var ybuf = discreteUniform( 8, 0, 10, {
'dtype': 'generic'
});
var y = new ndarray( 'generic', ybuf, [ 2, 4 ], [ 4, 1 ], 0, 'row-major' );
console.log( ndarray2array( y ) );

var out = concat( [ x, y ], -1 );
console.log( ndarray2array( out ) );
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
190 changes: 190 additions & 0 deletions lib/node_modules/@stdlib/ndarray/concat/benchmark/benchmark.assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/**
* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var zeros = require( '@stdlib/ndarray/zeros' );
var pkg = require( './../package.json' ).name;
var concat = require( './../lib' );


// MAIN //

bench( pkg+'::1d', function benchmark( b ) {
var values;
var out;
var v;
var i;

/* eslint-disable object-curly-newline */

values = [
zeros( [ 2 ], { 'dtype': 'float64' }),
zeros( [ 2 ], { 'dtype': 'float32' }),
zeros( [ 2 ], { 'dtype': 'int32' }),
zeros( [ 2 ], { 'dtype': 'complex128' }),
zeros( [ 2 ], { 'dtype': 'generic' })
];
out = zeros( [ 10 ], { 'dtype': 'float64' });

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat( values, out, -1 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::2d', function benchmark( b ) {
var values;
var out;
var v;
var i;

/* eslint-disable object-curly-newline */

values = [
zeros( [ 2, 2 ], { 'dtype': 'float64' }),
zeros( [ 2, 2 ], { 'dtype': 'float32' }),
zeros( [ 2, 2 ], { 'dtype': 'int32' }),
zeros( [ 2, 2 ], { 'dtype': 'complex128' }),
zeros( [ 2, 2 ], { 'dtype': 'generic' })
];
out = zeros( [ 2, 10 ], { 'dtype': 'float64' });

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat( values, out, -1 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::3d', function benchmark( b ) {
var values;
var out;
var v;
var i;

/* eslint-disable object-curly-newline */

values = [
zeros( [ 2, 2, 2 ], { 'dtype': 'float64' }),
zeros( [ 2, 2, 2 ], { 'dtype': 'float32' }),
zeros( [ 2, 2, 2 ], { 'dtype': 'int32' }),
zeros( [ 2, 2, 2 ], { 'dtype': 'complex128' }),
zeros( [ 2, 2, 2 ], { 'dtype': 'generic' })
];
out = zeros( [ 2, 2, 10 ], { 'dtype': 'float64' });

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat( values, out, -1 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::4d', function benchmark( b ) {
var values;
var out;
var v;
var i;

/* eslint-disable object-curly-newline */

values = [
zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float64' }),
zeros( [ 2, 2, 2, 2 ], { 'dtype': 'float32' }),
zeros( [ 2, 2, 2, 2 ], { 'dtype': 'int32' }),
zeros( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' }),
zeros( [ 2, 2, 2, 2 ], { 'dtype': 'generic' })
];
out = zeros( [ 2, 2, 2, 10 ], { 'dtype': 'float64' });

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat( values, out, -1 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::5d', function benchmark( b ) {
var values;
var out;
var v;
var i;

/* eslint-disable object-curly-newline */

values = [
zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' }),
zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' }),
zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' }),
zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' }),
zeros( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' })
];
out = zeros( [ 2, 2, 2, 2, 10 ], { 'dtype': 'float64' });

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = concat( values, out, -1 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( v ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading